@@ -29,6 +29,11 @@ import (
29
29
30
30
const (
31
31
DefaultRetentionValue = "15d"
32
+
33
+ // Limit the body size from scrape queries
34
+ // Assumptions: one node has maximum 110 pods, each pod exposes 100 metrics, each metric is expressed by at most 100 bytes.
35
+ // 1.5x the size for a safe margin, it rounds up to 2MB.
36
+ DefaultScrapeBodySizeLimit = "2MB"
32
37
)
33
38
34
39
type Config struct {
@@ -105,6 +110,7 @@ type ClusterMonitoringConfiguration struct {
105
110
K8sPrometheusAdapter * K8sPrometheusAdapter `json:"k8sPrometheusAdapter"`
106
111
ThanosQuerierConfig * ThanosQuerierConfig `json:"thanosQuerier"`
107
112
UserWorkloadEnabled * bool `json:"enableUserWorkload"`
113
+ LimitScrapeBodySize * bool `json:"limitScrapeBodySize"`
108
114
}
109
115
110
116
type Images struct {
@@ -168,17 +174,18 @@ type RemoteWriteSpec struct {
168
174
}
169
175
170
176
type PrometheusK8sConfig struct {
171
- LogLevel string `json:"logLevel"`
172
- Retention string `json:"retention"`
173
- NodeSelector map [string ]string `json:"nodeSelector"`
174
- Tolerations []v1.Toleration `json:"tolerations"`
175
- Resources * v1.ResourceRequirements `json:"resources"`
176
- ExternalLabels map [string ]string `json:"externalLabels"`
177
- VolumeClaimTemplate * monv1.EmbeddedPersistentVolumeClaim `json:"volumeClaimTemplate"`
178
- RemoteWrite []RemoteWriteSpec `json:"remoteWrite"`
179
- TelemetryMatches []string `json:"-"`
180
- AlertmanagerConfigs []AdditionalAlertmanagerConfig `json:"additionalAlertmanagerConfigs"`
181
- QueryLogFile string `json:"queryLogFile"`
177
+ LogLevel string `json:"logLevel"`
178
+ Retention string `json:"retention"`
179
+ NodeSelector map [string ]string `json:"nodeSelector"`
180
+ Tolerations []v1.Toleration `json:"tolerations"`
181
+ Resources * v1.ResourceRequirements `json:"resources"`
182
+ ExternalLabels map [string ]string `json:"externalLabels"`
183
+ VolumeClaimTemplate * monv1.EmbeddedPersistentVolumeClaim `json:"volumeClaimTemplate"`
184
+ RemoteWrite []RemoteWriteSpec `json:"remoteWrite"`
185
+ TelemetryMatches []string `json:"-"`
186
+ AlertmanagerConfigs []AdditionalAlertmanagerConfig `json:"additionalAlertmanagerConfigs"`
187
+ QueryLogFile string `json:"queryLogFile"`
188
+ EnforcedBodySizeLimit string `json:"enforcedBodySizeLimit,omitempty"`
182
189
}
183
190
184
191
type AdditionalAlertmanagerConfig struct {
@@ -385,6 +392,25 @@ func (c *Config) applyDefaults() {
385
392
if c .ClusterMonitoringConfiguration .EtcdConfig == nil {
386
393
c .ClusterMonitoringConfiguration .EtcdConfig = & EtcdConfig {}
387
394
}
395
+ if c .ClusterMonitoringConfiguration .LimitScrapeBodySize == nil {
396
+ disable := false
397
+ c .ClusterMonitoringConfiguration .LimitScrapeBodySize = & disable
398
+ } else if * c .ClusterMonitoringConfiguration .LimitScrapeBodySize {
399
+ c .ClusterMonitoringConfiguration .PrometheusK8sConfig .EnforcedBodySizeLimit = DefaultScrapeBodySizeLimit
400
+ }
401
+ }
402
+
403
+ func (c * Config ) ActivatePromEnforceBodyLimit () {
404
+ c .ClusterMonitoringConfiguration .PrometheusK8sConfig .EnforcedBodySizeLimit = DefaultScrapeBodySizeLimit
405
+ if * c .ClusterMonitoringConfiguration .UserWorkloadEnabled {
406
+ c .UserWorkloadConfiguration .Prometheus .EnforcedBodySizeLimit = DefaultScrapeBodySizeLimit
407
+ }
408
+ }
409
+ func (c * Config ) DeactivatePromEnforceBodyLimit () {
410
+ c .ClusterMonitoringConfiguration .PrometheusK8sConfig .EnforcedBodySizeLimit = ""
411
+ if * c .ClusterMonitoringConfiguration .UserWorkloadEnabled {
412
+ c .UserWorkloadConfiguration .Prometheus .EnforcedBodySizeLimit = ""
413
+ }
388
414
}
389
415
390
416
func (c * Config ) SetImages (images map [string ]string ) {
@@ -498,18 +524,19 @@ type UserWorkloadConfiguration struct {
498
524
}
499
525
500
526
type PrometheusRestrictedConfig struct {
501
- LogLevel string `json:"logLevel"`
502
- Retention string `json:"retention"`
503
- NodeSelector map [string ]string `json:"nodeSelector"`
504
- Tolerations []v1.Toleration `json:"tolerations"`
505
- Resources * v1.ResourceRequirements `json:"resources"`
506
- ExternalLabels map [string ]string `json:"externalLabels"`
507
- VolumeClaimTemplate * monv1.EmbeddedPersistentVolumeClaim `json:"volumeClaimTemplate"`
508
- RemoteWrite []RemoteWriteSpec `json:"remoteWrite"`
509
- EnforcedSampleLimit * uint64 `json:"enforcedSampleLimit"`
510
- EnforcedTargetLimit * uint64 `json:"enforcedTargetLimit"`
511
- AlertmanagerConfigs []AdditionalAlertmanagerConfig `json:"additionalAlertmanagerConfigs"`
512
- QueryLogFile string `json:"queryLogFile"`
527
+ LogLevel string `json:"logLevel"`
528
+ Retention string `json:"retention"`
529
+ NodeSelector map [string ]string `json:"nodeSelector"`
530
+ Tolerations []v1.Toleration `json:"tolerations"`
531
+ Resources * v1.ResourceRequirements `json:"resources"`
532
+ ExternalLabels map [string ]string `json:"externalLabels"`
533
+ VolumeClaimTemplate * monv1.EmbeddedPersistentVolumeClaim `json:"volumeClaimTemplate"`
534
+ RemoteWrite []RemoteWriteSpec `json:"remoteWrite"`
535
+ EnforcedSampleLimit * uint64 `json:"enforcedSampleLimit"`
536
+ EnforcedTargetLimit * uint64 `json:"enforcedTargetLimit"`
537
+ AlertmanagerConfigs []AdditionalAlertmanagerConfig `json:"additionalAlertmanagerConfigs"`
538
+ QueryLogFile string `json:"queryLogFile"`
539
+ EnforcedBodySizeLimit string `json:"enforcedBodySizeLimit,omitempty"`
513
540
}
514
541
515
542
func (u * UserWorkloadConfiguration ) applyDefaults () {
0 commit comments