7
7
"io"
8
8
"net/http"
9
9
"net/url"
10
- "regexp"
11
10
12
11
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13
12
"k8s.io/client-go/kubernetes"
@@ -21,15 +20,11 @@ import (
21
20
"github.com/openshift/insights-operator/pkg/utils/marshal"
22
21
)
23
22
24
- const (
25
- dvoNamespace = "deployment-validation-operator"
26
- )
27
-
28
23
var (
29
- // Only services with the word "metrics" in their name should be considered.
30
- dvoMetricsServiceNameRegex = regexp .MustCompile (`\bmetrics\b` )
31
24
// Only metrics with the DVO prefix should be gathered.
32
25
dvoMetricsPrefix = []byte ("deployment_validation_operator_" )
26
+ // label selector used for searching the required service
27
+ serviceLabelSelector = "name=deployment-validation-operator"
33
28
)
34
29
35
30
// GatherDVOMetrics collects metrics from the Deployment Validation Operator's
@@ -55,7 +50,9 @@ func gatherDVOMetrics(
55
50
coreClient corev1client.CoreV1Interface ,
56
51
rateLimiter flowcontrol.RateLimiter ,
57
52
) ([]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
+ })
59
56
if err != nil {
60
57
return nil , []error {err }
61
58
}
@@ -65,13 +62,10 @@ func gatherDVOMetrics(
65
62
for svcIdx := range serviceList .Items {
66
63
// Use pointer to make gocritic happy and avoid copying the whole Service struct.
67
64
service := & serviceList .Items [svcIdx ]
68
- if ! dvoMetricsServiceNameRegex .MatchString (service .Name ) {
69
- continue
70
- }
71
65
for _ , port := range service .Spec .Ports {
72
66
apiURL := url.URL {
73
67
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 ),
75
69
}
76
70
77
71
prefixedLines , err := gatherDVOMetricsFromEndpoint (ctx , & apiURL , rateLimiter )
0 commit comments