Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy: support configurable metrics #3027

Merged
merged 1 commit into from
Apr 22, 2024
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
9 changes: 4 additions & 5 deletions proxy/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zalando/skipper/filters/builtin"
"github.com/zalando/skipper/metrics"
"github.com/zalando/skipper/metrics/metricstest"
"github.com/zalando/skipper/proxy"
"github.com/zalando/skipper/proxy/proxytest"
"github.com/zalando/skipper/routing"
"github.com/zalando/skipper/routing/testdataclient"
)

func TestMetricsUncompressed(t *testing.T) {
dm := metrics.Default
t.Cleanup(func() { metrics.Default = dm })

m := &metricstest.MockMetrics{}
metrics.Default = m

// will update routes after proxy address is known
dc := testdataclient.New(nil)
Expand All @@ -32,6 +28,9 @@ func TestMetricsUncompressed(t *testing.T) {
FilterRegistry: builtin.MakeRegistry(),
DataClients: []routing.DataClient{dc},
},
ProxyParams: proxy.Params{
Metrics: m,
},
}.Create()
defer p.Close()

Expand Down
10 changes: 9 additions & 1 deletion proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ type Params struct {
// Control flags. See the Flags values.
Flags Flags

// Metrics collector.
// If not specified proxy uses global metrics.Default.
Metrics metrics.Metrics

// And optional list of priority routes to be used for matching
// before the general lookup tree.
PriorityRoutes []PriorityRoute
Expand Down Expand Up @@ -766,7 +770,11 @@ func WithParams(p Params) *Proxy {
}
}

m := metrics.Default
m := p.Metrics
if m == nil {
m = metrics.Default
}

if p.Flags.Debug() {
m = metrics.Void
}
Expand Down
11 changes: 6 additions & 5 deletions skipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1309,9 +1309,8 @@ func listenAndServeQuit(
}

if o.EnableConnMetricsServer {
m := metrics.Default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: why were metrics.Default and mtr were mixed in this function at all?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷

srv.ConnState = func(conn net.Conn, state http.ConnState) {
m.IncCounter(fmt.Sprintf("lb-conn-%s", state))
mtr.IncCounter(fmt.Sprintf("lb-conn-%s", state))
}
}

Expand Down Expand Up @@ -1521,6 +1520,7 @@ func run(o Options, sig chan os.Signal, idleConnsCH chan struct{}) error {
if mtr == nil {
mtr = metrics.NewMetrics(mtrOpts)
}
// set global instance for backwards compatibility
metrics.Default = mtr

// *DEPRECATED* client tracking parameter
Expand Down Expand Up @@ -2010,10 +2010,8 @@ func run(o Options, sig chan os.Signal, idleConnsCH chan struct{}) error {
proxyFlags := proxy.Flags(o.ProxyOptions) | o.ProxyFlags
proxyParams := proxy.Params{
Routing: routing,
EndpointRegistry: endpointRegistry,
EnablePassiveHealthCheck: passiveHealthCheckEnabled,
PassiveHealthCheck: passiveHealthCheck,
Flags: proxyFlags,
Metrics: mtr,
PriorityRoutes: o.PriorityRoutes,
IdleConnectionsPerHost: o.IdleConnectionsPerHost,
CloseIdleConnsPeriod: o.CloseIdleConnsPeriod,
Expand All @@ -2034,6 +2032,9 @@ func run(o Options, sig chan os.Signal, idleConnsCH chan struct{}) error {
ClientTLS: o.ClientTLS,
CustomHttpRoundTripperWrap: o.CustomHttpRoundTripperWrap,
RateLimiters: ratelimitRegistry,
EndpointRegistry: endpointRegistry,
EnablePassiveHealthCheck: passiveHealthCheckEnabled,
PassiveHealthCheck: passiveHealthCheck,
}

if o.EnableBreakers || len(o.BreakerSettings) > 0 {
Expand Down
Loading