Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on:
push:
branches: [main]

permissions:
contents: read

concurrency:
group: deploy
cancel-in-progress: false
Expand Down
10 changes: 5 additions & 5 deletions go/internal/services/keys/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keys

import (
"context"
"strconv"
"time"

"github.com/unkeyed/unkey/go/internal/services/ratelimit"
Expand Down Expand Up @@ -116,12 +115,13 @@ func (k *KeyVerifier) Verify(ctx context.Context, opts ...VerifyOption) error {
Tags: config.tags,
})

keyType := "key"
if k.isRootKey {
keyType = "root_key"
}
// Emit Prometheus metrics for key verification
metrics.KeyVerificationsTotal.WithLabelValues(
k.AuthorizedWorkspaceID, // workspaceId
k.Key.ApiID, // apiId
k.Key.ID, // keyId
strconv.FormatBool(k.Status == StatusValid), // valid
keyType,
string(k.Status), // code
).Inc()

Expand Down
7 changes: 4 additions & 3 deletions go/pkg/prometheus/metrics/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ import (
)

var (
// KeyVerificationsTotal tracks the number of key verifications handled, labeled by some data.
// KeyVerificationsTotal tracks the number of key verifications handled, labeled by type and outcome.
// The type should be either "root_key" or "key"
// Use this counter to monitor API traffic patterns and error rates.
//
// Example usage:
// metrics.KeyVerificationsTotal.WithLabelValues("ws_1234", "api_5678", "key_abcd", "true", "VALID").Inc()
// metrics.KeyVerificationsTotal.WithLabelValues("root_key", "VALID").Inc()
KeyVerificationsTotal = promauto.NewCounterVec(
prometheus.CounterOpts{
Subsystem: "key",
Name: "verifications_total",
Help: "Total number of Key verifications processed.",
ConstLabels: constLabels,
},
[]string{"workspaceId", "apiId", "keyId", "valid", "code"},
[]string{"type", "code"},
)

// KeyCreditsSpentTotal tracks the total credits spent by keys, labeled by workspace ID, key ID, and identity ID.
Expand Down
Loading