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

prometheus: add support for prometheus.io/scheme #22628 #25163

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 13 additions & 5 deletions comp/core/autodiscovery/common/types/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ import (

const (
// Default openmetrics check configuration values
openmetricsURLPrefix = "http://%%host%%:"
openmetricsDefaultPort = "%%port%%"
openmetricsDefaultPath = "/metrics"
openmetricsDefaultNS = ""
openmetricsURLInfix = "://%%host%%:"
openmetricsDefaultScheme = "http"
openmetricsDefaultPort = "%%port%%"
openmetricsDefaultPath = "/metrics"
openmetricsDefaultNS = ""

// PrometheusScrapeAnnotation standard Prometheus scrape annotation key
PrometheusScrapeAnnotation = "prometheus.io/scrape"
// PrometheusPathAnnotation standard Prometheus path annotation key
PrometheusPathAnnotation = "prometheus.io/path"
// PrometheusPortAnnotation standard Prometheus port annotation key
PrometheusPortAnnotation = "prometheus.io/port"
// PrometheusSchemeAnnotation standard Prometheus scheme annotation key
PrometheusSchemeAnnotation = "prometheus.io/scheme"
)

var (
Expand Down Expand Up @@ -336,7 +339,12 @@ func BuildURL(annotations map[string]string) string {
path = pathFromAnnotation
}

return openmetricsURLPrefix + port + path
scheme := openmetricsDefaultScheme
if schemeFromAnnotation, found := annotations[PrometheusSchemeAnnotation]; found {
scheme = schemeFromAnnotation
}

return scheme + openmetricsURLInfix + port + path
}

// PrometheusAnnotations abstracts a map of prometheus annotations
Expand Down