1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-21 11:48:53 +00:00

Support dropping metrics at scrape time ()

* added skipMetrics field to servicemonitor

* generating drop metric relabelings from skipMetrics config

* added servicemonitor with skipMetrics config to promcfg unit test

* format tests

* update docs

* generate deepcopy methods

* use relabel object for metric relabel configs

* fix relabel config typos in remote write config

* update generated content

* updated docs
This commit is contained in:
Zack Brenton 2018-01-11 10:17:06 -04:00 committed by Frederic Branczyk
parent 8e1b536125
commit 1263b927d4
5 changed files with 89 additions and 2 deletions
Documentation
pkg

View file

@ -143,6 +143,7 @@ Endpoint defines a scrapeable endpoint serving Prometheus metrics.
| bearerTokenFile | File to read bearer token for scraping targets. | string | false |
| honorLabels | HonorLabels chooses the metric's labels on collisions with target labels. | bool | false |
| basicAuth | BasicAuth allow an endpoint to authenticate over basic authentication More info: https://prometheus.io/docs/operating/configuration/#endpoints | *[BasicAuth](#basicauth) | false |
| metricRelabelings | MetricRelabelConfigs to apply to samples before ingestion. | []*[RelabelConfig](#relabelconfig) | false |
[Back to TOC](#table-of-contents)

View file

@ -294,6 +294,8 @@ type Endpoint struct {
// BasicAuth allow an endpoint to authenticate over basic authentication
// More info: https://prometheus.io/docs/operating/configuration/#endpoints
BasicAuth *BasicAuth `json:"basicAuth,omitempty"`
// MetricRelabelConfigs to apply to samples before ingestion.
MetricRelabelConfigs []*RelabelConfig `json:"metricRelabelings,omitempty"`
}
// BasicAuth allow an endpoint to authenticate over basic authentication

View file

@ -391,6 +391,18 @@ func (in *Endpoint) DeepCopyInto(out *Endpoint) {
(*in).DeepCopyInto(*out)
}
}
if in.MetricRelabelConfigs != nil {
in, out := &in.MetricRelabelConfigs, &out.MetricRelabelConfigs
*out = make([]*RelabelConfig, len(*in))
for i := range *in {
if (*in)[i] == nil {
(*out)[i] = nil
} else {
(*out)[i] = new(RelabelConfig)
(*in)[i].DeepCopyInto((*out)[i])
}
}
}
return
}

View file

@ -370,6 +370,42 @@ func generateServiceMonitorConfig(version semver.Version, m *v1.ServiceMonitor,
cfg = append(cfg, yaml.MapItem{Key: "relabel_configs", Value: relabelings})
if ep.MetricRelabelConfigs != nil {
var metricRelabelings []yaml.MapSlice
for _, c := range ep.MetricRelabelConfigs {
relabeling := yaml.MapSlice{
{Key: "source_labels", Value: c.SourceLabels},
}
if c.Separator != "" {
relabeling = append(relabeling, yaml.MapItem{Key: "separator", Value: c.Separator})
}
if c.TargetLabel != "" {
relabeling = append(relabeling, yaml.MapItem{Key: "target_label", Value: c.TargetLabel})
}
if c.Regex != "" {
relabeling = append(relabeling, yaml.MapItem{Key: "regex", Value: c.Regex})
}
if c.Modulus != uint64(0) {
relabeling = append(relabeling, yaml.MapItem{Key: "modulus", Value: c.Modulus})
}
if c.Replacement != "" {
relabeling = append(relabeling, yaml.MapItem{Key: "replacement", Value: c.Replacement})
}
if c.Action != "" {
relabeling = append(relabeling, yaml.MapItem{Key: "action", Value: c.Action})
}
metricRelabelings = append(metricRelabelings, relabeling)
}
cfg = append(cfg, yaml.MapItem{Key: "metric_relabel_configs", Value: metricRelabelings})
}
return cfg
}
@ -584,11 +620,11 @@ func generateRemoteWriteConfig(version semver.Version, specs []v1.RemoteWriteSpe
}
if c.Replacement != "" {
relabeling = append(relabeling, yaml.MapItem{Key: "replacememt", Value: c.Replacement})
relabeling = append(relabeling, yaml.MapItem{Key: "replacement", Value: c.Replacement})
}
if c.Action != "" {
relabeling = append(relabeling, yaml.MapItem{Key: "action", Value: c.TargetLabel})
relabeling = append(relabeling, yaml.MapItem{Key: "action", Value: c.Action})
}
relabelings = append(relabelings, relabeling)
}

View file

@ -175,5 +175,41 @@ func makeServiceMonitors() map[string]*monitoringv1.ServiceMonitor {
},
}
res["servicemonitor4"] = &monitoringv1.ServiceMonitor{
ObjectMeta: metav1.ObjectMeta{
Name: "testservicemonitor4",
Namespace: "default",
Labels: map[string]string{
"group": "group6",
},
},
Spec: monitoringv1.ServiceMonitorSpec{
Selector: metav1.LabelSelector{
MatchLabels: map[string]string{
"group": "group6",
"group3": "group7",
},
},
Endpoints: []monitoringv1.Endpoint{
monitoringv1.Endpoint{
Port: "web",
Interval: "30s",
MetricRelabelConfigs: []*monitoringv1.RelabelConfig{
&monitoringv1.RelabelConfig{
Action: "drop",
Regex: "my-job-pod-.+",
SourceLabels: []string{"pod_name"},
},
&monitoringv1.RelabelConfig{
Action: "drop",
Regex: "test",
SourceLabels: []string{"namespace"},
},
},
},
},
},
}
return res
}