Skip to content
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

[release-4.10] OCPBUGS-10419: [metrics] Ignore case of cluster monitoring label #1497

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package metrics
import (
"context"
"encoding/json"
"strconv"

"github.com/pkg/errors"
monclient "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned/typed/monitoring/v1"
Expand Down Expand Up @@ -236,21 +237,29 @@ func (c *Config) Configure(ctx context.Context) error {
return nil
}

// validate will verify if cluster monitoring is enabled in the operator namespace.
// If the label is not present, it will log and send warning events to the user.
// validate will verify if cluster monitoring is enabled in the operator namespace. If the label is set to false or not
// present, it will log and send warning events to the user. If the label holds a non-boolean value, returns an error.
func (c *Config) validate(ctx context.Context) (bool, error) {
// validate if metrics label is added to namespace
wmcoNamespace, err := c.CoreV1().Namespaces().Get(ctx, c.namespace, metav1.GetOptions{})
if err != nil {
return false, errors.Wrap(err, "error getting operator namespace")
}
if wmcoNamespace.Labels["openshift.io/cluster-monitoring"] != "true" {
metricsEnabled = false

labelValue := false
// if the label exists, update value from default of false
if value, ok := wmcoNamespace.Labels["openshift.io/cluster-monitoring"]; ok {
labelValue, err = strconv.ParseBool(value)
if err != nil {
return false, errors.Wrap(err, "monitoring label must have a boolean value")
}
}
if !labelValue {
c.recorder.Eventf(wmcoNamespace, v1.EventTypeWarning, "labelValidationFailed",
"Cluster monitoring openshift.io/cluster-monitoring=true label is not enabled in %s namespace", c.namespace)
return false, nil
}
return true, nil
metricsEnabled = labelValue
return metricsEnabled, nil
}

// createEndpoint creates an endpoint object in the operator namespace.
Expand Down