diff --git a/CHANGELOG.md b/CHANGELOG.md index ded6410f6b67..36a41ff6dac1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,8 @@ Main (unreleased) - Propagate request metadata for `faro.receiver` to downstream components. (@hainenber) +- Allow `prometheus.operators.*` components to accept relabel rules exported from `prometheus.relabel`. (@hainenber) + ### Features - A new `loki.rules.kubernetes` component that discovers `PrometheusRule` Kubernetes resources and loads them into a Loki Ruler instance. (@EStork09) diff --git a/docs/sources/flow/reference/components/prometheus.operator.podmonitors.md b/docs/sources/flow/reference/components/prometheus.operator.podmonitors.md index 34d73ae78477..7de6d6ddaee0 100644 --- a/docs/sources/flow/reference/components/prometheus.operator.podmonitors.md +++ b/docs/sources/flow/reference/components/prometheus.operator.podmonitors.md @@ -41,6 +41,13 @@ Name | Type | Description | Default | Required ---- | ---- | ----------- | ------- | -------- `forward_to` | `list(MetricsReceiver)` | List of receivers to send scraped metrics to. | | yes `namespaces` | `list(string)` | List of namespaces to search for PodMonitor resources. If not specified, all namespaces will be searched. || no +`relabel_rules` | `RelabelRules` | Relabeling rules to apply on scraped metric data points. | `{}` | no + +The `relabel_rules` argument can make use of the `rules` export value from a +[prometheus.relabel][] component to apply one or more relabeling rules to metric data points +before they're forwarded to the list of receivers in `forward_to`. + +[prometheus.relabel]: {{< relref "./prometheus.relabel.md" >}} ## Blocks diff --git a/docs/sources/flow/reference/components/prometheus.operator.probes.md b/docs/sources/flow/reference/components/prometheus.operator.probes.md index 01ca2fd73017..033c824bc241 100644 --- a/docs/sources/flow/reference/components/prometheus.operator.probes.md +++ b/docs/sources/flow/reference/components/prometheus.operator.probes.md @@ -44,6 +44,13 @@ Name | Type | Description | Default | Required ---- | ---- | ----------- | ------- | -------- `forward_to` | `list(MetricsReceiver)` | List of receivers to send scraped metrics to. | | yes `namespaces` | `list(string)` | List of namespaces to search for Probe resources. If not specified, all namespaces will be searched. || no +`relabel_rules` | `RelabelRules` | Relabeling rules to apply on scraped metric data points. | `{}` | no + +The `relabel_rules` argument can make use of the `rules` export value from a +[prometheus.relabel][] component to apply one or more relabeling rules to metric data points +before they're forwarded to the list of receivers in `forward_to`. + +[prometheus.relabel]: {{< relref "./prometheus.relabel.md" >}} ## Blocks diff --git a/docs/sources/flow/reference/components/prometheus.operator.servicemonitors.md b/docs/sources/flow/reference/components/prometheus.operator.servicemonitors.md index 24a1b886aa30..3a15049a9c50 100644 --- a/docs/sources/flow/reference/components/prometheus.operator.servicemonitors.md +++ b/docs/sources/flow/reference/components/prometheus.operator.servicemonitors.md @@ -43,6 +43,13 @@ Name | Type | Description | Default | Required ---- | ---- | ----------- | ------- | -------- `forward_to` | `list(MetricsReceiver)` | List of receivers to send scraped metrics to. | | yes `namespaces` | `list(string)` | List of namespaces to search for ServiceMonitor resources. If not specified, all namespaces will be searched. || no +`relabel_rules` | `RelabelRules` | Relabeling rules to apply on scraped metric data points. | `{}` | no + +The `relabel_rules` argument can make use of the `rules` export value from a +[prometheus.relabel][] component to apply one or more relabeling rules to metric data points +before they're forwarded to the list of receivers in `forward_to`. + +[prometheus.relabel]: {{< relref "./prometheus.relabel.md" >}} ## Blocks diff --git a/internal/component/prometheus/operator/common/crdmanager.go b/internal/component/prometheus/operator/common/crdmanager.go index d5f4b9bbb975..522e44e725cd 100644 --- a/internal/component/prometheus/operator/common/crdmanager.go +++ b/internal/component/prometheus/operator/common/crdmanager.go @@ -394,10 +394,14 @@ func (c *crdManager) addDebugInfo(ns string, name string, err error) { func (c *crdManager) addPodMonitor(pm *promopv1.PodMonitor) { var err error + totalRelabelRules := c.args.RelabelConfigs + if c.args.RelabelRules != nil && len(c.args.RelabelRules) > 0 { + totalRelabelRules = append(totalRelabelRules, c.args.RelabelRules...) + } gen := configgen.ConfigGenerator{ Secrets: configgen.NewSecretManager(c.client), Client: &c.args.Client, - AdditionalRelabelConfigs: c.args.RelabelConfigs, + AdditionalRelabelConfigs: totalRelabelRules, ScrapeOptions: c.args.Scrape, } mapKeys := []string{} @@ -449,10 +453,14 @@ func (c *crdManager) onDeletePodMonitor(obj interface{}) { func (c *crdManager) addServiceMonitor(sm *promopv1.ServiceMonitor) { var err error + totalRelabelRules := c.args.RelabelConfigs + if c.args.RelabelRules != nil && len(c.args.RelabelRules) > 0 { + totalRelabelRules = append(totalRelabelRules, c.args.RelabelRules...) + } gen := configgen.ConfigGenerator{ Secrets: configgen.NewSecretManager(c.client), Client: &c.args.Client, - AdditionalRelabelConfigs: c.args.RelabelConfigs, + AdditionalRelabelConfigs: totalRelabelRules, ScrapeOptions: c.args.Scrape, } @@ -505,10 +513,14 @@ func (c *crdManager) onDeleteServiceMonitor(obj interface{}) { func (c *crdManager) addProbe(p *promopv1.Probe) { var err error + totalRelabelRules := c.args.RelabelConfigs + if c.args.RelabelRules != nil && len(c.args.RelabelRules) > 0 { + totalRelabelRules = append(totalRelabelRules, c.args.RelabelRules...) + } gen := configgen.ConfigGenerator{ Secrets: configgen.NewSecretManager(c.client), Client: &c.args.Client, - AdditionalRelabelConfigs: c.args.RelabelConfigs, + AdditionalRelabelConfigs: totalRelabelRules, ScrapeOptions: c.args.Scrape, } var pmc *config.ScrapeConfig diff --git a/internal/component/prometheus/operator/types.go b/internal/component/prometheus/operator/types.go index eefd8ab7c8eb..bc9975814b9b 100644 --- a/internal/component/prometheus/operator/types.go +++ b/internal/component/prometheus/operator/types.go @@ -31,6 +31,8 @@ type Arguments struct { RelabelConfigs []*flow_relabel.Config `river:"rule,block,optional"` + RelabelRules flow_relabel.Rules `river:"relabel_rules,attr,optional"` + Scrape ScrapeOptions `river:"scrape,block,optional"` } @@ -54,6 +56,7 @@ var DefaultArguments = Arguments{ Client: kubernetes.ClientArguments{ HTTPClientConfig: config.DefaultHTTPClientConfig, }, + RelabelConfigs: []*flow_relabel.Config{}, } // SetToDefault implements river.Defaulter.