Skip to content
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

Console support for event streams #28

Closed
5 tasks done
johanstokking opened this issue Jan 29, 2019 · 4 comments
Closed
5 tasks done

Console support for event streams #28

johanstokking opened this issue Jan 29, 2019 · 4 comments
Assignees
Labels
c/console This is related to the Console umbrella This issue needs actionable issues referenced
Milestone

Comments

@johanstokking
Copy link
Member

johanstokking commented Jan 29, 2019

Summary:

The console should support displaying real-time event streams.

All entities trigger events when they are created/updated/deleted:

  • Applications
  • Clients
  • EndDevices
  • Gateways
  • Organizations
  • Users
  • API Keys and Collaborations of above entities

LoRaWAN traffic also triggers messages while being processed by the stack. This is specifically useful for debugging EndDevices.

Why do we need this?

The purpose of event streams is mostly to let users trace messages through the stack, typically for debugging. Users will go to a single entity page and navigate to the events section. The console will then display some historical events if available (history is not stored by default) and add events as they come in. Users will be able to inspect event details. Users will be able to filter events by event name, and some other fields.

What is already there? What do you see now?

We have the Events API (see api doc). The Events.Stream RPC is mapped to HTTP on a POST /api/v3/events (note the POST). The request contains the identifiers of entities (plural) that the caller is interested in. All event names are selected, and it is not (yet) possible to filter event names server-side. Matching events are streamed as newline-delimited JSON objects in the response.

NOTE: In the future we may add a websocket version of this endpoint, but for now we're only working with this.

We also have the ttn-lw-cli events command that subscribes to the events stream (over gRPC).

The Event message contains the following fields:

  • name (string) of the event. An example is application.api-key.create. This name has a translation with key event:application.api-key.create.
  • time (timestamp) of the event.
  • identifiers one or more entity identifiers of entities related to the event (for example, an OAuth authorize event involves a user and an OAuth client)
  • data (optional object) details of the event, can be different for each event type
  • correlation_ids (list of strings) used for correlating this event to other events. In the future we may define an API for getting historical events by correlation ID, but that's currently not possible yet.
  • origin (string) origin of the event (typically the hostname of the instance/container), so may not say much.

What is missing? What do you want to see?


Original issue: https://github.com/TheThingsIndustries/lorawan-stack/issues/1071 by @bafonins

@johanstokking
Copy link
Member Author

johanstokking commented Feb 26, 2019

For UX, it's going to be streaming in the browser, pretty much like with the V2 Console today. In terms of memory, I think it would be wise to have a maximum duration (maybe also count) or entries to keep in memory. When you start the stream, there may already be history available (either duration or count is selectable) if the server supports it.

For technicalities, see https://github.com/TheThingsIndustries/lorawan-stack/issues/1640

@kschiffer kschiffer added the umbrella This issue needs actionable issues referenced label Mar 4, 2019
@htdvisser htdvisser changed the title Console support for gateways/applications/devices data streams Console support for event streams Mar 7, 2019
@bafonins
Copy link
Contributor

bafonins commented Apr 9, 2019

I tried several approaches to implement in the console, however none of the seem to work.

Approaches:

  1. Using native XMLHttpRequest as suggested here
  2. Using fetch and process the response.body stream. Note, that support for streams in the browser is very limited in comarison to nodejs.
  3. Using https://github.com/jimhigson/oboe.js
      oboe({
        url: '/api/v3/events/applications/admin-app',
        method: 'GET',
        headers: {
          Authorization: `Bearer ${tk}`,
        },
      })
        .node('!.result', function (result) {
          // message received
        }).done(function (things) {
          // stream done
        }).fail(function (error) {
          // error
        })

Note, that the POST endpoint wont work with oboe, see jimhigson/oboe.js#146
4. Using https://github.com/eBay/jsonpipe

Every request gets into the OPENED (see readyState 1 ) state and is simply pending (so the browser doesnt receive even the reponse headers). However, sometimes when you kill the server you can see buffered events being flushed to the browser.

@johanstokking johanstokking assigned htdvisser and unassigned kschiffer Apr 9, 2019
@johanstokking johanstokking modified the milestones: Backlog, April 2019 Apr 9, 2019
@htdvisser
Copy link
Contributor

This turns out to be caused by the Gzip middleware not flushing response chunks. I created a PR to fix this: labstack/echo#1317

@bafonins can you try what you did with gzip disabled (Accept-Encoding: identity)?

@bafonins
Copy link
Contributor

bafonins commented Apr 9, 2019

Yes, I just verified that the problem is indeed with the gzip middleware. Commented this line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c/console This is related to the Console umbrella This issue needs actionable issues referenced
Projects
None yet
Development

No branches or pull requests

4 participants