@@ -45,8 +45,10 @@ type DataSource struct {
4545 extractors sync.Map // key: name, value: extractor
4646}
4747
48- // NewDataSource returns a new MSP compliant metrics data source, configured with the provided
49- // client factory. If ClientFactory is nil, a default factory is used.
48+ // NewDataSource returns a new MSP compliant metrics data source, configured with
49+ // the provided client factory. If ClientFactory is nil, a default factory is used.
50+ // The Scheme, port and path are command line options. It should be noted that
51+ // a port value of zero is set if the command line is unspecified.
5052func NewDataSource (metricsScheme string , metricsPort int32 , metricsPath string , skipCertVerification bool , cl Client ) * DataSource {
5153 if metricsScheme == "https" {
5254 httpsTransport := baseTransport .Clone ()
@@ -70,9 +72,18 @@ func NewDataSource(metricsScheme string, metricsPort int32, metricsPath string,
7072}
7173
7274// SetPort updates the port used for metrics scraping.
75+ // The port value can only be set once (i.e., if set by command line,
76+ // do not overwrite from Pool.Spec). A port value of 0 (i.e., unspecified
77+ // command line value) is ignored.
78+ // TODO: https://github.com/kubernetes-sigs/gateway-api-inference-extension/issues/1398
7379func (dataSrc * DataSource ) SetPort (metricsPort int32 ) {
74- port := strconv .Itoa (int (metricsPort ))
75- dataSrc .metricsPort .Store (& port )
80+ if dataSrc .metricsPort .Load () != nil { // do not overwrite
81+ return
82+ }
83+ if metricsPort != 0 { // ignore zero value for port
84+ port := strconv .Itoa (int (metricsPort ))
85+ dataSrc .metricsPort .Store (& port )
86+ }
7687}
7788
7889// Name returns the metrics data source name.
0 commit comments