Skip to content

Commit

Permalink
Merge pull request #16 from Toparvion/#12-incorrect-log-choose
Browse files Browse the repository at this point in the history
Fixes #12-incorrect-log-choose
  • Loading branch information
Toparvion authored Oct 28, 2018
2 parents 1a20047 + 58013f8 commit 800aa04
Show file tree
Hide file tree
Showing 29 changed files with 593 additions and 293 deletions.
116 changes: 97 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import com.bmuschko.gradle.docker.tasks.DockerInfo
import com.bmuschko.gradle.docker.tasks.DockerVersion
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.image.Dockerfile

buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
springIntegrationVersion = '5.0.4.RELEASE'
junitVersion = '5.0.2'
springBootVersion = '2.1.0.M1'
junitVersion = '5.1.0'
}
repositories {
mavenCentral()
Expand All @@ -11,6 +15,7 @@ buildscript {
dependencies {
classpath group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: "${springBootVersion}"
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.1'
classpath group: 'com.bmuschko', name: 'gradle-docker-plugin', version: '3.5.0'
}
}

Expand All @@ -19,9 +24,13 @@ apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.junit.platform.gradle.plugin'
apply plugin: 'application'
apply plugin: 'com.bmuschko.docker-remote-api'

version = '0.10.1'
sourceCompatibility = 1.9
targetCompatibility = 1.9

jar {
version = '0.10'
bootJar {
archiveName = 'analog.jar'
manifest {
attributes(
Expand All @@ -31,8 +40,71 @@ jar {
)
}
}
sourceCompatibility = 1.9
targetCompatibility = 1.9

//<editor-fold desc="Задачи по работе с Docker-образами">
docker {
url = project['docker.url']
registryCredentials {
url = project['docker.registry.url']
username = project['docker.registry.username']
password = project['docker.registry.password']
email = project['docker.registry.email']
}
}
task createDockerfile(type: Dockerfile) {
description 'Генерирует Dockerfile для сборки образа микросервиса'
group 'docker'

from 'openjdk:10-jdk-slim'
// все дальнейшие команды будут разрешать пути внутри контейнера относительно этой:
workingDir "/analog"
// копируем исполняемый файл микросервиса:
copyFile bootJar.archiveName, bootJar.archiveName
// копируем файлы конфигурации:
copyFile 'config/', 'config/'
// монтируем директории для сохранения данных мониторинга и Tomcat'а между перезапусками:
// volume "/microservice/work", "/microservice/log"
environmentVariable 'APP_NAME', project.name
// формируем команду на запуск:
entryPoint 'java'
// вся команда на запуск будет выглядеть 'java -X... -jar restorun.jar'
defaultCommand '-Xmx256M', '-XX:MaxMetaspaceSize=256M', '-XX:+HeapDumpOnOutOfMemoryError',
'-jar', "${bootJar.archiveName}"
}

task syncImageFiles(type: Sync) {
description 'Копирует в директорию build/docker файлы микросервиса для сборки образа'
group 'docker'

dependsOn assemble
from bootJar.archivePath
into createDockerfile.destFile.parentFile
// отдельно указываем, что файлы конфигурации нужно положить в директорию config
into 'config/', {
from 'config/'
}
}
createDockerfile.dependsOn syncImageFiles

task buildImage(type: DockerBuildImage) {
description 'Собирает и загружает в Docker образ микросервиса'

dependsOn createDockerfile
inputDir = createDockerfile.destFile.parentFile
tag = "${project.name}:${project.version}"
}

task dockerVersion(type: DockerVersion) {
description 'Выводит информацию о версии Docker'
}
task dockerInfo(type: DockerInfo) {
description 'Выводит общие сведения об используемом экземпляре Docker'
}
//</editor-fold>

test {
useJUnitPlatform()
}

repositories {
// mavenLocal()
Expand All @@ -44,14 +116,13 @@ repositories {
dependencies {
// Backend compile deps
// compile("org.springframework.boot:spring-boot-devtools:${springBootVersion}")
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: "${springBootVersion}"
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: "${springBootVersion}"
compile group: 'org.springframework.boot' , name: 'spring-boot-starter-websocket', version: "${springBootVersion}"
compile group: 'net.bull.javamelody', name: 'javamelody-spring-boot-starter', version: '1.71.0'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
compile group: 'org.springframework.boot' , name: 'spring-boot-starter-websocket'
compile group: 'net.bull.javamelody', name: 'javamelody-spring-boot-starter', version: '1.72.0'

compile group: 'org.springframework.integration', name: 'spring-integration-core', version: "${springIntegrationVersion}"
compile group: 'org.springframework.integration', name: 'spring-integration-file', version: "${springIntegrationVersion}"
compile group: 'org.springframework.integration', name: 'spring-integration-rmi', version: "${springIntegrationVersion}"
compile group: 'org.springframework.integration', name: 'spring-integration-file'
compile group: 'org.springframework.integration', name: 'spring-integration-rmi'

compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
compile group: 'net.sf.jtidy', name: 'jtidy', version: 'r938'
Expand All @@ -68,17 +139,24 @@ dependencies {
compile group: 'org.webjars', name: 'angular-ui-select', version: '0.19.6'
compile group: 'org.webjars.npm', name: 'balloon-css', version: '0.5.0'

compileOnly('org.springframework.boot:spring-boot-configuration-processor')

runtime group: 'commons-logging', name: 'commons-logging', version: '1.2'
runtime("org.springframework.boot:spring-boot-properties-migrator") // TODO remove after migration

// Test deps
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: "${springBootVersion}"
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: "${junitVersion}"
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
testCompile group: 'org.apache.commons', name: 'commons-math3', version: '3.6.1'

testRuntime group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "${junitVersion}"
// JUnit family
testCompileOnly 'junit:junit:4.12'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.1.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.1.0'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.1.0'
}

junitPlatform {
enableStandardTestTask = true
}

startScripts {
enabled = false
}
21 changes: 21 additions & 0 deletions config/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
server:
port: 8083
address: 0.0.0.0
logging:
config: config/logback-file.xml

nodes:
- name: myself
host: localhost
agentPort: 8085
myself: true

choices:
- group: АнаЛог
plainLogs:
- ${user.dir}/log/${APP_NAME}.log as "Логи АнаЛога :-)"

# - group: Микросервисы в Docker
# pathBase: /micros/
# plainLogs:
# - toffee/log/toffee.log as ToFFee (selected)
26 changes: 26 additions & 0 deletions config/logback-console.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="10 seconds">
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>

<!--<editor-fold desc="Консольный аппендер">-->
<property name="CONSOLE_LOG_PATTERN"
value="%clr(%d{HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) - %clr([%15.15t]){faint} - %clr(%-40.40logger{39}){cyan} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<charset>UTF-8</charset>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<!--</editor-fold>-->

<!-- Умолчательный (корневой) уровень логирования и аппендер -->
<root level="INFO">
<appender-ref ref="CONSOLE"/>
</root>

<!-- ================================== Прикладные логгеры (от бизнес-логики) ================================ -->
<logger name="tech.toparvion.analog" level="TRACE"/>
<!-- ===================================== Системные логгеры (от библиотек) ================================== -->

</configuration>
34 changes: 34 additions & 0 deletions config/logback-file.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds">
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>

<!--<editor-fold desc="Файловый аппендер">-->
<property name="FILE_LOG_PATTERN"
value="%d{ISO8601} ${LOG_LEVEL_PATTERN:-%5p} [%t] - %-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>log/${APP_NAME}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- daily rollover. Make sure the path matches the one in the file element or else
the rollover logs are placed in the working directory. -->
<fileNamePattern>log/${APP_NAME}_%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>15MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<charset>UTF-8</charset>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<!--</editor-fold>-->

<!-- Умолчательный (корневой) уровень логирования и аппендер -->
<root level="INFO">
<appender-ref ref="FILE"/>
</root>

<!-- ================================== Прикладные логгеры (от бизнес-логики) ================================ -->
<logger name="tech.toparvion.analog" level="DEBUG"/>
<!-- ===================================== Системные логгеры (от библиотек) ================================== -->

</configuration>
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
docker.url=<specify your own>
docker.registry.url=<specify your own>
docker.registry.username=<specify your own>
docker.registry.password=<specify your own>
docker.registry.email=<specify your own>
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public boolean isTailNeeded() {
}

/**
* A request with no timestamp format is considered 'plain' as it cannot be involved into complex aggregating
* tracking logic and thus is suitable for plain old tracking only.
* @return {@code true} if this is a request for plain tracking only
* A request with no timestamp format is considered 'flat' as it cannot be involved into lines grouping logic and
* thus is suitable for flat tracking only.
* @return {@code true} if this is a request for flat tracking only
*/
public boolean isPlain() {
public boolean isFlat() {
return (timestampFormat == null);
}

Expand All @@ -62,6 +62,7 @@ public String toString() {
return "TrackingRequest{" +
"logFullPath='" + logFullPath + '\'' +
", timestampFormat='" + timestampFormat + '\'' +
", isFlat='" + isFlat() + '\'' +
", nodeName='" + nodeName + '\'' +
", uid='" + uid + '\'' +
", isTailNeeded=" + isTailNeeded +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.List;

import static org.springframework.util.StringUtils.hasText;
import static tech.toparvion.analog.service.AnaLogUtils.convertPathToUnix;
import static tech.toparvion.analog.util.AnaLogUtils.convertPathToUnix;

/**
* Helper class aimed to simplicfy log choice instances construction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package tech.toparvion.analog.model.config;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import tech.toparvion.analog.util.AnaLogUtils;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -12,7 +14,7 @@
@SuppressWarnings({"unused", "WeakerAccess"}) // such access level and setters presence are required by Spring Boot
@Component
@ConfigurationProperties
public class ChoiceProperties {
public class ChoiceProperties implements InitializingBean {
private List<ChoiceGroup> choices = new ArrayList<>();

public List<ChoiceGroup> getChoices() {
Expand All @@ -22,4 +24,9 @@ public List<ChoiceGroup> getChoices() {
public void setChoices(List<ChoiceGroup> choices) {
this.choices = choices;
}

@Override
public void afterPropertiesSet() {
choices.forEach(AnaLogUtils::applyPathBase);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,18 @@ public String getUid() {
if (this.isPlain()) {
return path;
}
return Integer.toHexString(hashCode());
return Integer.toHexString(hashCode()).toUpperCase();
}

public boolean isPlain() {
return (timestamp == null);
}

/*public*/ LogConfigEntry prependPath(String pathBase) {
path = pathBase + path;
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import java.net.InetSocketAddress;

import static org.springframework.integration.dsl.channel.MessageChannels.direct;
import static org.springframework.integration.dsl.MessageChannels.direct;
import static tech.toparvion.analog.remote.RemotingConstants.*;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
* @author Toparvion
* @since v0.7
*/
class CompositeRecordAggregatorConfigurer {
private static final Logger log = LoggerFactory.getLogger(CompositeRecordAggregatorConfigurer.class);
class GroupingAggregatorConfigurer {
private static final Logger log = LoggerFactory.getLogger(GroupingAggregatorConfigurer.class);

private final MessagingTemplate preAggregatorQueueSender;
private final int groupSizeThreshold;
private final long groupTimeout;

CompositeRecordAggregatorConfigurer(MessageChannel preAggregatorQueueChannel, int groupSizeThreshold, long groupTimeout) {
GroupingAggregatorConfigurer(MessageChannel preAggregatorQueueChannel, int groupSizeThreshold, long groupTimeout) {
this.preAggregatorQueueSender = new MessagingTemplate(preAggregatorQueueChannel);
this.groupSizeThreshold = groupSizeThreshold;
this.groupTimeout = groupTimeout;
Expand Down Expand Up @@ -64,7 +64,7 @@ private boolean releaseStrategy(MessageGroup group) {

boolean isGroupComplete = !Objects.equals(lastMessageCorrId, prevMessageCorrId);
if (isGroupComplete) {
log.debug("Group {} is about to be released as last corrId {} differs from previous ones {}.",
log.trace("Group {} is about to be released as last corrId {} differs from previous ones {}.",
group.getGroupId(), lastMessageCorrId, prevMessageCorrId);
}
return isGroupComplete;
Expand Down
Loading

0 comments on commit 800aa04

Please sign in to comment.