Skip to content

Commit

Permalink
PMM-10312 fix datasource address for clickhouse (#1033)
Browse files Browse the repository at this point in the history
* PMM-10312 fix datasource address for clickhouse

* fix variable name

* fix format
  • Loading branch information
nikita-b committed Jul 15, 2022
1 parent ddc4bcd commit 2c740d9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
56 changes: 26 additions & 30 deletions managed/services/supervisord/supervisord.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ import (
)

const (
defaultClickhouseDatabase = "pmm"
defaultClickhouseAddr = "127.0.0.1:9000"
defaultClickhouseDatabase = "pmm"
defaultClickhouseAddr = "127.0.0.1:9000"
defaultClickhouseDataSourceAddr = "127.0.0.1:8123"
)

// Service is responsible for interactions with Supervisord via supervisorctl.
Expand Down Expand Up @@ -403,38 +404,33 @@ func (s *Service) reload(name string) error {
return err
}

// marshalConfig marshals supervisord program configuration.
func (s *Service) marshalConfig(tmpl *template.Template, settings *models.Settings, ssoDetails *models.PerconaSSODetails) ([]byte, error) {
clickhouseDatabase, ok := os.LookupEnv("PERCONA_TEST_PMM_CLICKHOUSE_DATABASE")
func getValueFromENV(envName string, defaultValue string) string {
value, ok := os.LookupEnv(envName)
if !ok {
clickhouseDatabase = defaultClickhouseDatabase
}

clickhouseAddr, ok := os.LookupEnv("PERCONA_TEST_PMM_CLICKHOUSE_ADDR")
if !ok {
clickhouseAddr = defaultClickhouseAddr
}

clickhousePoolSize, ok := os.LookupEnv("PERCONA_TEST_PMM_CLICKHOUSE_POOL_SIZE")
if !ok {
clickhousePoolSize = ""
value = defaultValue
}
return value
}

clickhouseBlockSize, ok := os.LookupEnv("PERCONA_TEST_PMM_CLICKHOUSE_BLOCK_SIZE")
if !ok {
clickhouseBlockSize = ""
}
// marshalConfig marshals supervisord program configuration.
func (s *Service) marshalConfig(tmpl *template.Template, settings *models.Settings, ssoDetails *models.PerconaSSODetails) ([]byte, error) {
clickhouseDatabase := getValueFromENV("PERCONA_TEST_PMM_CLICKHOUSE_DATABASE", defaultClickhouseDatabase)
clickhouseAddr := getValueFromENV("PERCONA_TEST_PMM_CLICKHOUSE_ADDR", defaultClickhouseAddr)
clickhouseDataSourceAddr := getValueFromENV("PERCONA_TEST_PMM_CLICKHOUSE_DATASOURCE_ADDR", defaultClickhouseDataSourceAddr)
clickhousePoolSize := getValueFromENV("PERCONA_TEST_PMM_CLICKHOUSE_POOL_SIZE", "")
clickhouseBlockSize := getValueFromENV("PERCONA_TEST_PMM_CLICKHOUSE_BLOCK_SIZE", "")

templateParams := map[string]interface{}{
"DataRetentionHours": int(settings.DataRetention.Hours()),
"DataRetentionDays": int(settings.DataRetention.Hours() / 24),
"VMAlertFlags": s.vmParams.VMAlertFlags,
"VMDBCacheDisable": !settings.VictoriaMetrics.CacheEnabled,
"PerconaTestDbaas": settings.DBaaS.Enabled,
"ClickhouseAddr": clickhouseAddr,
"ClickhouseDatabase": clickhouseDatabase,
"ClickhousePoolSize": clickhousePoolSize,
"ClickhouseBlockSize": clickhouseBlockSize,
"DataRetentionHours": int(settings.DataRetention.Hours()),
"DataRetentionDays": int(settings.DataRetention.Hours() / 24),
"VMAlertFlags": s.vmParams.VMAlertFlags,
"VMDBCacheDisable": !settings.VictoriaMetrics.CacheEnabled,
"PerconaTestDbaas": settings.DBaaS.Enabled,
"ClickhouseAddr": clickhouseAddr,
"ClickhouseDataSourceAddr": clickhouseDataSourceAddr,
"ClickhouseDatabase": clickhouseDatabase,
"ClickhousePoolSize": clickhousePoolSize,
"ClickhouseBlockSize": clickhouseBlockSize,
}

if ssoDetails != nil {
Expand Down Expand Up @@ -756,7 +752,7 @@ command =
environment=GF_AUTH_SIGNOUT_REDIRECT_URL="https://{{ .IssuerDomain }}/login/signout?fromURI=https://{{ .PMMServerAddress }}/graph/login"
{{- end}}
environment =
PERCONA_TEST_PMM_CLICKHOUSE_ADDR="{{ .ClickhouseAddr }}",
PERCONA_TEST_PMM_CLICKHOUSE_DATASOURCE_ADDR="{{ .ClickhouseDataSourceAddr }}",
{{- if .PerconaSSODetails}}GF_AUTH_SIGNOUT_REDIRECT_URL="https://{{ .IssuerDomain }}/login/signout?fromURI=https://{{ .PMMServerAddress }}/graph/login"{{- end}}
user = grafana
directory = /usr/share/grafana
Expand Down
2 changes: 1 addition & 1 deletion managed/testdata/supervisord.d/grafana.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ command =
cfg:default.log.console.format=console
cfg:default.server.root_url="https://%%(domain)s/graph"
environment =
PERCONA_TEST_PMM_CLICKHOUSE_ADDR="127.0.0.1:9000",
PERCONA_TEST_PMM_CLICKHOUSE_DATASOURCE_ADDR="127.0.0.1:8123",
user = grafana
directory = /usr/share/grafana
autorestart = true
Expand Down

0 comments on commit 2c740d9

Please sign in to comment.