Skip to content

pkg/manifests: Add EnforcedTargetLimit for user-workload monitoring #1278

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 1 commit into from
Jul 12, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 4.9

- [#1241](https://github.com/openshift/cluster-monitoring-operator/pull/1241) Add config option to disable Grafana deployment.
- [#1278](https://github.com/openshift/cluster-monitoring-operator/pull/1278) Add EnforcedTargetLimit option for user-workload Prometheus.

## 4.8

Expand Down
1 change: 1 addition & 0 deletions pkg/manifests/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ type PrometheusRestrictedConfig struct {
VolumeClaimTemplate *monv1.EmbeddedPersistentVolumeClaim `json:"volumeClaimTemplate"`
RemoteWrite []monv1.RemoteWriteSpec `json:"remoteWrite"`
EnforcedSampleLimit *uint64 `json:"enforcedSampleLimit"`
EnforcedTargetLimit *uint64 `json:"enforcedTargetLimit"`
}

func (u *UserWorkloadConfiguration) applyDefaults() {
Expand Down
4 changes: 4 additions & 0 deletions pkg/manifests/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,10 @@ func (f *Factory) PrometheusUserWorkload(grpcTLS *v1.Secret) (*monv1.Prometheus,
p.Spec.EnforcedSampleLimit = f.config.UserWorkloadConfiguration.Prometheus.EnforcedSampleLimit
}

if f.config.UserWorkloadConfiguration.Prometheus.EnforcedTargetLimit != nil {
p.Spec.EnforcedTargetLimit = f.config.UserWorkloadConfiguration.Prometheus.EnforcedTargetLimit
}

// end removal
if f.config.Images.Thanos != "" {
p.Spec.Thanos.Image = &f.config.Images.Thanos
Expand Down
25 changes: 25 additions & 0 deletions test/e2e/user_workload_monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestUserWorkloadMonitoring(t *testing.T) {
},
Data: map[string]string{
"config.yaml": `prometheus:
enforcedTargetLimit: 10
volumeClaimTemplate:
spec:
resources:
Expand Down Expand Up @@ -92,6 +93,7 @@ func TestUserWorkloadMonitoring(t *testing.T) {
{"assert tenancy model is enforced for rules", assertTenancyForRules},
{"assert prometheus and alertmanager is not deployed in user namespace", assertPrometheusAlertmanagerInUserNamespace},
{"assert grpc tls rotation", assertGRPCTLSRotation},
{"assert enforced target limit is configured", assertEnforcedTargetLimit(10)},
{"enable user workload monitoring, assert prometheus rollout", createUserWorkloadAssets(cm)},
{"set VolumeClaimTemplate for prometheus CR, assert that it is created", assertVolumeClaimsConfigAndRollout(rolloutParams{
namespace: f.UserWorkloadMonitoringNs,
Expand Down Expand Up @@ -983,3 +985,26 @@ func assertDeletedUserWorkloadAssets(cm *v1.ConfigMap) func(*testing.T) {
}
}
}

func assertEnforcedTargetLimit(limit uint64) func(*testing.T) {
return func(t *testing.T) {
err := framework.Poll(time.Second, 5*time.Minute, func() error {
prom, err := f.MonitoringClient.Prometheuses(f.UserWorkloadMonitoringNs).Get(f.Ctx, "user-workload", metav1.GetOptions{})
if err != nil {
return err
}

if prom.Spec.EnforcedTargetLimit == nil {
return errors.New("EnforcedTargetLimit not set")
} else if *prom.Spec.EnforcedTargetLimit != limit {
return fmt.Errorf("expected EnforcedTargetLimit to be %d, but got %d", limit, *prom.Spec.EnforcedTargetLimit)
}

return nil
})

if err != nil {
t.Fatalf("Timed out waiting for EnforcedTargetLimit configuration: %v", err)
}
}
}