Skip to content
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

Add detailed metrics to HttpApi #8510

Merged
merged 3 commits into from Nov 20, 2020

Conversation

BaptistG
Copy link
Contributor

@BaptistG BaptistG commented Nov 16, 2020

Closes: #8190

Hi @medikoo ,
This PR implements the change suggested in #8190 . I used the detailedMetrics flag instead of metrics in httpApi because it is closer to the flag used by Cloudformation (DetailedMetricsEnabled).

I had to change my commit because when testing my change I noticed that once you've set DetailedMetricsEnabled to true, removing the property from DefaultRouteSettings will not disable the detailed metrics, to do so you have to set DetailedMetricsEnabled to false.

@BaptistG BaptistG force-pushed the feat/httpApi_customMetrics branch 2 times, most recently from 61f8452 to 4514954 Compare November 16, 2020 22:59
@codecov-io
Copy link

codecov-io commented Nov 16, 2020

Codecov Report

Merging #8510 (4c0796a) into master (8c0d892) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #8510   +/-   ##
=======================================
  Coverage   87.26%   87.26%           
=======================================
  Files         255      255           
  Lines        9503     9503           
=======================================
  Hits         8293     8293           
  Misses       1210     1210           
Impacted Files Coverage Δ
lib/plugins/aws/provider/awsProvider.js 93.06% <ø> (ø)
...lugins/aws/package/compile/events/httpApi/index.js 92.59% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8c0d892...4c0796a. Read the comment docs.

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BaptistG thanks for giving that a spin! That looks very promising. Please see my comments

docs/providers/aws/events/http-api.md Outdated Show resolved Hide resolved
@@ -130,7 +130,11 @@ class HttpApiEvents {
ApiId: { Ref: this.provider.naming.getHttpApiLogicalId() },
StageName: '$default',
AutoDeploy: true,
DefaultRouteSettings: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create this configuration only if provider.httpApi.metrics is provided (technically provider.httpApi.metrics != null)

Copy link
Contributor Author

@BaptistG BaptistG Nov 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @medikoo , that's what I was initially going for but when testing I noticed that if you've set DefaultRouteSettings.DetailedMetricsEnabled to true, the only way to revert the change is to explicitely set it to false. If you just remove the DefaultRouteSettings in the CF template it will not deactivate detailed metrics.

(1) This activates metrics

"HttpApiStage": {
      "Type": "AWS::ApiGatewayV2::Stage",
      "Properties": {
        "ApiId": {
          "Ref": "HttpApi"
        },
        "StageName": "$default",
        "AutoDeploy": true,
        "DefaultRouteSettings": {
           "DetailedMetricsEnabled": true
        }
}

(2) This doesnt deactivate metrics if you've deployed (1) before

"HttpApiStage": {
      "Type": "AWS::ApiGatewayV2::Stage",
      "Properties": {
        "ApiId": {
          "Ref": "HttpApi"
        },
        "StageName": "$default",
        "AutoDeploy": true,
}

(3) This deactivates metrics if (1) was deployed previously, if it wasn't, it is equivalent to (2)

"HttpApiStage": {
      "Type": "AWS::ApiGatewayV2::Stage",
      "Properties": {
        "ApiId": {
          "Ref": "HttpApi"
        },
        "StageName": "$default",
        "AutoDeploy": true,
        "DefaultRouteSettings": {
           "DetailedMetricsEnabled": true
        }
}

So if I make it a no setting, users will have to use the console to deactivate detailed metrics or will have to explicitely set metrics to false which might be confusing. Let me know what you think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BaptistG thanks for clarification. Indeed in such case it makes big sense to always configure DefaultRouteSettings. Still let's comment in that reasoning (so it's not accidentally removed with some cleanup)

this.config = {
routes,
id: userConfig.id,
detailedMetrics: userConfig.detailedMetrics || false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make default a no setting and not false

Copy link
Contributor Author

@BaptistG BaptistG Nov 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, will make the change based on your answer for #8510 (comment)

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you @BaptistG!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HttpApi Gateway Detailed Metrics
3 participants