Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Restrict selector for ServiceMonitor to avoid double scraping (#665)
Browse files Browse the repository at this point in the history
Fixes #602

Adds a second expression to the `selector` of the `ServiceMonitor`.
Without it both the per-nodepool headless service and the per-cluster
service match and lead to Prometheus scraping every pod twice.
  • Loading branch information
swoehrl-mw authored and Eliatra committed Nov 26, 2023
1 parent 890e9ce commit 5cd060b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions opensearch-operator/pkg/builders/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,13 @@ func NewServiceMonitor(cr *eliatrav1.OpenSearchCluster) *monitoring.ServiceMonit
}
selector := metav1.LabelSelector{
MatchLabels: labels,
// Needed so only the pool-specific service is matched, otherwise there would be double scraping
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: helpers.NodePoolLabel,
Operator: metav1.LabelSelectorOpExists,
},
},
}

namespaceSelector := monitoring.NamespaceSelector{
Expand Down

0 comments on commit 5cd060b

Please sign in to comment.