Skip to content
Merged
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
1 change: 0 additions & 1 deletion dev/config/api.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ primary = "unkey:password@tcp(mysql:3306)/unkey?parseTime=true"
[clickhouse]
url = "clickhouse://default:password@clickhouse:9000?secure=false&skip_verify=true"
analytics_url = "http://clickhouse:8123/default"
proxy_token = "chproxy-test-token-123"

[vault]
url = "http://vault:8060"
Expand Down
1 change: 0 additions & 1 deletion dev/k8s/manifests/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ data:
[clickhouse]
url = "clickhouse://default:password@clickhouse:9000?secure=false&skip_verify=true"
analytics_url = "http://clickhouse:8123/default"
proxy_token = "chproxy-test-token-123"

[gossip]
lan_port = 7946
Expand Down
2 changes: 1 addition & 1 deletion internal/services/keys/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ go_library(
visibility = ["//:__subpackages__"],
deps = [
"//internal/services/caches",
"//internal/services/keys/metrics",
"//internal/services/ratelimit",
"//internal/services/usagelimiter",
"//pkg/assert",
Expand All @@ -31,7 +32,6 @@ go_library(
"//pkg/hash",
"//pkg/logger",
"//pkg/otel/tracing",
"//pkg/prometheus/metrics",
"//pkg/ptr",
"//pkg/rbac",
"//pkg/zen",
Expand Down
12 changes: 12 additions & 0 deletions internal/services/keys/metrics/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@rules_go//go:def.bzl", "go_library")

go_library(
name = "metrics",
srcs = ["prometheus.go"],
importpath = "github.com/unkeyed/unkey/internal/services/keys/metrics",
visibility = ["//:__subpackages__"],
deps = [
"@com_github_prometheus_client_golang//prometheus",
"@com_github_prometheus_client_golang//prometheus/promauto",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ var (
// metrics.KeyVerificationsTotal.WithLabelValues("root_key", "VALID").Inc()
KeyVerificationsTotal = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: "unkey",
Subsystem: "key",
Name: "verifications_total",
Help: "Total number of Key verifications processed.",
ConstLabels: constLabels,
Namespace: "unkey",
Subsystem: "key",
Name: "verifications_total",
Help: "Total number of Key verifications processed.",
},
[]string{"type", "code"},
)
Expand All @@ -37,11 +36,10 @@ var (
// metrics.KeyVerificationErrorsTotal.WithLabelValues("root_key").Inc()
KeyVerificationErrorsTotal = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: "unkey",
Subsystem: "key",
Name: "verification_errors_total",
Help: "Total number of key verification errors",
ConstLabels: constLabels,
Namespace: "unkey",
Subsystem: "key",
Name: "verification_errors_total",
Help: "Total number of key verification errors",
},
[]string{"type"},
)
Expand Down
2 changes: 1 addition & 1 deletion internal/services/keys/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"context"
"time"

"github.com/unkeyed/unkey/internal/services/keys/metrics"
"github.com/unkeyed/unkey/internal/services/ratelimit"
"github.com/unkeyed/unkey/internal/services/usagelimiter"
"github.com/unkeyed/unkey/pkg/clickhouse"
"github.com/unkeyed/unkey/pkg/clickhouse/schema"
"github.com/unkeyed/unkey/pkg/db"
"github.com/unkeyed/unkey/pkg/prometheus/metrics"
"github.com/unkeyed/unkey/pkg/rbac"
"github.com/unkeyed/unkey/pkg/zen"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/services/ratelimit/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ go_library(
importpath = "github.com/unkeyed/unkey/internal/services/ratelimit",
visibility = ["//:__subpackages__"],
deps = [
"//internal/services/ratelimit/metrics",
"//pkg/assert",
"//pkg/buffer",
"//pkg/circuitbreaker",
"//pkg/clock",
"//pkg/counter",
"//pkg/logger",
"//pkg/otel/tracing",
"//pkg/prometheus/metrics",
"//pkg/repeat",
"@io_opentelemetry_go_otel//attribute",
],
Expand Down
2 changes: 1 addition & 1 deletion internal/services/ratelimit/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sync"
"time"

"github.com/unkeyed/unkey/pkg/prometheus/metrics"
"github.com/unkeyed/unkey/internal/services/ratelimit/metrics"
)

// bucket maintains rate limit state for a specific identifier+limit+duration combination.
Expand Down
2 changes: 1 addition & 1 deletion internal/services/ratelimit/janitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ratelimit
import (
"time"

"github.com/unkeyed/unkey/pkg/prometheus/metrics"
"github.com/unkeyed/unkey/internal/services/ratelimit/metrics"
"github.com/unkeyed/unkey/pkg/repeat"
)

Expand Down
12 changes: 12 additions & 0 deletions internal/services/ratelimit/metrics/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@rules_go//go:def.bzl", "go_library")

go_library(
name = "metrics",
srcs = ["prometheus.go"],
importpath = "github.com/unkeyed/unkey/internal/services/ratelimit/metrics",
visibility = ["//:__subpackages__"],
deps = [
"@com_github_prometheus_client_golang//prometheus",
"@com_github_prometheus_client_golang//prometheus/promauto",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
)

// Standard histogram buckets for latency metrics in seconds
var latencyBuckets = []float64{
0.001, // 1ms
0.002, // 2ms
0.005, // 5ms
0.01, // 10ms
0.02, // 20ms
0.05, // 50ms
0.1, // 100ms
0.2, // 200ms
0.3, // 300ms
0.4, // 400ms
0.5, // 500ms
0.75, // 750ms
1.0, // 1s
2.0, // 2s
3.0, // 3s
5.0, // 5s
10.0, // 10s
}

var (

// RatelimitBuckets tracks how many rate-limit buckets are currently active.
Expand All @@ -19,11 +40,10 @@ var (
// metrics.RatelimitBuckets.Set(float64(activeBuckets))
RatelimitBuckets = promauto.NewGauge(
prometheus.GaugeOpts{
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "buckets",
Help: "Current number of active rate-limit buckets.",
ConstLabels: constLabels,
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "buckets",
Help: "Current number of active rate-limit buckets.",
},
)

Expand All @@ -34,11 +54,10 @@ var (
// metrics.RatelimitWindows.Set(float64(activeWindows))
RatelimitWindows = promauto.NewGauge(
prometheus.GaugeOpts{
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "windows",
Help: "Current number of rate-limit windows.",
ConstLabels: constLabels,
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "windows",
Help: "Current number of rate-limit windows.",
},
)

Expand All @@ -49,11 +68,10 @@ var (
// metrics.RatelimitBucketsCreated.Inc()
RatelimitBucketsCreated = promauto.NewCounter(
prometheus.CounterOpts{
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "buckets_created_total",
Help: "Total number of rate-limit buckets created.",
ConstLabels: constLabels,
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "buckets_created_total",
Help: "Total number of rate-limit buckets created.",
},
)

Expand All @@ -64,11 +82,10 @@ var (
// metrics.RatelimitBucketsEvicted.Inc()
RatelimitBucketsEvicted = promauto.NewCounter(
prometheus.CounterOpts{
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "buckets_evicted_total",
Help: "Total number of rate-limit buckets evicted.",
ConstLabels: constLabels,
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "buckets_evicted_total",
Help: "Total number of rate-limit buckets evicted.",
},
)

Expand All @@ -79,11 +96,10 @@ var (
// metrics.RatelimitWindowsCreated.Inc()
RatelimitWindowsCreated = promauto.NewCounter(
prometheus.CounterOpts{
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "windows_created_total",
Help: "Total number of rate-limit time windows created.",
ConstLabels: constLabels,
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "windows_created_total",
Help: "Total number of rate-limit time windows created.",
},
)

Expand All @@ -94,11 +110,10 @@ var (
// metrics.RatelimitWindowsEvicted.Inc()
RatelimitWindowsEvicted = promauto.NewCounter(
prometheus.CounterOpts{
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "windows_evicted_total",
Help: "Total number of rate-limit time windows evicted.",
ConstLabels: constLabels,
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "windows_evicted_total",
Help: "Total number of rate-limit time windows evicted.",
},
)

Expand All @@ -111,11 +126,10 @@ var (
// metrics.RatelimitDecisions.WithLabelValues("origin", "denied").Inc()
RatelimitDecision = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "decisions_total",
Help: "Total number of rate-limit decisions.",
ConstLabels: constLabels,
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "decisions_total",
Help: "Total number of rate-limit decisions.",
},
[]string{"source", "outcome"},
)
Expand All @@ -127,11 +141,10 @@ var (
// metrics.RatelimitRefreshFromOrigin.Inc()
RatelimitRefreshFromOrigin = promauto.NewCounter(
prometheus.CounterOpts{
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "refresh_from_origin_total",
Help: "Total number of refreshes from an origin.",
ConstLabels: constLabels,
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "refresh_from_origin_total",
Help: "Total number of refreshes from an origin.",
},
)

Expand All @@ -145,12 +158,11 @@ var (
// defer timer.ObserveDuration()
RatelimitOriginSyncLatency = promauto.NewHistogram(
prometheus.HistogramOpts{
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "origin_sync_latency_seconds",
Help: "Histogram of origin sync latencies in seconds.",
Buckets: latencyBuckets,
ConstLabels: constLabels,
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "origin_sync_latency_seconds",
Help: "Histogram of origin sync latencies in seconds.",
Buckets: latencyBuckets,
},
)

Expand All @@ -161,11 +173,10 @@ var (
// metrics.RatelimitRefreshFromOriginErrorsTotal.Inc()
RatelimitRefreshFromOriginErrorsTotal = promauto.NewCounter(
prometheus.CounterOpts{
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "refresh_from_origin_errors_total",
Help: "Total number of errors when refreshing from an origin.",
ConstLabels: constLabels,
Namespace: "unkey",
Subsystem: "ratelimit",
Name: "refresh_from_origin_errors_total",
Help: "Total number of errors when refreshing from an origin.",
},
)
)
3 changes: 2 additions & 1 deletion internal/services/ratelimit/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"github.com/unkeyed/unkey/pkg/assert"
"github.com/unkeyed/unkey/pkg/logger"
"github.com/unkeyed/unkey/pkg/otel/tracing"
"github.com/unkeyed/unkey/pkg/prometheus/metrics"

"github.com/unkeyed/unkey/internal/services/ratelimit/metrics"
)

// replayRequests processes buffered rate limit events by synchronizing them with
Expand Down
3 changes: 2 additions & 1 deletion internal/services/ratelimit/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
"github.com/unkeyed/unkey/pkg/counter"
"github.com/unkeyed/unkey/pkg/logger"
"github.com/unkeyed/unkey/pkg/otel/tracing"
"github.com/unkeyed/unkey/pkg/prometheus/metrics"

"github.com/unkeyed/unkey/internal/services/ratelimit/metrics"
"go.opentelemetry.io/otel/attribute"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/services/ratelimit/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ratelimit
import (
"time"

"github.com/unkeyed/unkey/pkg/prometheus/metrics"
"github.com/unkeyed/unkey/internal/services/ratelimit/metrics"
)

type window struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/services/usagelimiter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ go_library(
importpath = "github.com/unkeyed/unkey/internal/services/usagelimiter",
visibility = ["//:__subpackages__"],
deps = [
"//internal/services/usagelimiter/metrics",
"//pkg/assert",
"//pkg/buffer",
"//pkg/circuitbreaker",
"//pkg/counter",
"//pkg/db",
"//pkg/logger",
"//pkg/otel/tracing",
"//pkg/prometheus/metrics",
"//pkg/repeat",
],
)
2 changes: 1 addition & 1 deletion internal/services/usagelimiter/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"database/sql"

"github.com/unkeyed/unkey/internal/services/usagelimiter/metrics"
"github.com/unkeyed/unkey/pkg/db"
"github.com/unkeyed/unkey/pkg/otel/tracing"
"github.com/unkeyed/unkey/pkg/prometheus/metrics"
)

func (s *service) Limit(ctx context.Context, req UsageRequest) (UsageResponse, error) {
Expand Down
12 changes: 12 additions & 0 deletions internal/services/usagelimiter/metrics/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@rules_go//go:def.bzl", "go_library")

go_library(
name = "metrics",
srcs = ["prometheus.go"],
importpath = "github.com/unkeyed/unkey/internal/services/usagelimiter/metrics",
visibility = ["//:__subpackages__"],
deps = [
"@com_github_prometheus_client_golang//prometheus",
"@com_github_prometheus_client_golang//prometheus/promauto",
],
)
Loading