mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-21 11:48:53 +00:00
Provide option to turn on WAL compression
Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
This commit is contained in:
parent
14d447f845
commit
454962a809
8 changed files with 85 additions and 1 deletions
Documentation
example/prometheus-operator-crd
jsonnet/prometheus-operator
pkg
apis/monitoring/v1
prometheus
|
@ -340,6 +340,7 @@ PrometheusSpec is a specification of the desired behavior of the Prometheus clus
|
|||
| 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 |
|
||||
| walCompression | Enable compression of the write-ahead log using Snappy. This flag is only available in versions of Prometheus >= 2.11.0. | *bool | 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 |
|
||||
|
|
|
@ -3453,6 +3453,10 @@ spec:
|
|||
version:
|
||||
description: Version of Prometheus to be deployed.
|
||||
type: string
|
||||
walCompression:
|
||||
description: Enable compression of the write-ahead log using Snappy.
|
||||
This flag is only available in versions of Prometheus >= 2.11.0.
|
||||
type: boolean
|
||||
type: object
|
||||
status:
|
||||
description: 'PrometheusStatus is the most recent observed status of the
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1647,6 +1647,13 @@ func schema_pkg_apis_monitoring_v1_PrometheusSpec(ref common.ReferenceCallback)
|
|||
Format: "",
|
||||
},
|
||||
},
|
||||
"walCompression": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Enable compression of the write-ahead log using Snappy. This flag is only available in versions of Prometheus >= 2.11.0.",
|
||||
Type: []string{"boolean"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"logLevel": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Log level for Prometheus to be configured with.",
|
||||
|
|
|
@ -131,6 +131,9 @@ type PrometheusSpec struct {
|
|||
Retention string `json:"retention,omitempty"`
|
||||
// Maximum amount of disk space used by blocks.
|
||||
RetentionSize string `json:"retentionSize,omitempty"`
|
||||
// Enable compression of the write-ahead log using Snappy. This flag is
|
||||
// only available in versions of Prometheus >= 2.11.0.
|
||||
WALCompression *bool `json:"walCompression,omitempty"`
|
||||
// Log level for Prometheus to be configured with.
|
||||
LogLevel string `json:"logLevel,omitempty"`
|
||||
// Log format for Prometheus to be configured with.
|
||||
|
|
|
@ -715,6 +715,11 @@ func (in *PrometheusSpec) DeepCopyInto(out *PrometheusSpec) {
|
|||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
if in.WALCompression != nil {
|
||||
in, out := &in.WALCompression, &out.WALCompression
|
||||
*out = new(bool)
|
||||
**out = **in
|
||||
}
|
||||
out.Rules = in.Rules
|
||||
if in.ExternalLabels != nil {
|
||||
in, out := &in.ExternalLabels, &out.ExternalLabels
|
||||
|
|
|
@ -430,6 +430,14 @@ func makeStatefulSetSpec(p monitoringv1.Prometheus, c *Config, ruleConfigMapName
|
|||
}
|
||||
}
|
||||
|
||||
if version.GTE(semver.MustParse("2.11.0")) && p.Spec.WALCompression != nil {
|
||||
if *p.Spec.WALCompression {
|
||||
promArgs = append(promArgs, "-storage.tsdb.wal-compression")
|
||||
} else {
|
||||
promArgs = append(promArgs, "-no-storage.tsdb.wal-compression")
|
||||
}
|
||||
}
|
||||
|
||||
var ports []v1.ContainerPort
|
||||
if p.Spec.ListenLocal {
|
||||
promArgs = append(promArgs, "-web.listen-address=127.0.0.1:9090")
|
||||
|
|
|
@ -792,3 +792,59 @@ func TestAdditionalContainers(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWALCompression(t *testing.T) {
|
||||
var (
|
||||
tr = true
|
||||
fa = false
|
||||
)
|
||||
tests := []struct {
|
||||
version string
|
||||
enabled *bool
|
||||
expectedArg string
|
||||
shouldContain bool
|
||||
}{
|
||||
// Nil should not have either flag.
|
||||
{"v1.8.2", nil, "-no-storage.tsdb.wal-compression", false},
|
||||
{"v1.8.2", nil, "-storage.tsdb.wal-compression", false},
|
||||
{"v1.8.2", &fa, "-no-storage.tsdb.wal-compression", false},
|
||||
{"v1.8.2", &tr, "-storage.tsdb.wal-compression", false},
|
||||
{"v2.10.0", nil, "--no-storage.tsdb.wal-compression", false},
|
||||
{"v2.10.0", nil, "--storage.tsdb.wal-compression", false},
|
||||
{"v2.10.0", &fa, "--no-storage.tsdb.wal-compression", false},
|
||||
{"v2.10.0", &tr, "--storage.tsdb.wal-compression", false},
|
||||
{"v2.11.0", nil, "--no-storage.tsdb.wal-compression", false},
|
||||
{"v2.11.0", nil, "--storage.tsdb.wal-compression", false},
|
||||
{"v2.11.0", &fa, "--no-storage.tsdb.wal-compression", true},
|
||||
{"v2.11.0", &tr, "--storage.tsdb.wal-compression", true},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
sset, err := makeStatefulSet(monitoringv1.Prometheus{
|
||||
Spec: monitoringv1.PrometheusSpec{
|
||||
Version: test.version,
|
||||
WALCompression: test.enabled,
|
||||
},
|
||||
}, 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.expectedArg {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if found != test.shouldContain {
|
||||
if test.shouldContain {
|
||||
t.Fatalf("expected Prometheus args to contain %v, but got %v", test.expectedArg, promArgs)
|
||||
} else {
|
||||
t.Fatalf("expected Prometheus args to NOT contain %v, but got %v", test.expectedArg, promArgs)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue