Skip to content

OCPBUGS-439: update the DVO metrics gatherer #664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/conditional-gatherer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ echo '{
4. Wait for the alert to fire:
```bash
export PROMETHEUS_HOST=$(oc get route -n openshift-monitoring prometheus-k8s -o jsonpath='{@.spec.host}')
export INSECURE_PROMETHEUS_TOKEN=$(oc get secret $(oc get sa prometheus-k8s -n openshift-monitoring -o json | jq .secrets[0].name | tr --delete \") -n openshift-monitoring -o json | jq .metadata.annotations.\"openshift.io/token-secret.value\")
export INSECURE_PROMETHEUS_TOKEN=$(oc get secret $(oc get sa prometheus-k8s -n openshift-monitoring -o json | jq .secrets[0].name | tr --delete \") -n openshift-monitoring -o json | jq .metadata.annotations.\"openshift.io/token-secret.value\" | tr --delete \")
curl -g -s -k -H 'Cache-Control: no-cache' -H "Authorization: Bearer $INSECURE_PROMETHEUS_TOKEN" "https://$PROMETHEUS_HOST/api/v1/query" --data-urlencode 'query=ALERTS{alertstate="firing",alertname="SamplesImagestreamImportFailing"}' | jq ".data.result[]"
```

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/start/receiver.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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