mirror of https://github.com/grafana/grafana
K8s: Add grafana-apiserver config (#76649)
Co-authored-by: Kristin Laemmert <mildwonkey@users.noreply.github.com>pull/76547/head
parent
7da2cc9610
commit
863f25acf7
@ -0,0 +1,38 @@ |
||||
package grafanaapiserver |
||||
|
||||
import ( |
||||
"fmt" |
||||
"path/filepath" |
||||
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt" |
||||
"github.com/grafana/grafana/pkg/setting" |
||||
) |
||||
|
||||
type config struct { |
||||
enabled bool |
||||
devMode bool |
||||
|
||||
host string |
||||
appURL string |
||||
etcdServers []string |
||||
dataPath string |
||||
|
||||
logLevel int |
||||
} |
||||
|
||||
func newConfig(cfg *setting.Cfg) *config { |
||||
defaultLogLevel := 0 |
||||
if cfg.Env == setting.Dev { |
||||
defaultLogLevel = 10 |
||||
} |
||||
|
||||
return &config{ |
||||
enabled: cfg.IsFeatureToggleEnabled(featuremgmt.FlagGrafanaAPIServer), |
||||
devMode: cfg.Env == setting.Dev, |
||||
dataPath: filepath.Join(cfg.DataPath, "grafana-apiserver"), |
||||
host: fmt.Sprintf("%s:%s", cfg.HTTPAddr, cfg.HTTPPort), |
||||
logLevel: cfg.SectionWithEnvOverrides("grafana-apiserver").Key("log_level").MustInt(defaultLogLevel), |
||||
etcdServers: cfg.SectionWithEnvOverrides("grafana-apiserver").Key("etcd_servers").Strings(","), |
||||
appURL: cfg.AppURL, |
||||
} |
||||
} |
@ -0,0 +1,36 @@ |
||||
package grafanaapiserver |
||||
|
||||
import ( |
||||
"testing" |
||||
|
||||
"github.com/stretchr/testify/require" |
||||
|
||||
"github.com/grafana/grafana/pkg/setting" |
||||
) |
||||
|
||||
func TestNewConfig(t *testing.T) { |
||||
cfg := setting.NewCfg() |
||||
cfg.Env = setting.Dev |
||||
cfg.DataPath = "/tmp/grafana" |
||||
cfg.HTTPAddr = "test" |
||||
cfg.HTTPPort = "4000" |
||||
cfg.IsFeatureToggleEnabled = func(_ string) bool { return true } |
||||
cfg.AppURL = "http://test:4000" |
||||
|
||||
section := cfg.Raw.Section("grafana-apiserver") |
||||
section.Key("log_level").SetValue("5") |
||||
section.Key("etcd_servers").SetValue("http://localhost:2379") |
||||
|
||||
actual := newConfig(cfg) |
||||
|
||||
expected := &config{ |
||||
enabled: true, |
||||
devMode: true, |
||||
etcdServers: []string{"http://localhost:2379"}, |
||||
appURL: "http://test:4000", |
||||
host: "test:4000", |
||||
dataPath: "/tmp/grafana/grafana-apiserver", |
||||
logLevel: 5, |
||||
} |
||||
require.Equal(t, expected, actual) |
||||
} |
Loading…
Reference in new issue