Skip to content

Add outcome tag to upload_cert and log skipped IAM cert uploads - #364

Open
maperu wants to merge 1 commit into
masterfrom
maperu/iamUploadLog
Open

Add outcome tag to upload_cert and log skipped IAM cert uploads#364
maperu wants to merge 1 commit into
masterfrom
maperu/iamUploadLog

Conversation

@maperu

@maperu maperu commented Aug 13, 2026

Copy link
Copy Markdown

When a certificate is shared between a CloudFront destination (uploaded to IAM under /cloudfront/) and a plain IAM destination (uploaded under /), the second upload hits EntityAlreadyExists because IAM server-certificate names are unique per account regardless of path. upload_cert caught that error and returned silently, so the skipped destination upload left no log line and no distinct metric. That is exactly the shape behind CLOUDR-2050, and there was no telemetry to notice it happening.

This adds a warning log on that branch so the no-op shows up in the logs with the cert name and path.

It also reshapes the existing upload_cert counter instead of adding a parallel metric. The old emit fired before the upload with a high-cardinality name tag (per cert, so unqueryable in Datadog) and could not distinguish a success from a skip. Now the metric emits once the outcome is known, with the name tag dropped and a low-cardinality outcome tag added (success or skipped_already_exists), keeping path. I checked the Lemur dashboard and the Lemur monitors: nothing references lemur.upload_cert or its name tag, so reshaping it is safe.

@maperu
maperu force-pushed the maperu/iamUploadLog branch from 61dcae8 to 2de8726 Compare August 13, 2026 20:42
@maperu maperu changed the title Log and emit a metric when an IAM server-cert upload is skipped Add outcome tag to upload_cert and log skipped IAM cert uploads Aug 13, 2026
@maperu
maperu marked this pull request as ready for review August 13, 2026 20:53
@maperu
maperu requested review from a team as code owners August 13, 2026 20:53
@maperu

maperu commented Aug 13, 2026

Copy link
Copy Markdown
Author

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2de8726d65

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lemur/plugins/lemur_aws/iam.py Outdated
IAM server-certificate names are unique per account regardless of path,
so a cert shared between a CloudFront destination (/cloudfront/) and an
IAM destination (/) collides on the second upload with EntityAlreadyExists,
which upload_cert swallowed silently. Log an error and record the outcome
on that path so the no-op is observable.

Reshape the existing upload_cert counter: drop the high-cardinality name
tag (unqueryable in Datadog) and add a low-cardinality outcome tag
(success / skipped_already_exists), emitted once the result is known. The
emit is wrapped so a telemetry error can never escape into the @Retry
wrapper and re-run the non-idempotent upload. No dashboard or monitor
references the old tag shape.
@maperu
maperu force-pushed the maperu/iamUploadLog branch from 2de8726 to cb68f33 Compare August 13, 2026 21:08
@maperu

maperu commented Aug 13, 2026

Copy link
Copy Markdown
Author

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cb68f3373c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +176 to +178
metrics.send(
"upload_cert", "counter", 1, metric_tags={"path": path, "outcome": outcome}
)

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

"upload_cert", "counter", 1, metric_tags={"path": path, "outcome": outcome}
)
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}")

Comment on lines 161 to 163
except botocore.exceptions.ClientError as e:
if e.response["Error"]["Code"] != "EntityAlreadyExists":
raise e

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants