@@ -22,6 +22,7 @@ import (
22
22
23
23
configmap "knative.dev/pkg/configmap/parser"
24
24
pkgo11y "knative.dev/pkg/observability"
25
+ "knative.dev/pkg/observability/metrics"
25
26
)
26
27
27
28
const (
@@ -30,6 +31,9 @@ const (
30
31
31
32
// DefaultEnableSinkEventErrorReporting is used to set the default sink event error reporting value
32
33
DefaultEnableSinkEventErrorReporting = false
34
+
35
+ // DefaultMetricsPort is the default port used for prometheus metrics if the prometheus protocol is used
36
+ DefaultMetricsPort = 9092
33
37
)
34
38
35
39
type (
@@ -65,6 +69,11 @@ func NewFromMap(m map[string]string) (*Config, error) {
65
69
c .BaseConfig = * cfg
66
70
}
67
71
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
+
68
77
err := configmap .Parse (m , configmap .As (EnableSinkEventErrorReportingKey , & c .EnableSinkEventErrorReporting ))
69
78
if err != nil {
70
79
fmt .Printf ("failed to parse enable-sink-error-reporting: %s\n " , err .Error ())
@@ -99,6 +108,11 @@ func MergeWithDefaults(cfg *Config) *Config {
99
108
cfg .Metrics = d .Metrics
100
109
}
101
110
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
+
102
116
var emptyRuntime RuntimeConfig
103
117
if cfg .Runtime == emptyRuntime {
104
118
cfg .Runtime = d .Runtime
0 commit comments