OpenFeature: Add context attributes to frontend settings (#112105)

* Update targeting key to namespace

* Pass eval ctx attributes to frontend

* Add context config to the frontend

* Fix OF namespace not defined in e2e tests

* Set default namespace and targeting key

* remove e2e server config now that namespace is default

---------

Co-authored-by: joshhunt <josh.hunt@grafana.com>
This commit is contained in:
Tania
2025-10-10 13:43:24 +02:00
committed by GitHub
co-authored by joshhunt
parent fa9d6be255
commit 21e26aefdb
10 changed files with 35 additions and 12 deletions
+13 -4
View File
@@ -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 {
@@ -24,10 +24,15 @@ func (cfg *Cfg) readOpenFeatureSettings() error {
config := cfg.Raw.Section("feature_toggles.openfeature")
cfg.OpenFeature.APIEnabled = config.Key("enable_api").MustBool(true)
cfg.OpenFeature.ProviderType = config.Key("provider").MustString(StaticProviderType)
cfg.OpenFeature.TargetingKey = config.Key("targetingKey").MustString(cfg.AppURL)
strURL := config.Key("url").MustString("")
defaultTargetingKey := "default"
if cfg.StackID != "" {
defaultTargetingKey = fmt.Sprintf("stacks-%s", cfg.StackID)
}
cfg.OpenFeature.TargetingKey = config.Key("targetingKey").MustString(defaultTargetingKey)
if strURL != "" && cfg.OpenFeature.ProviderType == GOFFProviderType {
u, err := url.Parse(strURL)
if err != nil {
@@ -38,7 +43,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()
}
@@ -48,6 +53,10 @@ func (cfg *Cfg) readOpenFeatureSettings() error {
attrs["grafana_version"] = BuildVersion
}
if _, ok := attrs["namespace"]; !ok {
attrs["namespace"] = defaultTargetingKey
}
cfg.OpenFeature.ContextAttrs = attrs
return nil
}