Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions lemur/plugins/lemur_aws/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import botocore

from flask import current_app
from retrying import retry
from sentry_sdk import capture_exception

Expand Down Expand Up @@ -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),
Expand All @@ -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
Comment on lines 161 to 163

Copy link
Copy Markdown

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Tag upload outcomes with their destination datacenter

When IAM destinations in different physical locations use the same path (commonly /), these new success/skip series are aggregated because the metric includes only path and outcome; in particular, a skipped upload cannot be associated with the affected datacenter. Thread the destination description through AWSDestinationPlugin.upload and add its datacenter value as required for metrics describing certificate deployments.

AGENTS.md reference: AGENTS.md:L1-L1

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
current_app.logger.exception("Failed to emit upload_cert metric")
current_app.logger.exception(f"Failed to emit upload_cert metric, path: {path}, outcome {outcome}")


return response


@sts_client("iam")
Expand Down
Loading