-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added the object representation of the CloudWatch Alarm #485
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...ents/src/main/java/com/amazonaws/services/lambda/runtime/events/CloudWatchAlarmEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.amazonaws.services.lambda.runtime.events; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Data | ||
@Builder(setterPrefix = "with") | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CloudWatchAlarmEvent { | ||
msailes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private String source; | ||
private String alarmArn; | ||
private String accountId; | ||
private String time; | ||
private String region; | ||
private AlarmData alarmData; | ||
|
||
@Data | ||
@Builder(setterPrefix = "with") | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class AlarmData { | ||
private String alarmName; | ||
private State state; | ||
private State previousState; | ||
private Configuration configuration; | ||
} | ||
|
||
@Data | ||
@Builder(setterPrefix = "with") | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
private static class State { | ||
private String value; | ||
private String reason; | ||
private String reasonData; | ||
private String timestamp; | ||
private String actionsSuppressedBy; | ||
private String actionsSuppressedReason; | ||
} | ||
|
||
@Data | ||
@Builder(setterPrefix = "with") | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
private static class Configuration { | ||
private String description; | ||
private List<Metric> metrics; | ||
private Boolean returnData; | ||
|
||
private String alarmRule; | ||
private String actionsSuppressor; | ||
private Integer actionsSuppressorWaitPeriod; | ||
private Integer actionsSuppressorExtensionPeriod; | ||
} | ||
|
||
@Data | ||
@Builder(setterPrefix = "with") | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
private static class Metric { | ||
private String id; | ||
private MetricStat metricStat; | ||
private Integer period; | ||
private String stat; | ||
private String unit; | ||
} | ||
|
||
@Data | ||
@Builder(setterPrefix = "with") | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
private static class MetricStat { | ||
private String namespace; | ||
private String name; | ||
private Map<String, String> dimensions; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
.../src/test/java/com/amazonaws/services/lambda/runtime/events/CloudWatchAlarmEventTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.amazonaws.services.lambda.runtime.events; | ||
|
||
import com.amazonaws.services.lambda.runtime.serialization.PojoSerializer; | ||
import com.amazonaws.services.lambda.runtime.serialization.factories.JacksonFactory; | ||
import org.json.JSONException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals; | ||
import static org.skyscreamer.jsonassert.JSONCompareMode.STRICT; | ||
|
||
public class CloudWatchAlarmEventTest { | ||
msailes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
JacksonFactory jacksonFactory = JacksonFactory.getInstance(); | ||
|
||
@Test | ||
public void serdeCloudWatchCompositeAlarmEvent() throws JSONException { | ||
String expected = readResource("cloudwatch-composite-alarm.json"); | ||
String actual = deserializeSerializeJsonToString(expected, CloudWatchAlarmEvent.class); | ||
|
||
assertEquals(expected, actual, STRICT); | ||
} | ||
|
||
@Test | ||
public void serdeCloudWatchMetricAlarmEvent() throws JSONException { | ||
String expected = readResource("cloudwatch-composite-alarm.json"); | ||
String actual = deserializeSerializeJsonToString(expected, CloudWatchAlarmEvent.class); | ||
|
||
assertEquals(expected, actual, STRICT); | ||
} | ||
|
||
private <T> String deserializeSerializeJsonToString(String expected, Class<T> modelClass) { | ||
PojoSerializer<T> serializer = jacksonFactory.getSerializer(modelClass); | ||
T event = serializer.fromJson(expected); | ||
|
||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
serializer.toJson(event, baos); | ||
|
||
return new String(baos.toByteArray(), StandardCharsets.UTF_8); | ||
} | ||
|
||
private String readResource(String name) { | ||
Path filePath = Paths.get("src", "test", "resources", name); | ||
byte[] bytes = new byte[0]; | ||
try { | ||
bytes = Files.readAllBytes(filePath); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return new String(bytes, StandardCharsets.UTF_8); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
aws-lambda-java-events/src/test/resources/cloudwatch-composite-alarm.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"source": "aws.cloudwatch", | ||
"alarmArn": "arn:aws:cloudwatch:us-east-1:111122223333:alarm:SuppressionDemo.Main", | ||
"accountId": "111122223333", | ||
"time": "2023-08-04T12:56:46.138+0000", | ||
"region": "us-east-1", | ||
"alarmData": { | ||
"alarmName": "CompositeDemo.Main", | ||
"state": { | ||
"value": "ALARM", | ||
"reason": "arn:aws:cloudwatch:us-east-1:111122223333:alarm:CompositeDemo.FirstChild transitioned to ALARM at Friday 04 August, 2023 12:54:46 UTC", | ||
"reasonData": "{\"triggeringAlarms\":[{\"arn\":\"arn:aws:cloudwatch:us-east-1:111122223333:alarm:CompositeDemo.FirstChild\",\"state\":{\"value\":\"ALARM\",\"timestamp\":\"2023-08-04T12:54:46.138+0000\"}}]}", | ||
"timestamp": "2023-08-04T12:56:46.138+0000" | ||
}, | ||
"previousState": { | ||
"value": "ALARM", | ||
"reason": "arn:aws:cloudwatch:us-east-1:111122223333:alarm:CompositeDemo.FirstChild transitioned to ALARM at Friday 04 August, 2023 12:54:46 UTC", | ||
"reasonData": "{\"triggeringAlarms\":[{\"arn\":\"arn:aws:cloudwatch:us-east-1:111122223333:alarm:CompositeDemo.FirstChild\",\"state\":{\"value\":\"ALARM\",\"timestamp\":\"2023-08-04T12:54:46.138+0000\"}}]}", | ||
"timestamp": "2023-08-04T12:54:46.138+0000", | ||
"actionsSuppressedBy": "WaitPeriod", | ||
"actionsSuppressedReason": "Actions suppressed by WaitPeriod" | ||
}, | ||
"configuration": { | ||
"alarmRule": "ALARM(CompositeDemo.FirstChild) OR ALARM(CompositeDemo.SecondChild)", | ||
"actionsSuppressor": "CompositeDemo.ActionsSuppressor", | ||
"actionsSuppressorWaitPeriod": 120, | ||
"actionsSuppressorExtensionPeriod": 180 | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
aws-lambda-java-events/src/test/resources/cloudwatch-metric-alarm.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"source": "aws.cloudwatch", | ||
"alarmArn": "arn:aws:cloudwatch:us-east-1:444455556666:alarm:lambda-demo-metric-alarm", | ||
"accountId": "444455556666", | ||
"time": "2023-08-04T12:36:15.490+0000", | ||
"region": "us-east-1", | ||
"alarmData": { | ||
"alarmName": "lambda-demo-metric-alarm", | ||
"state": { | ||
"value": "ALARM", | ||
"reason": "test", | ||
"timestamp": "2023-08-04T12:36:15.490+0000" | ||
}, | ||
"previousState": { | ||
"value": "INSUFFICIENT_DATA", | ||
"reason": "Insufficient Data: 5 datapoints were unknown.", | ||
"reasonData": "{\"version\":\"1.0\",\"queryDate\":\"2023-08-04T12:31:29.591+0000\",\"statistic\":\"Average\",\"period\":60,\"recentDatapoints\":[],\"threshold\":5.0,\"evaluatedDatapoints\":[{\"timestamp\":\"2023-08-04T12:30:00.000+0000\"},{\"timestamp\":\"2023-08-04T12:29:00.000+0000\"},{\"timestamp\":\"2023-08-04T12:28:00.000+0000\"},{\"timestamp\":\"2023-08-04T12:27:00.000+0000\"},{\"timestamp\":\"2023-08-04T12:26:00.000+0000\"}]}", | ||
"timestamp": "2023-08-04T12:31:29.595+0000" | ||
}, | ||
"configuration": { | ||
"description": "Metric Alarm to test Lambda actions", | ||
"metrics": [ | ||
{ | ||
"id": "1234e046-06f0-a3da-9534-EXAMPLEe4c", | ||
"metricStat": { | ||
"metric": { | ||
"namespace": "AWS/Logs", | ||
"name": "CallCount", | ||
"dimensions": { | ||
"InstanceId": "i-12345678" | ||
} | ||
}, | ||
"period": 60, | ||
"stat": "Average", | ||
"unit": "Percent" | ||
}, | ||
"returnData": True | ||
} | ||
] | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@msailes is this change required in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. There was a warning in the build logs, I added these to remove the warning.