Skip to content

Commit db708fe

Browse files
authored
Added reflection metadata to aws-cloudwatch-logging module (#1860)
* Added reflection metadata to aws-cloudwatch-logging module * Added reflection metadata to aws-cloudwatch-logging module * Added reflection metadata to aws-cloudwatch-logging module
1 parent 32e4747 commit db708fe

File tree

6 files changed

+287
-0
lines changed

6 files changed

+287
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
[
2+
{
3+
"name": "io.micronaut.aws.cloudwatch.logging.CloudWatchLoggingAppender",
4+
"queryAllPublicMethods": true,
5+
"methods": [
6+
{
7+
"name": "<init>",
8+
"parameterTypes": [
9+
10+
]
11+
},
12+
{
13+
"name": "addBlackListLoggerName",
14+
"parameterTypes": [
15+
"java.lang.String"
16+
]
17+
},
18+
{
19+
"name": "setCreateGroupAndStream",
20+
"parameterTypes": [
21+
"boolean"
22+
]
23+
},
24+
{
25+
"name": "setDispatchOnStart",
26+
"parameterTypes": [
27+
"boolean"
28+
]
29+
},
30+
{
31+
"name": "setEncoder",
32+
"parameterTypes": [
33+
"ch.qos.logback.core.encoder.Encoder"
34+
]
35+
},
36+
{
37+
"name": "setGroupName",
38+
"parameterTypes": [
39+
"java.lang.String"
40+
]
41+
},
42+
{
43+
"name": "setMaxBatchSize",
44+
"parameterTypes": [
45+
"int"
46+
]
47+
},
48+
{
49+
"name": "setPublishPeriod",
50+
"parameterTypes": [
51+
"long"
52+
]
53+
},
54+
{
55+
"name": "setQueueSize",
56+
"parameterTypes": [
57+
"int"
58+
]
59+
},
60+
{
61+
"name": "setStreamName",
62+
"parameterTypes": [
63+
"java.lang.String"
64+
]
65+
}
66+
]
67+
},
68+
{
69+
"name": "io.micronaut.aws.cloudwatch.logging.CloudWatchJsonFormatter",
70+
"queryAllPublicMethods": true,
71+
"methods": [
72+
{
73+
"name": "<init>",
74+
"parameterTypes": [
75+
76+
]
77+
}
78+
]
79+
},
80+
{
81+
"name": "ch.qos.logback.core.encoder.LayoutWrappingEncoder",
82+
"queryAllPublicMethods": true,
83+
"methods": [
84+
{
85+
"name": "<init>",
86+
"parameterTypes": [
87+
88+
]
89+
},
90+
{
91+
"name": "setLayout",
92+
"parameterTypes": [
93+
"ch.qos.logback.core.Layout"
94+
]
95+
},
96+
{
97+
"name": "setParent",
98+
"parameterTypes": [
99+
"ch.qos.logback.core.spi.ContextAware"
100+
]
101+
}
102+
]
103+
},
104+
{
105+
"name": "ch.qos.logback.contrib.json.JsonLayoutBase",
106+
"methods": [
107+
{
108+
"name": "setJsonFormatter",
109+
"parameterTypes": [
110+
"ch.qos.logback.contrib.json.JsonFormatter"
111+
]
112+
}
113+
]
114+
},
115+
{
116+
"name": "ch.qos.logback.contrib.json.classic.JsonLayout",
117+
"queryAllPublicMethods": true,
118+
"methods": [
119+
{
120+
"name": "<init>",
121+
"parameterTypes": [
122+
123+
]
124+
}
125+
]
126+
}
127+
]

settings.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ include("function-client-aws")
4141
include("test-suite")
4242
include("test-suite-aws-sdk-v2")
4343
include("test-suite-graal")
44+
include("test-suite-graal-logging")
4445
include("test-suite-groovy")
4546
include("test-suite-http-server-tck-function-aws-api-gateway-proxy-alb")
4647
include("test-suite-http-server-tck-function-aws-api-gateway-proxy-payloadv1")
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
plugins {
2+
id("io.micronaut.application")
3+
}
4+
5+
dependencies {
6+
implementation(projects.micronautAwsCloudwatchLogging)
7+
testImplementation(mnTest.micronaut.test.junit5)
8+
}
9+
10+
micronaut {
11+
importMicronautPlatform = false
12+
runtime("netty")
13+
testRuntime("junit5")
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package example;
2+
3+
import io.micronaut.context.annotation.Replaces;
4+
import jakarta.inject.Singleton;
5+
import software.amazon.awssdk.awscore.exception.AwsServiceException;
6+
import software.amazon.awssdk.core.exception.SdkClientException;
7+
import software.amazon.awssdk.services.cloudwatchlogs.CloudWatchLogsClient;
8+
import software.amazon.awssdk.services.cloudwatchlogs.model.DescribeLogStreamsRequest;
9+
import software.amazon.awssdk.services.cloudwatchlogs.model.DescribeLogStreamsResponse;
10+
import software.amazon.awssdk.services.cloudwatchlogs.model.InputLogEvent;
11+
import software.amazon.awssdk.services.cloudwatchlogs.model.LogStream;
12+
import software.amazon.awssdk.services.cloudwatchlogs.model.PutLogEventsRequest;
13+
import software.amazon.awssdk.services.cloudwatchlogs.model.PutLogEventsResponse;
14+
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
18+
@Singleton
19+
@Replaces(CloudWatchLogsClient.class)
20+
public class CustomLogsClient implements CloudWatchLogsClient {
21+
22+
private final List<String> loggedMessages = new ArrayList<>();
23+
24+
@Override
25+
public String serviceName() {
26+
return null;
27+
}
28+
29+
@Override
30+
public void close() {
31+
32+
}
33+
34+
@Override
35+
public DescribeLogStreamsResponse describeLogStreams(DescribeLogStreamsRequest describeLogStreamsRequest)
36+
throws AwsServiceException, SdkClientException {
37+
LogStream logStream = LogStream.builder()
38+
.logStreamName("testStreamName")
39+
.uploadSequenceToken("testSequenceToken")
40+
.build();
41+
return DescribeLogStreamsResponse.builder()
42+
.logStreams(logStream)
43+
.build();
44+
}
45+
46+
@Override
47+
public PutLogEventsResponse putLogEvents(PutLogEventsRequest putLogEventsRequest)
48+
throws AwsServiceException, SdkClientException {
49+
for (InputLogEvent inputLogEvent : putLogEventsRequest.logEvents()) {
50+
loggedMessages.add(inputLogEvent.message());
51+
}
52+
return PutLogEventsResponse.builder()
53+
.nextSequenceToken("testNextSequenceToken")
54+
.build();
55+
}
56+
57+
public List<String> getLoggedMessages() {
58+
return loggedMessages;
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<configuration>
2+
3+
<appender name='STDOUT' class='ch.qos.logback.core.ConsoleAppender'>
4+
<encoder>
5+
<pattern>%msg%n</pattern>
6+
</encoder>
7+
</appender>
8+
9+
<appender name="CLOUDWATCH" class="io.micronaut.aws.cloudwatch.logging.CloudWatchLoggingAppender">
10+
<appender-ref ref="STDOUT"/>
11+
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
12+
<layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
13+
<jsonFormatter class="io.micronaut.aws.cloudwatch.logging.CloudWatchJsonFormatter" />
14+
</layout>
15+
</encoder>
16+
<blackListLoggerName>testLogger1</blackListLoggerName>
17+
<blackListLoggerName>testLogger2</blackListLoggerName>
18+
<createGroupAndStream>false</createGroupAndStream>
19+
<groupName>testGroupName</groupName>
20+
<streamName>testStreamName</streamName>
21+
<dispatchOnStart>false</dispatchOnStart>
22+
<queueSize>50</queueSize>
23+
<publishPeriod>200</publishPeriod>
24+
<maxBatchSize>15</maxBatchSize>
25+
</appender>
26+
27+
<root level="INFO">
28+
<appender-ref ref="CLOUDWATCH" />
29+
</root>
30+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package example;
2+
3+
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
4+
import jakarta.inject.Inject;
5+
import org.junit.jupiter.api.Test;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import java.util.List;
10+
import java.util.concurrent.Callable;
11+
12+
import static org.junit.jupiter.api.Assertions.assertTrue;
13+
14+
@MicronautTest
15+
public class LoggingTest {
16+
17+
public static final Logger log = LoggerFactory.getLogger("LoggingTest");
18+
19+
@Inject
20+
CustomLogsClient customLogsClient;
21+
22+
@Test
23+
void test() {
24+
log.info("test message");
25+
26+
List<String> loggedMessages = customLogsClient.getLoggedMessages();
27+
28+
waitUntil(() -> !loggedMessages.isEmpty(), 10, 1);
29+
30+
String lastMessage = loggedMessages.get(loggedMessages.size() - 1);
31+
assertTrue(lastMessage.contains("\"message\":\"test message\""));
32+
}
33+
34+
private void waitUntil(Callable<Boolean> conditionEvaluator, int timeoutSeconds, int sleepTimeSeconds) {
35+
Exception lastException = null;
36+
37+
long end = System.currentTimeMillis() + timeoutSeconds * 1000L;
38+
while (System.currentTimeMillis() < end) {
39+
try {
40+
Thread.sleep(sleepTimeSeconds * 1000L);
41+
} catch (InterruptedException e) {
42+
// continue
43+
}
44+
try {
45+
if (conditionEvaluator.call()) {
46+
return;
47+
}
48+
} catch (Exception e) {
49+
lastException = e;
50+
}
51+
}
52+
String errorMessage = "Condition was not fulfilled within " + timeoutSeconds + " seconds";
53+
throw lastException == null ? new IllegalStateException(errorMessage) : new IllegalStateException(errorMessage, lastException);
54+
}
55+
}

0 commit comments

Comments
 (0)