Skip to content

Commit

Permalink
fix: start returning flagSetId, flagSetVersion as well in flag metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
aasifkhan7 committed Dec 18, 2024
1 parent 5d8173e commit f75d5b5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
21 changes: 20 additions & 1 deletion core/pkg/evaluator/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const (
Disabled = "DISABLED"
ID = "id"
VERSION = "version"
FLAGSETVERSION = "flagSetVersion"
FLAGSETID = "flagSetId"
)

var regBrace *regexp.Regexp
Expand Down Expand Up @@ -336,6 +338,12 @@ func (je *Resolver) evaluateVariant(ctx context.Context, reqID string, flagKey s
if flagMetadata.Version != "" {
metadata[VERSION] = flagMetadata.Version
}
if flagMetadata.FlagSetID != "" {
metadata[FLAGSETID] = flagMetadata.FlagSetID
}
if flagMetadata.FlagSetVersion != "" {
metadata[FLAGSETVERSION] = flagMetadata.FlagSetVersion
}

if flag.State == Disabled {
je.Logger.DebugWithID(reqID, fmt.Sprintf("requested flag is disabled: %s", flagKey))
Expand Down Expand Up @@ -470,11 +478,22 @@ func configToFlags(log *logger.Logger, config string, newFlags *Flags) error {
return fmt.Errorf("transposing evaluators: %w", err)
}

err = json.Unmarshal([]byte(transposedConfig), &newFlags)
var configData ConfigWithMetadata
err = json.Unmarshal([]byte(transposedConfig), &configData)
if err != nil {
return fmt.Errorf("unmarshalling provided configurations: %w", err)
}

// Assign the flags from the unmarshalled config to the newFlags struct
newFlags.Flags = configData.Flags

// Assign version and id from metadata to the flags
for key, flag := range newFlags.Flags {
flag.Metadata.FlagSetID = configData.MetaData.ID
flag.Metadata.FlagSetVersion = configData.MetaData.Version
newFlags.Flags[key] = flag
}

return validateDefaultVariants(newFlags)
}

Expand Down
10 changes: 10 additions & 0 deletions core/pkg/evaluator/json_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ type Evaluators struct {
Evaluators map[string]json.RawMessage `json:"$evaluators"`
}

type Metadata struct {
ID string `json:"id"`
Version string `json:"version"`
}

type ConfigWithMetadata struct {
Flags map[string]model.Flag `json:"flags"`
MetaData Metadata `json:"metadata"`
}

type Flags struct {
Flags map[string]model.Flag `json:"flags"`
}
6 changes: 4 additions & 2 deletions core/pkg/model/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ type Flag struct {
}

type Metadata struct {
ID string `json:"id"`
Version string `json:"version"`
ID string `json:"id"`
Version string `json:"version"`
FlagSetID string `json:"flagSetId"`
FlagSetVersion string `json:"flagSetVersion"`
}

type Evaluators struct {
Expand Down
10 changes: 5 additions & 5 deletions core/pkg/store/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ type IStore interface {
}

type Flags struct {
mx sync.RWMutex
Flags map[string]model.Flag `json:"flags"`
FlagSources []string
SourceMetadata map[string]SourceDetails
FlagSetMetadata model.Metadata `json:"metadata"`
mx sync.RWMutex
Flags map[string]model.Flag `json:"flags"`
FlagSources []string
SourceMetadata map[string]SourceDetails
Metadata model.Metadata `json:"metadata"`
}

type SourceDetails struct {
Expand Down

0 comments on commit f75d5b5

Please sign in to comment.