mirror of
https://github.com/coder/coder.git
synced 2026-06-03 21:18:24 +00:00
9f6ce7542a
## Description Adds Prometheus metrics to the AI Bridge Proxy for observability into proxy traffic and performance. ## Changes * Add Metrics struct with the following metrics: * `connect_sessions_total`: counts CONNECT sessions by type (mitm/tunneled) * `mitm_requests_total`: counts MITM requests by provider * `inflight_mitm_requests`: gauge tracking in-flight requests by provider * `mitm_request_duration_seconds`: histogram of request latencies by provider * `mitm_responses_total`: counts responses by status code class (2XX/3XX/4XX/5XX) and provider * Register metrics with `coder_aibridgeproxyd_` prefix in CLI * Unregister metrics on server close to prevent registry leaks * Add `tunneledMiddleware` to track non-allowlisted CONNECT sessions * Add tests for metric recording in both MITM and tunneled paths Closes: https://github.com/coder/internal/issues/1185
40 lines
1.4 KiB
Go
40 lines
1.4 KiB
Go
//go:build !slim
|
|
|
|
package cli
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/coder/coder/v2/enterprise/aibridgeproxyd"
|
|
"github.com/coder/coder/v2/enterprise/coderd"
|
|
)
|
|
|
|
func newAIBridgeProxyDaemon(coderAPI *coderd.API) (*aibridgeproxyd.Server, error) {
|
|
ctx := context.Background()
|
|
coderAPI.Logger.Debug(ctx, "starting in-memory aibridgeproxy daemon")
|
|
|
|
logger := coderAPI.Logger.Named("aibridgeproxyd")
|
|
|
|
reg := prometheus.WrapRegistererWithPrefix("coder_aibridgeproxyd_", coderAPI.PrometheusRegistry)
|
|
metrics := aibridgeproxyd.NewMetrics(reg)
|
|
|
|
srv, err := aibridgeproxyd.New(ctx, logger, aibridgeproxyd.Options{
|
|
ListenAddr: coderAPI.DeploymentValues.AI.BridgeProxyConfig.ListenAddr.String(),
|
|
CoderAccessURL: coderAPI.AccessURL.String(),
|
|
CertFile: coderAPI.DeploymentValues.AI.BridgeProxyConfig.CertFile.String(),
|
|
KeyFile: coderAPI.DeploymentValues.AI.BridgeProxyConfig.KeyFile.String(),
|
|
DomainAllowlist: coderAPI.DeploymentValues.AI.BridgeProxyConfig.DomainAllowlist.Value(),
|
|
UpstreamProxy: coderAPI.DeploymentValues.AI.BridgeProxyConfig.UpstreamProxy.String(),
|
|
UpstreamProxyCA: coderAPI.DeploymentValues.AI.BridgeProxyConfig.UpstreamProxyCA.String(),
|
|
Metrics: metrics,
|
|
})
|
|
if err != nil {
|
|
return nil, xerrors.Errorf("failed to start in-memory aibridgeproxy daemon: %w", err)
|
|
}
|
|
|
|
return srv, nil
|
|
}
|