java-sdk icon indicating copy to clipboard operation
java-sdk copied to clipboard

[FEATURE] Make provider interface "stateless", SDK maintains provider state

Open toddbaert opened this issue 1 year ago • 4 comments

Stateless providers

Providers no longer maintain their own state: the state for each provider is maintained in the SDK automatically, and updated according to the success/failures of lifecycle methods (init/shutdown) or events emitted from providers spontaneously.

Similar work in C#: https://github.com/open-feature/dotnet-sdk/pull/276

### Tasks
- [ ] [Requirement 1.7.1](https://openfeature.dev/specification/sections/flag-evaluation#requirement-171): The client MUST define a provider status accessor which indicates the readiness of the associated provider, with possible values NOT_READY, READY, STALE, ERROR, or FATAL.
- [ ] [Requirement 1.7.3](https://openfeature.dev/specification/sections/flag-evaluation#requirement-173): The client's provider status accessor MUST indicate READY if the initialize function of the associated provider terminates normally.
- [ ] [Requirement 1.7.4](https://openfeature.dev/specification/sections/flag-evaluation#requirement-174): The client's provider status accessor MUST indicate ERROR if the initialize function of the associated provider terminates abnormally.
- [ ] [Requirement 1.7.5](https://openfeature.dev/specification/sections/flag-evaluation#requirement-175): The client's provider status accessor MUST indicate FATAL if the initialize function of the associated provider terminates abnormally and indicates error code PROVIDER_FATAL.
- [ ] [Requirement 1.7.6](https://openfeature.dev/specification/sections/flag-evaluation#requirement-176): The client MUST default, run error hooks, and indicate an error if flag resolution is attempted while the provider is in NOT_READY.
- [ ] [Requirement 1.7.7](https://openfeature.dev/specification/sections/flag-evaluation#requirement-177): The client MUST default, run error hooks, and indicate an error if flag resolution is attempted while the provider is in FATAL.
- [ ] [Requirement 1.7.8](https://openfeature.dev/specification/sections/flag-evaluation#requirement-178): Implementations SHOULD propagate the error code returned from any provider lifecycle methods.
- [ ] [Requirement 5.1.5](https://openfeature.dev/specification/sections/events#requirement-515): PROVIDER_ERROR events SHOULD populate the provider event details's error code field.
- [ ] [Requirement 5.3.5](https://openfeature.dev/specification/sections/events#requirement-535): If the provider emits an event, the value of the client's provider status MUST be updated accordingly.

toddbaert avatar Mar 15 '24 15:03 toddbaert

Hi @toddbaert I would like to work on this.

gunishmatta avatar May 08 '24 19:05 gunishmatta

Thanks, @gunishmatta, I've assigned you the issue. Please let us know if you have any questions!

beeme1mr avatar May 08 '24 20:05 beeme1mr

@gunishmatta here's the implementation I did in the JS SDK: https://github.com/open-feature/js-sdk/pull/795.

You can disregard the RECONCILING stuff - that only applies to client-side SDKs, which Java is not. The relevant stuff is all around the ProviderState. I used an internal wrapper class for this: https://github.com/open-feature/js-sdk/pull/795/files#diff-918e59c039e8a552dd77bdf93d9759acc86f58f677bf52e7a0990ff92683ef11R25, but take whatever approach you want.

toddbaert avatar May 17 '24 18:05 toddbaert

@toddbaert Thanks a lot for the guidance, you can expect my PR by end of this week.

Thanks Gunish.

gunishmatta avatar May 20 '24 07:05 gunishmatta

Unassigned due to inactivity.

toddbaert avatar Sep 04 '24 11:09 toddbaert

Hi @toddbaert I would like to work on this.

chrfwow avatar Sep 09 '24 13:09 chrfwow

I think this is done with https://github.com/open-feature/java-sdk/pull/1096. I will confirm and close in the next couple days.

toddbaert avatar Sep 24 '24 12:09 toddbaert