plugins: add more configuration parameters to the plugin-config (#83060)

* envvars: add more configs

* made row-limit optional

* more consistent naming
This commit is contained in:
Gábor Farkas
2024-02-21 12:32:10 +02:00
committed by GitHub
parent 778d80f922
commit a62dccb0c0
4 changed files with 111 additions and 28 deletions
+14
View File
@@ -100,6 +100,8 @@ func (s *Service) Get(ctx context.Context, p *plugins.Plugin) []string {
}
// GetConfigMap returns a map of configuration that should be passed in a plugin request.
//
//nolint:gocyclo
func (s *Service) GetConfigMap(ctx context.Context, pluginID string, _ *auth.ExternalService) map[string]string {
m := make(map[string]string)
@@ -110,6 +112,18 @@ func (s *Service) GetConfigMap(ctx context.Context, pluginID string, _ *auth.Ext
m[backend.ConcurrentQueryCount] = strconv.Itoa(s.cfg.ConcurrentQueryCount)
}
if s.cfg.UserFacingDefaultError != "" {
m[backend.UserFacingDefaultError] = s.cfg.UserFacingDefaultError
}
if s.cfg.DataProxyRowLimit != 0 {
m[backend.SQLRowLimit] = strconv.FormatInt(s.cfg.DataProxyRowLimit, 10)
}
m[backend.SQLMaxOpenConnsDefault] = strconv.Itoa(s.cfg.SQLDatasourceMaxOpenConnsDefault)
m[backend.SQLMaxIdleConnsDefault] = strconv.Itoa(s.cfg.SQLDatasourceMaxIdleConnsDefault)
m[backend.SQLMaxConnLifetimeSecondsDefault] = strconv.Itoa(s.cfg.SQLDatasourceMaxConnLifetimeDefault)
// TODO add support via plugin SDK
// if externalService != nil {
// m[oauthtokenretriever.AppURL] = s.cfg.GrafanaAppURL
+48
View File
@@ -671,6 +671,18 @@ func TestInitalizer_azureEnvVars(t *testing.T) {
})
}
func TestService_GetConfigMap_Defaults(t *testing.T) {
s := &Service{
cfg: &config.Cfg{},
}
require.Equal(t, map[string]string{
"GF_SQL_MAX_OPEN_CONNS_DEFAULT": "0",
"GF_SQL_MAX_IDLE_CONNS_DEFAULT": "0",
"GF_SQL_MAX_CONN_LIFETIME_SECONDS_DEFAULT": "0",
}, s.GetConfigMap(context.Background(), "", nil))
}
func TestService_GetConfigMap(t *testing.T) {
tcs := []struct {
name string
@@ -806,6 +818,42 @@ func TestService_GetConfigMap_appURL(t *testing.T) {
})
}
func TestService_GetConfigMap_SQL(t *testing.T) {
t.Run("Uses the configured values", func(t *testing.T) {
s := &Service{
cfg: &config.Cfg{
DataProxyRowLimit: 23,
SQLDatasourceMaxOpenConnsDefault: 24,
SQLDatasourceMaxIdleConnsDefault: 25,
SQLDatasourceMaxConnLifetimeDefault: 26,
},
}
require.Subset(t, s.GetConfigMap(context.Background(), "", nil), map[string]string{
"GF_SQL_ROW_LIMIT": "23",
"GF_SQL_MAX_OPEN_CONNS_DEFAULT": "24",
"GF_SQL_MAX_IDLE_CONNS_DEFAULT": "25",
"GF_SQL_MAX_CONN_LIFETIME_SECONDS_DEFAULT": "26",
})
})
t.Run("Uses the configured max-default-values, even when they are zero", func(t *testing.T) {
s := &Service{
cfg: &config.Cfg{
SQLDatasourceMaxOpenConnsDefault: 0,
SQLDatasourceMaxIdleConnsDefault: 0,
SQLDatasourceMaxConnLifetimeDefault: 0,
},
}
require.Equal(t, map[string]string{
"GF_SQL_MAX_OPEN_CONNS_DEFAULT": "0",
"GF_SQL_MAX_IDLE_CONNS_DEFAULT": "0",
"GF_SQL_MAX_CONN_LIFETIME_SECONDS_DEFAULT": "0",
}, s.GetConfigMap(context.Background(), "", nil))
})
}
func TestService_GetConfigMap_concurrentQueryCount(t *testing.T) {
t.Run("Uses the configured concurrent query count", func(t *testing.T) {
s := &Service{