@@ -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
2728const (
@@ -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
3539type (
@@ -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