Skip to content

Commit 53f8138

Browse files
committed
OCPBUGS-439 update the DVO metrics gatherer
1 parent 17a1052 commit 53f8138

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

docs/conditional-gatherer/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ echo '{
9494
4. Wait for the alert to fire:
9595
```bash
9696
export PROMETHEUS_HOST=$(oc get route -n openshift-monitoring prometheus-k8s -o jsonpath='{@.spec.host}')
97-
export INSECURE_PROMETHEUS_TOKEN=$(oc get secret $(oc get sa prometheus-k8s -n openshift-monitoring -o json | jq .secrets[0].name | tr --delete \") -n openshift-monitoring -o json | jq .metadata.annotations.\"openshift.io/token-secret.value\")
97+
export INSECURE_PROMETHEUS_TOKEN=$(oc get secret $(oc get sa prometheus-k8s -n openshift-monitoring -o json | jq .secrets[0].name | tr --delete \") -n openshift-monitoring -o json | jq .metadata.annotations.\"openshift.io/token-secret.value\" | tr --delete \")
9898
curl -g -s -k -H 'Cache-Control: no-cache' -H "Authorization: Bearer $INSECURE_PROMETHEUS_TOKEN" "https://$PROMETHEUS_HOST/api/v1/query" --data-urlencode 'query=ALERTS{alertstate="firing",alertname="SamplesImagestreamImportFailing"}' | jq ".data.result[]"
9999
```
100100

pkg/gatherers/clusterconfig/dvo_metrics.go

+6-12
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"io"
88
"net/http"
99
"net/url"
10-
"regexp"
1110

1211
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1312
"k8s.io/client-go/kubernetes"
@@ -21,15 +20,11 @@ import (
2120
"github.com/openshift/insights-operator/pkg/utils/marshal"
2221
)
2322

24-
const (
25-
dvoNamespace = "deployment-validation-operator"
26-
)
27-
2823
var (
29-
// Only services with the word "metrics" in their name should be considered.
30-
dvoMetricsServiceNameRegex = regexp.MustCompile(`\bmetrics\b`)
3124
// Only metrics with the DVO prefix should be gathered.
3225
dvoMetricsPrefix = []byte("deployment_validation_operator_")
26+
// label selector used for searching the required service
27+
serviceLabelSelector = "name=deployment-validation-operator"
3328
)
3429

3530
// GatherDVOMetrics collects metrics from the Deployment Validation Operator's
@@ -55,7 +50,9 @@ func gatherDVOMetrics(
5550
coreClient corev1client.CoreV1Interface,
5651
rateLimiter flowcontrol.RateLimiter,
5752
) ([]record.Record, []error) {
58-
serviceList, err := coreClient.Services(dvoNamespace).List(ctx, metav1.ListOptions{})
53+
serviceList, err := coreClient.Services("").List(ctx, metav1.ListOptions{
54+
LabelSelector: serviceLabelSelector,
55+
})
5956
if err != nil {
6057
return nil, []error{err}
6158
}
@@ -65,13 +62,10 @@ func gatherDVOMetrics(
6562
for svcIdx := range serviceList.Items {
6663
// Use pointer to make gocritic happy and avoid copying the whole Service struct.
6764
service := &serviceList.Items[svcIdx]
68-
if !dvoMetricsServiceNameRegex.MatchString(service.Name) {
69-
continue
70-
}
7165
for _, port := range service.Spec.Ports {
7266
apiURL := url.URL{
7367
Scheme: "http",
74-
Host: fmt.Sprintf("%s.%s.svc:%d", service.Name, dvoNamespace, port.Port),
68+
Host: fmt.Sprintf("%s.%s.svc:%d", service.Name, service.Namespace, port.Port),
7569
}
7670

7771
prefixedLines, err := gatherDVOMetricsFromEndpoint(ctx, &apiURL, rateLimiter)

0 commit comments

Comments
 (0)