feat(apigateway): add metrics for Stage and Method constructs#20617
feat(apigateway): add metrics for Stage and Method constructs#20617mergify[bot] merged 7 commits intoaws:mainfrom cecheta:metrics
Conversation
|
@comcalvi README updated and integration test added |
| class ImportWithApiName extends Import { | ||
| public readonly restApiName = restApiName; | ||
| } |
There was a problem hiding this comment.
Why not add restApiName to Import itself, so we don't need this extra class?
There was a problem hiding this comment.
I was struggling with the fact that the attribute was optional, but I guess we can fall back to id
There was a problem hiding this comment.
Removed the unnecessary class
| * Import an existing RestApi that can be configured with additional Methods and Resources. | ||
| */ | ||
| public static fromRestApiAttributes(scope: Construct, id: string, attrs: RestApiAttributes): IRestApi { | ||
| const restApiName = attrs.restApiName ?? ''; |
There was a problem hiding this comment.
why do we need to assign it ''? Line 684 of this file states that the default is ID of the RestApi construct. This is confusing since we assign it to the empty string here instead.
| public readonly restApiName = restApiName; | ||
| } | ||
|
|
||
| if (attrs.restApiName !== undefined) return new ImportWithApiName(scope, id); |
There was a problem hiding this comment.
we shouldn't be referencing attrs.restApiName here, we already have restApiName above. This usage is confusing; I would delete the restApiName local variable and use attrs.restApiName instead.
| /** | ||
| * Metric for the number of client-side errors captured in a given period. | ||
| * | ||
| * Default: sum over 5 minutes |
There was a problem hiding this comment.
throughout this PR, default comments should read analogously to:
| * Default: sum over 5 minutes | |
| * @default - sum over 5 minutes |
| const app = new cdk.App(); | ||
|
|
||
| const stack = new cdk.Stack(app, 'restapi-metrics'); | ||
|
|
||
| const restApi = new apigw.RestApi(stack, 'Api'); | ||
|
|
||
| const stage = restApi.deploymentStage; | ||
|
|
||
| const method = restApi.root.addMethod('GET'); |
There was a problem hiding this comment.
| const app = new cdk.App(); | |
| const stack = new cdk.Stack(app, 'restapi-metrics'); | |
| const restApi = new apigw.RestApi(stack, 'Api'); | |
| const stage = restApi.deploymentStage; | |
| const method = restApi.root.addMethod('GET'); | |
| const app = new cdk.App(); | |
| const stack = new cdk.Stack(app, 'restapi-metrics'); | |
| const restApi = new apigw.RestApi(stack, 'Api'); | |
| const stage = restApi.deploymentStage; | |
| const method = restApi.root.addMethod('GET'); |
| The APIs with the `metric` prefix can be used to get reference to specific metrics for this API. For example, | ||
| the method below refers to the client side errors metric for this API. | ||
| These metrics can be referred to using the metric APIs available on the `RestApi`, `Stage` and `Method` constructs. | ||
| Note that detailed metrics must be enabled for a stage to use the `Method` metrics. |
There was a problem hiding this comment.
Please include a link to documentation that explains how to enable detailed metrics.
| * Returns the given named metric for this API method | ||
| */ | ||
| public metric(metricName: string, stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric { |
There was a problem hiding this comment.
I find this confusing; the doc string says that it returns "the given named metric", as if the metric already exists, but then the method invokes a constructor.
can we rename this to or attachMetric and change the docstring to something like "adds the named metric for this API method. It has metric name metricName and dimensions:
{please list them here in some form}
to this method."
There was a problem hiding this comment.
I've mainly copied the existing code from restapi.ts, all the metric methods invoke a constructor and return a metric after calling attachTo().
The docstring seems to match metrics in other modules such as SQS and Lambda
I would think that renaming the docstring to something like "Returns a metric for this API method with the given name" would be sufficient to make it clearer
| * | ||
| * @default - sum over 5 minutes | ||
| */ | ||
| public metricCacheHitCount(stage: IStage, props?: cloudwatch.MetricOptions): cloudwatch.Metric { |
There was a problem hiding this comment.
I like this abstraction on top of the canned metrics, nice work 👍
| /** | ||
| * Returns the given named metric for this stage | ||
| */ | ||
| public metric(metricName: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric { |
There was a problem hiding this comment.
similar comment as above.
Additionally, having metric() next to metricClientError() is confusing; can we add a more descriptive name to metric(), to better distinguish it from the other metric*() methods in both classes?
There was a problem hiding this comment.
Again, the naming metric() here seems to match the naming in other modules such as SQS and Lambda, maybe it is better to leave them consistent?
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
This PR adds metrics for API Gateway stages and methods. The metrics have been largely copied from the existing RestApi metrics methods.
Closes #16433
All Submissions:
Adding new Unconventional Dependencies:
New Features
yarn integto deploy the infrastructure and generate the snapshot (i.e.yarn integwithout--dry-run)?By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license