Skip to content

Commit c1ca4fa

Browse files
[release-1.19] fix: metrics with prometheus default to same port as before (#8670)
* fix: metrics with prometheus default to same port as before Signed-off-by: Calum Murray <[email protected]> * fix: spell overridden correctly in comments Signed-off-by: Calum Murray <[email protected]> --------- Signed-off-by: Calum Murray <[email protected]> Co-authored-by: Calum Murray <[email protected]>
1 parent 8a4f284 commit c1ca4fa

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/observability/config.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
configmap "knative.dev/pkg/configmap/parser"
2424
pkgo11y "knative.dev/pkg/observability"
25+
"knative.dev/pkg/observability/metrics"
2526
)
2627

2728
const (
@@ -30,6 +31,9 @@ const (
3031

3132
// DefaultEnableSinkEventErrorReporting is used to set the default sink event error reporting value
3233
DefaultEnableSinkEventErrorReporting = false
34+
35+
// DefaultMetricsPort is the default port used for prometheus metrics if the prometheus protocol is used
36+
DefaultMetricsPort = 9092
3337
)
3438

3539
type (
@@ -65,6 +69,11 @@ func NewFromMap(m map[string]string) (*Config, error) {
6569
c.BaseConfig = *cfg
6670
}
6771

72+
// Force the port to the default queue user metrics port if it's not overridden
73+
if c.BaseConfig.Metrics.Protocol == metrics.ProtocolPrometheus && c.BaseConfig.Metrics.Endpoint == "" {
74+
c.BaseConfig.Metrics.Endpoint = fmt.Sprintf(":%d", DefaultMetricsPort)
75+
}
76+
6877
err := configmap.Parse(m, configmap.As(EnableSinkEventErrorReportingKey, &c.EnableSinkEventErrorReporting))
6978
if err != nil {
7079
fmt.Printf("failed to parse enable-sink-error-reporting: %s\n", err.Error())
@@ -99,6 +108,11 @@ func MergeWithDefaults(cfg *Config) *Config {
99108
cfg.Metrics = d.Metrics
100109
}
101110

111+
// Force the port to the default queue user metrics port if it's not overridden
112+
if cfg.BaseConfig.Metrics.Protocol == metrics.ProtocolPrometheus && cfg.BaseConfig.Metrics.Endpoint == "" {
113+
cfg.BaseConfig.Metrics.Endpoint = fmt.Sprintf(":%d", DefaultMetricsPort)
114+
}
115+
102116
var emptyRuntime RuntimeConfig
103117
if cfg.Runtime == emptyRuntime {
104118
cfg.Runtime = d.Runtime

0 commit comments

Comments
 (0)