feat(inputs.prometheus): Always apply kubernetes label and field selectors (#13624)
This commit is contained in:
parent
22100d4914
commit
42c7a2027f
|
|
@ -166,24 +166,22 @@ func (p *Prometheus) Init() error {
|
||||||
p.MonitorKubernetesPodsMethod = MonitorMethodAnnotations
|
p.MonitorKubernetesPodsMethod = MonitorMethodAnnotations
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.isNodeScrapeScope || p.MonitorKubernetesPodsMethod != MonitorMethodAnnotations {
|
// Parse label and field selectors - will be used to filter pods after cAdvisor call
|
||||||
// Parse label and field selectors - will be used to filter pods after cAdvisor call
|
var err error
|
||||||
var err error
|
p.podLabelSelector, err = labels.Parse(p.KubernetesLabelSelector)
|
||||||
p.podLabelSelector, err = labels.Parse(p.KubernetesLabelSelector)
|
if err != nil {
|
||||||
if err != nil {
|
return fmt.Errorf("error parsing the specified label selector(s): %w", err)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
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 {
|
for k, vs := range p.NamespaceAnnotationPass {
|
||||||
tagFilter := models.TagFilter{}
|
tagFilter := models.TagFilter{}
|
||||||
|
|
|
||||||
|
|
@ -352,6 +352,7 @@ func TestPrometheusGeneratesSummaryMetricsV2(t *testing.T) {
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
p := &Prometheus{
|
p := &Prometheus{
|
||||||
|
Log: &testutil.Logger{},
|
||||||
URLs: []string{ts.URL},
|
URLs: []string{ts.URL},
|
||||||
URLTag: "url",
|
URLTag: "url",
|
||||||
MetricVersion: 2,
|
MetricVersion: 2,
|
||||||
|
|
@ -385,6 +386,7 @@ go_gc_duration_seconds_count 42`
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
p := &Prometheus{
|
p := &Prometheus{
|
||||||
|
Log: &testutil.Logger{},
|
||||||
URLs: []string{ts.URL},
|
URLs: []string{ts.URL},
|
||||||
URLTag: "",
|
URLTag: "",
|
||||||
MetricVersion: 2,
|
MetricVersion: 2,
|
||||||
|
|
@ -444,6 +446,7 @@ func TestPrometheusGeneratesGaugeMetricsV2(t *testing.T) {
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
p := &Prometheus{
|
p := &Prometheus{
|
||||||
|
Log: &testutil.Logger{},
|
||||||
URLs: []string{ts.URL},
|
URLs: []string{ts.URL},
|
||||||
URLTag: "url",
|
URLTag: "url",
|
||||||
MetricVersion: 2,
|
MetricVersion: 2,
|
||||||
|
|
|
||||||
|
|
@ -389,6 +389,7 @@ rpc_duration_seconds_count 2693
|
||||||
})
|
})
|
||||||
|
|
||||||
input := &inputs.Prometheus{
|
input := &inputs.Prometheus{
|
||||||
|
Log: logger,
|
||||||
URLs: []string{address},
|
URLs: []string{address},
|
||||||
URLTag: "",
|
URLTag: "",
|
||||||
MetricVersion: 1,
|
MetricVersion: 1,
|
||||||
|
|
|
||||||
|
|
@ -420,6 +420,7 @@ rpc_duration_seconds_count 2693
|
||||||
})
|
})
|
||||||
|
|
||||||
input := &inputs.Prometheus{
|
input := &inputs.Prometheus{
|
||||||
|
Log: logger,
|
||||||
URLs: []string{url},
|
URLs: []string{url},
|
||||||
URLTag: "",
|
URLTag: "",
|
||||||
MetricVersion: 2,
|
MetricVersion: 2,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue