Skip to content

Commit

Permalink
fix filter running logic (#3588)
Browse files Browse the repository at this point in the history
  • Loading branch information
captncraig authored and clayton-cornell committed Aug 14, 2023
1 parent 1a5642e commit 868755e
Showing 3 changed files with 83 additions and 2 deletions.
81 changes: 81 additions & 0 deletions pkg/operator/config/metrics_templates_test.go
Original file line number Diff line number Diff line change
@@ -918,6 +918,87 @@ func TestServiceMonitor(t *testing.T) {
- __tmp_hash
`),
},
{
name: "no_filter_running",
input: map[string]interface{}{
"agentNamespace": "operator",
"monitor": prom_v1.ServiceMonitor{
ObjectMeta: meta_v1.ObjectMeta{
Namespace: "operator",
Name: "servicemonitor",
},
},
"endpoint": prom_v1.Endpoint{
Port: "metrics",
},
"index": 0,
"apiServer": prom_v1.APIServerConfig{},
"overrideHonorLabels": false,
"overrideHonorTimestamps": false,
"ignoreNamespaceSelectors": false,
"enforcedNamespaceLabel": "",
"enforcedSampleLimit": nil,
"enforcedTargetLimit": nil,
"shards": 1,
},
expect: util.Untab(`
job_name: serviceMonitor/operator/servicemonitor/0
honor_labels: false
kubernetes_sd_configs:
- role: endpoints
namespaces:
names: [operator]
relabel_configs:
- source_labels:
- job
target_label: __tmp_prometheus_job_name
- action: keep
regex: metrics
source_labels:
- __meta_kubernetes_endpoint_port_name
- regex: Node;(.*)
replacement: $1
separator: ;
source_labels:
- __meta_kubernetes_endpoint_address_target_kind
- __meta_kubernetes_endpoint_address_target_name
target_label: node
- regex: Pod;(.*)
replacement: $1
separator: ;
source_labels:
- __meta_kubernetes_endpoint_address_target_kind
- __meta_kubernetes_endpoint_address_target_name
target_label: pod
- source_labels:
- __meta_kubernetes_namespace
target_label: namespace
- source_labels:
- __meta_kubernetes_service_name
target_label: service
- source_labels:
- __meta_kubernetes_pod_name
target_label: pod
- source_labels:
- __meta_kubernetes_pod_container_name
target_label: container
- replacement: $1
source_labels:
- __meta_kubernetes_service_name
target_label: job
- replacement: metrics
target_label: endpoint
- action: hashmod
modulus: 1
source_labels:
- __address__
target_label: __tmp_hash
- action: keep
regex: $(SHARD)
source_labels:
- __tmp_hash
`),
},
}

for _, tc := range tt {
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ function(
relabel_configs: (
[{ source_labels: ['job'], target_label: '__tmp_prometheus_job_name' }] +

(if endpoint.FilterRunning then [{
(if endpoint.FilterRunning != null && endpoint.FilterRunning then [{
source_labels: ['__meta_kubernetes_pod_phase'],
regex: '(Failed|Succeeded)',
action: 'drop',
Original file line number Diff line number Diff line change
@@ -176,7 +176,7 @@ function(
target_label: 'container',
}] +

(if endpoint.FilterRunning then [{
(if endpoint.FilterRunning != null && endpoint.FilterRunning then [{
source_labels: ['__meta_kubernetes_pod_phase'],
regex: '(Failed|Succeeded)',
action: 'drop',

0 comments on commit 868755e

Please sign in to comment.