Skip to content

Commit 962597a

Browse files
committed
LOG-9356: Implement Collector ServiceMontitor Changes
1 parent ff06c7a commit 962597a

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

internal/metrics/service_monitor.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,22 @@ func newServiceMonitor(namespace, name string, owner metav1.OwnerReference, sele
3030
ServerName: fmt.Sprintf("%s.%s.svc", name, namespace),
3131
},
3232
},
33-
// Replaces labels that have `-` with `_`
34-
// Example:
35-
// app_kubernetes_io_part-of -> app_kubernetes_io_part_of
3633
MetricRelabelConfigs: []*monitoringv1.RelabelConfig{
3734
{
38-
SourceLabels: []monitoringv1.LabelName{
39-
"__name__",
40-
},
41-
TargetLabel: "__name__",
42-
Regex: "(.*)-(.*)",
43-
Replacement: "${1}_${2}",
35+
SourceLabels: []monitoringv1.LabelName{"__name__"},
36+
TargetLabel: "__name__",
37+
Regex: "(.*)-(.*)",
38+
Replacement: "${1}_${2}",
39+
},
40+
{
41+
Action: "keep",
42+
SourceLabels: []monitoringv1.LabelName{"__name__"},
43+
Regex: "logcollector_component_event_unmatched_count|vector_buffer_byte_size|vector_buffer_discarded_events_total|vector_buffer_events|vector_buffer_sent_events_total|vector_component_discarded_events_total|vector_component_errors_total|vector_component_received_bytes_total|vector_component_received_event_bytes_total|vector_component_received_events_total|vector_component_sent_bytes_total|vector_events_in_total|vector_http_client_errors_total|vector_http_client_requests_sent_total|vector_http_client_responses_total|vector_open_files",
44+
},
45+
{
46+
Action: "drop",
47+
SourceLabels: []monitoringv1.LabelName{"component_kind", "__name__"},
48+
Regex: `transform;(vector_component_received_bytes_total|vector_component_received_event_bytes_total|vector_component_received_events_total|vector_component_sent_bytes_total)`,
4449
},
4550
},
4651
},

internal/metrics/service_monitor_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,19 @@ var _ = Describe("Reconcile ServiceMonitor", func() {
7272

7373
Expect(smInstance.Spec.Endpoints[0].BearerTokenFile).
7474
To(Equal("/var/run/secrets/kubernetes.io/serviceaccount/token"))
75+
76+
By("verifying MetricRelabelConfigs")
77+
relabelConfigs := smInstance.Spec.Endpoints[0].MetricRelabelConfigs
78+
Expect(relabelConfigs).To(HaveLen(3))
79+
80+
Expect(relabelConfigs[0].Regex).To(Equal("(.*)-(.*)"))
81+
Expect(relabelConfigs[0].TargetLabel).To(Equal("__name__"))
82+
83+
Expect(string(relabelConfigs[1].Action)).To(Equal("keep"))
84+
Expect(relabelConfigs[1].SourceLabels).To(Equal([]monitoringv1.LabelName{"__name__"}))
85+
86+
Expect(string(relabelConfigs[2].Action)).To(Equal("drop"))
87+
Expect(relabelConfigs[2].SourceLabels).To(Equal([]monitoringv1.LabelName{"component_kind", "__name__"}))
88+
Expect(relabelConfigs[2].Regex).To(Equal(`transform;(vector_component_received_bytes_total|vector_component_received_event_bytes_total|vector_component_received_events_total|vector_component_sent_bytes_total)`))
7589
})
7690
})

0 commit comments

Comments
 (0)