Skip to content

Commit 2123773

Browse files
committed
pkg/manifests: Expose retention size settings for Platform Prometheus
Introduce a new "retentionSize" field under the prometheusK8s key When neither retention nor retentionSize are defined, a default of 15d for time retention applies. When "retentionSize" is defined and "retention" isn't, only size retention applies. When "retentionSize" isn't defined and "retention" is, only time retention applies When both time and size retention fields are defined, both apply. Signed-off-by: Jayapriya Pai <[email protected]>
1 parent 96a7c1d commit 2123773

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [#1350](https://github.com/openshift/cluster-monitoring-operator/pull/1350) Support label scrape limits in user-workload monitoring
99
- [#1601](https://github.com/openshift/cluster-monitoring-operator/pull/1601) Expose the /federate endpoint of UWM Prometheus as a service
1010
- [#1617](https://github.com/openshift/cluster-monitoring-operator/pull/1617) Add Oauth2 setting to PrometheusK8s remoteWrite config
11+
- [#1579](https://github.com/openshift/cluster-monitoring-operator/pull/1579) Expose retention size settings for Platform Prometheus
1112

1213
## 4.10
1314

pkg/manifests/config.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ type RemoteWriteSpec struct {
171171
type PrometheusK8sConfig struct {
172172
LogLevel string `json:"logLevel"`
173173
Retention string `json:"retention"`
174+
RetentionSize string `json:"retentionSize"`
174175
NodeSelector map[string]string `json:"nodeSelector"`
175176
Tolerations []v1.Toleration `json:"tolerations"`
176177
Resources *v1.ResourceRequirements `json:"resources"`
@@ -339,7 +340,7 @@ func (c *Config) applyDefaults() {
339340
if c.ClusterMonitoringConfiguration.PrometheusK8sConfig == nil {
340341
c.ClusterMonitoringConfiguration.PrometheusK8sConfig = &PrometheusK8sConfig{}
341342
}
342-
if c.ClusterMonitoringConfiguration.PrometheusK8sConfig.Retention == "" {
343+
if c.ClusterMonitoringConfiguration.PrometheusK8sConfig.Retention == "" && c.ClusterMonitoringConfiguration.PrometheusK8sConfig.RetentionSize == "" {
343344
c.ClusterMonitoringConfiguration.PrometheusK8sConfig.Retention = DefaultRetentionValue
344345
}
345346
if c.ClusterMonitoringConfiguration.AlertmanagerMainConfig == nil {

pkg/manifests/manifests.go

+4
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,10 @@ func (f *Factory) PrometheusK8s(grpcTLS *v1.Secret, trustedCABundleCM *v1.Config
14421442
p.Spec.Retention = f.config.ClusterMonitoringConfiguration.PrometheusK8sConfig.Retention
14431443
}
14441444

1445+
if f.config.ClusterMonitoringConfiguration.PrometheusK8sConfig.RetentionSize != "" {
1446+
p.Spec.RetentionSize = f.config.ClusterMonitoringConfiguration.PrometheusK8sConfig.RetentionSize
1447+
}
1448+
14451449
p.Spec.Image = &f.config.Images.Prometheus
14461450

14471451
if f.consoleConfig != nil && f.consoleConfig.Status.ConsoleURL != "" {

pkg/manifests/manifests_test.go

+68
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,74 @@ func TestPrometheusQueryLogFileConfig(t *testing.T) {
15571557
}
15581558
}
15591559

1560+
func TestPrometheusRetentionConfigs(t *testing.T) {
1561+
for _, tc := range []struct {
1562+
name string
1563+
retention string
1564+
retentionSize string
1565+
expectedRetention string
1566+
expectedRetentionSize string
1567+
}{
1568+
{
1569+
name: "both retention and retentionSize defined",
1570+
retention: "30d",
1571+
retentionSize: "15GiB",
1572+
expectedRetention: "30d",
1573+
expectedRetentionSize: "15GiB",
1574+
},
1575+
{
1576+
name: "only retention defined",
1577+
retention: "45d",
1578+
expectedRetention: "45d",
1579+
expectedRetentionSize: "",
1580+
},
1581+
{
1582+
name: "only retentionSize defined",
1583+
retentionSize: "25GB",
1584+
expectedRetention: "",
1585+
expectedRetentionSize: "25GB",
1586+
},
1587+
{
1588+
name: "both retention and retentionSize empty",
1589+
expectedRetention: "15d",
1590+
expectedRetentionSize: "",
1591+
},
1592+
} {
1593+
t.Run(tc.name, func(t *testing.T) {
1594+
c := NewDefaultConfig()
1595+
c.ClusterMonitoringConfiguration.PrometheusK8sConfig.Retention = tc.retention
1596+
c.ClusterMonitoringConfiguration.PrometheusK8sConfig.RetentionSize = tc.retentionSize
1597+
1598+
f := NewFactory("openshift-monitoring", "openshift-user-workload-monitoring", c, defaultInfrastructureReader(), &fakeProxyReader{}, NewAssets(assetsPath), &APIServerConfig{}, &configv1.Console{})
1599+
1600+
p, err := f.PrometheusK8s(
1601+
&v1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
1602+
&v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
1603+
)
1604+
1605+
if tc.retention == "" && tc.retentionSize == "" {
1606+
if p.Spec.Retention != "15d" && p.Spec.RetentionSize != "" {
1607+
t.Fatal("Default Retention is not configured correctly")
1608+
}
1609+
return
1610+
}
1611+
1612+
if p.Spec.Retention != tc.expectedRetention {
1613+
t.Fatal("Retention is not configured correctly")
1614+
}
1615+
1616+
if p.Spec.RetentionSize != tc.expectedRetentionSize {
1617+
t.Fatal("RetentionSize is not configured correctly")
1618+
}
1619+
1620+
if err != nil {
1621+
t.Fatalf("Unexpected error occured %v", err)
1622+
return
1623+
}
1624+
})
1625+
}
1626+
}
1627+
15601628
func TestPrometheusK8sAdditionalAlertManagerConfigsSecret(t *testing.T) {
15611629
testCases := []struct {
15621630
name string

0 commit comments

Comments
 (0)