Skip to content

Commit 0693e3d

Browse files
committed
First pass at adding asynchronous flush support
1 parent ab1f24a commit 0693e3d

File tree

16 files changed

+303
-140
lines changed

16 files changed

+303
-140
lines changed

build.gradle

Lines changed: 124 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -14,117 +14,118 @@
1414

1515

1616
plugins {
17-
id 'java-library'
18-
id 'com.diffplug.spotless' version '5.8.2'
19-
id 'maven-publish'
20-
id 'signing'
17+
id 'java-library'
18+
id 'com.diffplug.spotless' version '5.8.2'
19+
id 'maven-publish'
20+
id 'signing'
2121
}
2222

2323
group "software.amazon.cloudwatchlogs"
2424

2525
allprojects {
26-
compileJava {
27-
sourceCompatibility = '1.8'
28-
targetCompatibility = '1.8'
29-
}
26+
compileJava {
27+
sourceCompatibility = '1.8'
28+
targetCompatibility = '1.8'
29+
}
3030

31-
version = '1.0.4'
31+
version = '1.0.4'
3232
}
3333

3434
java {
35-
withJavadocJar()
36-
withSourcesJar()
35+
withJavadocJar()
36+
withSourcesJar()
3737
}
3838

3939
repositories {
40-
jcenter()
41-
mavenCentral()
40+
jcenter()
41+
mavenCentral()
4242
}
4343

4444
sourceSets {
45-
integrationTest {
46-
java {
47-
compileClasspath += main.output + test.output
48-
runtimeClasspath += main.output + test.output
49-
srcDir file('src/integration-test/java')
50-
}
51-
resources.srcDir file('src/integration-test/resources')
52-
}
45+
integrationTest {
46+
java {
47+
compileClasspath += main.output + test.output
48+
runtimeClasspath += main.output + test.output
49+
srcDir file('src/integration-test/java')
50+
}
51+
resources.srcDir file('src/integration-test/resources')
52+
}
5353
}
5454

5555
configurations {
56-
integrationTestImplementation.extendsFrom testImplementation
56+
integrationTestImplementation.extendsFrom testImplementation
5757
}
5858

5959
dependencies {
60-
annotationProcessor 'org.projectlombok:lombok:1.18.12'
61-
62-
compileOnly 'org.projectlombok:lombok:1.18.12'
63-
implementation 'com.fasterxml.jackson.core:jackson-core:2.11.1'
64-
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.11.1'
65-
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.1'
66-
implementation 'org.slf4j:slf4j-api:1.7.30'
67-
68-
// Use JUnit test framework
69-
testImplementation 'software.amazon.awssdk:cloudwatch:2.13.54'
70-
testImplementation 'junit:junit:4.13'
71-
testImplementation 'org.apache.commons:commons-lang3:3.10'
72-
testImplementation "org.mockito:mockito-core:2.+"
73-
testImplementation "org.powermock:powermock-module-junit4:2.0.2"
74-
testImplementation "org.powermock:powermock-api-mockito2:2.0.2"
75-
testImplementation "com.github.javafaker:javafaker:1.0.2"
76-
testImplementation "com.github.tomakehurst:wiremock-jre8:2.27.0"
77-
testImplementation 'software.amazon.awssdk:cloudwatch:2.13.54'
78-
testCompileOnly 'org.projectlombok:lombok:1.18.12'
79-
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
60+
annotationProcessor 'org.projectlombok:lombok:1.18.12'
61+
62+
compileOnly 'org.projectlombok:lombok:1.18.12'
63+
implementation 'com.fasterxml.jackson.core:jackson-core:2.11.1'
64+
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.11.1'
65+
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.1'
66+
implementation 'org.slf4j:slf4j-api:1.7.30'
67+
implementation 'org.javatuples:javatuples:1.2'
68+
69+
// Use JUnit test framework
70+
testImplementation 'software.amazon.awssdk:cloudwatch:2.13.54'
71+
testImplementation 'junit:junit:4.13'
72+
testImplementation 'org.apache.commons:commons-lang3:3.10'
73+
testImplementation "org.mockito:mockito-core:2.+"
74+
testImplementation "org.powermock:powermock-module-junit4:2.0.2"
75+
testImplementation "org.powermock:powermock-api-mockito2:2.0.2"
76+
testImplementation "com.github.javafaker:javafaker:1.0.2"
77+
testImplementation "com.github.tomakehurst:wiremock-jre8:2.27.0"
78+
testImplementation 'software.amazon.awssdk:cloudwatch:2.13.54'
79+
testCompileOnly 'org.projectlombok:lombok:1.18.12'
80+
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
8081
}
8182

8283
spotless {
83-
format 'misc', {
84-
target '*.gradle', '*.md', '.gitignore'
84+
format 'misc', {
85+
target '*.gradle', '*.md', '.gitignore'
8586

86-
trimTrailingWhitespace()
87-
indentWithTabs()
88-
endWithNewline()
89-
}
87+
trimTrailingWhitespace()
88+
indentWithTabs()
89+
endWithNewline()
90+
}
9091

91-
java {
92-
importOrder()
93-
googleJavaFormat('1.7').aosp()
94-
removeUnusedImports()
92+
java {
93+
importOrder()
94+
googleJavaFormat('1.7').aosp()
95+
removeUnusedImports()
9596

96-
}
97+
}
9798
}
9899

99100
test {
100-
outputs.upToDateWhen {false}
101+
outputs.upToDateWhen {false}
101102
}
102103

103104
jar {
104-
manifest {
105-
attributes 'Implementation-Version': archiveVersion.get()
106-
}
105+
manifest {
106+
attributes 'Implementation-Version': archiveVersion.get()
107+
}
107108
}
108109

109110

110111
task integrationTest(type: Test) {
111-
testClassesDirs = sourceSets.integrationTest.output.classesDirs
112-
classpath = sourceSets.integrationTest.runtimeClasspath
113-
testLogging.showStandardStreams = true
112+
testClassesDirs = sourceSets.integrationTest.output.classesDirs
113+
classpath = sourceSets.integrationTest.runtimeClasspath
114+
testLogging.showStandardStreams = true
114115
}
115116

116117
task integ(type: Exec) {
117-
commandLine './bin/run-integ-tests.sh'
118+
commandLine './bin/run-integ-tests.sh'
118119
}
119120

120121

121122
tasks.withType(JavaCompile) {
122-
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
123+
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
123124
}
124125

125126
tasks.named('wrapper') {
126-
gradleVersion = '6.5.1'
127-
distributionType = Wrapper.DistributionType.ALL
127+
gradleVersion = '6.5.1'
128+
distributionType = Wrapper.DistributionType.ALL
128129
}
129130

130131
def repoUrl = "https://aws.oss.sonatype.org/service/local/staging/deploy/maven2/"
@@ -134,66 +135,66 @@ def buildNumber = System.getenv('CODEBUILD_BUILD_NUMBER')
134135

135136

136137
publishing {
137-
publications {
138-
mavenJava(MavenPublication) {
139-
ext.get_version = {
140-
if (buildNumber == null) {
141-
return version + ".dev"
142-
} else {
143-
return version + "." + buildNumber
144-
}
145-
}
146-
//TODO: add the build version properly
147-
//version = get_version()
148-
from components.java
149-
versionMapping {
150-
usage('java-api') {
151-
fromResolutionOf('runtimeClasspath')
152-
}
153-
usage('java-runtime') {
154-
fromResolutionResult()
155-
}
156-
}
157-
pom {
158-
name = 'aws-embedded-metrics'
159-
description = 'aws-embedded-metrics for java'
160-
url = 'https://github.com/awslabs/aws-embedded-metrics-java'
161-
scm {
162-
url = 'https://github.com/awslabs/aws-embedded-metrics-java'
163-
connection = 'https://github.com/awslabs/aws-embedded-metrics-java'
164-
developerConnection = 'https://github.com/awslabs/aws-embedded-metrics-java'
165-
}
166-
licenses {
167-
license {
168-
name = 'The Apache License, Version 2.0'
169-
url = 'https://github.com/awslabs/aws-embedded-metrics-java/blob/master/LICENSE'
170-
}
171-
}
172-
developers {
173-
developer {
174-
id = 'aws_emf'
175-
name = 'AWS CloudWatch'
176-
email = 'logs-emf@amazon.com'
177-
}
178-
}
179-
}
180-
}
181-
}
182-
repositories {
183-
maven {
184-
name = "mavenRepo"
185-
url = repoUrl
186-
credentials {
187-
username = repoUserName
188-
password = repoPassword
189-
}
190-
}
191-
}
138+
publications {
139+
mavenJava(MavenPublication) {
140+
ext.get_version = {
141+
if (buildNumber == null) {
142+
return version + ".dev"
143+
} else {
144+
return version + "." + buildNumber
145+
}
146+
}
147+
//TODO: add the build version properly
148+
//version = get_version()
149+
from components.java
150+
versionMapping {
151+
usage('java-api') {
152+
fromResolutionOf('runtimeClasspath')
153+
}
154+
usage('java-runtime') {
155+
fromResolutionResult()
156+
}
157+
}
158+
pom {
159+
name = 'aws-embedded-metrics'
160+
description = 'aws-embedded-metrics for java'
161+
url = 'https://github.com/awslabs/aws-embedded-metrics-java'
162+
scm {
163+
url = 'https://github.com/awslabs/aws-embedded-metrics-java'
164+
connection = 'https://github.com/awslabs/aws-embedded-metrics-java'
165+
developerConnection = 'https://github.com/awslabs/aws-embedded-metrics-java'
166+
}
167+
licenses {
168+
license {
169+
name = 'The Apache License, Version 2.0'
170+
url = 'https://github.com/awslabs/aws-embedded-metrics-java/blob/master/LICENSE'
171+
}
172+
}
173+
developers {
174+
developer {
175+
id = 'aws_emf'
176+
name = 'AWS CloudWatch'
177+
email = 'logs-emf@amazon.com'
178+
}
179+
}
180+
}
181+
}
182+
}
183+
repositories {
184+
maven {
185+
name = "mavenRepo"
186+
url = repoUrl
187+
credentials {
188+
username = repoUserName
189+
password = repoPassword
190+
}
191+
}
192+
}
192193
}
193194

194195
signing {
195-
def signingKey = findProperty("signingKey")
196-
def signingPassword = findProperty("signingPassword")
197-
useInMemoryPgpKeys(signingKey, signingPassword)
198-
sign publishing.publications.mavenJava
196+
def signingKey = findProperty("signingKey")
197+
def signingPassword = findProperty("signingPassword")
198+
useInMemoryPgpKeys(signingKey, signingPassword)
199+
sign publishing.publications.mavenJava
199200
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
package agent;
22

3+
import software.amazon.cloudwatchlogs.emf.config.EnvironmentConfigurationProvider;
4+
import software.amazon.cloudwatchlogs.emf.environment.DefaultEnvironment;
35
import software.amazon.cloudwatchlogs.emf.logger.MetricsLogger;
46
import software.amazon.cloudwatchlogs.emf.model.DimensionSet;
57
import software.amazon.cloudwatchlogs.emf.model.Unit;
68

9+
import java.util.concurrent.TimeUnit;
10+
711
public class App {
812

913
public static void main(String[] args) {
10-
MetricsLogger logger = new MetricsLogger();
14+
DefaultEnvironment environment = new DefaultEnvironment(EnvironmentConfigurationProvider.getConfig());
15+
MetricsLogger logger = new MetricsLogger(environment);
1116
logger.putDimensions(DimensionSet.of("Operation", "Agent"));
1217
logger.putMetric("ExampleMetric", 100, Unit.MILLISECONDS);
1318
logger.putProperty("RequestId", "422b1569-16f6-4a03-b8f0-fe3fd9b100f8");
1419
logger.flush();
20+
environment.getSink().shutdown().orTimeout(1000L, TimeUnit.MILLISECONDS);
1521
}
1622
}

src/main/java/software/amazon/cloudwatchlogs/emf/Constants.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ public class Constants {
2424
public static final int MAX_METRICS_PER_EVENT = 100;
2525

2626
public static final int MAX_DATAPOINTS_PER_METRIC = 100;
27+
28+
public static final int DEFAULT_ASYNC_BUFFER_SIZE = 100;
29+
30+
public static final int MAX_ATTEMPTS_PER_MESSAGE = 10;
31+
32+
public static final int MAX_BACKOFF_MILLIS = 2000;
2733
}

src/main/java/software/amazon/cloudwatchlogs/emf/config/Configuration.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818

1919
import java.util.Optional;
2020
import lombok.AllArgsConstructor;
21+
import lombok.Getter;
2122
import lombok.NoArgsConstructor;
2223
import lombok.Setter;
24+
import software.amazon.cloudwatchlogs.emf.Constants;
2325
import software.amazon.cloudwatchlogs.emf.environment.Environments;
2426
import software.amazon.cloudwatchlogs.emf.util.StringUtils;
2527

@@ -54,6 +56,11 @@ public class Configuration {
5456
*/
5557
@Setter Environments environmentOverride;
5658

59+
/**
60+
* Queue length for asynchronous sinks.
61+
*/
62+
@Setter @Getter int asyncBufferSize = Constants.DEFAULT_ASYNC_BUFFER_SIZE;
63+
5764
public Optional<String> getServiceName() {
5865
return getStringOptional(serviceName);
5966
}
@@ -85,6 +92,6 @@ private Optional<String> getStringOptional(String value) {
8592
if (StringUtils.isNullOrEmpty(value)) {
8693
return Optional.empty();
8794
}
88-
return Optional.ofNullable(value);
95+
return Optional.of(value);
8996
}
9097
}

src/main/java/software/amazon/cloudwatchlogs/emf/config/ConfigurationKeys.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ public class ConfigurationKeys {
2727
public static final String LOG_STREAM_NAME = "LOG_STREAM_NAME";
2828
public static final String AGENT_ENDPOINT = "AGENT_ENDPOINT";
2929
public static final String ENVIRONMENT_OVERRIDE = "ENVIRONMENT";
30+
public static final String ASYNC_BUFFER_SIZE = "ASYNC_BUFFER_SIZE";
3031
}

0 commit comments

Comments
 (0)