Skip to content

Commit

Permalink
feat: add metric relabeling so namespace label has the correct value …
Browse files Browse the repository at this point in the history
…(which is the same as container_namespace) applied after scraping

Signed-off-by: Bastien Grasnick <[email protected]>
  • Loading branch information
BGrasnick committed Nov 17, 2023
1 parent d6abc5e commit 05f3ac1
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pkg/components/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,14 @@ func NewServiceMonitor() *monv1.ServiceMonitor {
TargetLabel: "instance",
}}

metricRelabelings := []*monv1.RelabelConfig{{
Action: "replace",
SourceLabels: []monv1.LabelName{
"container_namespace",
},
TargetLabel: "namespace",
}}

return &monv1.ServiceMonitor{
TypeMeta: metav1.TypeMeta{
APIVersion: monv1.SchemeGroupVersion.String(),
Expand All @@ -501,10 +509,11 @@ func NewServiceMonitor() *monv1.ServiceMonitor {
},
Spec: monv1.ServiceMonitorSpec{
Endpoints: []monv1.Endpoint{{
Port: ServicePortName,
Interval: "3s",
Scheme: "http",
RelabelConfigs: relabelings,
Port: ServicePortName,
Interval: "3s",
Scheme: "http",
RelabelConfigs: relabelings,
MetricRelabelConfigs: metricRelabelings,
}},
JobLabel: "app.kubernetes.io/name",
Selector: metav1.LabelSelector{
Expand Down

0 comments on commit 05f3ac1

Please sign in to comment.