Skip to content

Commit 074bee5

Browse files
committed
MON-4057: Expose scrapeInterval setting for UWM Prometheus
Signed-off-by: Jayapriya Pai <[email protected]>
1 parent 9018920 commit 074bee5

File tree

7 files changed

+50
-0
lines changed

7 files changed

+50
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Note: This CHANGELOG is only for the monitoring team to track all monitoring related changes. Please see OpenShift release notes for official changes.
22

3+
## 4.18
4+
5+
- [#2503] (https://github.com/openshift/cluster-monitoring-operator/issues/2503) Expose `scrapeInterval` setting for UWM Prometheus.
6+
37
## 4.17
48

59
- [#2409](https://github.com/openshift/cluster-monitoring-operator/issues/2409) Remove prometheus-adapter code from CMO

Documentation/api.md

+1
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ The `PrometheusRestrictedConfig` resource defines the settings for the Prometheu
484484

485485
| Property | Type | Description |
486486
| -------- | ---- | ----------- |
487+
| scrapeInterval | string | Configures Interval between consecutive scrapes. The default value is `30s`. |
487488
| additionalAlertmanagerConfigs | [][AdditionalAlertmanagerConfig](#additionalalertmanagerconfig) | Configures additional Alertmanager instances that receive alerts from the Prometheus component. By default, no additional Alertmanager instances are configured. |
488489
| enforcedLabelLimit | *uint64 | Specifies a per-scrape limit on the number of labels accepted for a sample. If the number of labels exceeds this limit after metric relabeling, the entire scrape is treated as failed. The default value is `0`, which means that no limit is set. |
489490
| enforcedLabelNameLengthLimit | *uint64 | Specifies a per-scrape limit on the length of a label name for a sample. If the length of a label name exceeds this limit after metric relabeling, the entire scrape is treated as failed. The default value is `0`, which means that no limit is set. |

Documentation/openshiftdocs/modules/prometheusrestrictedconfig.adoc

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Appears in: link:userworkloadconfiguration.adoc[UserWorkloadConfiguration]
1818
[options="header"]
1919
|===
2020
| Property | Type | Description
21+
|scrapeInterval|string|Configures Interval between consecutive scrapes. The default value is `30s`.
22+
2123
|additionalAlertmanagerConfigs|[]link:additionalalertmanagerconfig.adoc[AdditionalAlertmanagerConfig]|Configures additional Alertmanager instances that receive alerts from the Prometheus component. By default, no additional Alertmanager instances are configured.
2224

2325
|enforcedLabelLimit|*uint64|Specifies a per-scrape limit on the number of labels accepted for a sample. If the number of labels exceeds this limit after metric relabeling, the entire scrape is treated as failed. The default value is `0`, which means that no limit is set.

pkg/manifests/manifests.go

+4
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,10 @@ func (f *Factory) PrometheusUserWorkload(grpcTLS *v1.Secret) (*monv1.Prometheus,
16581658
if err != nil {
16591659
return nil, err
16601660
}
1661+
if f.config.UserWorkloadConfiguration.Prometheus.ScrapeInterval != "" {
1662+
p.Spec.ScrapeInterval = monv1.Duration(f.config.UserWorkloadConfiguration.Prometheus.ScrapeInterval)
1663+
}
1664+
16611665
if f.config.UserWorkloadConfiguration.Prometheus.LogLevel != "" {
16621666
p.Spec.LogLevel = f.config.UserWorkloadConfiguration.Prometheus.LogLevel
16631667
}

pkg/manifests/manifests_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,7 @@ func TestPrometheusUserWorkloadConfiguration(t *testing.T) {
16431643
c := NewDefaultConfig()
16441644

16451645
uwc, err := NewUserConfigFromString(`prometheus:
1646+
scrapeInterval: 15s
16461647
resources:
16471648
requests:
16481649
cpu: 100m
@@ -1670,6 +1671,10 @@ func TestPrometheusUserWorkloadConfiguration(t *testing.T) {
16701671
t.Fatal(err)
16711672
}
16721673

1674+
if p.Spec.ScrapeInterval != "15s" {
1675+
t.Fatal("Prometheus UWM scrapeInterval not configured correctly")
1676+
}
1677+
16731678
if p.Spec.TopologySpreadConstraints[0].MaxSkew != 1 {
16741679
t.Fatal("Prometheus UWM spread constraints MaxSkew not configured correctly")
16751680
}

pkg/manifests/types.go

+3
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,9 @@ type AlertmanagerUserWorkloadConfig struct {
601601
// The `PrometheusRestrictedConfig` resource defines the settings for the
602602
// Prometheus component that monitors user-defined projects.
603603
type PrometheusRestrictedConfig struct {
604+
// Configures Interval between consecutive scrapes.
605+
// The default value is `30s`.
606+
ScrapeInterval string `json:"scrapeInterval,omitempty"`
604607
// Configures additional Alertmanager instances that receive alerts from
605608
// the Prometheus component. By default, no additional Alertmanager
606609
// instances are configured.

test/e2e/config_test.go

+31
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ import (
3030
"github.com/openshift/cluster-monitoring-operator/test/e2e/framework"
3131
"github.com/stretchr/testify/require"
3232

33+
monv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
3334
v1 "k8s.io/api/core/v1"
35+
3436
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3537
)
3638

@@ -585,6 +587,7 @@ func TestUserWorkloadMonitorPrometheusK8Config(t *testing.T) {
585587

586588
uwmCM := f.BuildUserWorkloadConfigMap(t,
587589
fmt.Sprintf(`prometheus:
590+
scrapeInterval: 15s
588591
enforcedTargetLimit: 10
589592
enforcedLabelLimit: 500
590593
enforcedLabelNameLengthLimit: 50
@@ -671,6 +674,10 @@ func TestUserWorkloadMonitorPrometheusK8Config(t *testing.T) {
671674
name: "assert query log file value is set and correct",
672675
assertion: assertQueryLogValueEquals(f.UserWorkloadMonitoringNs, crName, "/tmp/test.log"),
673676
},
677+
{
678+
name: "assert scrape interval is configured",
679+
assertion: assertScrapeInterval("15s"),
680+
},
674681
} {
675682
t.Run(tc.name, tc.assertion)
676683
}
@@ -1028,6 +1035,30 @@ func assertRemoteWriteWasSet(namespace, crName, urlValue string) func(t *testing
10281035
}
10291036
}
10301037

1038+
func assertScrapeInterval(scrapeInterval string) func(*testing.T) {
1039+
ctx := context.Background()
1040+
return func(t *testing.T) {
1041+
err := framework.Poll(time.Second, 5*time.Minute, func() error {
1042+
p, err := f.MonitoringClient.Prometheuses(f.UserWorkloadMonitoringNs).Get(ctx, "user-workload", metav1.GetOptions{})
1043+
if err != nil {
1044+
return err
1045+
}
1046+
1047+
if p.Spec.ScrapeInterval == "" {
1048+
return errors.New("scrapeInterval is not set")
1049+
} else if p.Spec.ScrapeInterval != monv1.Duration(scrapeInterval) {
1050+
return fmt.Errorf("expected scrapeInterval to be %s, but got %s", scrapeInterval, p.Spec.ScrapeInterval)
1051+
}
1052+
1053+
return nil
1054+
})
1055+
1056+
if err != nil {
1057+
t.Fatalf("Timed out waiting for scrapeInterval configuration: %v", err)
1058+
}
1059+
}
1060+
}
1061+
10311062
func assertEnforcedTargetLimit(limit uint64) func(*testing.T) {
10321063
ctx := context.Background()
10331064
return func(t *testing.T) {

0 commit comments

Comments
 (0)