Skip to main content

Listen to events

Izanami provide a way to listen what is happening inside. There is two to achieve that :

  • SSE
  • Webhooks

Events model

An event is json with the following structure :

{
"_id": 942711288101863450,
"type": "CONFIG_UPDATED",
"key": "demo:title",
"domain": "Config",
"payload": {
"id": "demo:title",
"value": "{\n \"title\": \"Changed title\"\n}"
},
"oldValue": {
"id": "demo:title",
"value": "{\n \"title\": \"Title\"\n}"
},
"timestamp": "2017-12-18T11:01:00.469"
}
FieldDescription
_idUnique id of the event. A recent id is greater than a previous
typeThe type of the event (see the chapter below)
keyThe key of the modified object.
domainThe domain concerned by the event (see the chapter below)
payloadThe json of the updated object
oldValueThe oldValue is optional and only present during an update.
timestampThe timestamp of the event

The field oldValue is optional and only present during an update.

Domains

DomainDescription
ExperimentEvents from experiments, bindings and experiment events
ApiKeyEvents from api keys
ConfigEvents from configs
FeatureEvents from features
UserEvents from users
ScriptEvents from scripts
WebhookEvents from web hooks

Types

TypesDescription
CONFIG_CREATEDWhen a config is created
CONFIG_UPDATEDWhen a config is updated
CONFIG_DELETEDWhen a config is deleted
CONFIGS_DELETEDWhen configs are deleted
FEATURE_CREATEDWhen a feature is created
FEATURE_UPDATEDWhen a feature is updated
FEATURE_DELETEDWhen a feature is deleted
FEATURES_DELETEDWhen features are deleted
GLOBALSCRIPT_CREATEDWhen a global script is created
GLOBALSCRIPT_UPDATEDWhen a global script is updated
GLOBALSCRIPT_DELETEDWhen a global script is deleted
GLOBALSCRIPTS_DELETEDWhen global scripts are deleted
USER_CREATEDWhen a user is created
USER_UPDATEDWhen a user is updates
USER_DELETEDWhen a user is deleted
USERS_DELETEDWhen users are deleted
WEBHOOK_CREATEDWhen a webhook is created
WEBHOOK_UPDATEDWhen a webhook is updated
WEBHOOK_DELETEDWhen a webhook is deleted
WEBHOOKS_DELETEDWhen webhooks are deleted
APIKEY_CREATEDWhen an apikey is created
APIKEY_UPDATEDWhen an apikey is updated
APIKEY_DELETEDWhen an apikey is deleted
APIKEYS_DELETEDWhen apikeys are created
EXPERIMENT_CREATEDWhen an experiment is created
EXPERIMENT_UPDATEDWhen an experiment is updated
EXPERIMENT_DELETEDWhen an experiment is deleted
EXPERIMENTS_DELETEDWhen experiments are deleted
VARIANT_BINDING_CREATEDWhen an binding is created
EXPERIMENT_VARIANT_EVENT_CREATEDWhen an experiment event is created
EXPERIMENT_VARIANT_EVENT_DELETEDWhen an experiment event is deleted

Web hooks

Webooks

Web hooks allow you to get notified when events occurred in izanami. You have to register an endpoint in izanami, the endpoint needs to be a POST api handling a json payload of the form :

{
"objectsEdited": [
{...},
{...}
]
}

If the call to the registered endpoint failed too much, the registered web hook will be deactivated.

Server sent event

Server sent event allow the server to push event to a client. The server keep a connection opened to send notifications. The Server-Sent Events EventSource API is standardized as part of HTML5 by the W3C.

Izanami expose server sent events endpoint to listen what is happening. There is two endpoint:

  • /api/events?domains=Config,Feature&patterns=* : a global listener
  • /api/events/Config?patterns=* : a listener for a specific domain
curl -X GET \
'http://localhost:9000/api/events?domains=Config,Feature&patterns=*' \
-H 'Content-Type: application/json' \
-H 'Izanami-Client-Id: xxxx' \
-H 'Izanami-Client-Secret: xxxx'

Will return

id: 942740804979392517
data: {"_id":942740804979392517,"type":"FEATURE_UPDATED","key":"drop:hbomb:in:random:place","domain":"Feature","payload":{"id":"drop:hbomb:in:random:place","enabled":false,"parameters":{"releaseDate":"11/01/2018 09:58:00"},"activationStrategy":"RELEASE_DATE"},"timestamp":"2017-12-18T13:58:17.841","oldValue":{"id":"drop:hbomb:in:random:place","enabled":false,"parameters":{"releaseDate":"11/01/2018 09:58:00"},"activationStrategy":"RELEASE_DATE"}}

Replay Events

If you're using kafka as a data store for events, you can replay events from the last day using the Last-Event-Id header.

With this request, the event after the id 942740804979392517 will be replayed.

curl -X GET \
'http://localhost:9000/api/events?domains=Config,Feature&patterns=*' \
-H 'Content-Type: application/json' \
-H 'Izanami-Client-Id: xxxx' \
-H 'Izanami-Client-Secret: xxxx' \
-H 'Last-Event-Id: 942740804979392517'

The replay can be used for failure handling while listening to events. If the client lose the connection or crash, it can specify the last event id to get the event that append since the failure.