The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/setting/setting_openfeature.go

51 lines
1.2 KiB

package setting
import (
"fmt"
"net/url"
)
const (
StaticProviderType = "static"
GOFFProviderType = "goff"
)
type OpenFeatureSettings struct {
ProviderType string
URL *url.URL
TargetingKey string
ContextAttrs map[string]any
}
func (cfg *Cfg) readOpenFeatureSettings() error {
cfg.OpenFeature = OpenFeatureSettings{}
config := cfg.Raw.Section("feature_toggles.openfeature")
cfg.OpenFeature.ProviderType = config.Key("provider").MustString(StaticProviderType)
cfg.OpenFeature.TargetingKey = config.Key("targetingKey").MustString(cfg.AppURL)
strURL := config.Key("url").MustString("")
if strURL != "" && cfg.OpenFeature.ProviderType == GOFFProviderType {
u, err := url.Parse(strURL)
if err != nil {
return fmt.Errorf("invalid feature provider url: %w", err)
}
cfg.OpenFeature.URL = u
}
// build the eval context attributes using [feature_toggles.openfeature.context] section
ctxConf := cfg.Raw.Section("feature_toggles.openfeature.context")
attrs := map[string]any{}
for _, key := range ctxConf.KeyStrings() {
attrs[key] = ctxConf.Key(key).String()
}
// Some default attributes
if _, ok := attrs["grafana_version"]; !ok {
attrs["grafana_version"] = BuildVersion
}
cfg.OpenFeature.ContextAttrs = attrs
return nil
}