Skip to content

Client logging and metrics#60

Open
piceri wants to merge 5 commits intomainfrom
client-logging-and-metrics
Open

Client logging and metrics#60
piceri wants to merge 5 commits intomainfrom
client-logging-and-metrics

Conversation

@piceri
Copy link
Contributor

@piceri piceri commented Mar 16, 2026

This change:

  • Changes not_saved metric to no_attestation
  • Adds rate_limited metric
  • Document new metrics in README
  • Refactor client logging to better handle rate limiting and 404s for no artifact found
  • Add tests for PostOne

@piceri piceri marked this pull request as ready for review March 16, 2026 21:28
@piceri piceri requested a review from a team as a code owner March 16, 2026 21:28
Copilot AI review requested due to automatic review settings March 16, 2026 21:28
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the deployment record client’s observability and behavior around GitHub API responses (rate limiting and “no artifacts found”), including new Prometheus metrics and expanded PostOne test coverage.

Changes:

  • Add new Prometheus counters for no_attestation and rate_limited outcomes.
  • Refactor PostOne response handling/logging to distinguish rate limiting and “no artifacts found” 404s.
  • Add comprehensive PostOne unit tests and document the new metrics in the README.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
pkg/dtmetrics/prom.go Adds new counters for no_attestation and rate_limited.
pkg/deploymentrecord/client.go Introduces NoArtifactError and refines retry/logging logic for 4xx/5xx, including rate-limited detection.
pkg/deploymentrecord/client_test.go Adds table-driven tests validating PostOne behavior and metric deltas across outcomes.
internal/controller/controller.go Treats NoArtifactError as non-fatal (no requeue) when posting records.
README.md Documents the newly added metrics.
go.mod Adds an indirect dependency entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +281 to +291
if resp.Header.Get("retry-after") != "" || resp.Header.Get("x-ratelimit-remaining") == "0" {
// rate limited — retry with backoff
// Could be 403 or 429
dtmetrics.PostDeploymentRecordRateLimited.Inc()
slog.Warn("rate limited, retrying",
"attempt", attempt,
"status_code", resp.StatusCode,
"retry_after", resp.Header.Get("Retry-After"),
"container_name", record.Name,
"resp_msg", string(respBody),
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will handle this in a seperate change

// (rate limit)
if resp.StatusCode >= 400 && resp.StatusCode < 500 && resp.StatusCode != 429 {
switch {
case resp.StatusCode == 404 && bytes.Contains(respBody, []byte("no artifacts found")):

Choose a reason for hiding this comment

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

In case the error message changes from "no artifacts found", what do you think of flipping the logic a bit so if-else logic branch ordering is as follows:

  • check if the status code >= 400 and < 500
  • check whether the response includes the rate limiting headers
  • check if the response status code is specifically 404

Or alternatively just dropping the bytes.Contains(respBody, []byte("no artifacts found")) check?

wantClientError: 1,
},
{
name: "400 returns ClientError",

Choose a reason for hiding this comment

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

We could also throw in a case for 422 responses when the request body is invalid.

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.

3 participants