Skip to content

Commit 6c013e7

Browse files
authored
[release-4.11] OCPBUGS-1355: update the DVO metrics gatherer (#664) (#677)
* OCPBUGS-439 update the DVO metrics gatherer * Fix linting
1 parent 3b9cfcb commit 6c013e7

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

pkg/cmd/start/receiver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func NewReceiver() *cobra.Command {
2020
Use: "start-receiver",
2121
Short: "Start a listener that accepts and logs uploaded content",
2222
RunE: func(cmd *cobra.Command, args []string) error {
23-
return http.ListenAndServe(listen, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
23+
return http.ListenAndServe(listen, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { // nolint: gosec
2424
klog.Infof("Handling %s", req.URL.Path)
2525
contentType := req.Header.Get("Content-Type")
2626
if len(contentType) == 0 {

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)

pkg/recorder/diskrecorder/diskrecorder.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (d *DiskRecorder) Summary(_ context.Context, since time.Time) (*insightscli
158158
if isNotArchiveFile(fileInfo) {
159159
continue
160160
}
161-
if !fileInfo.ModTime().After(since) {
161+
if fileInfo.ModTime().Before(since) {
162162
continue
163163
}
164164
recentFiles = append(recentFiles, file.Name())

0 commit comments

Comments
 (0)