From dd7bffa62b3ad6c60ec7b9d174583364c7646c53 Mon Sep 17 00:00:00 2001 From: Himtanaya Bhadada Date: Fri, 29 Jul 2022 11:47:39 -0700 Subject: [PATCH 1/3] Support 30 dimensions per dimension set (#103) * Support 30 dimensions per dimension set * Bump version to 3.0.0 Co-authored-by: Himtanaya Bhadada --- build.gradle | 2 +- .../amazon/cloudwatchlogs/emf/Constants.java | 2 + .../DimensionSetExceededException.java | 33 ++++++++ .../emf/model/DimensionSet.java | 12 +++ .../emf/model/DimensionSetTest.java | 77 +++++++++++++++++++ 5 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 src/main/java/software/amazon/cloudwatchlogs/emf/exception/DimensionSetExceededException.java create mode 100644 src/test/java/software/amazon/cloudwatchlogs/emf/model/DimensionSetTest.java diff --git a/build.gradle b/build.gradle index b0d65d66..912faa61 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ allprojects { targetCompatibility = '1.8' } - version = '2.0.0-beta-1' + version = '3.0.0' } java { diff --git a/src/main/java/software/amazon/cloudwatchlogs/emf/Constants.java b/src/main/java/software/amazon/cloudwatchlogs/emf/Constants.java index ac089a0e..68693a5d 100644 --- a/src/main/java/software/amazon/cloudwatchlogs/emf/Constants.java +++ b/src/main/java/software/amazon/cloudwatchlogs/emf/Constants.java @@ -23,6 +23,8 @@ public class Constants { public static final int MAX_METRICS_PER_EVENT = 100; + public static final int MAX_DIMENSION_SET_SIZE = 30; + public static final int MAX_DATAPOINTS_PER_METRIC = 100; /** diff --git a/src/main/java/software/amazon/cloudwatchlogs/emf/exception/DimensionSetExceededException.java b/src/main/java/software/amazon/cloudwatchlogs/emf/exception/DimensionSetExceededException.java new file mode 100644 index 00000000..8a08583c --- /dev/null +++ b/src/main/java/software/amazon/cloudwatchlogs/emf/exception/DimensionSetExceededException.java @@ -0,0 +1,33 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package software.amazon.cloudwatchlogs.emf.exception; + +import software.amazon.cloudwatchlogs.emf.Constants; + +public class DimensionSetExceededException extends RuntimeException { + + public DimensionSetExceededException() { + super( + "Maximum number of dimensions allowed are " + + Constants.MAX_DIMENSION_SET_SIZE + + ". Account for default dimensions if not using setDimensions."); + } + + public DimensionSetExceededException(String message) { + super(message); + } +} diff --git a/src/main/java/software/amazon/cloudwatchlogs/emf/model/DimensionSet.java b/src/main/java/software/amazon/cloudwatchlogs/emf/model/DimensionSet.java index b55e833b..157be2dd 100644 --- a/src/main/java/software/amazon/cloudwatchlogs/emf/model/DimensionSet.java +++ b/src/main/java/software/amazon/cloudwatchlogs/emf/model/DimensionSet.java @@ -22,6 +22,8 @@ import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; +import software.amazon.cloudwatchlogs.emf.Constants; +import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException; /** A combination of dimension values. */ public class DimensionSet { @@ -149,6 +151,10 @@ private static DimensionEntry entryOf(String key, String value) { * @param value Value of the dimension */ public void addDimension(String dimension, String value) { + if (this.getDimensionKeys().size() >= Constants.MAX_DIMENSION_SET_SIZE) { + throw new DimensionSetExceededException(); + } + this.getDimensionRecords().put(dimension, value); } @@ -161,6 +167,12 @@ public void addDimension(String dimension, String value) { */ public DimensionSet add(DimensionSet other) { DimensionSet mergedDimensionSet = new DimensionSet(); + int mergedDimensionSetSize = + this.getDimensionKeys().size() + other.dimensionRecords.keySet().size(); + if (mergedDimensionSetSize > Constants.MAX_DIMENSION_SET_SIZE) { + throw new DimensionSetExceededException(); + } + mergedDimensionSet.dimensionRecords.putAll(dimensionRecords); mergedDimensionSet.dimensionRecords.putAll(other.dimensionRecords); return mergedDimensionSet; diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/model/DimensionSetTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/model/DimensionSetTest.java new file mode 100644 index 00000000..f9e9ea1b --- /dev/null +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/model/DimensionSetTest.java @@ -0,0 +1,77 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package software.amazon.cloudwatchlogs.emf.model; + +import static org.junit.Assert.*; + +import org.junit.Test; +import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException; + +public class DimensionSetTest { + @Test + public void testAddDimension() { + int dimensionsToBeAdded = 30; + DimensionSet dimensionSet = generateDimensionSet(dimensionsToBeAdded); + + assertEquals(dimensionsToBeAdded, dimensionSet.getDimensionKeys().size()); + } + + @Test + public void testAddDimensionLimitExceeded() { + Exception exception = + assertThrows( + DimensionSetExceededException.class, + () -> { + int dimensionSetSize = 33; + generateDimensionSet(dimensionSetSize); + }); + + String expectedMessage = "Maximum number of dimensions"; + String actualMessage = exception.getMessage(); + + assertTrue(actualMessage.contains(expectedMessage)); + } + + @Test + public void testMergeDimensionSets() { + Exception exception = + assertThrows( + DimensionSetExceededException.class, + () -> { + int dimensionSetSize = 28; + int otherDimensionSetSize = 5; + DimensionSet dimensionSet = generateDimensionSet(dimensionSetSize); + DimensionSet otherDimensionSet = + generateDimensionSet(otherDimensionSetSize); + dimensionSet.add(otherDimensionSet); + }); + String expectedMessage = "Maximum number of dimensions"; + String actualMessage = exception.getMessage(); + + assertTrue(actualMessage.contains(expectedMessage)); + } + + private DimensionSet generateDimensionSet(int numOfDimensions) { + DimensionSet dimensionSet = new DimensionSet(); + + for (int i = 0; i < numOfDimensions; i++) { + dimensionSet.addDimension("Dimension" + i, "value" + i); + } + + return dimensionSet; + } +} From 4ac68ab9ef2caec3ac0b959119b85b520ceffc5b Mon Sep 17 00:00:00 2001 From: Himtanaya Bhadada Date: Wed, 3 Aug 2022 14:17:50 -0700 Subject: [PATCH 2/3] Update version to 3.0.0-beta-1 (#107) Co-authored-by: Himtanaya Bhadada --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 912faa61..db0a2026 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ allprojects { targetCompatibility = '1.8' } - version = '3.0.0' + version = '3.0.0-beta-1' } java { From a49c96e7590e4c6a3b98d7dd0cfc0f1d47c3948f Mon Sep 17 00:00:00 2001 From: Himtanaya Bhadada Date: Fri, 5 Aug 2022 12:46:10 -0700 Subject: [PATCH 3/3] Update jdk version for canaries (#109) Co-authored-by: Himtanaya Bhadada --- canarytests/agent/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canarytests/agent/Dockerfile b/canarytests/agent/Dockerfile index 4dfc1c8d..d9c53563 100644 --- a/canarytests/agent/Dockerfile +++ b/canarytests/agent/Dockerfile @@ -1,4 +1,4 @@ -FROM openjdk:8-jdk-slim +FROM openjdk:11-jdk-slim RUN mkdir /app COPY build/libs/*.jar /app/agent.jar ENV JAVA_OPTS=""