Skip to content

Commit 800aa04

Browse files
authored
Merge pull request #16 from Toparvion/#12-incorrect-log-choose
Fixes #12-incorrect-log-choose
2 parents 1a20047 + 58013f8 commit 800aa04

29 files changed

+593
-293
lines changed

build.gradle

Lines changed: 97 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import com.bmuschko.gradle.docker.tasks.DockerInfo
2+
import com.bmuschko.gradle.docker.tasks.DockerVersion
3+
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
4+
import com.bmuschko.gradle.docker.tasks.image.Dockerfile
5+
16
buildscript {
27
ext {
3-
springBootVersion = '2.0.1.RELEASE'
4-
springIntegrationVersion = '5.0.4.RELEASE'
5-
junitVersion = '5.0.2'
8+
springBootVersion = '2.1.0.M1'
9+
junitVersion = '5.1.0'
610
}
711
repositories {
812
mavenCentral()
@@ -11,6 +15,7 @@ buildscript {
1115
dependencies {
1216
classpath group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: "${springBootVersion}"
1317
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.1'
18+
classpath group: 'com.bmuschko', name: 'gradle-docker-plugin', version: '3.5.0'
1419
}
1520
}
1621

@@ -19,9 +24,13 @@ apply plugin: 'org.springframework.boot'
1924
apply plugin: 'io.spring.dependency-management'
2025
apply plugin: 'org.junit.platform.gradle.plugin'
2126
apply plugin: 'application'
27+
apply plugin: 'com.bmuschko.docker-remote-api'
28+
29+
version = '0.10.1'
30+
sourceCompatibility = 1.9
31+
targetCompatibility = 1.9
2232

23-
jar {
24-
version = '0.10'
33+
bootJar {
2534
archiveName = 'analog.jar'
2635
manifest {
2736
attributes(
@@ -31,8 +40,71 @@ jar {
3140
)
3241
}
3342
}
34-
sourceCompatibility = 1.9
35-
targetCompatibility = 1.9
43+
44+
//<editor-fold desc="Задачи по работе с Docker-образами">
45+
docker {
46+
url = project['docker.url']
47+
registryCredentials {
48+
url = project['docker.registry.url']
49+
username = project['docker.registry.username']
50+
password = project['docker.registry.password']
51+
email = project['docker.registry.email']
52+
}
53+
}
54+
task createDockerfile(type: Dockerfile) {
55+
description 'Генерирует Dockerfile для сборки образа микросервиса'
56+
group 'docker'
57+
58+
from 'openjdk:10-jdk-slim'
59+
// все дальнейшие команды будут разрешать пути внутри контейнера относительно этой:
60+
workingDir "/analog"
61+
// копируем исполняемый файл микросервиса:
62+
copyFile bootJar.archiveName, bootJar.archiveName
63+
// копируем файлы конфигурации:
64+
copyFile 'config/', 'config/'
65+
// монтируем директории для сохранения данных мониторинга и Tomcat'а между перезапусками:
66+
// volume "/microservice/work", "/microservice/log"
67+
environmentVariable 'APP_NAME', project.name
68+
// формируем команду на запуск:
69+
entryPoint 'java'
70+
// вся команда на запуск будет выглядеть 'java -X... -jar restorun.jar'
71+
defaultCommand '-Xmx256M', '-XX:MaxMetaspaceSize=256M', '-XX:+HeapDumpOnOutOfMemoryError',
72+
'-jar', "${bootJar.archiveName}"
73+
}
74+
75+
task syncImageFiles(type: Sync) {
76+
description 'Копирует в директорию build/docker файлы микросервиса для сборки образа'
77+
group 'docker'
78+
79+
dependsOn assemble
80+
from bootJar.archivePath
81+
into createDockerfile.destFile.parentFile
82+
// отдельно указываем, что файлы конфигурации нужно положить в директорию config
83+
into 'config/', {
84+
from 'config/'
85+
}
86+
}
87+
createDockerfile.dependsOn syncImageFiles
88+
89+
task buildImage(type: DockerBuildImage) {
90+
description 'Собирает и загружает в Docker образ микросервиса'
91+
92+
dependsOn createDockerfile
93+
inputDir = createDockerfile.destFile.parentFile
94+
tag = "${project.name}:${project.version}"
95+
}
96+
97+
task dockerVersion(type: DockerVersion) {
98+
description 'Выводит информацию о версии Docker'
99+
}
100+
task dockerInfo(type: DockerInfo) {
101+
description 'Выводит общие сведения об используемом экземпляре Docker'
102+
}
103+
//</editor-fold>
104+
105+
test {
106+
useJUnitPlatform()
107+
}
36108

37109
repositories {
38110
// mavenLocal()
@@ -44,14 +116,13 @@ repositories {
44116
dependencies {
45117
// Backend compile deps
46118
// compile("org.springframework.boot:spring-boot-devtools:${springBootVersion}")
47-
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: "${springBootVersion}"
48-
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: "${springBootVersion}"
49-
compile group: 'org.springframework.boot' , name: 'spring-boot-starter-websocket', version: "${springBootVersion}"
50-
compile group: 'net.bull.javamelody', name: 'javamelody-spring-boot-starter', version: '1.71.0'
119+
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web'
120+
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
121+
compile group: 'org.springframework.boot' , name: 'spring-boot-starter-websocket'
122+
compile group: 'net.bull.javamelody', name: 'javamelody-spring-boot-starter', version: '1.72.0'
51123

52-
compile group: 'org.springframework.integration', name: 'spring-integration-core', version: "${springIntegrationVersion}"
53-
compile group: 'org.springframework.integration', name: 'spring-integration-file', version: "${springIntegrationVersion}"
54-
compile group: 'org.springframework.integration', name: 'spring-integration-rmi', version: "${springIntegrationVersion}"
124+
compile group: 'org.springframework.integration', name: 'spring-integration-file'
125+
compile group: 'org.springframework.integration', name: 'spring-integration-rmi'
55126

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

142+
compileOnly('org.springframework.boot:spring-boot-configuration-processor')
143+
71144
runtime group: 'commons-logging', name: 'commons-logging', version: '1.2'
72-
runtime("org.springframework.boot:spring-boot-properties-migrator") // TODO remove after migration
73145

74146
// Test deps
75-
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: "${springBootVersion}"
76-
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: "${junitVersion}"
147+
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
77148
testCompile group: 'org.apache.commons', name: 'commons-math3', version: '3.6.1'
78-
79-
testRuntime group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "${junitVersion}"
149+
// JUnit family
150+
testCompileOnly 'junit:junit:4.12'
151+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.1.0'
152+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.1.0'
153+
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.1.0'
80154
}
81155

82156
junitPlatform {
83157
enableStandardTestTask = true
84158
}
159+
160+
startScripts {
161+
enabled = false
162+
}

config/application.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
server:
2+
port: 8083
3+
address: 0.0.0.0
4+
logging:
5+
config: config/logback-file.xml
6+
7+
nodes:
8+
- name: myself
9+
host: localhost
10+
agentPort: 8085
11+
myself: true
12+
13+
choices:
14+
- group: АнаЛог
15+
plainLogs:
16+
- ${user.dir}/log/${APP_NAME}.log as "Логи АнаЛога :-)"
17+
18+
# - group: Микросервисы в Docker
19+
# pathBase: /micros/
20+
# plainLogs:
21+
# - toffee/log/toffee.log as ToFFee (selected)

config/logback-console.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration scan="true" scanPeriod="10 seconds">
3+
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
4+
5+
<!--<editor-fold desc="Консольный аппендер">-->
6+
<property name="CONSOLE_LOG_PATTERN"
7+
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}"/>
8+
9+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
10+
<encoder>
11+
<charset>UTF-8</charset>
12+
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
13+
</encoder>
14+
</appender>
15+
<!--</editor-fold>-->
16+
17+
<!-- Умолчательный (корневой) уровень логирования и аппендер -->
18+
<root level="INFO">
19+
<appender-ref ref="CONSOLE"/>
20+
</root>
21+
22+
<!-- ================================== Прикладные логгеры (от бизнес-логики) ================================ -->
23+
<logger name="tech.toparvion.analog" level="TRACE"/>
24+
<!-- ===================================== Системные логгеры (от библиотек) ================================== -->
25+
26+
</configuration>

config/logback-file.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration scan="true" scanPeriod="30 seconds">
3+
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
4+
5+
<!--<editor-fold desc="Файловый аппендер">-->
6+
<property name="FILE_LOG_PATTERN"
7+
value="%d{ISO8601} ${LOG_LEVEL_PATTERN:-%5p} [%t] - %-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>
8+
9+
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
10+
<file>log/${APP_NAME}.log</file>
11+
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
12+
<!-- daily rollover. Make sure the path matches the one in the file element or else
13+
the rollover logs are placed in the working directory. -->
14+
<fileNamePattern>log/${APP_NAME}_%d{yyyy-MM-dd}.%i.log</fileNamePattern>
15+
<maxFileSize>15MB</maxFileSize>
16+
<maxHistory>30</maxHistory>
17+
</rollingPolicy>
18+
<encoder>
19+
<charset>UTF-8</charset>
20+
<pattern>${FILE_LOG_PATTERN}</pattern>
21+
</encoder>
22+
</appender>
23+
<!--</editor-fold>-->
24+
25+
<!-- Умолчательный (корневой) уровень логирования и аппендер -->
26+
<root level="INFO">
27+
<appender-ref ref="FILE"/>
28+
</root>
29+
30+
<!-- ================================== Прикладные логгеры (от бизнес-логики) ================================ -->
31+
<logger name="tech.toparvion.analog" level="DEBUG"/>
32+
<!-- ===================================== Системные логгеры (от библиотек) ================================== -->
33+
34+
</configuration>

gradle.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
docker.url=<specify your own>
2+
docker.registry.url=<specify your own>
3+
docker.registry.username=<specify your own>
4+
docker.registry.password=<specify your own>
5+
docker.registry.email=<specify your own>

src/main/java/tech/toparvion/analog/model/TrackingRequest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ public boolean isTailNeeded() {
4949
}
5050

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

@@ -62,6 +62,7 @@ public String toString() {
6262
return "TrackingRequest{" +
6363
"logFullPath='" + logFullPath + '\'' +
6464
", timestampFormat='" + timestampFormat + '\'' +
65+
", isFlat='" + isFlat() + '\'' +
6566
", nodeName='" + nodeName + '\'' +
6667
", uid='" + uid + '\'' +
6768
", isTailNeeded=" + isTailNeeded +

src/main/java/tech/toparvion/analog/model/api/LogChoiceBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.util.List;
44

55
import static org.springframework.util.StringUtils.hasText;
6-
import static tech.toparvion.analog.service.AnaLogUtils.convertPathToUnix;
6+
import static tech.toparvion.analog.util.AnaLogUtils.convertPathToUnix;
77

88
/**
99
* Helper class aimed to simplicfy log choice instances construction

src/main/java/tech/toparvion/analog/model/config/ChoiceProperties.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package tech.toparvion.analog.model.config;
22

3+
import org.springframework.beans.factory.InitializingBean;
34
import org.springframework.boot.context.properties.ConfigurationProperties;
45
import org.springframework.stereotype.Component;
6+
import tech.toparvion.analog.util.AnaLogUtils;
57

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

1820
public List<ChoiceGroup> getChoices() {
@@ -22,4 +24,9 @@ public List<ChoiceGroup> getChoices() {
2224
public void setChoices(List<ChoiceGroup> choices) {
2325
this.choices = choices;
2426
}
27+
28+
@Override
29+
public void afterPropertiesSet() {
30+
choices.forEach(AnaLogUtils::applyPathBase);
31+
}
2532
}

src/main/java/tech/toparvion/analog/model/config/LogConfigEntry.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,18 @@ public String getUid() {
7676
if (this.isPlain()) {
7777
return path;
7878
}
79-
return Integer.toHexString(hashCode());
79+
return Integer.toHexString(hashCode()).toUpperCase();
8080
}
8181

8282
public boolean isPlain() {
8383
return (timestamp == null);
8484
}
8585

86+
/*public*/ LogConfigEntry prependPath(String pathBase) {
87+
path = pathBase + path;
88+
return this;
89+
}
90+
8691
@Override
8792
public boolean equals(Object o) {
8893
if (this == o) return true;

src/main/java/tech/toparvion/analog/remote/agent/AgentConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import java.net.InetSocketAddress;
1414

15-
import static org.springframework.integration.dsl.channel.MessageChannels.direct;
15+
import static org.springframework.integration.dsl.MessageChannels.direct;
1616
import static tech.toparvion.analog.remote.RemotingConstants.*;
1717

1818
/**

0 commit comments

Comments
 (0)