OpenFeature: Fix bulk evaluation request postprocessing (#108155)

pull/108139/head
Tania 5 days ago committed by GitHub
parent 6fd75ebc54
commit 7186aa4bd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 28
      pkg/registry/apis/ofrep/proxy.go
  2. 2
      pkg/services/featuremgmt/static_evaluator.go
  3. 2
      pkg/services/featuremgmt/static_provider_test.go

@ -1,15 +1,20 @@
package ofrep
import (
"bytes"
"crypto/tls"
"crypto/x509"
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httputil"
"os"
"path"
"strconv"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/util/proxyutil"
)
@ -22,20 +27,31 @@ func (b *APIBuilder) proxyAllFlagReq(isAuthedUser bool, w http.ResponseWriter, r
proxy.ModifyResponse = func(resp *http.Response) error {
if resp.StatusCode == http.StatusOK && !isAuthedUser {
var result map[string]interface{}
var result featuremgmt.OFREPBulkResponse
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return err
}
_ = resp.Body.Close()
filtered := make(map[string]any)
for k, v := range result {
if isPublicFlag(k) {
filtered[k] = v
var filteredFlags []featuremgmt.OFREPFlag
for _, f := range result.Flags {
if isPublicFlag(f.Key) {
filteredFlags = append(filteredFlags, f)
}
}
writeResponse(http.StatusOK, filtered, b.logger, w)
result.Flags = filteredFlags
newBodyBytes, err := json.Marshal(result)
if err != nil {
logger.Error("Failed to encode filtered result", "error", err)
return err
}
// Replace the body
resp.Body = io.NopCloser(bytes.NewReader(newBodyBytes))
resp.ContentLength = int64(len(newBodyBytes))
resp.Header.Set("Content-Length", strconv.Itoa(len(newBodyBytes)))
resp.Header.Set("Content-Type", "application/json")
}
return nil

@ -98,7 +98,7 @@ type OFREPBulkResponse struct {
// OFREPFlag represents a single flag in the bulk response
type OFREPFlag struct {
Key string `json:"key"`
Value bool `json:"value"`
Value any `json:"value"`
Reason string `json:"reason"`
Variant string `json:"variant,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`

@ -80,7 +80,7 @@ ABCD = true
openFeatureEnabledFlags := map[string]bool{}
for _, flag := range allFlags.Flags {
if flag.Value {
if v, ok := flag.Value.(bool); ok && v {
openFeatureEnabledFlags[flag.Key] = true
}
}

Loading…
Cancel
Save