-
Notifications
You must be signed in to change notification settings - Fork 49
feat: add events #182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: add events #182
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
affa0b9
feat: events
toddbaert 339ea60
fixup: fix numbering
toddbaert 02e93d4
fixup: sync
toddbaert d872a1c
fixup: remove shutdown
toddbaert eaa2b00
fixup: additional clarity, event metadata
toddbaert 0563cbd
fixup: error event metadata
toddbaert 9c37221
fixup: numbering (thx anna)
toddbaert 857a09d
fixup: add handler error req
toddbaert 4801e2c
fixup: add global events
toddbaert 25c0f21
fixup: spelling
toddbaert 4068982
Update specification/types.md
toddbaert cf4932f
fixup: more clarity
toddbaert b072502
fixup: client shutdown
toddbaert e09a20a
fixup: simplify event details
toddbaert 7cba5ba
fixup: add specific point about event scoping
toddbaert c47b03f
fixup: add mermaid diagram
toddbaert 5bc1c52
fixup: mark API global in diagram
toddbaert 8da59ab
fixup: more clarity on events and init
toddbaert d0e7251
fixup: handler name flexibility
toddbaert a4e70ab
fixup: no client shutdown, event handler removal
toddbaert f2c9367
fixup: loosen event handler def
toddbaert bc0452c
fixup: lint fix
toddbaert 5f4c75b
fixup: add event handler removal ex
toddbaert 736f9ec
Update specification/sections/05-events.md
toddbaert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
toddbaert marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| --- | ||
| title: Events | ||
toddbaert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| description: Specification defining event semantics | ||
| toc_max_heading_level: 4 | ||
| --- | ||
|
|
||
| # 5. Events | ||
|
|
||
| [](https://github.com/open-feature/spec/tree/main/specification#experimental) | ||
|
|
||
| ## Overview | ||
|
|
||
| `Events` allow consumers (_application integrator_, _application author_, _integration author_) to react to state changes in the provider or underlying flag management system, such as flag definition changes, provider readiness, or error conditions. A provider may emit events or run a callback indicating that it received a certain event, optionally providing data associated with that event. Handlers registered on the `client` or the global `API` are then invoked with this data. | ||
|
|
||
| The data that providers supply in event payloads may include a list of `flag keys` changed, error messages, and possibly updated flag values. | ||
|
|
||
| ```mermaid | ||
| graph | ||
| P(Provider) -->|emit event| A[API] | ||
| A -->|run handlers| AH("API (global) event handlers") | ||
| A --> C[Client] | ||
| C -->|run handlers| CH(Client event handlers) | ||
| ``` | ||
|
|
||
Kavindu-Dodan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ### 5.1. Provider events | ||
|
|
||
| #### Requirement 5.1.1 | ||
|
|
||
| > The `provider` **MAY** define a mechanism for signaling the occurrence of one of a set of events, including `PROVIDER_READY`, `PROVIDER_ERROR`, `PROVIDER_CONFIGURATION_CHANGED` and `PROVIDER_STALE`, with an `provider event details` payload. | ||
| If available, native event-emitter or observable/observer language constructs can be used. | ||
|
|
||
| see: [provider event types](../types.md#provider-events), [`event details`](../types.md#provider-event-details). | ||
|
|
||
| #### Requirement 5.1.2 | ||
|
|
||
| > When a `provider` signals the occurrence of a particular `event`, the associated `client` and `API` `event handlers` **MUST** run. | ||
| see: [provider event types](./../types.md#provider-events) and [event handlers](#52-event-handlers). | ||
|
|
||
| #### Requirement 5.1.3 | ||
|
|
||
| > When a `provider` signals the occurrence of a particular `event`, `event handlers` on clients which are not associated with that provider **MUST NOT** run. | ||
| Providers bound to a named client constitute their own scope events scope. | ||
|
|
||
| see: [setting a provider](./01-flag-evaluation.md#setting-a-provider) | ||
|
|
||
| #### Requirement 5.1.4 | ||
|
|
||
| > `PROVIDER_ERROR` events **SHOULD** populate the `provider event details`'s `error message` field. | ||
| The error message field should contain an informative message as to the nature of the error. | ||
|
|
||
| See [event metadata](../types.md#error-event-details) | ||
|
|
||
| ### 5.2. Event handlers | ||
|
|
||
| #### Requirement 5.2.1 | ||
|
|
||
| > The `client` **MUST** provide an `addHandler` function for associating callbacks with `provider events`, which accepts an `event type` and a `event handler function`. | ||
| ```java | ||
| // run the myClientOnReadyHandler function when the PROVIDER_READY event is fired | ||
| client.addHandler(ProviderEvents.Ready, MyClass::myClientOnReadyHandler); | ||
| ``` | ||
|
|
||
| see: [provider events](#51-provider-events) | ||
|
|
||
| #### Requirement 5.2.2 | ||
|
|
||
| > The `API` **MUST** provide an `addHandler` function for associating callbacks with `provider events`, which accepts an `event type` and a `event handler function`. | ||
| ```java | ||
| // run the myGlobalErrorHandler function when the PROVIDER_READY event is fired | ||
| OpenFeature.addHandler(ProviderEvents.Error, MyClass::myGlobalErrorHandler); | ||
| ``` | ||
|
|
||
| see: [provider events](#51-provider-events), [`provider event types`](../types.md#provider-events) | ||
|
|
||
| #### Requirement 5.2.3 | ||
|
|
||
| > The `event details` **MUST** contain the `client name` associated with the event. | ||
| The `client name` indicates the client/provider with which the event is associated. | ||
| This is particularly relevant for `event handler functions` which are attached to the `API`, not a particular client. | ||
|
|
||
| #### Requirement 5.2.4 | ||
|
|
||
| > The `event handler` function **MUST** accept a `event details` parameter. | ||
| see: [`event details`](../types.md#event-details) | ||
|
|
||
| #### Requirement 5.2.5 | ||
|
|
||
| > If a `handler functions` terminates abnormally, other event handlers **MUST** run. | ||
| #### Requirement 5.2.6 | ||
|
|
||
| > Event handlers **MUST** persist across `provider` changes. | ||
| Behavior of event handlers should be independent of the order of handler addition and provider configuration. | ||
|
|
||
| ### Event handlers and initialization | ||
|
|
||
| Though providers themselves need not implement events, the `flag evaluation API` uses events to convey relevant state changes during configuration and initialization. | ||
| _Application authors_ and _application integrators_ use these events to wait for proper initialization of the SDK and provider and to do basic monitoring and error handling. | ||
|
|
||
| #### Requirement 5.3.1 | ||
|
|
||
| > If the provider's `initialize` function terminates normally, `PROVIDER_READY` handlers **MUST** run. | ||
| See [provider initialization](./02-providers.md#24-initialization) and [setting a provider](./01-flag-evaluation.md#setting-a-provider). | ||
|
|
||
Kavindu-Dodan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #### Requirement 5.3.2 | ||
|
|
||
| > If the provider's `initialize` function terminates abnormally, `PROVIDER_ERROR` handlers **MUST** run. | ||
| A failed initialization could represent an unrecoverable error, such as bad credentials or a missing file. | ||
| If a failed initialization could also represent a transient error. | ||
| A provider which maintains a persistent connection to a remote `flag management system` may attempt to reconnect, and emit `PROVIDER_READY` after a failed initialization. | ||
|
|
||
| See [provider initialization](./02-providers.md#24-initialization) and [setting a provider](./01-flag-evaluation.md#setting-a-provider). | ||
|
|
||
| #### Requirement 5.3.3 | ||
|
|
||
| > `PROVIDER_READY` handlers attached after the provider is already in a ready state **MUST** run immediately. | ||
| See [provider initialization](./02-providers.md#24-initialization) and [setting a provider](./01-flag-evaluation.md#setting-a-provider). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.