Skip to content

Commit

Permalink
fixup! metrics: allow disabling OpenMetrics negotiation
Browse files Browse the repository at this point in the history
  • Loading branch information
hairyhenderson committed Dec 30, 2020
1 parent 3ad5c33 commit 134ca8a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion modules/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)

// UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:
//
// metrics <matcher> {
// metrics [<matcher>] {
// disable_openmetrics
// }
//
Expand All @@ -90,6 +90,8 @@ func (m *Metrics) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
switch d.Val() {
case "disable_openmetrics":
m.DisableOpenMetrics = true
default:
return d.Errf("unrecognized subdirective %q", d.Val())
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions modules/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ func TestMetricsUnmarshalCaddyfile(t *testing.T) {
if m.DisableOpenMetrics != true {
t.Errorf("DisableOpenMetrics should've been true: %v", m.DisableOpenMetrics)
}

m = &Metrics{}
d = caddyfile.NewTestDispenser(`metrics { bogus }`)
err = m.UnmarshalCaddyfile(d)
if err == nil {
t.Errorf("expected error: %v", err)
}
}

0 comments on commit 134ca8a

Please sign in to comment.