mirror of https://github.com/grafana/grafana.git
Pass eval ctx attributes to frontend
This commit is contained in:
parent
a595f4d489
commit
4d8e56debe
|
@ -305,6 +305,7 @@ type FrontendSettingsDTO struct {
|
|||
|
||||
LocalFileSystemAvailable bool `json:"localFileSystemAvailable"`
|
||||
// Experimental Scope settings
|
||||
ListScopesEndpoint string `json:"listScopesEndpoint"`
|
||||
ListDashboardScopesEndpoint string `json:"listDashboardScopesEndpoint"`
|
||||
ListScopesEndpoint string `json:"listScopesEndpoint"`
|
||||
ListDashboardScopesEndpoint string `json:"listDashboardScopesEndpoint"`
|
||||
OpenFeatureContext map[string]string `json:"openFeatureContext"`
|
||||
}
|
||||
|
|
|
@ -350,6 +350,7 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro
|
|||
MaxIdleConns: hs.Cfg.SqlDatasourceMaxIdleConnsDefault,
|
||||
ConnMaxLifetime: hs.Cfg.SqlDatasourceMaxConnLifetimeDefault,
|
||||
},
|
||||
OpenFeatureContext: hs.Cfg.OpenFeature.ContextAttrs,
|
||||
}
|
||||
|
||||
if hs.Cfg.UnifiedAlerting.StateHistory.Enabled {
|
||||
|
|
|
@ -40,7 +40,12 @@ func InitOpenFeatureWithCfg(cfg *setting.Cfg) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("failed to initialize OpenFeature: %w", err)
|
||||
}
|
||||
openfeature.SetEvaluationContext(openfeature.NewEvaluationContext(cfg.OpenFeature.TargetingKey, cfg.OpenFeature.ContextAttrs))
|
||||
// Convert map[string]string to map[string]any for OpenFeature SDK
|
||||
contextAttrs := make(map[string]any)
|
||||
for k, v := range cfg.OpenFeature.ContextAttrs {
|
||||
contextAttrs[k] = v
|
||||
}
|
||||
openfeature.SetEvaluationContext(openfeature.NewEvaluationContext(cfg.OpenFeature.TargetingKey, contextAttrs))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ type OpenFeatureSettings struct {
|
|||
ProviderType string
|
||||
URL *url.URL
|
||||
TargetingKey string
|
||||
ContextAttrs map[string]any
|
||||
ContextAttrs map[string]string
|
||||
}
|
||||
|
||||
func (cfg *Cfg) readOpenFeatureSettings() error {
|
||||
|
@ -38,7 +38,7 @@ func (cfg *Cfg) readOpenFeatureSettings() error {
|
|||
|
||||
// build the eval context attributes using [feature_toggles.openfeature.context] section
|
||||
ctxConf := cfg.Raw.Section("feature_toggles.openfeature.context")
|
||||
attrs := map[string]any{}
|
||||
attrs := map[string]string{}
|
||||
for _, key := range ctxConf.KeyStrings() {
|
||||
attrs[key] = ctxConf.Key(key).String()
|
||||
}
|
||||
|
|
|
@ -11,11 +11,11 @@ func Test_CtxAttrs(t *testing.T) {
|
|||
testCases := []struct {
|
||||
name string
|
||||
conf string
|
||||
expected map[string]any
|
||||
expected map[string]string
|
||||
}{
|
||||
{
|
||||
name: "empty config - only default attributes should be present",
|
||||
expected: map[string]any{
|
||||
expected: map[string]string{
|
||||
"grafana_version": "",
|
||||
},
|
||||
},
|
||||
|
@ -26,7 +26,7 @@ func Test_CtxAttrs(t *testing.T) {
|
|||
foo = bar
|
||||
baz = qux
|
||||
quux = corge`,
|
||||
expected: map[string]any{
|
||||
expected: map[string]string{
|
||||
"foo": "bar",
|
||||
"baz": "qux",
|
||||
"quux": "corge",
|
||||
|
@ -39,7 +39,7 @@ quux = corge`,
|
|||
[feature_toggles.openfeature.context]
|
||||
grafana_version = 10.0.0
|
||||
foo = bar`,
|
||||
expected: map[string]any{
|
||||
expected: map[string]string{
|
||||
"grafana_version": "10.0.0",
|
||||
"foo": "bar",
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue