1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-21 11:48:53 +00:00

Support for storage.tsdb.retention.size for prometheus 2.7+

This commit is contained in:
Johan Gonzalez 2019-05-15 20:54:46 -04:00
parent 27ae867fe1
commit 129e8c019c
7 changed files with 64 additions and 1 deletions
Documentation
example/prometheus-operator-crd
jsonnet/prometheus-operator
pkg

View file

@ -278,6 +278,7 @@ PrometheusSpec is a specification of the desired behavior of the Prometheus clus
| replicaExternalLabelName | Name of Prometheus external label used to denote replica name. Defaults to the value of `prometheus_replica`. External label will _not_ be added when value is set to empty string (`\"\"`). | *string | false |
| prometheusExternalLabelName | Name of Prometheus external label used to denote Prometheus instance name. Defaults to the value of `prometheus`. External label will _not_ be added when value is set to empty string (`\"\"`). | *string | false |
| retention | Time duration Prometheus shall retain data for. Default is '24h', and must match the regular expression `[0-9]+(ms\|s\|m\|h\|d\|w\|y)` (milliseconds seconds minutes hours days weeks years). | string | false |
| retentionSize | Maximum amount of disk space used by blocks. | string | false |
| logLevel | Log level for Prometheus to be configured with. | string | false |
| logFormat | Log format for Prometheus to be configured with. | string | false |
| scrapeInterval | Interval between consecutive scrapes. | string | false |

View file

@ -2338,6 +2338,9 @@ spec:
is '24h', and must match the regular expression `[0-9]+(ms|s|m|h|d|w|y)`
(milliseconds seconds minutes hours days weeks years).
type: string
retentionSize:
description: Maximum amount of disk space used by blocks.
type: string
routePrefix:
description: The route prefix Prometheus registers HTTP handlers for.
This is useful, if using ExternalURL and a proxy is rewriting HTTP

File diff suppressed because one or more lines are too long

View file

@ -1346,6 +1346,13 @@ func schema_pkg_apis_monitoring_v1_PrometheusSpec(ref common.ReferenceCallback)
Format: "",
},
},
"retentionSize": {
SchemaProps: spec.SchemaProps{
Description: "Maximum amount of disk space used by blocks.",
Type: []string{"string"},
Format: "",
},
},
"logLevel": {
SchemaProps: spec.SchemaProps{
Description: "Log level for Prometheus to be configured with.",

View file

@ -120,6 +120,8 @@ type PrometheusSpec struct {
// Time duration Prometheus shall retain data for. Default is '24h',
// and must match the regular expression `[0-9]+(ms|s|m|h|d|w|y)` (milliseconds seconds minutes hours days weeks years).
Retention string `json:"retention,omitempty"`
// Maximum amount of disk space used by blocks.
RetentionSize string `json:"retentionSize,omitempty"`
// Log level for Prometheus to be configured with.
LogLevel string `json:"logLevel,omitempty"`
// Log format for Prometheus to be configured with.

View file

@ -339,6 +339,11 @@ func makeStatefulSetSpec(p monitoringv1.Prometheus, c *Config, ruleConfigMapName
retentionTimeFlag := "-storage.tsdb.retention="
if version.Minor >= 7 {
retentionTimeFlag = "-storage.tsdb.retention.time="
if p.Spec.RetentionSize != "" {
promArgs = append(promArgs,
fmt.Sprintf("-storage.tsdb.retention.size=%s", p.Spec.RetentionSize),
)
}
}
promArgs = append(promArgs,
fmt.Sprintf("-config.file=%s", path.Join(confOutDir, configEnvsubstFilename)),

View file

@ -609,6 +609,51 @@ func TestThanosObjectStorage(t *testing.T) {
}
}
func TestRetentionSize(t *testing.T) {
tests := []struct {
version string
specRetentionSize string
expectedRetentionArg string
shouldContain bool
}{
{"v1.8.2", "2M", "--storage.tsdb.retention.size=2M", false},
{"v1.8.2", "1Gi", "--storage.tsdb.retention.size=1Gi", false},
{"v2.5.0", "2M", "--storage.tsdb.retention.size=2M", false},
{"v2.5.0", "1Gi", "--storage.tsdb.retention.size=1Gi", false},
{"v2.7.0", "2M", "--storage.tsdb.retention.size=2M", true},
{"v2.7.0", "1Gi", "--storage.tsdb.retention.size=1Gi", true},
}
for _, test := range tests {
sset, err := makeStatefulSet(monitoringv1.Prometheus{
Spec: monitoringv1.PrometheusSpec{
Version: test.version,
RetentionSize: test.specRetentionSize,
},
}, defaultTestConfig, nil, "")
if err != nil {
t.Fatal(err)
}
promArgs := sset.Spec.Template.Spec.Containers[0].Args
found := false
for _, flag := range promArgs {
if flag == test.expectedRetentionArg {
found = true
break
}
}
if found != test.shouldContain {
if test.shouldContain {
t.Fatalf("expected Prometheus args to contain %v, but got %v", test.expectedRetentionArg, promArgs)
} else {
t.Fatalf("expected Prometheus args to NOT contain %v, but got %v", test.expectedRetentionArg, promArgs)
}
}
}
}
func TestRetention(t *testing.T) {
tests := []struct {
version string