js-sdk-contrib icon indicating copy to clipboard operation
js-sdk-contrib copied to clipboard

[flagd-in-process] Add targeting validation and log warning

Open toddbaert opened this issue 1 year ago • 1 comments

The Go/in-process, Java/in-process and standalone versions of flagd log a warning message with invalid targeting rules when they are fetched. We should implement this in the JS/in-process.

Targeting rules can be validated with the flags.json schema in conjunction with the targeting.json schema. Both will have to be loaded into AJV to fully validate. See similar examples in Go and Java

The in-process provider should be modified to use both of these schemas, and validate against them, only logging a warning if validation fails. Only a failure to parse the definition into a FeatureFlag instance should cause an abortive error (this means relaxing the existing validation to be consistent with all other impls which just do basic parsing).

toddbaert avatar Feb 29 '24 19:02 toddbaert

Fully agree on this improvement. For example in our go provider, we use flag's core modules which also follow this approach [1]. So this definitely helps us with the consistency.

[1] - https://github.com/open-feature/flagd/blob/core/v0.8.0/core/pkg/evaluator/json.go#L428-L435

Kavindu-Dodan avatar Feb 29 '24 19:02 Kavindu-Dodan

I am not sure if I understand this task correctly, but https://github.com/open-feature/js-sdk-contrib/blob/main/libs/shared/flagd-core/src/lib/parser.ts#L8 seems to me we're already doing validation, and only throw an exception if the property is set, else it is a warning.

Did I miss something here, @toddbaert? or should we do something differently?

aepfli avatar Jun 18 '24 17:06 aepfli

specifically due to https://github.com/open-feature/js-sdk-contrib/pull/878 - funny how the numbers are just twisted between pr and issue ;)

aepfli avatar Jun 18 '24 18:06 aepfli

You are right. I or somebody else must have done this!

toddbaert avatar Jun 18 '24 18:06 toddbaert