diff --git a/pkg/scalers/prometheus_scaler.go b/pkg/scalers/prometheus_scaler.go index cb35d14dfc9..dfb6c0dbfbd 100644 --- a/pkg/scalers/prometheus_scaler.go +++ b/pkg/scalers/prometheus_scaler.go @@ -106,15 +106,6 @@ func NewPrometheusScaler(config *ScalerConfig) (Scaler, error) { httpClient.Transport = transport } } else { - awsTransport, err := NewSigV4RoundTripper(config.TriggerMetadata, httpClient.Transport) - if err != nil { - logger.V(1).Error(err, "failed to get AWS client HTTP transport ") - return nil, err - } - - if err == nil && awsTransport != nil { - httpClient.Transport = awsTransport - } // could be the case of azure managed prometheus. Try and get the round-tripper. // If it's not the case of azure managed prometheus, we will get both transport and err as nil and proceed assuming no auth. azureTransport, err := azure.TryAndGetAzureManagedPrometheusHTTPRoundTripper(logger, config.PodIdentity, config.TriggerMetadata) @@ -137,8 +128,19 @@ func NewPrometheusScaler(config *ScalerConfig) (Scaler, error) { if err == nil && gcpTransport != nil { httpClient.Transport = gcpTransport } - } + awsTransport, err := NewSigV4RoundTripper(config.TriggerMetadata, httpClient.Transport) + if err != nil { + logger.V(1).Error(err, "failed to get AWS client HTTP transport ") + return nil, err + } + + if err == nil && awsTransport != nil { + httpClient.Transport = awsTransport + logger.Info("Got AWS Transport ", nil) + } + } + logger.Info("transport is ", httpClient.Transport) return &prometheusScaler{ metricType: metricType, metadata: meta, @@ -284,6 +286,8 @@ func (s *prometheusScaler) ExecutePromQuery(ctx context.Context) (float64, error queryEscaped := url_pkg.QueryEscape(s.metadata.query) url := fmt.Sprintf("%s/api/v1/query?query=%s&time=%s", s.metadata.serverAddress, queryEscaped, t) + s.logger.Info("Prometheues URL ", url) + // set 'namespace' parameter for namespaced Prometheus requests (e.g. for Thanos Querier) if s.metadata.namespace != "" { url = fmt.Sprintf("%s&namespace=%s", url, s.metadata.namespace) @@ -315,8 +319,6 @@ func (s *prometheusScaler) ExecutePromQuery(ctx context.Context) (float64, error req.Header.Set(s.metadata.prometheusAuth.CustomAuthHeader, s.metadata.prometheusAuth.CustomAuthValue) } - //cli := &http.Client{Transport: s.httpClient.Transport} - r, err := s.httpClient.Do(req) if err != nil { return -1, err @@ -328,6 +330,8 @@ func (s *prometheusScaler) ExecutePromQuery(ctx context.Context) (float64, error } defer r.Body.Close() + s.logger.Info("Prometheues query status code ", r.StatusCode) + if !(r.StatusCode >= 200 && r.StatusCode <= 299) { err := fmt.Errorf("prometheus query api returned error. status: %d response: %s", r.StatusCode, string(b)) s.logger.Error(err, "prometheus query api returned error") @@ -381,6 +385,7 @@ func (s *prometheusScaler) ExecutePromQuery(ctx context.Context) (float64, error return -1, err } + s.logger.Info(" value ", v) return v, nil }