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