Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(prometheus/operator): accept relabel rules exported from prometheus.relabel #6830

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Comment on lines +46 to +48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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`.
The `relabel_rules` argument uses the `rules` export value from a [prometheus.relabel][] component to apply one or more relabeling rules to your metric data points. The metric data points are relabeled and forwarded to the list of receivers in `forward_to`.

A small rework to make the information active instead of passive. Is it still technically accurate with these changes?

If this is correct, this change shoudl be applied to teh other cases here in each of the following doc topics.


[prometheus.relabel]: {{< relref "./prometheus.relabel.md" >}}

## Blocks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 15 additions & 3 deletions internal/component/prometheus/operator/common/crdmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions internal/component/prometheus/operator/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand All @@ -54,6 +56,7 @@ var DefaultArguments = Arguments{
Client: kubernetes.ClientArguments{
HTTPClientConfig: config.DefaultHTTPClientConfig,
},
RelabelConfigs: []*flow_relabel.Config{},
}

// SetToDefault implements river.Defaulter.
Expand Down
Loading