Skip to content

fix: use less expensive prometheus labels#3572

Merged
chronark merged 1 commit intomainfrom
key_verification_prometheus
Jul 16, 2025
Merged

fix: use less expensive prometheus labels#3572
chronark merged 1 commit intomainfrom
key_verification_prometheus

Conversation

@chronark
Copy link
Collaborator

@chronark chronark commented Jul 15, 2025

This replaces the high-cardinality labels with just a key_type and outcome

Summary by CodeRabbit

  • Refactor
    • Simplified Prometheus metrics for key verifications by reducing the number of labels and updating label names and documentation. The metrics now use only "type" and "code" as labels, making monitoring and analysis more straightforward.

@vercel
Copy link

vercel bot commented Jul 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 15, 2025 5:03pm
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 15, 2025 5:03pm

@changeset-bot
Copy link

changeset-bot bot commented Jul 15, 2025

⚠️ No Changeset found

Latest commit: db7f923

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 15, 2025

📝 Walkthrough

Walkthrough

The changes simplify the Prometheus metric for key verifications by reducing its label set from five to two: "type" (indicating "root_key" or "key") and "code" (the key's status). The code and documentation are updated to reflect this new labeling scheme, removing references to workspace, API, key IDs, and validity booleans.

Changes

File(s) Change Summary
go/internal/services/keys/verifier.go Refactored metric emission in the Verify method to use only "type" and "code" labels; removed "strconv".
go/pkg/prometheus/metrics/keys.go Changed KeyVerificationsTotal metric to use "type" and "code" labels; updated documentation and examples.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant KeyVerifier
    participant Prometheus

    Client->>KeyVerifier: Verify(key)
    KeyVerifier->>Prometheus: Increment KeyVerificationsTotal(type, code)
    KeyVerifier-->>Client: Return verification result
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 79c1648 and db7f923.

📒 Files selected for processing (2)
  • go/internal/services/keys/verifier.go (1 hunks)
  • go/pkg/prometheus/metrics/keys.go (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
go/internal/services/keys/verifier.go (1)
Learnt from: chronark
PR: unkeyed/unkey#2294
File: apps/api/src/pkg/keys/service.ts:268-271
Timestamp: 2024-10-20T07:05:55.471Z
Learning: In `apps/api/src/pkg/keys/service.ts`, `ratelimitAsync` is a table relation, not a column selection. When querying, ensure that table relations are included appropriately, not as columns.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Test Agent Local / test_agent_local
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Test Go API Local / Test (Shard )
  • GitHub Check: Build / Build
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Test Packages / Test ./packages/nextjs
  • GitHub Check: Test Packages / Test ./internal/keys
  • GitHub Check: Test Packages / Test ./internal/clickhouse
  • GitHub Check: Test Packages / Test ./internal/resend
  • GitHub Check: Test Packages / Test ./packages/cache
🔇 Additional comments (4)
go/pkg/prometheus/metrics/keys.go (2)

14-19: Documentation and example usage correctly updated.

The documentation clearly explains the new label schema and the example usage is properly aligned with the simplified labels.


27-27: Verify external monitoring for metric label change

  • go/pkg/prometheus/metrics/keys.go (line 27): label list reduced from
    - []string{"workspaceId", "apiId", "keyId", "type", "code"},
    + []string{"type", "code"},
  • go/internal/services/keys/verifier.go: call to
    metrics.KeyVerificationsTotal.WithLabelValues(type, code) now matches the new 2-label schema.
  • No other internal references to the old 5-label counter were found.

Please update or document any Prometheus queries, dashboards, alert rules or automation that depended on workspaceId, apiId or keyId labels. Consider adding a migration guide or transitional period in your release notes to help teams adapt.

go/internal/services/keys/verifier.go (2)

118-121: Clean implementation of key type determination.

The logic correctly maps k.isRootKey to the appropriate string value for the "type" label, maintaining consistency with the metric definition.


123-126: Metric emission correctly updated to match new schema.

The metric emission now uses only the two simplified labels (keyType and string(k.Status)), which aligns perfectly with the updated metric definition in keys.go. This change will reduce metric cardinality and improve performance as intended.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 15, 2025

Thank you for following the naming conventions for pull request titles! 🙏

@chronark chronark enabled auto-merge July 15, 2025 17:03
@vercel vercel bot temporarily deployed to Preview – engineering July 15, 2025 17:03 Inactive
@vercel vercel bot temporarily deployed to Preview – dashboard July 15, 2025 17:03 Inactive
@graphite-app
Copy link

graphite-app bot commented Jul 15, 2025

Movie gif. Joaquin Phoenix as Commodus from Gladiator doesn't look happy as he holds out his hand, but gradually looks calmer as he slowly gives us a thumbs up. (Added via Giphy)

@graphite-app
Copy link

graphite-app bot commented Jul 15, 2025

Graphite Automations

"Post a GIF when PR approved" took an action on this PR • (07/15/25)

1 gif was posted to this PR based on Andreas Thomas's automation.

@chronark chronark disabled auto-merge July 16, 2025 07:43
@chronark chronark merged commit 01c5137 into main Jul 16, 2025
31 of 33 checks passed
@chronark chronark deleted the key_verification_prometheus branch July 16, 2025 07:43
@coderabbitai coderabbitai bot mentioned this pull request Jul 16, 2025
16 tasks
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