Thanks to visit codestin.com
Credit goes to github.com

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
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ endif
examples/examples.gen.json \
docs/manifest.json \
docs/admin/integrations/prometheus.md \
docs/ai-coder/ai-gateway/monitoring.md \
docs/admin/security/audit-logs.md \
docs/admin/setup/configuration-reference.md \
docs/reference/cli/index.md \
Expand Down Expand Up @@ -1015,6 +1016,7 @@ GEN_FILES := \
coderd/rbac/scopes_constants_gen.go \
codersdk/apikey_scopes_gen.go \
docs/admin/integrations/prometheus.md \
docs/ai-coder/ai-gateway/monitoring.md \
docs/reference/cli/index.md \
docs/admin/security/audit-logs.md \
docs/install/releases/feature-stages.md \
Expand Down Expand Up @@ -1114,6 +1116,7 @@ gen/mark-fresh:
site/src/api/countriesGenerated.ts \
site/src/api/chatModelOptionsGenerated.json \
docs/admin/integrations/prometheus.md \
docs/ai-coder/ai-gateway/monitoring.md \
docs/reference/cli/index.md \
docs/admin/security/audit-logs.md \
docs/install/releases/feature-stages.md \
Expand Down Expand Up @@ -1330,7 +1333,17 @@ scripts/metricsdocgen/generated_metrics: $(GO_SRC_FILES) | _gen _gen/bin/metrics

docs/admin/integrations/prometheus.md: node_modules/.installed scripts/metricsdocgen/main.go scripts/metricsdocgen/metrics scripts/metricsdocgen/generated_metrics | _gen _gen/bin/metricsdocgen
tmpdir=$$(mktemp -d -p _gen) && tmpfile=$$(realpath "$$tmpdir")/$(notdir $@) && cp "$@" "$$tmpfile" && \
_gen/bin/metricsdocgen --prometheus-doc-file="$$tmpfile" && \
_gen/bin/metricsdocgen --doc-file="$$tmpfile" --doc-target="$@" && \
pnpm exec markdownlint-cli2 --fix "$$tmpfile" && \
pnpm exec markdown-table-formatter "$$tmpfile" && \
mv "$$tmpfile" "$@" && rm -rf "$$tmpdir"

docs/ai-coder/ai-gateway/monitoring.md: node_modules/.installed scripts/metricsdocgen/main.go scripts/metricsdocgen/metrics scripts/metricsdocgen/generated_metrics | _gen _gen/bin/metricsdocgen
Comment thread
pawbana marked this conversation as resolved.
tmpdir=$$(mktemp -d -p _gen) && tmpfile=$$(realpath "$$tmpdir")/$(notdir $@) && cp "$@" "$$tmpfile" && \
_gen/bin/metricsdocgen --doc-file="$$tmpfile" --doc-target="$@" \
--section='common=prefix:coder_ai_gateway_,!coder_ai_gateway_cost_control_,!coder_ai_gateway_proxy_' \
--section='cost-control=prefix:coder_ai_gateway_cost_control_' \
--section='proxy=prefix:coder_ai_gateway_proxy_' && \
pnpm exec markdownlint-cli2 --fix "$$tmpfile" && \
pnpm exec markdown-table-formatter "$$tmpfile" && \
mv "$$tmpfile" "$@" && rm -rf "$$tmpdir"
Expand Down
8 changes: 5 additions & 3 deletions aibridge/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
var baseLabels = []string{"provider", "model"}

const (
// PrometheusMetricPrefix is the canonical prefix applied to every metric
// defined in this package. The registration wiring wraps the registerer
// with it, so the metric options below omit it.
PrometheusMetricPrefix = "coder_ai_gateway_"

InterceptionCountStatusFailed = "failed"
Expand Down Expand Up @@ -69,9 +72,8 @@ func NewMetrics(reg prometheus.Registerer) *Metrics {
InterceptionDuration: promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{
Subsystem: "interceptions",
Name: "duration_seconds",
Help: "The total duration of intercepted requests, in seconds. " +
"The majority of this time will be the upstream processing of the request. " +
"AI Gateway has no control over upstream processing time, so it's just an illustrative metric.",
Help: "The total time each intercepted request spent inside AI Gateway, in seconds. " +
"Dominated by upstream provider latency; use distributed tracing spans to isolate AI Gateway's own overhead.",
// TODO: add docs around determining aibridge's *own* latency with distributed traces
// once https://github.com/coder/aibridge/issues/26 lands.
Buckets: []float64{0.5, 2, 5, 15, 30, 60, 120},
Expand Down
2 changes: 1 addition & 1 deletion cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
// https://linear.app/codercom/issue/AIGOV-447/remove-legacy-ai-gateway-metric-aliases
aibridgeReg := prometheusmetrics.NewMetricAliasRegisterer(coderAPI.PrometheusRegistry, aibridgemetrics.PrometheusMetricPrefix, "coder_aibridged_")
aibridgeMetrics := aibridge.NewMetrics(aibridgeReg)
costControlReg := prometheus.WrapRegistererWithPrefix("coder_ai_gateway_", coderAPI.PrometheusRegistry)
costControlReg := prometheus.WrapRegistererWithPrefix(aibridgemetrics.PrometheusMetricPrefix, coderAPI.PrometheusRegistry)
coderAPI.AIGatewayServerMetrics = aibridgedserver.NewMetrics(costControlReg)
if vals.Prometheus.Enable {
budgetPeriod := codersdk.NewAIBudgetPeriodFromString(vals.AI.BridgeConfig.BudgetPeriod)
Expand Down
3 changes: 2 additions & 1 deletion coderd/aibridgedserver/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func NewMetrics(reg prometheus.Registerer) *Metrics {
Subsystem: "cost_control",
Name: "unpriced_token_usage_records_total",
Help: "The number of recorded AI token-usage records for which no (provider_type, model) price was found. " +
"provider is the provider instance name, and provider_type is its configured type.",
"provider is the provider instance name, and provider_type is its configured type, " +
"or unknown when the provider could not be resolved.",
}, []string{"provider", "provider_type", "model"}),
// Pessimistic cardinality: 3 outcomes, 8 buckets + 3 extra series
// (count, sum, +Inf) = up to 33.
Expand Down
Loading
Loading