Skip to content

Commit 6ddd8b6

Browse files
committed
DVO metrics gatherer minor changes
1 parent a836d6c commit 6ddd8b6

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

docs/gathered-data.md

+6
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,12 @@ If the DVO service is deployed in a namespace other than `openshift-deployment-v
751751
then the names of the workloads (e.g., namespace, deployment) are collected.
752752
Otherwise, only the UIDs of those resources are collected.
753753

754+
If no service with label selector `name=deployment-validation-operator` is found,
755+
then there is no `dvo_metrics` file in the archive (and the warning is present in the archive metadata).
756+
If a service with the selector `name=deployment-validation-operator` is found,
757+
but no active DVO checks are available,
758+
then the `dvo_metrics` file in the archive is almost empty (only the URL of the service is there).
759+
754760
### API Reference
755761
None
756762

pkg/gatherers/clusterconfig/gather_dvo_metrics.go

+22-10
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ import (
2020

2121
"github.com/openshift/insights-operator/pkg/config"
2222
"github.com/openshift/insights-operator/pkg/record"
23+
"github.com/openshift/insights-operator/pkg/types"
2324
"github.com/openshift/insights-operator/pkg/utils"
2425
"github.com/openshift/insights-operator/pkg/utils/marshal"
2526
)
2627

2728
const (
2829
managedDVONamespaceName = "openshift-deployment-validation-operator"
30+
serviceLabelSelector = "name=deployment-validation-operator"
2931
)
3032

3133
// GatherDVOMetrics Collects metrics from the Deployment Validation Operator's
@@ -35,6 +37,12 @@ const (
3537
// then the names of the workloads (e.g., namespace, deployment) are collected.
3638
// Otherwise, only the UIDs of those resources are collected.
3739
//
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+
//
3846
// ### API Reference
3947
// None
4048
//
@@ -71,14 +79,24 @@ func gatherDVOMetrics(
7179
obfuscation config.Obfuscation,
7280
) ([]record.Record, []error) {
7381
serviceList, err := coreClient.Services("").List(ctx, metav1.ListOptions{
74-
LabelSelector: "name=deployment-validation-operator",
82+
LabelSelector: serviceLabelSelector,
7583
})
7684
if err != nil {
7785
return nil, []error{err}
7886
}
7987

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+
8098
useUIDs := false
81-
nonFatalErrors := []error{}
99+
errors := []error{}
82100
allDVOMetricsLines := []byte{}
83101
for svcIdx := range serviceList.Items {
84102
// Use pointer to make gocritic happy and avoid copying the whole Service struct.
@@ -97,7 +115,7 @@ func gatherDVOMetrics(
97115
// It is possible that this service is not really the correct one
98116
// and a different service may return the metrics we are looking for.
99117
klog.Warningf("Unable to read metrics from endpoint %q: %v", apiURL.String(), err)
100-
nonFatalErrors = append(nonFatalErrors, err)
118+
errors = append(errors, err)
101119
continue
102120
}
103121

@@ -112,15 +130,9 @@ func gatherDVOMetrics(
112130
}
113131
}
114132

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-
121133
return []record.Record{
122134
{Name: "config/dvo_metrics", Item: marshal.RawByte(allDVOMetricsLines)},
123-
}, nonFatalErrors
135+
}, errors
124136
}
125137

126138
func gatherDVOMetricsFromEndpoint(

0 commit comments

Comments
 (0)