-
Notifications
You must be signed in to change notification settings - Fork 3
Java upgrade and api pathwise metrics #16
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
Merged
sanketmehta28
merged 4 commits into
master
from
feature/java_upgrade_and_api_pathwise_metrics
Aug 25, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
560e400
Upgraded java version to 17. added stage and resource in the metric p…
cold-magma 2518c55
Changed apiNames field to apiIds as the api names field is not presen…
cold-magma 03dde6e
Reverting hardcoded values
cold-magma 3bcf18c
Reverting config values
cold-magma 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -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,20 +50,21 @@ 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<IncludeMetric> includeMetrics; | ||
private List<String> apiNamesList; | ||
private List<String> apiIdList; | ||
private APIGatewayConfiguration apiGatewayConfiguration; | ||
private Map<String, ?> 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(); | ||
} | ||
|
||
@Override | ||
public List<AWSMetric> getMetrics(AmazonCloudWatch awsCloudWatch, String accountName, LongAdder awsRequestsCounter) { | ||
public List<AWSMetric> 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 | ||
|
@@ -75,20 +79,30 @@ public List<AWSMetric> getMetrics(AmazonCloudWatch awsCloudWatch, String account | |
* 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(awsCloudWatch, awsRequestsCounter, NAMESPACE, includeMetrics, dimensionFilters, apiNamesPredicate); | ||
return MetricsProcessorHelper.getFilteredMetrics(cloudWatchClient, awsRequestsCounter, NAMESPACE, includeMetrics, dimensionFilters, apiNamesPredicate); | ||
} | ||
|
||
private List<DimensionFilter> getDimensionFilters(){ | ||
List<DimensionFilter> 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<Metric> 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()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
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(); | ||
|
||
} | ||
|
This file contains hidden or 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
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.
instead of APIName, why 3 diff dimention filters were created?
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.
ApiName is not a filter in cloudwatch. they changed the schema to ApiId,Stage and Resource
