launchdarkly/java-server-sdk

Allow duplicate flag keys in file data sources

laura-maimon opened this issue · 3 comments

Is your feature request related to a problem? Please describe.
We are using the "reading flags from files" feature to provide our developers with an isolated environment for testing/prototyping purposes, and we have several use cases where we would like to "override" flag values from a baseline (i.e. the current set of flags which we pull from https://app.launchdarkly.com/sdk/latest-all). We would love to be able to use multiple file data sources to do this:

FileData.dataSource().filePaths("overrides.json", "base.json")

where a feature flag in base.json is overridden by its definition in overrides.json. However, according to the docs, having duplicate flag keys within a file or across multiple files is not supported.

Describe the solution you'd like
Duplicate flag keys across files are allowed, and there is a way to specify the order in which files take precedence (could simply use the order of parameters in filePaths for this)

Describe alternatives you've considered
One alternative which would also solve our problem is to allow duplicate flag keys between "flags" and "flagValues" (in the same file and across multiple files) where a flag in "flagValues" overrides its definition in "flags".

If these can't be supported, we'll need to build our own overriding / de-duplicating logic into our infrastructure, and our developers will need to manually de-duplicate when making changes to their flag data files.

That's reasonable and my first thought was "didn't we already implement something like that?"— but I was thinking of the equivalent feature in the .NET SDK; we added it there but forgot to port that to Java. Should be pretty simple.

The 5.3.0 release includes this capability. What you'll want to do is:

FileData.dataSource()
    .filePaths("overrides.json", "base.json")
    .duplicateKeysHandling(FileData.DuplicateKeysHandling.IGNORE)

The result should be that if the same flag key exists in both overrides.json and base.json, it will use the one from overrides.json (because that file is first).

Sorry for the delay - this worked perfectly, thank you so much! 😀