SignalFlow stream messages reference
SignalFlow runs SignalFlow programs in the background. When you use the SignalFlow API to run a program, you receive streaming messages as SignalFlow executes the program.
When you send an API request, you need to use the endpoint specific to your organization's realm. To learn more, see Realms in endpoints.
SignalFlow streams the following types of messages:
- Control messages: Provide information about the stream itself
- Information messages: Contain information and warnings for the computation
- Metadata messages: Contain the metadata from the time series generated by the computation
- Data messages: Contain the data points from the computation
- Event messages: Sent when an anomaly triggers a detector, or when the triggered detector resolves
- Error messages: Report fatal errors that stop the computation
These message types give you all the information you need to control and use the output of the computation.
SignalFlow client libraries
SignalFlow provides open-source, language-specific client libraries that encapsulate the following tasks:
- Choosing the best connection method (HTTP or WebSocket) to use
- Parsing and decoding the stream of the messages coming from your SignalFlow computations
- High-level abstractions that simplify and speed up the process of building SignalFlow analytics applications
Use a client library rather than writing your own low-level connection, message processing, and request routines. This provides information for developers who want to handle SignalFlow requests and responses at a low level.
You can receive messages using either the Server-Sent Event (SSE) or WebSocket protocol. The format of the message you receive depends on the protocol you use.
The following are links to the client libraries in GitHub:
Receiving messages using Server-Sent Events
If you send a computation request to SignalFlow using the HTTP REST API,
SignalFlow returns response messages using the Server-Sent Event (SSE)
protocol. The content type is text/event-stream. Each SSE message has
the name event, which is also the message type, and a data payload
formatted in JSON. In accordance with the SSE standard, SignalFlow puts
an empty new line between each event.
Receiving messages using WebSocket
If you send a computation request to SignalFlow using a WebSocket connection to Splunk Observability Cloud, SignalFlow returns your response messages in either JSON text or binary format. The format SignalFlow uses depends on these factors:
- Message type: The
messageTypeSignalFlow assigns to the message. Data messages are binary-encoded, but all other messages use JSON. - Message compression settings: Whether you requested message compression when you connected to a channel using WebSocket.
SignalFlow identifies all WebSocket response messages with the channel
value you specify when you make an execute request. SignalFlow also
identifies the type of message in one of the top-level message
properties. In all other respects, WebSocket response messages formatted
in JSON have the same structure as SSE payloads.
Message compression
When you request message compression, SignalFlow attempts to compress response messages for the channel and client that sent the request. If the compressed message is smaller, SignalFlow sends it as a compressed binary message. The base format of this message is JSON except for data messages, which use the data message format.
Response message examples
SSE response messages
The following JSON contains the first SSE control messages you usually see when you request a SignalFlow computation using HTTP:
event: control-messagedata: {data: "event" : "STREAM_START",data: "timestampMs" : 1461351769440data: }event: control-messagedata: {
WebSocket response messages
The following JSON contains the first SSE control messages you usually see when you request a SignalFlow computation using HTTP:
{"type" : "control-message","channel" : "channel-1","event" : "STREAM_START","timestampMs" : 1461351769440}
{"type" : "control-message","channel" : "channel-1","event" : "JOB_START","handle" : "ChkVxy0AEAA","timestampMs" : 1461351771160}
{"type" : "control-message","channel" : "channel-1","event" : "JOB_PROGRESS","timestampMs" : 1461351771168,"progress" : 10}
Binary encoding of WebSocket messages
Binary messages coming from a SignalFlow WebSocket connection have a 4-byte preamble followed by the 16-byte ASCII channel name.
All binary messages use big endian encoding.
This text graphic shows the layout of the first 20 bytes of a WebSocket message:
0 1 2 3 4 5 6 7 8 A B C D E F 0 1 2 3 4 5 6 7 8 A B C D E F+-------------+-------------+---------------+-------------+| Version | Message type| Flags | Reserved |+---------------------------------------------------------+| Channel name (bytes 0-3) |+---------------------------------------------------------+| Channel name (bytes 4-7) |+---------------------------------------------------------+
- Version: Always
1 - Message type: Always
5(data batch) for binary encoded messages - Flags: Bitfield that contains the following bit flags:
000000x0: message payload isn't compressed.000000x1: message payload is compressed, so you have to decompress it with a tool such asgzip -d.0000001x: message payload is UTF-8 encoded JSON0000000x: message payload is binary
SignalFlow only compresses data messages. If the compressed payload is smaller, SignalFlow sends a compressed payload, and SignalFlow sets the compressed bit. Otherwise, SignalFlow sends an uncompressed payload, and SignalFlow leaves the compressed bit unset.
Message types
The following sections describe each response message type in more detail.
Control messages
Control messages provide information about the status and progress of a
SignalFlow computation. Each control message has an event property and
a timestampMs property. The event defines the type of control
message ("what happened"), while timestampMs contains a timestamp in
Unix time format noting the time the event occurred.
SSE example
event: control-messagedata: {data: "event" : "...",data: ...data: }
WebSocket example
"type": "control-message","channel": "channel-1","event": "...",...
STREAM_START control message
STREAM_START indicates that SignalFlow has opened the response stream
and started the computation.
STREAM_START SSE example
event: control-messagedata: {data: "event" : "STREAM_START",data: "timestampMs" : 1461360399704data: }
STREAM_START WebSocket example
{"type" : "control-message","channel" : "channel-1","event": "STREAM_START","timestampMs" : 1461360399704}
JOB_START control message
JOB_START indicates that the SignalFlow computation is initialized and
is starting to process data. The message contains the computation handle
ID, which you can use to control the computation using request messages
such as keep-alive, stop, and so forth.
JOB_START SSE example
event: control-messagedata: {data: "event" : "JOB_START",data: "handle" : "ChkVxy0AEAA",data: "timestampMs" : 1461360399772data: }
JOB_START WebSocket example
{"type" : "control-message","channel" : "channel-1","event" : "JOB_START","handle" : "ChkVxy0AEAA","timestampMs" : 1461360399772}
JOB_PROGRESS control message
If your computation contains a moving transformation such as a one-hour
moving average, SignalFlow has to feed initialization data into the
computation to seed the data window. As a result, it might take longer for
SignalFlow to generate the first data batch, especially if the data
window is large. In this situation, SignalFlow sends JOB_PROGRESS
control messages during the seeding phase.
The control message contains the progress property, which is an
integer between 0 and 100 inclusive representing the percent completion
of the operation. SignalFlow usually sends the message after it has
completed an additional 10% of the operation.
JOB_PROGRESS SSE example
event: control-messagedata: {data: "event" : "JOB_PROGRESS",data: "timestampMs" : 1461360399784,data: "progress" : 10data: }
JOB_PROGRESS WebSocket example
{"type" : "control-message","channel" : "channel-1","event" : "JOB_PROGRESS","timestampMs" : 1461360399784,"progress" : 10}
CHANNEL_ABORT control message
If your computation fails, SignalFlow sends you the CHANNEL_ABORT
message. This is the last message you receive for the computation.
The message contains an abortInfo object property that contains child
properties that provide additional information about the error cause.
The following table describes these properties:
Table 1. abortInfo child properties
Property | Description |
|---|---|
sf_job_abortReason | Why SignalFlow aborted the computation job |
sf_job_abortState | Code that indicates the current state of the computation |
CHANNEL_ABORT SSE example
event: control-messagedata: {data: "event" : "CHANNEL_ABORT",data: "timestampMs" : 1461360400235,data: "abortInfo" : {data: "sf_job_abortReason" : "job expired",data: "sf_job_abortState" : "EXPIRED"data: }
CHANNEL_ABORT WebSocket example
{"type" : "control-message","channel" : "channel-1","event" : "CHANNEL_ABORT","timestampMs" : 1461360400235,"abortInfo" : {"sf_job_abortReason" : "job expired","sf_job_abortState" : "EXPIRED"
END_OF_CHANNEL control message
You receive END_OF_CHANNEL when your computation reaches the end of
its execution time range. This only happens when you explicitly specify
a stop time. This message is the last you receive for the computation.
END_OF_CHANNEL SSE example
event: control-messagedata: {data: "event" : "END_OF_CHANNEL",data: "timestampMs" : 1461360400235data: }
END_OF_CHANNEL WebSocket example
{"type" : "control-message","channel" : "channel-1","event" : "END_OF_CHANNEL","timestampMs" : 1461360400235}
Information messages
During the initialization and execution of your computation, SignalFlow captures messages about decisions taken by the system, anomalies, and other conditions of interest. SignalFlow sends these messages during the computation, and in particular at the end of the first compute iteration. SignalFlow also sends messages at the end of the last compute iteration if you set an explicit stop time.
The reference documentation for all the information messages is in the SignalFlow Information Messages Reference.
Metadata messages
Metadata messages contain the metadata from the output time series of
your computation. Each message contains the metadata for a single time
series, identified by the tsId property of the message. The message
also contains a properties object property that contains the metadata.
The properties object contains these child properties:
Table 2. Metadata message child properties
Property | Description |
|---|---|
jobId | Identifier assigned by SignalFlow to the job that’s running the computation |
sf_OrganizationId | The organization identifier for the access token used to send the SignalFlow API request. This is either the organization that owns the org token, or the organization that the owner of the user token belongs to |
sf_key | An array of property keys that identify the computation |
sf_metric | For the metric time series (MTS) that’s the source of data for this computation, sf_metric is the name of the metric. |
sf_resolutionMs | The resolution of the computation, in milliseconds. The section Resolution of computations describes how SignalFlow determines this resolution. |
sf_type | The type of the incoming data, for example "Metric Time Series" |
sf_isPreQuantized | For internal use |
The following code contains examples of metadata messages in SSE and WebSocket format:
Metadata message in SSE format
event: metadatadata: {data: "tsId" : "CgrT2EkAAAA",data: "properties" : {data: "jobId" : "CgrS6A4AIAM",data: "sf_organizationID" : "BqDQY5OAAAA",data: "sf_key" : [ "jobId", "sf_metric" ],data: "sf_metric" : "mean_latency",
Metadata message in WebSocket format
{"type" : "metadata","channel" : "channel-1","tsId" : "CgrT2EkAAAA","properties" : {"jobId" : "CgrS6A4AIAM","sf_organizationID" : "BqDQY5OAAAA","sf_key" : [ "jobId", "sf_metric" ],
Metadata about a particular MTS is always emitted before any data for that MTS.
Expired tsId messages
Expired tsID messages indicate that a specific output time series is
probably no longer useful for the computation. This message helps a
client that maintains a repository of received metadata, organized by
tsId, to remove unnecessary entries.
SignalFlow sends this message if the computation has not sent any data for this output time series for a long time. In this case, the time series itself is no longer relevant. If the same time series reappears, SignalFlow sends a new metadata message to describe it again.
Expired tsId message in SSE format
event: expired-tsiddata: {data: "tsId" : "CgrT2EkAAAA"data: }
Expired tsId message in WebSocket format
{"type" : "expired-tsid","channel" : "channel-1","tsId" : "CgrT2EkAAAA"}
Data messages
Data messages contain the actual MTS generated by the
computation. In general, SignalFlow issues a data message for each
compute iteration, which occurs at the end of each period defined by the
resolution of the computation. If you call publish() multiple times
for a computation, you get a separate data message for each compute
iteration for each publish() call.
Each data message contains the logical timestamp for the data and a list of data points identified by a time series identifier.
Data message SSE example
The following listing is an example of a data message in SSE format. See the next section for the WebSocket binary format.
event: dataid: data-1461353198000data: {data: "data" : [ {data: "tsId" : "CgrT2EkAAAA",data: "value" : 199.53076547689204data: } ],data: "logicalTimestampMs" : 1461353198000
Binary data message format for WebSocket
When you send computation requests to SignalFlow using a WebSocket connection, you receive data messages in an efficient binary data encoding. Because data messages constitute most of the messages sent by SignalFlow computations, binary encoding helps reduce the data bandwidth, in some cases by more than 60%.
The following text diagram describes the format of the payload:
0 10 1 2 3 4 5 6 7 8 9 A B C D E F 0 1 2 3 4 5 6 7 8 9 A B C D E F+-------------------------------------------------------------+| Data batch (logical millisecond timestamp) |+- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+| Timestamp (continued) |+-------------------------------------------------------------+| Payload element count |
Table 3. Data message payload fields
Field | Length | Description |
|---|---|---|
Data batch time stamp | 64 bits (int64) | The logical timestamp in Unix time (milliseconds) |
Payload element count | 32 bits (int) | Number of data points in the payload |
Payload data | 136 bits (17 bytes) per data point | Bits 0 - 7 (byte 1): value type with one of the following values: 0x01 — long 0x02 — double 0x03 — int Bits 8 - 71 (bytes 2 - 9): time series ID (long) Bits 72 - 135 (bytes 10 - 16): data point value, with size determined by value type |
Both int and long are 64-bit integers, but the value type int
indicates that the value fits in a 32-bit integer, which means that the
32 high-order bits are zero.
You can convert the time series ID to its string representation by
Base64-decoding the bytes and removing the = padding characters.
The data is sent "big-endian".
Event messages
SignalFlow sends an event message when a detect() block detects or
clears an incident. The metadata for the event time series, identified
by the tsId specified in the event message, always arrives before the
event message. The event message itself contains a Unix time timestamp
in milliseconds and a properties object.
The inputValues child property of properties is an object that
contains the names and values of each detect condition variables that,
when evaluated, caused the alert to fire or to clear. inputValues is a
JSON-encoded map of the detect condition’s variables and their values
which, when evaluated, caused the alert to fire (was: ok, is: anomalous) or clear (was: anomalous, is: ok).
The following table describes each property of the event message:
Table 4. Event message properties
Property | Description |
|---|---|
timestampMs | Timestamp (in Unix time format) of the incident that resulted in the event message |
tsId | Identifier of the input MTS for the computation that caused the event message |
incidentId | Identifier for the incident that resulted in the event message |
inputValues | Object that containing the variables and values that caused the alert to fire or to clear |
was | State of the alert before the computation |
is | State of the alert after the computation |
Event message SSE example
event: eventdata: {data: "properties" : {data: "incidentId" : "Cj5VGRiAEAM",data: "inputValues" : "{\"a\":4}",data: "is" : "anomalous",data: "was" : "ok"data: },
Event message WebSocket example
{"type" : "event","channel" : "channel-1","properties" : {"incidentId" : "Cj5VGRiAEAM","inputValues" : "{\"a\":4}","is" : "anomalous","was" : "ok"