From c9bfa781fd7b54ad9799c9624b93d9a0802ba087 Mon Sep 17 00:00:00 2001 From: bergquist Date: Sun, 22 Oct 2017 23:05:17 +0200 Subject: [PATCH] datasource as cfg: improve name for this feature --- conf/datasources.yaml | 41 +++++++++++++++++++------- pkg/cmd/grafana-server/server.go | 6 ++-- pkg/setting/datasources/datasources.go | 2 +- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/conf/datasources.yaml b/conf/datasources.yaml index 8d40d49f83c..53fc9a70a50 100644 --- a/conf/datasources.yaml +++ b/conf/datasources.yaml @@ -1,20 +1,41 @@ +# purge data source not listed in configuration. +# not recommended in HA setups if config can +# can differ between instances. purge_other_datasources: false + +# list of datasources to insert/update depending +# whats available in the datbase datasources: + # name of the datasource. Required - name: Graphite + # datasource type. Required type: graphite + # access mode. direct or proxy. Required access: proxy + # url url: http://localhost:8080 - password: #string - user: #string - database: #string - basic_auth: #bool - basic_authUser: #string - basic_auth_password: #string - with_credentials: #bool - is_default: true #bool - json_data: '{"graphiteVersion":"0.9"}' # string json - secure_json_fields: '' #string json + # database password, if used + password: + # database user, if used + user: + # database name, if used + database: + # enable/disable basic auth + basic_auth: + # basic auth username + basic_authUser: + # basic auth password + basic_auth_password: + # enable/disable with credentials headers + with_credentials: + # mark as default datasource. Max one per org + is_default: + # json data + json_data: '{"graphiteVersion":"0.9"}' + # json object of data that will be encrypted in UI. + secure_json_fields: '' - name: Prometheus type: prometheus access: proxy url: http://localhost:9090 + diff --git a/pkg/cmd/grafana-server/server.go b/pkg/cmd/grafana-server/server.go index eee9f76e37c..825aa9811f7 100644 --- a/pkg/cmd/grafana-server/server.go +++ b/pkg/cmd/grafana-server/server.go @@ -23,7 +23,7 @@ import ( "github.com/grafana/grafana/pkg/services/search" "github.com/grafana/grafana/pkg/services/sqlstore" "github.com/grafana/grafana/pkg/setting" - dsSettings "github.com/grafana/grafana/pkg/setting/datasources" + datasourcesFromConfig "github.com/grafana/grafana/pkg/setting/datasources" "github.com/grafana/grafana/pkg/social" "github.com/grafana/grafana/pkg/tracing" ) @@ -56,9 +56,9 @@ func (g *GrafanaServerImpl) Start() { g.writePIDFile() initSql() - err := dsSettings.Init(filepath.Join(setting.HomePath, "conf/datasources.yaml")) + err := datasourcesFromConfig.Apply(filepath.Join(setting.HomePath, "conf/datasources.yaml")) if err != nil { - g.log.Error("Failed to load datasources from config", "error", err) + g.log.Error("Failed to configure datasources from config", "error", err) g.Shutdown(1, "Startup failed") return } diff --git a/pkg/setting/datasources/datasources.go b/pkg/setting/datasources/datasources.go index 25eeba426f3..68abf3bff1e 100644 --- a/pkg/setting/datasources/datasources.go +++ b/pkg/setting/datasources/datasources.go @@ -16,7 +16,7 @@ var ( ErrInvalidConfigToManyDefault = errors.New("datasource.yaml config is invalid. Only one datasource can be marked as default") ) -func Init(configPath string) error { +func Apply(configPath string) error { dc := NewDatasourceConfiguration() return dc.applyChanges(configPath) }