Add ConfigProvider and modify quota.Service to use it (#109395)
* Add config provider and integrate with wire setup * Refactor quota service to use config provider for configuration management * Enhance OSSConfigProvider to include logging and update ProvideService to return an error. Refactor server initialization to handle potential errors from config provider. Remove unnecessary wire binding for OSSConfigProvider. * Update CODEOWNERS to include the configprovider package under the grafana-backend-services-squad. * Refactor quota service initialization to include context in multiple service providers. Update tests and service implementations to ensure proper context handling during service creation.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package alerting
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -10,8 +11,7 @@ import (
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"bytes"
|
||||
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||
@@ -180,7 +180,9 @@ func TestIntegration_NamespacingForRules(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("org separation", func(t *testing.T) {
|
||||
orgService, err := orgimpl.ProvideService(store, cfg, quotaimpl.ProvideService(store, cfg))
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
orgService, err := orgimpl.ProvideService(store, cfg, quotaimpl.ProvideService(context.Background(), store, cfgProvider))
|
||||
require.NoError(t, err)
|
||||
newOrg, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "Test Org 2"})
|
||||
require.NoError(t, err)
|
||||
@@ -386,7 +388,9 @@ func TestIntegration_NamespacingForPrometheusRules(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("should maintain org separation for Prometheus rules", func(t *testing.T) {
|
||||
orgService, err := orgimpl.ProvideService(store, cfg, quotaimpl.ProvideService(store, cfg))
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
orgService, err := orgimpl.ProvideService(store, cfg, quotaimpl.ProvideService(context.Background(), store, cfgProvider))
|
||||
require.NoError(t, err)
|
||||
newOrg, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "Prometheus Test Org 2"})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api"
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/expr"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
@@ -1460,7 +1461,9 @@ func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCom
|
||||
cfg.AutoAssignOrg = true
|
||||
cfg.AutoAssignOrgId = 1
|
||||
|
||||
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), db, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/server"
|
||||
"github.com/grafana/grafana/pkg/services/correlations"
|
||||
@@ -144,7 +145,9 @@ func (c TestContext) createOrg(name string) int64 {
|
||||
c.t.Helper()
|
||||
store := c.env.SQLStore
|
||||
c.env.Cfg.AutoAssignOrg = false
|
||||
quotaService := quotaimpl.ProvideService(store, c.env.Cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(c.env.Cfg)
|
||||
require.NoError(c.t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), store, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(store, c.env.Cfg, quotaService)
|
||||
require.NoError(c.t, err)
|
||||
orgId, err := orgService.GetOrCreate(context.Background(), name)
|
||||
@@ -158,7 +161,9 @@ func (c TestContext) createUser(cmd user.CreateUserCommand) User {
|
||||
c.env.Cfg.AutoAssignOrg = true
|
||||
c.env.Cfg.AutoAssignOrgId = 1
|
||||
|
||||
quotaService := quotaimpl.ProvideService(store, c.env.Cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(c.env.Cfg)
|
||||
require.NoError(c.t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), store, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(store, c.env.Cfg, quotaService)
|
||||
require.NoError(c.t, err)
|
||||
usrSvc, err := userimpl.ProvideService(
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
@@ -199,7 +200,9 @@ func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCom
|
||||
cfg.AutoAssignOrg = true
|
||||
cfg.AutoAssignOrgId = 1
|
||||
|
||||
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), db, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(
|
||||
@@ -224,7 +227,7 @@ func makePostRequest(t *testing.T, URL string) (int, map[string]interface{}) {
|
||||
b, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
|
||||
var body = make(map[string]interface{})
|
||||
body := make(map[string]interface{})
|
||||
err = json.Unmarshal(b, &body)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -251,7 +254,7 @@ func expectedResp(t *testing.T, filename string) dtos.PluginList {
|
||||
}
|
||||
|
||||
func updateRespSnapshot(t *testing.T, filename string, body string) {
|
||||
err := os.WriteFile(filepath.Join("data", filename), []byte(body), 0600)
|
||||
err := os.WriteFile(filepath.Join("data", filename), []byte(body), 0o600)
|
||||
if err != nil {
|
||||
t.Errorf("error writing snapshot %s: %v", filename, err)
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
@@ -110,7 +111,9 @@ func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCom
|
||||
cfg.AutoAssignOrg = true
|
||||
cfg.AutoAssignOrgId = 1
|
||||
|
||||
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), db, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/configprovider"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
@@ -90,7 +91,9 @@ func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCom
|
||||
cfg.AutoAssignOrg = true
|
||||
cfg.AutoAssignOrgId = 1
|
||||
|
||||
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||
cfgProvider, err := configprovider.ProvideService(cfg)
|
||||
require.NoError(t, err)
|
||||
quotaService := quotaimpl.ProvideService(context.Background(), db, cfgProvider)
|
||||
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(
|
||||
|
||||
Reference in New Issue
Block a user