From 560e4003a1b473a434abb183244f55c61c13af8e Mon Sep 17 00:00:00 2001 From: Amal Nair Date: Thu, 21 Aug 2025 13:06:47 +0530 Subject: [PATCH 1/4] Upgraded java version to 17. added stage and resource in the metric path to show data per api endpoint --- pom.xml | 44 ++++++++++----- .../aws/apigateway/ApiNamesPredicate.java | 4 +- .../APIGatewayMetricsProcessor.java | 53 +++++++++++++------ src/main/resources/conf/config.yml | 12 ++--- .../aws/apigateway/ApiNamesPredicateTest.java | 46 ++++++++-------- .../org.mockito.plugins.MockMaker | 1 + 6 files changed, 102 insertions(+), 58 deletions(-) create mode 100644 src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker diff --git a/pom.xml b/pom.xml index a248646..63b2280 100644 --- a/pom.xml +++ b/pom.xml @@ -26,12 +26,12 @@ com.appdynamics.extensions aws-cloudwatch-exts-commons - 2.2.5 + 2.2.8 com.amazonaws aws-java-sdk-api-gateway - 1.11.642 + 1.12.788 junit @@ -40,15 +40,15 @@ test - org.powermock - powermock-api-mockito - 1.7.3 + org.mockito + mockito-core + 4.11.0 test - org.powermock - powermock-module-junit4 - 1.7.3 + org.mockito + mockito-inline + 4.11.0 test @@ -59,10 +59,30 @@ org.apache.maven.plugins maven-compiler-plugin - 2.3.2 + 3.14.0 - 1.8 - 1.8 + 17 + 17 + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + + --add-opens java.base/jdk.internal.reflect=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.lang.reflect=ALL-UNNAMED + --add-opens java.base/java.lang.invoke=ALL-UNNAMED + --add-opens java.base/java.util.regex=ALL-UNNAMED + --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED + --add-opens java.base/java.io=ALL-UNNAMED + --add-opens java.base/java.xml=ALL-UNNAMED + --add-exports java.xml/jdk.xml.internal=ALL-UNNAMED + --add-opens java.base/java.util.stream=ALL-UNNAMED + @@ -133,7 +153,7 @@ - + diff --git a/src/main/java/com/appdynamics/extensions/aws/apigateway/ApiNamesPredicate.java b/src/main/java/com/appdynamics/extensions/aws/apigateway/ApiNamesPredicate.java index f61d3b6..163a268 100644 --- a/src/main/java/com/appdynamics/extensions/aws/apigateway/ApiNamesPredicate.java +++ b/src/main/java/com/appdynamics/extensions/aws/apigateway/ApiNamesPredicate.java @@ -16,7 +16,7 @@ package com.appdynamics.extensions.aws.apigateway; -import com.amazonaws.services.cloudwatch.model.Metric; +import software.amazon.awssdk.services.cloudwatch.model.Metric; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.base.Strings; @@ -58,7 +58,7 @@ public boolean apply(Metric metric) { return true; } else{ - String apiName = metric.getDimensions().get(0).getValue(); + String apiName = metric.dimensions().get(0).value(); return patternPredicate.apply(apiName); } } diff --git a/src/main/java/com/appdynamics/extensions/aws/apigateway/processors/APIGatewayMetricsProcessor.java b/src/main/java/com/appdynamics/extensions/aws/apigateway/processors/APIGatewayMetricsProcessor.java index e5ba1a9..a7b79c9 100644 --- a/src/main/java/com/appdynamics/extensions/aws/apigateway/processors/APIGatewayMetricsProcessor.java +++ b/src/main/java/com/appdynamics/extensions/aws/apigateway/processors/APIGatewayMetricsProcessor.java @@ -15,13 +15,13 @@ package com.appdynamics.extensions.aws.apigateway.processors; -import com.amazonaws.services.cloudwatch.AmazonCloudWatch; -import com.amazonaws.services.cloudwatch.model.Dimension; -import com.amazonaws.services.cloudwatch.model.DimensionFilter; +import software.amazon.awssdk.services.cloudwatch.CloudWatchClient; +import software.amazon.awssdk.services.cloudwatch.model.Dimension; +import software.amazon.awssdk.services.cloudwatch.model.DimensionFilter; import com.appdynamics.extensions.aws.apigateway.ApiNamesPredicate; import com.appdynamics.extensions.aws.apigateway.EventsServiceMetricsWriter; import com.appdynamics.extensions.aws.apigateway.configuration.APIGatewayConfiguration; -import com.appdynamics.extensions.aws.apigateway.configuration.EventsService; + import com.appdynamics.extensions.aws.config.IncludeMetric; import com.appdynamics.extensions.aws.dto.AWSMetric; import com.appdynamics.extensions.aws.metric.*; @@ -31,6 +31,9 @@ import com.appdynamics.extensions.metrics.Metric; import com.google.common.collect.Lists; import com.google.common.collect.Maps; + + + import org.slf4j.Logger; @@ -47,6 +50,7 @@ public class APIGatewayMetricsProcessor implements MetricsProcessor { private static final Logger logger = ExtensionsLoggerFactory.getLogger(APIGatewayMetricsProcessor.class); private static final String NAMESPACE = "AWS/ApiGateway"; private static final String APINAME = "ApiName"; + private static final String APIID = "ApiId"; private List includeMetrics; private List apiNamesList; private APIGatewayConfiguration apiGatewayConfiguration; @@ -60,7 +64,7 @@ public APIGatewayMetricsProcessor(APIGatewayConfiguration apiGatewayConfiguratio } @Override - public List getMetrics(AmazonCloudWatch awsCloudWatch, String accountName, LongAdder awsRequestsCounter) { + public List getMetrics(CloudWatchClient cloudWatchClient, String accountName, LongAdder awsRequestsCounter) { /*The dimension being used here for filtering is "ApiName". * Another available dimension is "ApiName" and "Stage". * The "ApiName" dimension filter will retrieve metrics with just the @@ -77,18 +81,28 @@ public List getMetrics(AmazonCloudWatch awsCloudWatch, String account * */ ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiNamesList); - return MetricsProcessorHelper.getFilteredMetrics(awsCloudWatch, awsRequestsCounter, NAMESPACE, includeMetrics, dimensionFilters, apiNamesPredicate); + return MetricsProcessorHelper.getFilteredMetrics(cloudWatchClient, awsRequestsCounter, NAMESPACE, includeMetrics, dimensionFilters, apiNamesPredicate); } private List getDimensionFilters(){ List dimensionFilters = Lists.newArrayList(); - DimensionFilter apiNameDimensionFilter = new DimensionFilter(); - apiNameDimensionFilter.withName(APINAME); + DimensionFilter apiNameDimensionFilter = DimensionFilter.builder() + .name(APIID) + .build(); + DimensionFilter resourceNameDimensionFilter = DimensionFilter.builder() + .name("Resource") + .build(); + DimensionFilter stageNameDimensionFilter = DimensionFilter.builder() + .name("Stage") + .build(); + dimensionFilters.add(apiNameDimensionFilter); + dimensionFilters.add(stageNameDimensionFilter); + dimensionFilters.add(resourceNameDimensionFilter); /*DimensionFilter stageDimensionFilter = new DimensionFilter(); - stageDimensionFilter.withName("Stage"); + stageDimensionFilter.setName("Stage"); dimensionFilters.add(stageDimensionFilter);*/ return dimensionFilters; @@ -148,16 +162,20 @@ private void uploadToEventsServiceIfEnabled(List metricList){ private String createMetricPath(String accountName, String region, MetricStatistic metricStatistic){ AWSMetric awsMetric = metricStatistic.getMetric(); IncludeMetric includeMetric = awsMetric.getIncludeMetric(); - com.amazonaws.services.cloudwatch.model.Metric metric = awsMetric.getMetric(); + software.amazon.awssdk.services.cloudwatch.model.Metric metric = awsMetric.getMetric(); String apiName = null; String stageName = null; + String routeName = null; - for(Dimension dimension : metric.getDimensions()) { - if(dimension.getName().equalsIgnoreCase("ApiName")) { - apiName = dimension.getValue(); + for(Dimension dimension : metric.dimensions()) { + if(dimension.name().equalsIgnoreCase("ApiId")) { + apiName = dimension.value(); + } + if(dimension.name().equalsIgnoreCase("Stage")) { + stageName = dimension.value(); } - if(dimension.getName().equalsIgnoreCase("Stage")) { - stageName = dimension.getValue(); + if(dimension.name().equalsIgnoreCase("Resource")) { + routeName = dimension.value(); } } //apiName will never be null @@ -171,7 +189,12 @@ private String createMetricPath(String accountName, String region, MetricStatist stringBuilder.append(stageName) .append("|"); } + if(routeName != null) { + stringBuilder.append(routeName) + .append("|"); + } stringBuilder.append(includeMetric.getName()); + logger.info(stringBuilder.toString()); return stringBuilder.toString(); } diff --git a/src/main/resources/conf/config.yml b/src/main/resources/conf/config.yml index e593450..0174851 100644 --- a/src/main/resources/conf/config.yml +++ b/src/main/resources/conf/config.yml @@ -1,7 +1,7 @@ #Use the following metricPrefix if SIM is enabled. #metricPrefix: "Custom Metrics|AWS APIGateway|" #Use the following metricPrefix if SIM is not enabled. -metricPrefix: "Server|Component:|Custom Metrics|AWS APIGateway|" +metricPrefix: "Server|Component:dev-node123|Custom Metrics|AWS APIGateway|" #Allowed values are Basic and Detailed. Refer https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-cloudwatch-new.html for more information # Basic will fire CloudWatch API calls every 5 minutes @@ -21,15 +21,15 @@ concurrencyConfig: accounts: - awsAccessKey: "" awsSecretKey: "" - displayAccountName: "AppD" - regions: ["us-west-2"] + displayAccountName: "Test Gateway" + regions: ["ap-south-1"] apiNames: [] metricsConfig: # Global time range configuration, applicable to all the metrics configured below. metricsTimeRange: - startTimeInMinsBeforeNow: 10 + startTimeInMinsBeforeNow: 60 endTimeInMinsBeforeNow: 0 # Rate limit ( per second ) for GetMetricStatistics, default value is 400. https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_limits.html getMetricStatisticsRateLimit: 400 @@ -53,9 +53,6 @@ metricsConfig: multiplier: 1 timeRollUpType: "AVERAGE" clusterRollUpType: "INDIVIDUAL" - metricsTimeRange: - startTimeInMinsBeforeNow: 10 - endTimeInMinsBeforeNow: 0 - name: "5XXError" alias: "5XXError" statType: "ave" @@ -103,6 +100,7 @@ regionEndPoints: ap-northeast-1: monitoring.ap-northeast-1.amazonaws.com ap-southeast-1: monitoring.ap-southeast-1.amazonaws.com ap-southeast-2: monitoring.ap-southeast-2.amazonaws.com + ap-south-1: monitoring.ap-south-1.amazonaws.com eu-central-1: monitoring.eu-central-1.amazonaws.com us-east-1: monitoring.us-east-1.amazonaws.com us-west-1: monitoring.us-west-1.amazonaws.com diff --git a/src/test/java/com/appdynamics/aws/apigateway/ApiNamesPredicateTest.java b/src/test/java/com/appdynamics/aws/apigateway/ApiNamesPredicateTest.java index c5c90e9..f771b4c 100644 --- a/src/test/java/com/appdynamics/aws/apigateway/ApiNamesPredicateTest.java +++ b/src/test/java/com/appdynamics/aws/apigateway/ApiNamesPredicateTest.java @@ -15,98 +15,100 @@ package com.appdynamics.aws.apigateway; -import com.amazonaws.services.cloudwatch.model.Dimension; -import com.amazonaws.services.cloudwatch.model.Metric; +import software.amazon.awssdk.services.cloudwatch.model.Dimension; +import software.amazon.awssdk.services.cloudwatch.model.Metric; import static org.mockito.Mockito.when; +import static org.mockito.Mockito.mock; import com.appdynamics.extensions.aws.apigateway.ApiNamesPredicate; import com.google.common.collect.Lists; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.List; /** * Created by venkata.konala on 5/22/18. */ -@RunWith(PowerMockRunner.class) +@RunWith(MockitoJUnitRunner.class) public class ApiNamesPredicateTest { - @Mock private Metric metric; - - @Mock private Dimension dimension; @Test public void matchedApiNameMetricShouldReturnTrue(){ + metric = mock(Metric.class); + dimension = mock(Dimension.class); List apiNamesList = Lists.newArrayList("sampleName"); ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiNamesList); - when(metric.getDimensions()).thenReturn(Lists.newArrayList(dimension)); - when(dimension.getValue()).thenReturn("sampleName"); + when(metric.dimensions()).thenReturn(Lists.newArrayList(dimension)); + when(dimension.value()).thenReturn("sampleName"); Assert.assertTrue(apiNamesPredicate.apply(metric)); } @Test public void unMatchedApiNameMetricShouldReturnFalse(){ + metric = mock(Metric.class); + dimension = mock(Dimension.class); List apiNamesList = Lists.newArrayList("sampleName1", "sampleName2"); ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiNamesList); - when(metric.getDimensions()).thenReturn(Lists.newArrayList(dimension)); - when(dimension.getValue()).thenReturn("sampleName"); + when(metric.dimensions()).thenReturn(Lists.newArrayList(dimension)); + when(dimension.value()).thenReturn("sampleName"); Assert.assertFalse(apiNamesPredicate.apply(metric)); } @Test public void emptyPredicateShouldReturnTrue(){ + metric = mock(Metric.class); List apiNamesList = Lists.newArrayList(); ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiNamesList); - when(metric.getDimensions()).thenReturn(Lists.newArrayList(dimension)); - when(dimension.getValue()).thenReturn("sampleName"); Assert.assertTrue(apiNamesPredicate.apply(metric)); } @Test public void nullPredicateShouldReturnTrue(){ + metric = mock(Metric.class); List apiNamesList = null; ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiNamesList); - when(metric.getDimensions()).thenReturn(Lists.newArrayList(dimension)); - when(dimension.getValue()).thenReturn("sampleName"); Assert.assertTrue(apiNamesPredicate.apply(metric)); } @Test public void emptyApiNamesInListShouldReturnTrue(){ + metric = mock(Metric.class); List apiNamesList = Lists.newArrayList("", ""); ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiNamesList); - when(metric.getDimensions()).thenReturn(Lists.newArrayList(dimension)); - when(dimension.getValue()).thenReturn("sampleName"); Assert.assertTrue(apiNamesPredicate.apply(metric)); } @Test public void emptyApiNamesAndNonEmtyApiNamesInListShouldReturnTrueIfMatched(){ + metric = mock(Metric.class); + dimension = mock(Dimension.class); List apiNamesList = Lists.newArrayList("sampleName", ""); ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiNamesList); - when(metric.getDimensions()).thenReturn(Lists.newArrayList(dimension)); - when(dimension.getValue()).thenReturn("sampleName"); + when(metric.dimensions()).thenReturn(Lists.newArrayList(dimension)); + when(dimension.value()).thenReturn("sampleName"); Assert.assertTrue(apiNamesPredicate.apply(metric)); } @Test public void emptyApiNamesAndNonEmtyApiNamesInListShouldReturnFalseIfNotMatched(){ + metric = mock(Metric.class); + dimension = mock(Dimension.class); List apiNamesList = Lists.newArrayList("sampleName$", ""); ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiNamesList); - when(metric.getDimensions()).thenReturn(Lists.newArrayList(dimension)); - when(dimension.getValue()).thenReturn("sampleName1"); + when(metric.dimensions()).thenReturn(Lists.newArrayList(dimension)); + when(dimension.value()).thenReturn("sampleName1"); Assert.assertFalse(apiNamesPredicate.apply(metric)); } diff --git a/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 0000000..1f0955d --- /dev/null +++ b/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline From 2518c55f80fa5cd2e83b6e26830d7d9cf623be1e Mon Sep 17 00:00:00 2001 From: Amal Nair Date: Thu, 21 Aug 2025 13:32:39 +0530 Subject: [PATCH 2/4] Changed apiNames field to apiIds as the api names field is not present in the cloudwatch apigateway namespace --- README.md | 28 +++++++++++++++++-- .../aws/apigateway/ApiNamesPredicate.java | 10 +++---- .../APIGatewayConfiguration.java | 10 +++---- .../APIGatewayMetricsProcessor.java | 6 ++-- src/main/resources/conf/config.yml | 6 +++- .../aws/apigateway/ApiNamesPredicateTest.java | 28 +++++++++---------- 6 files changed, 58 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 4e22285..9268d03 100644 --- a/README.md +++ b/README.md @@ -52,12 +52,36 @@ More details around metric prefix can be found [here](https://community.appdynam regions: ["eu-central-1","eu-west-1"] ~~~ -3. Provide the list of Api names that needs to be monitored. This list accepts regular expressions. +3. Provide the list of Api Ids that needs to be monitored. This list accepts regular expressions. (Previously api names were expected but the field has been deprecated) ~~~ - apiNames: ["api1", "api2"] + apiId: ["api1", "api2"] ~~~ +4. Configure the `metricsConfig` section to control how metrics are collected from CloudWatch: + + **metricsTimeRange**: Controls the time window for metric collection + - `startTimeInMinsBeforeNow`: How many minutes back from current time to start collecting metrics (default: 60) + - `endTimeInMinsBeforeNow`: How many minutes back from current time to end collecting metrics (default: 0, meaning current time) + + **getMetricStatisticsRateLimit**: Rate limit per second for CloudWatch GetMetricStatistics API calls (default: 400). + This helps avoid hitting AWS API throttling limits. See [AWS CloudWatch limits](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_limits.html) for more details. + + **maxErrorRetrySize**: Maximum number of retry attempts for failed requests or throttling errors (default: 0, meaning no retries). + + **defaultPeriod**: Default time period in seconds for all metrics. Must be a multiple of 60 (default: 300). + Valid values include 60, 300, 3600, etc. Individual metrics can override this using the 'period' field in their specific configuration. + + ~~~ + metricsConfig: + metricsTimeRange: + startTimeInMinsBeforeNow: 60 + endTimeInMinsBeforeNow: 0 + getMetricStatisticsRateLimit: 400 + maxErrorRetrySize: 0 + defaultPeriod: 300 + ~~~ + ## Metrics 1. 4XXError - The number of client-side errors captured in a specified period. diff --git a/src/main/java/com/appdynamics/extensions/aws/apigateway/ApiNamesPredicate.java b/src/main/java/com/appdynamics/extensions/aws/apigateway/ApiNamesPredicate.java index 163a268..ea5095d 100644 --- a/src/main/java/com/appdynamics/extensions/aws/apigateway/ApiNamesPredicate.java +++ b/src/main/java/com/appdynamics/extensions/aws/apigateway/ApiNamesPredicate.java @@ -28,18 +28,18 @@ */ public class ApiNamesPredicate implements Predicate { - private List apiNamesList; + private List apiIdList; private Predicate patternPredicate; - public ApiNamesPredicate(List apiNamesList){ - this.apiNamesList = apiNamesList; + public ApiNamesPredicate(List apiIdList){ + this.apiIdList = apiIdList; buildPattern(); } private void buildPattern(){ - if(apiNamesList != null && !apiNamesList.isEmpty()){ + if(apiIdList != null && !apiIdList.isEmpty()){ - for(String apiPattern : apiNamesList){ + for(String apiPattern : apiIdList){ if(!Strings.isNullOrEmpty(apiPattern)) { Predicate apiPatternPredicate = Predicates.containsPattern(apiPattern); if (patternPredicate == null) { diff --git a/src/main/java/com/appdynamics/extensions/aws/apigateway/configuration/APIGatewayConfiguration.java b/src/main/java/com/appdynamics/extensions/aws/apigateway/configuration/APIGatewayConfiguration.java index 6a80464..5756de0 100644 --- a/src/main/java/com/appdynamics/extensions/aws/apigateway/configuration/APIGatewayConfiguration.java +++ b/src/main/java/com/appdynamics/extensions/aws/apigateway/configuration/APIGatewayConfiguration.java @@ -27,7 +27,7 @@ public class APIGatewayConfiguration extends Configuration { private Map eventsService; - private List apiNames; + private List apiId; public void setEventsService(Map eventsService) { @@ -38,11 +38,11 @@ public void setEventsService(Map eventsService) { return eventsService; } - public void setApiNames(List apiNames) { - this.apiNames = apiNames; + public void setApiId(List apiId) { + this.apiId = apiId; } - public List getApiNames() { - return apiNames; + public List getApiId() { + return apiId; } } diff --git a/src/main/java/com/appdynamics/extensions/aws/apigateway/processors/APIGatewayMetricsProcessor.java b/src/main/java/com/appdynamics/extensions/aws/apigateway/processors/APIGatewayMetricsProcessor.java index a7b79c9..61d4c43 100644 --- a/src/main/java/com/appdynamics/extensions/aws/apigateway/processors/APIGatewayMetricsProcessor.java +++ b/src/main/java/com/appdynamics/extensions/aws/apigateway/processors/APIGatewayMetricsProcessor.java @@ -52,14 +52,14 @@ public class APIGatewayMetricsProcessor implements MetricsProcessor { private static final String APINAME = "ApiName"; private static final String APIID = "ApiId"; private List includeMetrics; - private List apiNamesList; + private List apiIdList; private APIGatewayConfiguration apiGatewayConfiguration; private Map eventsService; public APIGatewayMetricsProcessor(APIGatewayConfiguration apiGatewayConfiguration){ this.apiGatewayConfiguration = apiGatewayConfiguration; this.includeMetrics = apiGatewayConfiguration.getMetricsConfig().getIncludeMetrics(); - this.apiNamesList = apiGatewayConfiguration.getApiNames(); + this.apiIdList = apiGatewayConfiguration.getApiId(); this.eventsService = apiGatewayConfiguration.getEventsService(); } @@ -79,7 +79,7 @@ public List getMetrics(CloudWatchClient cloudWatchClient, String acco * Since the dimension used for filtering is "ApiName", we can filter * further with the ApiName values. * */ - ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiNamesList); + ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiIdList); return MetricsProcessorHelper.getFilteredMetrics(cloudWatchClient, awsRequestsCounter, NAMESPACE, includeMetrics, dimensionFilters, apiNamesPredicate); } diff --git a/src/main/resources/conf/config.yml b/src/main/resources/conf/config.yml index 0174851..0a6b054 100644 --- a/src/main/resources/conf/config.yml +++ b/src/main/resources/conf/config.yml @@ -24,7 +24,7 @@ accounts: displayAccountName: "Test Gateway" regions: ["ap-south-1"] -apiNames: [] +apiId: [] metricsConfig: # Global time range configuration, applicable to all the metrics configured below. @@ -36,6 +36,10 @@ metricsConfig: # The max number of retry attempts for failed retryable requests # (ex: 5xx error responses from a service) or throttling errors maxErrorRetrySize: 0 + # Default period for all metrics (in seconds). Must be a multiple of 60. + # Valid values: 60, 300, 3600, etc. + # Individual metrics can override this value using the 'period' field in the specific includeMetrics section + defaultPeriod: 300 # By default, all metrics retrieved from cloudwatch are 'Average' values. # This option allows you to override the metric type. # Allowed statTypes are: ave, max, min, sum, samplecount diff --git a/src/test/java/com/appdynamics/aws/apigateway/ApiNamesPredicateTest.java b/src/test/java/com/appdynamics/aws/apigateway/ApiNamesPredicateTest.java index f771b4c..46b4332 100644 --- a/src/test/java/com/appdynamics/aws/apigateway/ApiNamesPredicateTest.java +++ b/src/test/java/com/appdynamics/aws/apigateway/ApiNamesPredicateTest.java @@ -42,8 +42,8 @@ public class ApiNamesPredicateTest { public void matchedApiNameMetricShouldReturnTrue(){ metric = mock(Metric.class); dimension = mock(Dimension.class); - List apiNamesList = Lists.newArrayList("sampleName"); - ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiNamesList); + List apiIdList = Lists.newArrayList("sampleName"); + ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiIdList); when(metric.dimensions()).thenReturn(Lists.newArrayList(dimension)); when(dimension.value()).thenReturn("sampleName"); Assert.assertTrue(apiNamesPredicate.apply(metric)); @@ -54,8 +54,8 @@ public void matchedApiNameMetricShouldReturnTrue(){ public void unMatchedApiNameMetricShouldReturnFalse(){ metric = mock(Metric.class); dimension = mock(Dimension.class); - List apiNamesList = Lists.newArrayList("sampleName1", "sampleName2"); - ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiNamesList); + List apiIdList = Lists.newArrayList("sampleName1", "sampleName2"); + ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiIdList); when(metric.dimensions()).thenReturn(Lists.newArrayList(dimension)); when(dimension.value()).thenReturn("sampleName"); Assert.assertFalse(apiNamesPredicate.apply(metric)); @@ -65,8 +65,8 @@ public void unMatchedApiNameMetricShouldReturnFalse(){ @Test public void emptyPredicateShouldReturnTrue(){ metric = mock(Metric.class); - List apiNamesList = Lists.newArrayList(); - ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiNamesList); + List apiIdList = Lists.newArrayList(); + ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiIdList); Assert.assertTrue(apiNamesPredicate.apply(metric)); } @@ -74,8 +74,8 @@ public void emptyPredicateShouldReturnTrue(){ @Test public void nullPredicateShouldReturnTrue(){ metric = mock(Metric.class); - List apiNamesList = null; - ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiNamesList); + List apiIdList = null; + ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiIdList); Assert.assertTrue(apiNamesPredicate.apply(metric)); } @@ -83,8 +83,8 @@ public void nullPredicateShouldReturnTrue(){ @Test public void emptyApiNamesInListShouldReturnTrue(){ metric = mock(Metric.class); - List apiNamesList = Lists.newArrayList("", ""); - ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiNamesList); + List apiIdList = Lists.newArrayList("", ""); + ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiIdList); Assert.assertTrue(apiNamesPredicate.apply(metric)); } @@ -93,8 +93,8 @@ public void emptyApiNamesInListShouldReturnTrue(){ public void emptyApiNamesAndNonEmtyApiNamesInListShouldReturnTrueIfMatched(){ metric = mock(Metric.class); dimension = mock(Dimension.class); - List apiNamesList = Lists.newArrayList("sampleName", ""); - ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiNamesList); + List apiIdList = Lists.newArrayList("sampleName", ""); + ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiIdList); when(metric.dimensions()).thenReturn(Lists.newArrayList(dimension)); when(dimension.value()).thenReturn("sampleName"); Assert.assertTrue(apiNamesPredicate.apply(metric)); @@ -105,8 +105,8 @@ public void emptyApiNamesAndNonEmtyApiNamesInListShouldReturnTrueIfMatched(){ public void emptyApiNamesAndNonEmtyApiNamesInListShouldReturnFalseIfNotMatched(){ metric = mock(Metric.class); dimension = mock(Dimension.class); - List apiNamesList = Lists.newArrayList("sampleName$", ""); - ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiNamesList); + List apiIdList = Lists.newArrayList("sampleName$", ""); + ApiNamesPredicate apiNamesPredicate = new ApiNamesPredicate(apiIdList); when(metric.dimensions()).thenReturn(Lists.newArrayList(dimension)); when(dimension.value()).thenReturn("sampleName1"); Assert.assertFalse(apiNamesPredicate.apply(metric)); From 03dde6e889872636b5165620bfcf05ac9bab4f84 Mon Sep 17 00:00:00 2001 From: Amal Nair Date: Mon, 25 Aug 2025 12:21:41 +0530 Subject: [PATCH 3/4] Reverting hardcoded values --- src/main/resources/conf/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/conf/config.yml b/src/main/resources/conf/config.yml index 0a6b054..4c94f11 100644 --- a/src/main/resources/conf/config.yml +++ b/src/main/resources/conf/config.yml @@ -1,7 +1,7 @@ #Use the following metricPrefix if SIM is enabled. #metricPrefix: "Custom Metrics|AWS APIGateway|" #Use the following metricPrefix if SIM is not enabled. -metricPrefix: "Server|Component:dev-node123|Custom Metrics|AWS APIGateway|" +metricPrefix: "Server|Component:|Custom Metrics|AWS APIGateway|" #Allowed values are Basic and Detailed. Refer https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-cloudwatch-new.html for more information # Basic will fire CloudWatch API calls every 5 minutes From 3bcf18c95631f89f04f2146f993700a4c84e81a8 Mon Sep 17 00:00:00 2001 From: Amal Nair Date: Mon, 25 Aug 2025 12:31:20 +0530 Subject: [PATCH 4/4] Reverting config values --- src/main/resources/conf/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/conf/config.yml b/src/main/resources/conf/config.yml index 4c94f11..4744d8f 100644 --- a/src/main/resources/conf/config.yml +++ b/src/main/resources/conf/config.yml @@ -21,15 +21,15 @@ concurrencyConfig: accounts: - awsAccessKey: "" awsSecretKey: "" - displayAccountName: "Test Gateway" - regions: ["ap-south-1"] + displayAccountName: "AppD" + regions: ["us-west-2"] apiId: [] metricsConfig: # Global time range configuration, applicable to all the metrics configured below. metricsTimeRange: - startTimeInMinsBeforeNow: 60 + startTimeInMinsBeforeNow: 10 endTimeInMinsBeforeNow: 0 # Rate limit ( per second ) for GetMetricStatistics, default value is 400. https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_limits.html getMetricStatisticsRateLimit: 400