-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metrics: allow disabling OpenMetrics negotiation (#3944)
* metrics: allow disabling OpenMetrics negotiation Signed-off-by: Dave Henderson <dhenderson@gmail.com> * fixup! metrics: allow disabling OpenMetrics negotiation
- Loading branch information
1 parent
79f3af9
commit ebc278e
Showing
7 changed files
with
292 additions
and
19 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
caddytest/integration/caddyfile_adapt/metrics_disable_om.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
:80 { | ||
metrics /metrics { | ||
disable_openmetrics | ||
} | ||
} | ||
---------- | ||
{ | ||
"apps": { | ||
"http": { | ||
"servers": { | ||
"srv0": { | ||
"listen": [ | ||
":80" | ||
], | ||
"routes": [ | ||
{ | ||
"match": [ | ||
{ | ||
"path": [ | ||
"/metrics" | ||
] | ||
} | ||
], | ||
"handle": [ | ||
{ | ||
"disable_openmetrics": true, | ||
"handler": "metrics" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
:80 { | ||
metrics /metrics | ||
} | ||
---------- | ||
{ | ||
"apps": { | ||
"http": { | ||
"servers": { | ||
"srv0": { | ||
"listen": [ | ||
":80" | ||
], | ||
"routes": [ | ||
{ | ||
"match": [ | ||
{ | ||
"path": [ | ||
"/metrics" | ||
] | ||
} | ||
], | ||
"handle": [ | ||
{ | ||
"handler": "metrics" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package metrics | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile" | ||
) | ||
|
||
func TestMetricsUnmarshalCaddyfile(t *testing.T) { | ||
m := &Metrics{} | ||
d := caddyfile.NewTestDispenser(`metrics bogus`) | ||
err := m.UnmarshalCaddyfile(d) | ||
if err == nil { | ||
t.Errorf("expected error") | ||
} | ||
|
||
m = &Metrics{} | ||
d = caddyfile.NewTestDispenser(`metrics`) | ||
err = m.UnmarshalCaddyfile(d) | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
|
||
if m.DisableOpenMetrics != false { | ||
t.Errorf("DisableOpenMetrics should've been false: %v", m.DisableOpenMetrics) | ||
} | ||
|
||
m = &Metrics{} | ||
d = caddyfile.NewTestDispenser(`metrics { disable_openmetrics }`) | ||
err = m.UnmarshalCaddyfile(d) | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
|
||
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) | ||
} | ||
} |