@@ -20,12 +20,14 @@ import (
20
20
21
21
"github.com/openshift/insights-operator/pkg/config"
22
22
"github.com/openshift/insights-operator/pkg/record"
23
+ "github.com/openshift/insights-operator/pkg/types"
23
24
"github.com/openshift/insights-operator/pkg/utils"
24
25
"github.com/openshift/insights-operator/pkg/utils/marshal"
25
26
)
26
27
27
28
const (
28
29
managedDVONamespaceName = "openshift-deployment-validation-operator"
30
+ serviceLabelSelector = "name=deployment-validation-operator"
29
31
)
30
32
31
33
// GatherDVOMetrics Collects metrics from the Deployment Validation Operator's
@@ -35,6 +37,12 @@ const (
35
37
// then the names of the workloads (e.g., namespace, deployment) are collected.
36
38
// Otherwise, only the UIDs of those resources are collected.
37
39
//
40
+ // If no service with label selector `name=deployment-validation-operator` is found,
41
+ // then there is no `dvo_metrics` file in the archive (and the warning is present in the archive metadata).
42
+ // If a service with the selector `name=deployment-validation-operator` is found,
43
+ // but no active DVO checks are available,
44
+ // then the `dvo_metrics` file in the archive is almost empty (only the URL of the service is there).
45
+ //
38
46
// ### API Reference
39
47
// None
40
48
//
@@ -71,14 +79,24 @@ func gatherDVOMetrics(
71
79
obfuscation config.Obfuscation ,
72
80
) ([]record.Record , []error ) {
73
81
serviceList , err := coreClient .Services ("" ).List (ctx , metav1.ListOptions {
74
- LabelSelector : "name=deployment-validation-operator" ,
82
+ LabelSelector : serviceLabelSelector ,
75
83
})
76
84
if err != nil {
77
85
return nil , []error {err }
78
86
}
79
87
88
+ // This means that no service was found with the "name=deployment-validation-operator" label selector,
89
+ // which may indicate that DVO is not installed (or not properly installed).
90
+ // Record is not created.
91
+ if len (serviceList .Items ) == 0 {
92
+ klog .Warning ("No DVO metrics gathered" )
93
+ return nil , []error {
94
+ & types.Warning {UnderlyingValue : fmt .Errorf ("no service found with label selector %s" , serviceLabelSelector )},
95
+ }
96
+ }
97
+
80
98
useUIDs := false
81
- nonFatalErrors := []error {}
99
+ errors := []error {}
82
100
allDVOMetricsLines := []byte {}
83
101
for svcIdx := range serviceList .Items {
84
102
// Use pointer to make gocritic happy and avoid copying the whole Service struct.
@@ -97,7 +115,7 @@ func gatherDVOMetrics(
97
115
// It is possible that this service is not really the correct one
98
116
// and a different service may return the metrics we are looking for.
99
117
klog .Warningf ("Unable to read metrics from endpoint %q: %v" , apiURL .String (), err )
100
- nonFatalErrors = append (nonFatalErrors , err )
118
+ errors = append (errors , err )
101
119
continue
102
120
}
103
121
@@ -112,15 +130,9 @@ func gatherDVOMetrics(
112
130
}
113
131
}
114
132
115
- // If there are no DVO metrics (or no DVO metrics service), don't create a record at all.
116
- if len (allDVOMetricsLines ) == 0 {
117
- klog .Warning ("No DVO metrics gathered" )
118
- return nil , nonFatalErrors
119
- }
120
-
121
133
return []record.Record {
122
134
{Name : "config/dvo_metrics" , Item : marshal .RawByte (allDVOMetricsLines )},
123
- }, nonFatalErrors
135
+ }, errors
124
136
}
125
137
126
138
func gatherDVOMetricsFromEndpoint (
0 commit comments