Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

PMM-7246 Tweak flags #605

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion models/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ type Settings struct {
AlertManagerURL string `json:"alert_manager_url"`

VictoriaMetrics struct {
CacheEnabled bool `json:"cache_enabled"`
// Deprecated: does nothing now but kept to ensure that we don't reuse that JSON name.
DeprecatedCacheEnabled bool `json:"cache_enabled"`
} `json:"victoria_metrics"`

// Saas config options
Expand Down
16 changes: 0 additions & 16 deletions models/settings_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ type ChangeSettingsParams struct {
// LogOut user from Percona Platform, i.e. remove user email and session id
LogOut bool

// EnableVMCache enables caching for vmdb search queries
EnableVMCache bool
// DisableVMCache disables caching for vmdb search queries
DisableVMCache bool

// PMM Server public address.
PMMPublicAddress string
RemovePMMPublicAddress bool
Expand Down Expand Up @@ -207,14 +202,6 @@ func UpdateSettings(q reform.DBTX, params *ChangeSettingsParams) (*Settings, err
settings.SaaS.Email = params.Email
}

if params.DisableVMCache {
settings.VictoriaMetrics.CacheEnabled = false
}

if params.EnableVMCache {
settings.VictoriaMetrics.CacheEnabled = true
}

if params.PMMPublicAddress != "" {
settings.PMMPublicAddress = params.PMMPublicAddress
}
Expand Down Expand Up @@ -260,9 +247,6 @@ func ValidateSettings(params *ChangeSettingsParams) error {
if params.EnableSTT && params.DisableSTT {
return fmt.Errorf("Both enable_stt and disable_stt are present.") //nolint:golint,stylecheck
}
if params.EnableVMCache && params.DisableVMCache {
return fmt.Errorf("Both enable_vm_cache and disable_vm_cache are present.") //nolint:golint,stylecheck
}
if params.EnableAlerting && params.DisableAlerting {
return fmt.Errorf("Both enable_alerting and disable_alerting are present.") //nolint:golint,stylecheck
}
Expand Down
7 changes: 5 additions & 2 deletions models/victoriametrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func NewVictoriaMetricsParams(basePath string) (*VictoriaMetricsParams, error) {

// UpdateParams - reads configuration file and updates corresponding flags.
func (vmp *VictoriaMetricsParams) UpdateParams() error {
// TODO read settings, set -external.url and -external.alert.source

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
models/victoriametrics.go:50: Line contains TODO/BUG/FIXME: "TODO read settings, set -external.url an..." (godox)

// https://jira.percona.com/browse/PMM-7248

if err := vmp.loadVMAlertParams(); err != nil {
return errors.Wrap(err, "cannot update VMAlertFlags config param")
}
Expand All @@ -72,10 +75,10 @@ func (vmp *VictoriaMetricsParams) loadVMAlertParams() error {
}
vmalertFlags := make([]string, 0, len(vmp.VMAlertFlags))
for _, r := range cfg.RuleFiles {
vmalertFlags = append(vmalertFlags, "--rule="+r)
vmalertFlags = append(vmalertFlags, "-rule="+r)
}
if cfg.GlobalConfig.EvaluationInterval != 0 {
vmalertFlags = append(vmalertFlags, "--evaluationInterval="+cfg.GlobalConfig.EvaluationInterval.String())
vmalertFlags = append(vmalertFlags, "-evaluationInterval="+cfg.GlobalConfig.EvaluationInterval.String())
}
vmp.VMAlertFlags = vmalertFlags

Expand Down
2 changes: 1 addition & 1 deletion models/victoriametrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ func TestVictoriaMetricsParams(t *testing.T) {
t.Run("check params for VMAlert", func(t *testing.T) {
vmp, err := NewVictoriaMetricsParams("../testdata/victoriametrics/prometheus.external.alerts.yml")
require.NoError(t, err)
require.Equal(t, []string{"--rule=/srv/external_rules/rul1.yml", "--rule=/srv/external_rules/rule2.yml", "--evaluationInterval=10s"}, vmp.VMAlertFlags)
require.Equal(t, []string{"-rule=/srv/external_rules/rul1.yml", "-rule=/srv/external_rules/rule2.yml", "-evaluationInterval=10s"}, vmp.VMAlertFlags)
})
}
39 changes: 19 additions & 20 deletions services/supervisord/supervisord.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ func (s *Service) marshalConfig(tmpl *template.Template, settings *models.Settin
"DataRetentionHours": int(settings.DataRetention.Hours()),
"DataRetentionDays": int(settings.DataRetention.Hours() / 24),
"VMAlertFlags": s.vmParams.VMAlertFlags,
"VMDBCacheDisable": !settings.VictoriaMetrics.CacheEnabled,
"PerconaTestDbaas": settings.DBaaS.Enabled,
}
if err := addAlertManagerParams(settings.AlertManagerURL, templateParams); err != nil {
Expand Down Expand Up @@ -572,15 +571,15 @@ redirect_stderr = true
priority = 7
command =
/usr/sbin/victoriametrics
--promscrape.config=/etc/victoriametrics-promscrape.yml
--retentionPeriod={{ .DataRetentionDays }}d
--storageDataPath=/srv/victoriametrics/data
--httpListenAddr=127.0.0.1:9090
--search.disableCache={{ .VMDBCacheDisable }}
--search.maxQueryLen=72KB
--search.maxUniqueTimeseries=1500000
--prometheusDataPath=/srv/prometheus/data
--http.pathPrefix=/prometheus
-http.pathPrefix=/prometheus
-httpListenAddr=127.0.0.1:9090
-prometheusDataPath=/srv/prometheus/data
-promscrape.config=/etc/victoriametrics-promscrape.yml
-retentionPeriod={{ .DataRetentionDays }}d
-search.latencyOffset=5s
-search.maxQueryLen=72KB
-search.maxUniqueTimeseries=1500000
-storageDataPath=/srv/victoriametrics/data
user = pmm
autorestart = true
autostart = true
Expand All @@ -599,16 +598,16 @@ redirect_stderr = true
priority = 7
command =
/usr/sbin/vmalert
--notifier.url="{{ .AlertmanagerURL }}"
--notifier.basicAuth.password='{{ .AlertManagerPassword }}'
--notifier.basicAuth.username="{{ .AlertManagerUser }}"
--external.url=http://localhost:9090/prometheus
--datasource.url=http://127.0.0.1:9090/prometheus
--remoteRead.url=http://127.0.0.1:9090/prometheus
--remoteWrite.url=http://127.0.0.1:9090/prometheus
--rule=/srv/prometheus/rules/*.yml
--rule=/etc/ia/rules/*.yml
--httpListenAddr=127.0.0.1:8880
-datasource.url=http://127.0.0.1:9090/prometheus
-external.url=http://localhost/
-httpListenAddr=127.0.0.1:8880
-notifier.basicAuth.password='{{ .AlertManagerPassword }}'
-notifier.basicAuth.username="{{ .AlertManagerUser }}"
-notifier.url="{{ .AlertmanagerURL }}"
-remoteRead.url=http://127.0.0.1:9090/prometheus
-remoteWrite.url=http://127.0.0.1:9090/prometheus
-rule=/etc/ia/rules/*.yml
-rule=/srv/prometheus/rules/*.yml
{{- range $index, $param := .VMAlertFlags }}
{{ $param }}
{{- end }}
Expand Down
1 change: 0 additions & 1 deletion services/supervisord/supervisord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func TestConfig(t *testing.T) {
DataRetention: 30 * 24 * time.Hour,
AlertManagerURL: "https://external-user:passw!,ord@external-alertmanager:6443/alerts",
}
settings.VictoriaMetrics.CacheEnabled = false

for _, tmpl := range templates.Templates() {
n := tmpl.Name()
Expand Down
18 changes: 9 additions & 9 deletions testdata/supervisord.d/victoriametrics.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
priority = 7
command =
/usr/sbin/victoriametrics
--promscrape.config=/etc/victoriametrics-promscrape.yml
--retentionPeriod=30d
--storageDataPath=/srv/victoriametrics/data
--httpListenAddr=127.0.0.1:9090
--search.disableCache=true
--search.maxQueryLen=72KB
--search.maxUniqueTimeseries=1500000
--prometheusDataPath=/srv/prometheus/data
--http.pathPrefix=/prometheus
-http.pathPrefix=/prometheus
-httpListenAddr=127.0.0.1:9090
-prometheusDataPath=/srv/prometheus/data
-promscrape.config=/etc/victoriametrics-promscrape.yml
-retentionPeriod=30d
-search.latencyOffset=5s
-search.maxQueryLen=72KB
-search.maxUniqueTimeseries=1500000
-storageDataPath=/srv/victoriametrics/data
user = pmm
autorestart = true
autostart = true
Expand Down
20 changes: 10 additions & 10 deletions testdata/supervisord.d/vmalert.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
priority = 7
command =
/usr/sbin/vmalert
--notifier.url="http://127.0.0.1:9093/alertmanager,https://external-alertmanager:6443/alerts"
--notifier.basicAuth.password=',"passw!,ord"'
--notifier.basicAuth.username=",external-user"
--external.url=http://localhost:9090/prometheus
--datasource.url=http://127.0.0.1:9090/prometheus
--remoteRead.url=http://127.0.0.1:9090/prometheus
--remoteWrite.url=http://127.0.0.1:9090/prometheus
--rule=/srv/prometheus/rules/*.yml
--rule=/etc/ia/rules/*.yml
--httpListenAddr=127.0.0.1:8880
-datasource.url=http://127.0.0.1:9090/prometheus
-external.url=http://localhost/
-httpListenAddr=127.0.0.1:8880
-notifier.basicAuth.password=',"passw!,ord"'
-notifier.basicAuth.username=",external-user"
-notifier.url="http://127.0.0.1:9093/alertmanager,https://external-alertmanager:6443/alerts"
-remoteRead.url=http://127.0.0.1:9090/prometheus
-remoteWrite.url=http://127.0.0.1:9090/prometheus
-rule=/etc/ia/rules/*.yml
-rule=/srv/prometheus/rules/*.yml
user = pmm
autorestart = true
autostart = true
Expand Down
19 changes: 7 additions & 12 deletions utils/envvars/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,22 @@ func ParseEnvVars(envs []string) (envSettings *models.ChangeSettingsParams, errs
if envSettings.DataRetention, err = parseStringDuration(v); err != nil {
err = formatEnvVariableError(err, env, v)
}
case "ENABLE_VM_CACHE":
envSettings.EnableVMCache, err = strconv.ParseBool(v)
if err != nil {
err = fmt.Errorf("invalid value %q for environment variable %q", v, k)
}
if !envSettings.EnableVMCache {
// disable cache explicitly
envSettings.DisableVMCache = true
}

case "PERCONA_TEST_IA": // FIXME remove
warns = append(warns, fmt.Sprintf("Environment variable %q WILL BE REMOVED SOON, please use %q instead.", k, "ENABLE_ALERTING"))
fallthrough
case "ENABLE_ALERTING":
envSettings.EnableAlerting, err = strconv.ParseBool(v)
if err != nil {
err = fmt.Errorf("invalid value %q for environment variable %q", v, k)
}

// deprecated variables that produce warnings
case "ENABLE_VM_CACHE": // keep it forever since it does not have PERCONA_TEST_ prefix
warns = append(warns, fmt.Sprintf("environment variable %q does nothing now", k))

// removed variables that produce errors
case "PERCONA_TEST_AUTH_HOST", "PERCONA_TEST_CHECKS_HOST", "PERCONA_TEST_TELEMETRY_HOST":
err = fmt.Errorf("environment variable %q is removed and replaced by %q", k, envSaaSHost)
case "PERCONA_TEST_IA":
err = fmt.Errorf("environment variable %q is removed and replaced by %q", k, "ENABLE_ALERTING")

default:
// handle prefixes
Expand Down