diff --git a/canarytests/agent/src/main/java/emf/canary/ECSRunnable.java b/canarytests/agent/src/main/java/emf/canary/ECSRunnable.java index 0c0e8d93..65cfc328 100644 --- a/canarytests/agent/src/main/java/emf/canary/ECSRunnable.java +++ b/canarytests/agent/src/main/java/emf/canary/ECSRunnable.java @@ -2,6 +2,7 @@ import software.amazon.cloudwatchlogs.emf.config.Configuration; import software.amazon.cloudwatchlogs.emf.config.EnvironmentConfigurationProvider; +import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException; import software.amazon.cloudwatchlogs.emf.exception.InvalidDimensionException; import software.amazon.cloudwatchlogs.emf.exception.InvalidMetricException; import software.amazon.cloudwatchlogs.emf.exception.InvalidNamespaceException; @@ -33,7 +34,7 @@ public void run() { "Platform", "ECS", "Agent", "CloudWatchAgent", "Version", version)); - } catch (InvalidNamespaceException | InvalidDimensionException e) { + } catch (InvalidNamespaceException | InvalidDimensionException | DimensionSetExceededException e) { System.out.println(e); } diff --git a/examples/agent/src/main/java/agent/App.java b/examples/agent/src/main/java/agent/App.java index a63b8464..9e17b133 100644 --- a/examples/agent/src/main/java/agent/App.java +++ b/examples/agent/src/main/java/agent/App.java @@ -3,6 +3,7 @@ import software.amazon.cloudwatchlogs.emf.config.EnvironmentConfigurationProvider; import software.amazon.cloudwatchlogs.emf.environment.DefaultEnvironment; import software.amazon.cloudwatchlogs.emf.environment.Environment; +import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException; import software.amazon.cloudwatchlogs.emf.exception.InvalidDimensionException; import software.amazon.cloudwatchlogs.emf.exception.InvalidMetricException; import software.amazon.cloudwatchlogs.emf.logger.MetricsLogger; @@ -19,13 +20,14 @@ public static void main(String[] args) { emitMetric(environment); emitMetric(environment); emitMetric(environment); - } catch (InvalidMetricException | InvalidDimensionException e) { + } catch (InvalidMetricException | InvalidDimensionException | DimensionSetExceededException e) { System.out.println(e); } environment.getSink().shutdown().orTimeout(360_000L, TimeUnit.MILLISECONDS); } - private static void emitMetric(Environment environment) throws InvalidDimensionException, InvalidMetricException { + private static void emitMetric(Environment environment) + throws InvalidDimensionException, InvalidMetricException, DimensionSetExceededException { MetricsLogger logger = new MetricsLogger(environment); logger.setDimensions(DimensionSet.of("Operation", "Agent")); logger.putMetric("ExampleMetric", 100, Unit.MILLISECONDS); diff --git a/examples/lambda/src/main/java/Handler.java b/examples/lambda/src/main/java/Handler.java index 767c2b75..6feb3e5f 100644 --- a/examples/lambda/src/main/java/Handler.java +++ b/examples/lambda/src/main/java/Handler.java @@ -1,5 +1,6 @@ import com.amazonaws.services.lambda.runtime.Context; import com.amazonaws.services.lambda.runtime.RequestHandler; +import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException; import software.amazon.cloudwatchlogs.emf.exception.InvalidDimensionException; import software.amazon.cloudwatchlogs.emf.exception.InvalidMetricException; import software.amazon.cloudwatchlogs.emf.logger.MetricsLogger; @@ -19,7 +20,7 @@ public String handleRequest(Map event, Context context) { try { logger.putDimensions(DimensionSet.of("Service", "Aggregator")); logger.putMetric("ProcessingLatency", 100, Unit.MILLISECONDS); - } catch (InvalidDimensionException | InvalidMetricException e) { + } catch (InvalidDimensionException | InvalidMetricException | DimensionSetExceededException e) { System.out.println(e); } diff --git a/src/integration-test/java/software/amazon/cloudwatchlogs/emf/MetricsLoggerIntegrationTest.java b/src/integration-test/java/software/amazon/cloudwatchlogs/emf/MetricsLoggerIntegrationTest.java index 325fa74f..658e08b8 100644 --- a/src/integration-test/java/software/amazon/cloudwatchlogs/emf/MetricsLoggerIntegrationTest.java +++ b/src/integration-test/java/software/amazon/cloudwatchlogs/emf/MetricsLoggerIntegrationTest.java @@ -33,6 +33,7 @@ import software.amazon.cloudwatchlogs.emf.config.EnvironmentConfigurationProvider; import software.amazon.cloudwatchlogs.emf.environment.DefaultEnvironment; import software.amazon.cloudwatchlogs.emf.environment.Environment; +import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException; import software.amazon.cloudwatchlogs.emf.exception.InvalidDimensionException; import software.amazon.cloudwatchlogs.emf.exception.InvalidMetricException; import software.amazon.cloudwatchlogs.emf.logger.MetricsLogger; @@ -50,7 +51,8 @@ public class MetricsLoggerIntegrationTest { private DimensionSet dimensions = DimensionSet.of(dimensionName, dimensionValue); private EMFIntegrationTestHelper testHelper = new EMFIntegrationTestHelper(); - public MetricsLoggerIntegrationTest() throws InvalidDimensionException {} + public MetricsLoggerIntegrationTest() + throws InvalidDimensionException, DimensionSetExceededException {} @Before public void setUp() { diff --git a/src/main/java/software/amazon/cloudwatchlogs/emf/exception/DimensionSetExceededException.java b/src/main/java/software/amazon/cloudwatchlogs/emf/exception/DimensionSetExceededException.java index 8a08583c..34ab39b4 100644 --- a/src/main/java/software/amazon/cloudwatchlogs/emf/exception/DimensionSetExceededException.java +++ b/src/main/java/software/amazon/cloudwatchlogs/emf/exception/DimensionSetExceededException.java @@ -18,7 +18,7 @@ import software.amazon.cloudwatchlogs.emf.Constants; -public class DimensionSetExceededException extends RuntimeException { +public class DimensionSetExceededException extends Exception { public DimensionSetExceededException() { super( 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 5e8435ba..418dbe87 100644 --- a/src/main/java/software/amazon/cloudwatchlogs/emf/model/DimensionSet.java +++ b/src/main/java/software/amazon/cloudwatchlogs/emf/model/DimensionSet.java @@ -40,8 +40,10 @@ public class DimensionSet { * @param v1 Value of the single dimension * @return a DimensionSet from the parameters * @throws InvalidDimensionException if the dimension name or value is invalid + * @throws DimensionSetExceededException if the number of dimensions exceeds the limit */ - public static DimensionSet of(String d1, String v1) throws InvalidDimensionException { + public static DimensionSet of(String d1, String v1) + throws InvalidDimensionException, DimensionSetExceededException { return fromEntries(entryOf(d1, v1)); } @@ -54,9 +56,10 @@ public static DimensionSet of(String d1, String v1) throws InvalidDimensionExcep * @param v2 Value of the second dimension * @return a DimensionSet from the parameters * @throws InvalidDimensionException if the dimension name or value is invalid + * @throws DimensionSetExceededException if the number of dimensions exceeds the limit */ public static DimensionSet of(String d1, String v1, String d2, String v2) - throws InvalidDimensionException { + throws InvalidDimensionException, DimensionSetExceededException { return fromEntries(entryOf(d1, v1), entryOf(d2, v2)); } @@ -71,9 +74,10 @@ public static DimensionSet of(String d1, String v1, String d2, String v2) * @param v3 Value of the third dimension * @return a DimensionSet from the parameters * @throws InvalidDimensionException if the dimension name or value is invalid + * @throws DimensionSetExceededException if the number of dimensions exceeds the limit */ public static DimensionSet of(String d1, String v1, String d2, String v2, String d3, String v3) - throws InvalidDimensionException { + throws InvalidDimensionException, DimensionSetExceededException { return fromEntries(entryOf(d1, v1), entryOf(d2, v2), entryOf(d3, v3)); } @@ -90,10 +94,11 @@ public static DimensionSet of(String d1, String v1, String d2, String v2, String * @param v4 Value of the fourth dimension * @return a DimensionSet from the parameters * @throws InvalidDimensionException if the dimension name or value is invalid + * @throws DimensionSetExceededException if the number of dimensions exceeds the limit */ public static DimensionSet of( String d1, String v1, String d2, String v2, String d3, String v3, String d4, String v4) - throws InvalidDimensionException { + throws InvalidDimensionException, DimensionSetExceededException { return fromEntries(entryOf(d1, v1), entryOf(d2, v2), entryOf(d3, v3), entryOf(d4, v4)); } @@ -113,6 +118,7 @@ public static DimensionSet of( * @param v5 Value of the fifth dimension * @return a DimensionSet from the parameters * @throws InvalidDimensionException if the dimension name or value is invalid + * @throws DimensionSetExceededException if the number of dimensions exceeds the limit */ public static DimensionSet of( String d1, @@ -125,7 +131,7 @@ public static DimensionSet of( String v4, String d5, String v5) - throws InvalidDimensionException { + throws InvalidDimensionException, DimensionSetExceededException { return fromEntries( entryOf(d1, v1), @@ -136,7 +142,7 @@ public static DimensionSet of( } private static DimensionSet fromEntries(DimensionEntry... entries) - throws InvalidDimensionException { + throws InvalidDimensionException, DimensionSetExceededException { DimensionSet ds = new DimensionSet(); for (DimensionEntry entry : entries) { ds.addDimension(entry.key, entry.value); @@ -154,8 +160,10 @@ private static DimensionEntry entryOf(String key, String value) { * @param dimension Name of the dimension * @param value Value of the dimension * @throws InvalidDimensionException if the dimension name or value is invalid + * @throws DimensionSetExceededException if the number of dimensions exceeds the limit */ - public void addDimension(String dimension, String value) throws InvalidDimensionException { + public void addDimension(String dimension, String value) + throws InvalidDimensionException, DimensionSetExceededException { Validator.validateDimensionSet(dimension, value); if (this.getDimensionKeys().size() >= Constants.MAX_DIMENSION_SET_SIZE) { @@ -171,8 +179,9 @@ public void addDimension(String dimension, String value) throws InvalidDimension * * @param other Other dimension sets to merge with current * @return a new DimensionSet from combining the current DimensionSet with other + * @throws DimensionSetExceededException if the number of dimensions exceeds the limit */ - public DimensionSet add(DimensionSet other) { + public DimensionSet add(DimensionSet other) throws DimensionSetExceededException { DimensionSet mergedDimensionSet = new DimensionSet(); int mergedDimensionSetSize = this.getDimensionKeys().size() + other.dimensionRecords.keySet().size(); diff --git a/src/main/java/software/amazon/cloudwatchlogs/emf/model/MetricDirective.java b/src/main/java/software/amazon/cloudwatchlogs/emf/model/MetricDirective.java index f369614d..c4d166d1 100644 --- a/src/main/java/software/amazon/cloudwatchlogs/emf/model/MetricDirective.java +++ b/src/main/java/software/amazon/cloudwatchlogs/emf/model/MetricDirective.java @@ -22,6 +22,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import lombok.*; +import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException; /** Represents the MetricDirective part of the EMF schema. */ @AllArgsConstructor @@ -87,7 +88,7 @@ Collection getAllMetrics() { } @JsonProperty("Dimensions") - List> getAllDimensionKeys() { + List> getAllDimensionKeys() throws DimensionSetExceededException { return getAllDimensions().stream() .map(DimensionSet::getDimensionKeys) .collect(Collectors.toList()); @@ -128,7 +129,7 @@ void resetDimensions(boolean useDefault) { * Return all the dimension sets. If there's a default dimension set, the custom dimensions are * prepended with the default dimensions. */ - List getAllDimensions() { + List getAllDimensions() throws DimensionSetExceededException { if (!shouldUseDefaultDimension) { return dimensions; } @@ -137,9 +138,12 @@ List getAllDimensions() { return Arrays.asList(defaultDimensions); } - return dimensions.stream() - .map(dim -> defaultDimensions.add(dim)) - .collect(Collectors.toList()); + List allDimensions = new ArrayList<>(); + for (DimensionSet dim : dimensions) { + allDimensions.add(defaultDimensions.add(dim)); + } + + return allDimensions; } /** diff --git a/src/main/java/software/amazon/cloudwatchlogs/emf/model/MetricsContext.java b/src/main/java/software/amazon/cloudwatchlogs/emf/model/MetricsContext.java index abdaf478..7db829f7 100644 --- a/src/main/java/software/amazon/cloudwatchlogs/emf/model/MetricsContext.java +++ b/src/main/java/software/amazon/cloudwatchlogs/emf/model/MetricsContext.java @@ -21,6 +21,7 @@ import java.util.*; import lombok.Getter; import software.amazon.cloudwatchlogs.emf.Constants; +import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException; import software.amazon.cloudwatchlogs.emf.exception.InvalidDimensionException; import software.amazon.cloudwatchlogs.emf.exception.InvalidMetricException; import software.amazon.cloudwatchlogs.emf.exception.InvalidNamespaceException; @@ -179,13 +180,20 @@ public void putDimension(DimensionSet dimensionSet) { * @param dimension the name of the dimension * @param value the value associated with the dimension * @throws InvalidDimensionException if the dimension is invalid + * @throws DimensionSetExceededException if the number of dimensions exceeds the limit */ - public void putDimension(String dimension, String value) throws InvalidDimensionException { + public void putDimension(String dimension, String value) + throws InvalidDimensionException, DimensionSetExceededException { metricDirective.putDimensionSet(DimensionSet.of(dimension, value)); } - /** @return the list of dimensions that has been added, including default dimensions. */ - public List getDimensions() { + /** + * Get list of all dimensions including default dimensions + * + * @return the list of dimensions that has been added, including default dimensions. + * @throws DimensionSetExceededException if the number of dimensions exceeds the limit + */ + public List getDimensions() throws DimensionSetExceededException { return metricDirective.getAllDimensions(); } diff --git a/src/main/java/software/amazon/cloudwatchlogs/emf/model/RootNode.java b/src/main/java/software/amazon/cloudwatchlogs/emf/model/RootNode.java index fb790322..0559746b 100644 --- a/src/main/java/software/amazon/cloudwatchlogs/emf/model/RootNode.java +++ b/src/main/java/software/amazon/cloudwatchlogs/emf/model/RootNode.java @@ -29,6 +29,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.With; +import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException; /** Represents the root of the EMF schema. */ @AllArgsConstructor @@ -60,7 +61,7 @@ Map getProperties() { /** Return the target members that are referenced by metrics, dimensions and properties. */ @JsonAnyGetter - Map getTargetMembers() { + Map getTargetMembers() throws DimensionSetExceededException { Map targetMembers = new HashMap<>(); targetMembers.putAll(properties); targetMembers.putAll(getDimensions()); @@ -74,7 +75,7 @@ Map getTargetMembers() { } /** Return a list of all dimensions that are referenced by each dimension set. */ - Map getDimensions() { + Map getDimensions() throws DimensionSetExceededException { Map dimensions = new HashMap<>(); for (MetricDirective mc : aws.getCloudWatchMetrics()) { for (DimensionSet dimensionSet : mc.getAllDimensions()) { diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/logger/MetricsLoggerTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/logger/MetricsLoggerTest.java index 569cac1b..089e0dba 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/logger/MetricsLoggerTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/logger/MetricsLoggerTest.java @@ -29,6 +29,7 @@ import software.amazon.cloudwatchlogs.emf.Constants; import software.amazon.cloudwatchlogs.emf.environment.Environment; import software.amazon.cloudwatchlogs.emf.environment.EnvironmentProvider; +import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException; import software.amazon.cloudwatchlogs.emf.exception.InvalidDimensionException; import software.amazon.cloudwatchlogs.emf.exception.InvalidMetricException; import software.amazon.cloudwatchlogs.emf.exception.InvalidNamespaceException; @@ -70,7 +71,8 @@ void putProperty_setsProperty() { } @Test - void putDimensions_setsDimension() throws InvalidDimensionException { + void putDimensions_setsDimension() + throws InvalidDimensionException, DimensionSetExceededException { String dimensionName = "dim"; String dimensionValue = "dimValue"; logger.putDimensions(DimensionSet.of(dimensionName, dimensionValue)); @@ -121,7 +123,8 @@ void whenSetDimension_withNullName_thenThrowDimensionException() { } @Test - void setDefaultDimensions_overridesDefaultDimensions() throws InvalidDimensionException { + void setDefaultDimensions_overridesDefaultDimensions() + throws InvalidDimensionException, DimensionSetExceededException { String dimensionName = "dim"; String dimensionValue = "dimValue"; String defaultDimName = "defaultDim"; @@ -139,7 +142,8 @@ void setDefaultDimensions_overridesDefaultDimensions() throws InvalidDimensionEx } @Test - void resetDimensions_resetsDimensionsWithDefaultDimensions() throws InvalidDimensionException { + void resetDimensions_resetsDimensionsWithDefaultDimensions() + throws InvalidDimensionException, DimensionSetExceededException { String dimensionName = "dim"; String dimensionValue = "dimValue"; logger.putDimensions(DimensionSet.of("foo", "bar")); @@ -156,7 +160,7 @@ void resetDimensions_resetsDimensionsWithDefaultDimensions() throws InvalidDimen @Test void resetDimensions_resetsDimensionsWithoutDefaultDimensions() - throws InvalidDimensionException { + throws InvalidDimensionException, DimensionSetExceededException { String dimensionName = "dim"; String dimensionValue = "dimValue"; logger.putDimensions(DimensionSet.of("foo", "bar")); @@ -172,8 +176,8 @@ void resetDimensions_resetsDimensionsWithoutDefaultDimensions() } @Test - void setDimensions_overridesPreviousDimensions() throws InvalidDimensionException { - + void setDimensions_overridesPreviousDimensions() + throws InvalidDimensionException, DimensionSetExceededException { String dimensionName = "dim"; String dimensionValue = "dimValue"; logger.putDimensions(DimensionSet.of("foo", "bar")); @@ -189,7 +193,7 @@ void setDimensions_overridesPreviousDimensions() throws InvalidDimensionExceptio @Test void setDimensions_overridesPreviousDimensionsAndPreservesDefault() - throws InvalidDimensionException { + throws InvalidDimensionException, DimensionSetExceededException { String dimensionName = "dim"; String dimensionValue = "dimValue"; logger.putDimensions(DimensionSet.of("foo", "bar")); @@ -204,7 +208,8 @@ void setDimensions_overridesPreviousDimensionsAndPreservesDefault() } @Test - void setDimensions_clearsDefaultDimensions() throws InvalidMetricException { + void setDimensions_clearsDefaultDimensions() + throws InvalidMetricException, DimensionSetExceededException { MetricsLogger logger = new MetricsLogger(envProvider); logger.setDimensions(); logger.putMetric("Count", 1); @@ -219,7 +224,8 @@ void setDimensions_clearsDefaultDimensions() throws InvalidMetricException { } @Test - void flush_PreservesDimensions() throws InvalidDimensionException { + void flush_PreservesDimensions() + throws InvalidDimensionException, DimensionSetExceededException { MetricsLogger logger = new MetricsLogger(envProvider); logger.setDimensions(DimensionSet.of("Name", "Test")); logger.flush(); @@ -230,7 +236,8 @@ void flush_PreservesDimensions() throws InvalidDimensionException { } @Test - void flush_doesNotPreserveDimensions() throws InvalidDimensionException { + void flush_doesNotPreserveDimensions() + throws InvalidDimensionException, DimensionSetExceededException { logger.putDimensions(DimensionSet.of("Name", "Test")); logger.setFlushPreserveDimensions(false); @@ -244,7 +251,7 @@ void flush_doesNotPreserveDimensions() throws InvalidDimensionException { } @Test - void setDimensions_clearsAllDimensions() { + void setDimensions_clearsAllDimensions() throws DimensionSetExceededException { MetricsLogger logger = new MetricsLogger(envProvider); logger.setDimensions(); @@ -255,7 +262,8 @@ void setDimensions_clearsAllDimensions() { } @Test - void whenSetDimensions_withMultipleFlush_thenClearsDimensions() { + void whenSetDimensions_withMultipleFlush_thenClearsDimensions() + throws DimensionSetExceededException { MetricsLogger logger = new MetricsLogger(envProvider); logger.setDimensions(); @@ -370,7 +378,7 @@ void setTimestamp_withValidValueInPast() throws InvalidTimestampException { } @Test - void testFlushWithConfiguredServiceName() { + void testFlushWithConfiguredServiceName() throws DimensionSetExceededException { String serviceName = "TestServiceName"; when(environment.getName()).thenReturn(serviceName); logger.flush(); @@ -379,7 +387,7 @@ void testFlushWithConfiguredServiceName() { } @Test - void testFlushWithConfiguredServiceType() { + void testFlushWithConfiguredServiceType() throws DimensionSetExceededException { String serviceType = "TestServiceType"; when(environment.getType()).thenReturn(serviceType); logger.flush(); @@ -388,7 +396,7 @@ void testFlushWithConfiguredServiceType() { } @Test - void testFlushWithConfiguredLogGroup() { + void testFlushWithConfiguredLogGroup() throws DimensionSetExceededException { String logGroup = "MyLogGroup"; when(environment.getLogGroupName()).thenReturn(logGroup); logger.flush(); @@ -397,7 +405,8 @@ void testFlushWithConfiguredLogGroup() { } @Test - void testFlushWithDefaultDimensionDefined() throws InvalidDimensionException { + void testFlushWithDefaultDimensionDefined() + throws InvalidDimensionException, DimensionSetExceededException { MetricsContext metricsContext = new MetricsContext(); metricsContext.setDefaultDimensions(DimensionSet.of("foo", "bar")); logger = new MetricsLogger(envProvider, metricsContext); @@ -411,7 +420,7 @@ void testFlushWithDefaultDimensionDefined() throws InvalidDimensionException { @SuppressWarnings("") @Test - void testUseDefaultEnvironmentOnResolverException() { + void testUseDefaultEnvironmentOnResolverException() throws DimensionSetExceededException { String serviceType = "TestServiceType"; CompletableFuture future = CompletableFuture.supplyAsync( @@ -430,7 +439,9 @@ void testUseDefaultEnvironmentOnResolverException() { } @Test - void flush_doesNotPreserveMetrics() throws InvalidMetricException, InvalidDimensionException { + void flush_doesNotPreserveMetrics() + throws InvalidMetricException, InvalidDimensionException, + DimensionSetExceededException { MetricsLogger logger = new MetricsLogger(envProvider); logger.setDimensions(DimensionSet.of("Name", "Test")); logger.putMetric("Count", 1.0); @@ -441,7 +452,8 @@ void flush_doesNotPreserveMetrics() throws InvalidMetricException, InvalidDimens assertFalse(sink.getLogEvents().get(0).contains("Count")); } - private void expectDimension(String dimension, String value) { + private void expectDimension(String dimension, String value) + throws DimensionSetExceededException { List dimensions = sink.getContext().getDimensions(); assertEquals(1, dimensions.size()); assertEquals(value, dimensions.get(0).getDimensionValue(dimension)); diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/logger/MetricsLoggerThreadSafetyTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/logger/MetricsLoggerThreadSafetyTest.java index f17c5a34..3a4fd86e 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/logger/MetricsLoggerThreadSafetyTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/logger/MetricsLoggerThreadSafetyTest.java @@ -38,6 +38,7 @@ import org.junit.Test; import software.amazon.cloudwatchlogs.emf.environment.Environment; import software.amazon.cloudwatchlogs.emf.environment.EnvironmentProvider; +import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException; import software.amazon.cloudwatchlogs.emf.exception.InvalidDimensionException; import software.amazon.cloudwatchlogs.emf.model.DimensionSet; import software.amazon.cloudwatchlogs.emf.model.MetricsContext; @@ -110,7 +111,8 @@ public void testConcurrentPutProperty() throws InterruptedException { } @Test - public void testConcurrentPutDimension() throws InterruptedException { + public void testConcurrentPutDimension() + throws InterruptedException, DimensionSetExceededException { final int N_THREAD = 100; final int N_PUT_DIMENSIONS = 100; @@ -168,7 +170,7 @@ public void testConcurrentPutDimension() throws InterruptedException { @Test public void testConcurrentPutDimensionAfterSetDimension() - throws InterruptedException, InvalidDimensionException { + throws InterruptedException, InvalidDimensionException, DimensionSetExceededException { final int N_THREAD = 100; final int N_PUT_DIMENSIONS = 100; @@ -338,7 +340,8 @@ public void testConcurrentFlushAndPutMetric() } @Test - public void testConcurrentFlushAndMethodsOtherThanPutMetric() throws InterruptedException { + public void testConcurrentFlushAndMethodsOtherThanPutMetric() + throws InterruptedException, DimensionSetExceededException { final int N_THREAD = 600; final int N_PUT_DIMENSIONS = 100; final int N_PUT_PROPERTY = 100; diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/model/DimensionSetTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/model/DimensionSetTest.java index 2d464eed..4d735f89 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/model/DimensionSetTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/model/DimensionSetTest.java @@ -23,7 +23,7 @@ class DimensionSetTest { @Test - void testAddDimension() throws InvalidDimensionException { + void testAddDimension() throws InvalidDimensionException, DimensionSetExceededException { int dimensionsToBeAdded = 30; DimensionSet dimensionSet = generateDimensionSet(dimensionsToBeAdded); @@ -66,7 +66,7 @@ void testMergeDimensionSets() { } private DimensionSet generateDimensionSet(int numOfDimensions) - throws InvalidDimensionException { + throws InvalidDimensionException, DimensionSetExceededException { DimensionSet dimensionSet = new DimensionSet(); for (int i = 0; i < numOfDimensions; i++) { diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricDirectiveTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricDirectiveTest.java index 8469b562..3a3385f1 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricDirectiveTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricDirectiveTest.java @@ -23,6 +23,7 @@ import java.util.Collections; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException; import software.amazon.cloudwatchlogs.emf.exception.InvalidDimensionException; class MetricDirectiveTest { @@ -90,7 +91,9 @@ void testPutMetricWithUnit() { } @Test - void testPutDimensions() throws JsonProcessingException, InvalidDimensionException { + void testPutDimensions() + throws JsonProcessingException, InvalidDimensionException, + DimensionSetExceededException { MetricDirective metricDirective = new MetricDirective(); metricDirective.putDimensionSet( DimensionSet.of("Region", "us-east-1", "Instance", "inst-1")); @@ -104,7 +107,8 @@ void testPutDimensions() throws JsonProcessingException, InvalidDimensionExcepti @Test void testPutDimensionSetWhenMultipleDimensionSets() - throws JsonProcessingException, InvalidDimensionException { + throws JsonProcessingException, InvalidDimensionException, + DimensionSetExceededException { MetricDirective metricDirective = new MetricDirective(); metricDirective.putDimensionSet(DimensionSet.of("Region", "us-east-1")); metricDirective.putDimensionSet(DimensionSet.of("Instance", "inst-1")); @@ -118,7 +122,8 @@ void testPutDimensionSetWhenMultipleDimensionSets() @Test void testPutDimensionSetWhenDuplicateDimensionSets() - throws JsonProcessingException, InvalidDimensionException { + throws JsonProcessingException, InvalidDimensionException, + DimensionSetExceededException { MetricDirective metricDirective = new MetricDirective(); metricDirective.putDimensionSet(new DimensionSet()); metricDirective.putDimensionSet(DimensionSet.of("Region", "us-east-1")); @@ -144,7 +149,8 @@ void testPutDimensionSetWhenDuplicateDimensionSets() @Test void testPutDimensionSetWhenDuplicateDimensionSetsWillSortCorrectly() - throws JsonProcessingException, InvalidDimensionException { + throws JsonProcessingException, InvalidDimensionException, + DimensionSetExceededException { MetricDirective metricDirective = new MetricDirective(); metricDirective.putDimensionSet(new DimensionSet()); metricDirective.putDimensionSet(DimensionSet.of("Region", "us-east-1")); @@ -169,7 +175,8 @@ void testPutDimensionSetWhenDuplicateDimensionSetsWillSortCorrectly() } @Test - void testGetDimensionAfterSetDimensions() throws InvalidDimensionException { + void testGetDimensionAfterSetDimensions() + throws InvalidDimensionException, DimensionSetExceededException { MetricDirective metricDirective = new MetricDirective(); metricDirective.setDefaultDimensions(DimensionSet.of("Dim", "Default")); metricDirective.setDimensions(Arrays.asList(DimensionSet.of("Name", "Test"))); @@ -179,7 +186,8 @@ void testGetDimensionAfterSetDimensions() throws InvalidDimensionException { @Test void testPutDimensionsWhenDefaultDimensionsDefined() - throws JsonProcessingException, InvalidDimensionException { + throws JsonProcessingException, InvalidDimensionException, + DimensionSetExceededException { MetricDirective metricDirective = new MetricDirective(); metricDirective.setDefaultDimensions(DimensionSet.of("Version", "1")); metricDirective.putDimensionSet(DimensionSet.of("Region", "us-east-1")); @@ -194,7 +202,8 @@ void testPutDimensionsWhenDefaultDimensionsDefined() @Test void testPutDimensionsAfterSetDimensions() - throws JsonProcessingException, InvalidDimensionException { + throws JsonProcessingException, InvalidDimensionException, + DimensionSetExceededException { MetricDirective metricDirective = new MetricDirective(); metricDirective.setDimensions(Collections.singletonList(DimensionSet.of("Version", "1"))); metricDirective.putDimensionSet(DimensionSet.of("Region", "us-east-1")); diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricsContextTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricsContextTest.java index a1d40a8d..78de1165 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricsContextTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricsContextTest.java @@ -26,6 +26,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import software.amazon.cloudwatchlogs.emf.Constants; +import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException; import software.amazon.cloudwatchlogs.emf.exception.InvalidDimensionException; import software.amazon.cloudwatchlogs.emf.exception.InvalidMetricException; import software.amazon.cloudwatchlogs.emf.exception.InvalidTimestampException; @@ -134,7 +135,9 @@ void testSerializeMetricsWith101DataPoints() } @Test - void testSerializeZeroMetric() throws JsonProcessingException, InvalidDimensionException { + void testSerializeZeroMetric() + throws JsonProcessingException, InvalidDimensionException, + DimensionSetExceededException { MetricsContext mc = new MetricsContext(); mc.putDimension(DimensionSet.of("Region", "IAD")); List events = mc.serialize(); diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/model/RootNodeTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/model/RootNodeTest.java index a01d87db..564e482e 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/model/RootNodeTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/model/RootNodeTest.java @@ -23,13 +23,14 @@ import java.util.Map; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException; import software.amazon.cloudwatchlogs.emf.exception.InvalidDimensionException; import software.amazon.cloudwatchlogs.emf.exception.InvalidMetricException; class RootNodeTest { @Test - void testPutProperty() { + void testPutProperty() throws DimensionSetExceededException { RootNode rootNode = new RootNode(); rootNode.putProperty("Property", "Value"); @@ -37,7 +38,7 @@ void testPutProperty() { } @Test - void testPutSamePropertyMultipleTimes() { + void testPutSamePropertyMultipleTimes() throws DimensionSetExceededException { RootNode rootNode = new RootNode(); rootNode.putProperty("Property", "Value"); rootNode.putProperty("Property", "NewValue"); @@ -46,7 +47,7 @@ void testPutSamePropertyMultipleTimes() { } @Test - void testGetDimension() throws InvalidDimensionException { + void testGetDimension() throws InvalidDimensionException, DimensionSetExceededException { RootNode rootNode = new RootNode(); MetricDirective metricDirective = rootNode.getAws().createMetricDirective(); metricDirective.putDimensionSet(DimensionSet.of("Dim1", "DimValue1")); @@ -55,7 +56,9 @@ void testGetDimension() throws InvalidDimensionException { } @Test - void testGetTargetMembers() throws InvalidMetricException, InvalidDimensionException { + void testGetTargetMembers() + throws InvalidMetricException, InvalidDimensionException, + DimensionSetExceededException { RootNode rootNode = new RootNode(); MetricsContext mc = new MetricsContext(rootNode); @@ -78,7 +81,8 @@ void testGetTargetMembers() throws InvalidMetricException, InvalidDimensionExcep @SuppressWarnings("unchecked") @Test void testSerializeRootNode() - throws JsonProcessingException, InvalidMetricException, InvalidDimensionException { + throws JsonProcessingException, InvalidMetricException, InvalidDimensionException, + DimensionSetExceededException { MetricsContext mc = new MetricsContext(); mc.setDefaultDimensions(DimensionSet.of("DefaultDim", "DefaultDimValue"));