Skip to content

Commit

Permalink
feat(prometheus/operator): accept relabel rules exported from `promet…
Browse files Browse the repository at this point in the history
…heus.relabel`

Signed-off-by: hainenber <[email protected]>
  • Loading branch information
hainenber committed Apr 7, 2024
1 parent 2e95228 commit 5362840
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 3 deletions.
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`.

[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

0 comments on commit 5362840

Please sign in to comment.