-
Notifications
You must be signed in to change notification settings - Fork 1
Add outcome tag to upload_cert and log skipped IAM cert uploads #364
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |||||
|
|
||||||
| import botocore | ||||||
|
|
||||||
| from flask import current_app | ||||||
| from retrying import retry | ||||||
| from sentry_sdk import capture_exception | ||||||
|
|
||||||
|
|
@@ -140,18 +141,18 @@ def upload_cert(name, body, private_key, path, cert_chain=None, **kwargs): | |||||
| if not path or path == "/": | ||||||
| path = "/" | ||||||
|
|
||||||
| metrics.send("upload_cert", "counter", 1, metric_tags={"name": name, "path": path}) | ||||||
| outcome = "success" | ||||||
| try: | ||||||
| if cert_chain: | ||||||
| return client.upload_server_certificate( | ||||||
| response = client.upload_server_certificate( | ||||||
| Path=path, | ||||||
| ServerCertificateName=name, | ||||||
| CertificateBody=str(body), | ||||||
| PrivateKey=str(private_key), | ||||||
| CertificateChain=str(cert_chain), | ||||||
| ) | ||||||
| else: | ||||||
| return client.upload_server_certificate( | ||||||
| response = client.upload_server_certificate( | ||||||
| Path=path, | ||||||
| ServerCertificateName=name, | ||||||
| CertificateBody=str(body), | ||||||
|
|
@@ -160,6 +161,25 @@ def upload_cert(name, body, private_key, path, cert_chain=None, **kwargs): | |||||
| except botocore.exceptions.ClientError as e: | ||||||
| if e.response["Error"]["Code"] != "EntityAlreadyExists": | ||||||
| raise e | ||||||
| current_app.logger.error( | ||||||
| "Skipped IAM server-certificate upload; name already exists in account " | ||||||
| "(name=%s path=%s). Destination upload was a no-op.", | ||||||
| name, | ||||||
| path, | ||||||
| ) | ||||||
| response = None | ||||||
| outcome = "skipped_already_exists" | ||||||
|
|
||||||
| # Never let a telemetry error escape: this function is retried, and the | ||||||
| # upload above is not idempotent, so a raised metric would re-run it. | ||||||
| try: | ||||||
| metrics.send( | ||||||
| "upload_cert", "counter", 1, metric_tags={"path": path, "outcome": outcome} | ||||||
| ) | ||||||
|
Comment on lines
+176
to
+178
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.
When IAM destinations in different physical locations use the same path (commonly AGENTS.md reference: AGENTS.md:L1-L1 Useful? React with 👍 / 👎.
Author
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. Skipping this one. There's already a destination_upload counter in certificates/models.py that fires right after this upload and carries datacenter |
||||||
| except Exception: | ||||||
| current_app.logger.exception("Failed to emit upload_cert metric") | ||||||
|
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.
Suggested change
|
||||||
|
|
||||||
| return response | ||||||
|
|
||||||
|
|
||||||
| @sts_client("iam") | ||||||
|
|
||||||
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.
This means we dont have any metric coverage for exceptions outside of skipped_already_exists and success