Skip to content

Commit

Permalink
[release-4.11] OCPBUGS-1355: update the DVO metrics gatherer (#664) (#…
Browse files Browse the repository at this point in the history
…677)

* OCPBUGS-439 update the DVO metrics gatherer

* Fix linting
  • Loading branch information
tremes committed Sep 19, 2022
1 parent 3b9cfcb commit 6c013e7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/start/receiver.go
Expand Up @@ -20,7 +20,7 @@ func NewReceiver() *cobra.Command {
Use: "start-receiver",
Short: "Start a listener that accepts and logs uploaded content",
RunE: func(cmd *cobra.Command, args []string) error {
return http.ListenAndServe(listen, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
return http.ListenAndServe(listen, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { // nolint: gosec
klog.Infof("Handling %s", req.URL.Path)
contentType := req.Header.Get("Content-Type")
if len(contentType) == 0 {
Expand Down
18 changes: 6 additions & 12 deletions pkg/gatherers/clusterconfig/dvo_metrics.go
Expand Up @@ -7,7 +7,6 @@ import (
"io"
"net/http"
"net/url"
"regexp"

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

const (
dvoNamespace = "deployment-validation-operator"
)

var (
// Only services with the word "metrics" in their name should be considered.
dvoMetricsServiceNameRegex = regexp.MustCompile(`\bmetrics\b`)
// Only metrics with the DVO prefix should be gathered.
dvoMetricsPrefix = []byte("deployment_validation_operator_")
// label selector used for searching the required service
serviceLabelSelector = "name=deployment-validation-operator"
)

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

prefixedLines, err := gatherDVOMetricsFromEndpoint(ctx, &apiURL, rateLimiter)
Expand Down
2 changes: 1 addition & 1 deletion pkg/recorder/diskrecorder/diskrecorder.go
Expand Up @@ -158,7 +158,7 @@ func (d *DiskRecorder) Summary(_ context.Context, since time.Time) (*insightscli
if isNotArchiveFile(fileInfo) {
continue
}
if !fileInfo.ModTime().After(since) {
if fileInfo.ModTime().Before(since) {
continue
}
recentFiles = append(recentFiles, file.Name())
Expand Down

0 comments on commit 6c013e7

Please sign in to comment.