diff --git a/plugins/inputs/prometheus/prometheus.go b/plugins/inputs/prometheus/prometheus.go index 5b5ac6e4b..c7b5cfbaa 100644 --- a/plugins/inputs/prometheus/prometheus.go +++ b/plugins/inputs/prometheus/prometheus.go @@ -166,24 +166,22 @@ func (p *Prometheus) Init() error { p.MonitorKubernetesPodsMethod = MonitorMethodAnnotations } - if p.isNodeScrapeScope || p.MonitorKubernetesPodsMethod != MonitorMethodAnnotations { - // Parse label and field selectors - will be used to filter pods after cAdvisor call - var err error - p.podLabelSelector, err = labels.Parse(p.KubernetesLabelSelector) - if err != nil { - return fmt.Errorf("error parsing the specified label selector(s): %w", err) - } - p.podFieldSelector, err = fields.ParseSelector(p.KubernetesFieldSelector) - if err != nil { - return fmt.Errorf("error parsing the specified field selector(s): %w", err) - } - isValid, invalidSelector := fieldSelectorIsSupported(p.podFieldSelector) - if !isValid { - return fmt.Errorf("the field selector %q is not supported for pods", invalidSelector) - } - - p.Log.Infof("Using the label selector: %v and field selector: %v", p.podLabelSelector, p.podFieldSelector) + // Parse label and field selectors - will be used to filter pods after cAdvisor call + var err error + p.podLabelSelector, err = labels.Parse(p.KubernetesLabelSelector) + if err != nil { + return fmt.Errorf("error parsing the specified label selector(s): %w", err) } + p.podFieldSelector, err = fields.ParseSelector(p.KubernetesFieldSelector) + if err != nil { + return fmt.Errorf("error parsing the specified field selector(s): %w", err) + } + isValid, invalidSelector := fieldSelectorIsSupported(p.podFieldSelector) + if !isValid { + return fmt.Errorf("the field selector %q is not supported for pods", invalidSelector) + } + + p.Log.Infof("Using the label selector: %v and field selector: %v", p.podLabelSelector, p.podFieldSelector) for k, vs := range p.NamespaceAnnotationPass { tagFilter := models.TagFilter{} diff --git a/plugins/inputs/prometheus/prometheus_test.go b/plugins/inputs/prometheus/prometheus_test.go index d93721dab..0e083db46 100644 --- a/plugins/inputs/prometheus/prometheus_test.go +++ b/plugins/inputs/prometheus/prometheus_test.go @@ -352,6 +352,7 @@ func TestPrometheusGeneratesSummaryMetricsV2(t *testing.T) { defer ts.Close() p := &Prometheus{ + Log: &testutil.Logger{}, URLs: []string{ts.URL}, URLTag: "url", MetricVersion: 2, @@ -385,6 +386,7 @@ go_gc_duration_seconds_count 42` defer ts.Close() p := &Prometheus{ + Log: &testutil.Logger{}, URLs: []string{ts.URL}, URLTag: "", MetricVersion: 2, @@ -444,6 +446,7 @@ func TestPrometheusGeneratesGaugeMetricsV2(t *testing.T) { defer ts.Close() p := &Prometheus{ + Log: &testutil.Logger{}, URLs: []string{ts.URL}, URLTag: "url", MetricVersion: 2, diff --git a/plugins/outputs/prometheus_client/prometheus_client_v1_test.go b/plugins/outputs/prometheus_client/prometheus_client_v1_test.go index 095451f8d..475b2cadf 100644 --- a/plugins/outputs/prometheus_client/prometheus_client_v1_test.go +++ b/plugins/outputs/prometheus_client/prometheus_client_v1_test.go @@ -389,6 +389,7 @@ rpc_duration_seconds_count 2693 }) input := &inputs.Prometheus{ + Log: logger, URLs: []string{address}, URLTag: "", MetricVersion: 1, diff --git a/plugins/outputs/prometheus_client/prometheus_client_v2_test.go b/plugins/outputs/prometheus_client/prometheus_client_v2_test.go index 10bdca37e..6a4ce7a87 100644 --- a/plugins/outputs/prometheus_client/prometheus_client_v2_test.go +++ b/plugins/outputs/prometheus_client/prometheus_client_v2_test.go @@ -420,6 +420,7 @@ rpc_duration_seconds_count 2693 }) input := &inputs.Prometheus{ + Log: logger, URLs: []string{url}, URLTag: "", MetricVersion: 2,