Skip to content

Commit

Permalink
operator: Add alert relabel config (#7415)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Amine Bouqsimi authored Oct 14, 2022
1 parent 2caf5f7 commit 30bdee8
Show file tree
Hide file tree
Showing 11 changed files with 657 additions and 8 deletions.
1 change: 1 addition & 0 deletions operator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Main

- [7415](https://github.com/grafana/loki/pull/7415) **aminesnow**: Add alert relabel config
- [7418](https://github.com/grafana/loki/pull/7418) **Red-GV**: Update golang to v1.19 and k8s dependencies to v0.25.2
- [7322](https://github.com/grafana/loki/pull/7322) **Red-GV**: Configuring server and client HTTP and GRPC TLS options
- [7272](https://github.com/grafana/loki/pull/7272) **aminesnow**: Use cluster monitoring alertmanager by default on openshift clusters
Expand Down
9 changes: 8 additions & 1 deletion operator/apis/loki/v1beta1/rulerconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ type AlertManagerSpec struct {
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:advanced",displayName="Notification Queue"
NotificationQueueSpec *AlertManagerNotificationQueueSpec `json:"notificationQueue,omitempty"`

// List of alert relabel configurations.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Alert Relabel Configuration"
RelabelConfigs []RelabelConfig `json:"relabelConfigs,omitempty"`
}

// RemoteWriteAuthType defines the type of authorization to use to access the remote write endpoint.
Expand Down Expand Up @@ -198,7 +205,7 @@ type RemoteWriteClientSpec struct {
type RelabelActionType string

// RelabelConfig allows dynamic rewriting of the label set, being applied to samples before ingestion.
// It defines `<metric_relabel_configs>`-section of Prometheus configuration.
// It defines `<metric_relabel_configs>` and `<alert_relabel_configs>` sections of Prometheus configuration.
// More info: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#metric_relabel_configs
type RelabelConfig struct {
// The source labels select values from existing labels. Their content is concatenated
Expand Down
7 changes: 7 additions & 0 deletions operator/apis/loki/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions operator/bundle/manifests/loki-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,45 @@ spec:
- description: HTTP timeout duration when sending notifications to the Alertmanager.
displayName: Timeout
path: alertmanager.notificationQueue.timeout
- description: List of alert relabel configurations.
displayName: Alert Relabel Configuration
path: alertmanager.relabelConfigs
- description: Action to perform based on regex matching. Default is 'replace'
displayName: Action
path: alertmanager.relabelConfigs[0].action
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:select:drop
- urn:alm:descriptor:com.tectonic.ui:select:hashmod
- urn:alm:descriptor:com.tectonic.ui:select:keep
- urn:alm:descriptor:com.tectonic.ui:select:labeldrop
- urn:alm:descriptor:com.tectonic.ui:select:labelkeep
- urn:alm:descriptor:com.tectonic.ui:select:labelmap
- urn:alm:descriptor:com.tectonic.ui:select:replace
- description: Modulus to take of the hash of the source label values.
displayName: Modulus
path: alertmanager.relabelConfigs[0].modulus
- description: Regular expression against which the extracted value is matched.
Default is '(.*)'
displayName: Regex
path: alertmanager.relabelConfigs[0].regex
- description: Replacement value against which a regex replace is performed
if the regular expression matches. Regex capture groups are available. Default
is '$1'
displayName: Replacement
path: alertmanager.relabelConfigs[0].replacement
- description: Separator placed between concatenated source label values. default
is ';'.
displayName: Separator
path: alertmanager.relabelConfigs[0].separator
- description: The source labels select values from existing labels. Their content
is concatenated using the configured separator and matched against the configured
regular expression for the replace, keep, and drop actions.
displayName: Source Labels
path: alertmanager.relabelConfigs[0].sourceLabels
- description: Label to which the resulting value is written in a replace action.
It is mandatory for replace actions. Regex capture groups are available.
displayName: Target Label
path: alertmanager.relabelConfigs[0].targetLabel
- description: Interval on how frequently to evaluate rules.
displayName: Evaluation Interval
path: evaluationInterval
Expand Down
59 changes: 59 additions & 0 deletions operator/bundle/manifests/loki.grafana.com_rulerconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,65 @@ spec:
pattern: ((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?|0)
type: string
type: object
relabelConfigs:
description: List of alert relabel configurations.
items:
description: 'RelabelConfig allows dynamic rewriting of the
label set, being applied to samples before ingestion. It defines
`<alert_relabel_configs>`-section of Prometheus configuration.
More info: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#alert_relabel_configs'
properties:
action:
default: replace
description: Action to perform based on regex matching.
Default is 'replace'
enum:
- drop
- hashmod
- keep
- labeldrop
- labelkeep
- labelmap
- replace
type: string
modulus:
description: Modulus to take of the hash of the source label
values.
format: int64
type: integer
regex:
default: (.*)
description: Regular expression against which the extracted
value is matched. Default is '(.*)'
type: string
replacement:
default: $1
description: Replacement value against which a regex replace
is performed if the regular expression matches. Regex
capture groups are available. Default is '$1'
type: string
separator:
default: ;
description: Separator placed between concatenated source
label values. default is ';'.
type: string
sourceLabels:
description: The source labels select values from existing
labels. Their content is concatenated using the configured
separator and matched against the configured regular expression
for the replace, keep, and drop actions.
items:
type: string
type: array
targetLabel:
description: Label to which the resulting value is written
in a replace action. It is mandatory for replace actions.
Regex capture groups are available.
type: string
required:
- sourceLabels
type: object
type: array
required:
- endpoints
type: object
Expand Down
59 changes: 59 additions & 0 deletions operator/config/crd/bases/loki.grafana.com_rulerconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,65 @@ spec:
pattern: ((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?|0)
type: string
type: object
relabelConfigs:
description: List of alert relabel configurations.
items:
description: 'RelabelConfig allows dynamic rewriting of the
label set, being applied to samples before ingestion. It defines
`<alert_relabel_configs>`-section of Prometheus configuration.
More info: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#alert_relabel_configs'
properties:
action:
default: replace
description: Action to perform based on regex matching.
Default is 'replace'
enum:
- drop
- hashmod
- keep
- labeldrop
- labelkeep
- labelmap
- replace
type: string
modulus:
description: Modulus to take of the hash of the source label
values.
format: int64
type: integer
regex:
default: (.*)
description: Regular expression against which the extracted
value is matched. Default is '(.*)'
type: string
replacement:
default: $1
description: Replacement value against which a regex replace
is performed if the regular expression matches. Regex
capture groups are available. Default is '$1'
type: string
separator:
default: ;
description: Separator placed between concatenated source
label values. default is ';'.
type: string
sourceLabels:
description: The source labels select values from existing
labels. Their content is concatenated using the configured
separator and matched against the configured regular expression
for the replace, keep, and drop actions.
items:
type: string
type: array
targetLabel:
description: Label to which the resulting value is written
in a replace action. It is mandatory for replace actions.
Regex capture groups are available.
type: string
required:
- sourceLabels
type: object
type: array
required:
- endpoints
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,45 @@ spec:
- description: HTTP timeout duration when sending notifications to the Alertmanager.
displayName: Timeout
path: alertmanager.notificationQueue.timeout
- description: List of alert relabel configurations.
displayName: Alert Relabel Configuration
path: alertmanager.relabelConfigs
- description: Action to perform based on regex matching. Default is 'replace'
displayName: Action
path: alertmanager.relabelConfigs[0].action
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:select:drop
- urn:alm:descriptor:com.tectonic.ui:select:hashmod
- urn:alm:descriptor:com.tectonic.ui:select:keep
- urn:alm:descriptor:com.tectonic.ui:select:labeldrop
- urn:alm:descriptor:com.tectonic.ui:select:labelkeep
- urn:alm:descriptor:com.tectonic.ui:select:labelmap
- urn:alm:descriptor:com.tectonic.ui:select:replace
- description: Modulus to take of the hash of the source label values.
displayName: Modulus
path: alertmanager.relabelConfigs[0].modulus
- description: Regular expression against which the extracted value is matched.
Default is '(.*)'
displayName: Regex
path: alertmanager.relabelConfigs[0].regex
- description: Replacement value against which a regex replace is performed
if the regular expression matches. Regex capture groups are available. Default
is '$1'
displayName: Replacement
path: alertmanager.relabelConfigs[0].replacement
- description: Separator placed between concatenated source label values. default
is ';'.
displayName: Separator
path: alertmanager.relabelConfigs[0].separator
- description: The source labels select values from existing labels. Their content
is concatenated using the configured separator and matched against the configured
regular expression for the replace, keep, and drop actions.
displayName: Source Labels
path: alertmanager.relabelConfigs[0].sourceLabels
- description: Label to which the resulting value is written in a replace action.
It is mandatory for replace actions. Regex capture groups are available.
displayName: Target Label
path: alertmanager.relabelConfigs[0].targetLabel
- description: Interval on how frequently to evaluate rules.
displayName: Evaluation Interval
path: evaluationInterval
Expand Down
14 changes: 13 additions & 1 deletion operator/internal/manifests/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ func alertManagerConfig(s *lokiv1beta1.AlertManagerSpec) *config.AlertManagerCon
c.ResendDelay = string(n.ResendDelay)
}

for _, cfg := range s.RelabelConfigs {
c.RelabelConfigs = append(c.RelabelConfigs, config.RelabelConfig{
SourceLabels: cfg.SourceLabels,
Separator: cfg.Separator,
TargetLabel: cfg.TargetLabel,
Regex: cfg.Regex,
Modulus: cfg.Modulus,
Replacement: cfg.Replacement,
Action: string(cfg.Action),
})
}

return c
}

Expand Down Expand Up @@ -185,7 +197,7 @@ func remoteWriteConfig(s *lokiv1beta1.RemoteWriteSpec, rs *RulerSecret) *config.
}

for _, cfg := range cls.RelabelConfigs {
c.RelabelConfigs = append(c.RelabelConfigs, config.RemoteWriteRelabelConfig{
c.RelabelConfigs = append(c.RelabelConfigs, config.RelabelConfig{
SourceLabels: cfg.SourceLabels,
Separator: cfg.Separator,
TargetLabel: cfg.TargetLabel,
Expand Down
Loading

0 comments on commit 30bdee8

Please sign in to comment.