-
Notifications
You must be signed in to change notification settings - Fork 370
WIP: OCPBUGS-18282: Reject reserved labels used as external labels #2579
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
Conversation
prometheus and prometheus_replica are reserved labels, if a user configures this as a label in externalLabels in cluster-monitoring-configmap warn user about this and make operator status Degraded Signed-off-by: Jayapriya Pai <[email protected]>
Signed-off-by: Jayapriya Pai <[email protected]>
@slashpai: This pull request references Jira Issue OCPBUGS-18282, which is valid. The bug has been moved to the POST state. 3 validation(s) were run on this bug
Requesting review from QA contact: The bug has been updated to refer to the pull request using the external bug tracker. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: slashpai The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@slashpai: The following tests failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
@@ -34,6 +34,8 @@ const ( | |||
StorageNotConfiguredReason = "PrometheusDataPersistenceNotConfigured" | |||
UserAlermanagerConfigMisconfiguredMessage = "Misconfigured Alertmanager: Alertmanager for user-defined alerting is enabled in the openshift-monitoring/cluster-monitoring-config configmap by setting 'enableUserAlertmanagerConfig: true' field. This conflicts with a dedicated Alertmanager instance enabled in openshift-user-workload-monitoring/user-workload-monitoring-config. Alertmanager enabled in openshift-user-workload-monitoring takes precedence over the one in openshift-monitoring, so please remove the 'enableUserAlertmanagerConfig' field in openshift-monitoring/cluster-monitoring-config." | |||
UserAlermanagerConfigMisconfiguredReason = "UserAlertmanagerMisconfigured" | |||
CannotUseReservedExternalLabelsMessage = "Reserved Labels cannot be as External Labels. `externalLabels` specified under `prometheusK8s` field in the `openshift-monitoring/cluster-monitoring-config` uses reserved labels `prometheus` or `prometheus_replica` which is not allowed, please remove these from externalLabels" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UWM prometheus also can set external labels
https://github.com/openshift/cluster-monitoring-operator/blob/release-4.18/pkg/manifests/types.go#L654-L658
from warning message in https://docs.redhat.com/en/documentation/openshift_container_platform/4.17/html/monitoring/configuring-core-platform-monitoring#attaching-additional-labels-to-your-time-series-and-alerts_configuring-alerts-and-notifications |
Yeah good catch, I think |
Thanks for reviving this. diff --git a/pkg/manifests/config.go b/pkg/manifests/config.go
index be013ce12..247cd2340 100644
--- a/pkg/manifests/config.go
+++ b/pkg/manifests/config.go
@@ -52,6 +52,7 @@ const (
)
var errAlertmanagerV1NotSupported = errors.New("alertmanager's apiVersion=v1 is no longer supported, v2 has been available since Alertmanager 0.16.0")
+var reservedPrometheusExternalLabels = []string{"prometheus", "promtheus_replica"}
type Config struct {
Images *Images `json:"-"`
@@ -713,3 +714,17 @@ func NewDefaultUserWorkloadMonitoringConfig() *UserWorkloadConfiguration {
u.applyDefaults()
return u
}
+
+func (lb *ExternalLabels) UnmarshalJSON(data []byte) error {
+ var v map[string]string
+ if err := json.Unmarshal(data, &v); err != nil {
+ return err
+ }
+ for _, r := range reservedPrometheusExternalLabels {
+ if _, ok := v[r]; ok {
+ return fmt.Errorf("XXX")
+ }
+ }
+ *lb = v
+ return nil
+}
diff --git a/pkg/manifests/types.go b/pkg/manifests/types.go
index ad06174ba..c60162b40 100644
--- a/pkg/manifests/types.go
+++ b/pkg/manifests/types.go
@@ -22,6 +22,8 @@ import (
type CollectionProfile string
type CollectionProfiles []CollectionProfile
+type ExternalLabels map[string]string
+
const (
FullCollectionProfile = "full"
MinimalCollectionProfile = "minimal"
@@ -191,7 +193,7 @@ type PrometheusK8sConfig struct {
// Defines labels to be added to any time series or alerts when
// communicating with external systems such as federation, remote storage,
// and Alertmanager. By default, no labels are added.
- ExternalLabels map[string]string `json:"externalLabels,omitempty"`
+ ExternalLabels ExternalLabels `json:"externalLabels,omitempty"`
// Defines the log level setting for Prometheus.
// The possible values are: `error`, `warn`, `info`, and `debug`.
// The default value is `info`.
@@ -655,7 +657,7 @@ type PrometheusRestrictedConfig struct {
// communicating with external systems such as federation, remote storage,
// and Alertmanager.
// By default, no labels are added.
- ExternalLabels map[string]string `json:"externalLabels,omitempty"`
+ ExternalLabels ExternalLabels `json:"externalLabels,omitempty"`
// Defines the log level setting for Prometheus.
// The possible values are `error`, `warn`, `info`, and `debug`.
// The default setting is `info`. (implementing |
…rnalLabels supersedes openshift#2579 As this is done at the parsing level, the monitoringconfigmaps.openshift.io webhook would catch this early.
we agreed on implementing #2579 (comment) here #2604 /close |
@slashpai: This pull request references Jira Issue OCPBUGS-18282. The bug has been updated to no longer refer to the pull request using the external bug tracker. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
@machine424: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
…rnalLabels supersedes openshift#2579 As this is done at the parsing level, the monitoringconfigmaps.openshift.io webhook would catch this early.
API documentation for
externalLabels
is like thisWe also advise not to use reserved labels
prometheus
orprometheus_replica
as externalLabels, because they are reserved and will be overwritten. It was not overwritten due to bug in PO which is fixed in upstream.This change is for CMO to reject it beforehand and report to user if they use reserved labels as externalLabels