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

Add accept header check for prometheus mime type #7958

Merged
merged 2 commits into from
Dec 11, 2019
Merged
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion helper/metricsutil/metricsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
const (
OpenMetricsMIMEType = "application/openmetrics-text"

PrometheusSchemaMIMEType = "prometheus/telemetry"
Copy link
Contributor

Choose a reason for hiding this comment

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

This was added, but doesn't seem to be used anywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Fixed


// ErrorContentType is the content type returned by an error response.
ErrorContentType = "text/plain"
)
Expand All @@ -38,7 +40,14 @@ func FormatFromRequest(req *logical.Request) string {
if len(acceptHeaders) > 0 {
acceptHeader := acceptHeaders[0]
if strings.HasPrefix(acceptHeader, OpenMetricsMIMEType) {
return "prometheus"
return PrometheusMetricFormat
}

// Look for prometheus accept header
for _, header := range acceptHeaders {
if strings.Contains(header, PrometheusMetricFormat) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Guessing that this should be PrometheusSchemaMIMEType here? Also can we add a test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return PrometheusMetricFormat
}
}
}
return ""
Expand Down