From 97087e18a0f89e78f2b0093b9808afc429254e35 Mon Sep 17 00:00:00 2001 From: Mary Strodl Date: Tue, 6 Feb 2024 19:50:04 -0500 Subject: [PATCH] prometheus: add support for scheme --- pkg/autodiscovery/common/types/prometheus.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/pkg/autodiscovery/common/types/prometheus.go b/pkg/autodiscovery/common/types/prometheus.go index cc8c24b90772f..98b7440f8451b 100644 --- a/pkg/autodiscovery/common/types/prometheus.go +++ b/pkg/autodiscovery/common/types/prometheus.go @@ -17,10 +17,11 @@ 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" @@ -28,6 +29,8 @@ const ( 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 ( @@ -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