Splunk Developer Day: Watch all Sessions!Access the Playlist here

SignalFlow WebSocket API request messages

The SignalFlow streaming analytics service provides a WebSocket interface. This interface lets you run SignalFlow programs in background jobs and receive asynchronous results in a stream of control, metadata, and computation messages.

Info

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.

Compared to the SignalFlow REST API, the WebSocket interface offers these advantages:

  • Multiple data streams and computations using a single HTTP connection
  • Encoding protocol that’s more efficient than the one used by the REST API
  • Overall lower latency

To learn more about the REST API, see the topic SignalFlow API.

The following sections describe the WebSocket request messages. Refer to the topic SignalFlow Stream Messages Reference for the response messages.

Using WebSocket

To send SignalFlow WebSocket API requests, you need a WebSocket connection. You use this connection to send JSON objects called messages to the API. The API asynchronously sends response messages using the same connection.

Connect

To use the WebSocket API to make SignalFlow requests, you first have to connect to Splunk Observability Cloud using the REST API operation GET https://stream.<REALM>.observability.splunkcloud.com/v2/signalflow/connect. This operation doesn’t have a response body.

If the request succeeds, you can then send an authentication message using WebSocket.

Authenticate

To authenticate with Splunk Observability Cloud, send an authenticate message that contains a session authentication token. You need to send this message within 5 seconds of establishing the WebSocket connection.

You can also send this message with a new user access token to re-authenticate or switch to another organization without reconnecting. If the token is valid, re-authenticating does not affect running jobs. An invalid token causes the server to close the connection.

To use cost-related or rate-related token limits for WebSocket operations, use an org token. To learn more about org token limits, see Control Your Resource Usage using Token Limits.

Authenticate message syntax

{
"type": "authenticate",
"token": "<SESSION_TOKEN>"
}

Authenticate message properties

Table 1. Authenticate request: message properties

Property
Data type
Description
type
string
Must be "authenticate"
token
string
Session token

Execute a computation

Start a new SignalFlow computation by sending an execute message. You need to provide a channel name; SignalFlow puts the name into the streaming data messages emitted by the computation. Also provide the SignalFlow program you want to run.

You can also provide the following optional properties:

  • Job start time
  • Job stop time
  • Data resolution
  • maxDelay (the amount of time SignalFlow should wait for incoming data)
  • List of publish() labels to disable
  • List of detect() labels to disable

Execute message syntax

{
"type": "execute",
"channel": "<CHANNEL_NAME>",
"program": "<SIGNALFLOW_PROGRAM>",
"start": <JOB_START_TIME>,
"stop": <JOB_STOP_TIME>,
"resolution": <DATA_RESOLUTION>,
"maxDelay": <MAXIMUM_DELAY>,

Execute message properties

Table 2. Execute request: message properties

Property
Data type
Description
type
string
Must be "execute"
channel
string, 16 ASCII characters or less
WebSocket channel name
program
string
SignalFlow program you want to run
start
64-bit integer
Date and time, in milliseconds Unix time, when you want to start the execution
stop
64-bit integer
Date and time, in milliseconds Unix time, when you want to stop the execution
resolution
32-bit integer
Minimum data resolution in milliseconds
maxDelay
32-bit integer
Maximum time that you want the computation to wait after it detects that
input data has stopped arriving, in milliseconds. To get the automatic maximum,
specify 0. The maximum delay you can specify yourself is 900000, or 15 minutes.
timezone
string
Specifies the time zone SignalFlow should use as the basis of calendar-related
transformations in the computation job. For a list of supported time zones, see
Time Zones.
immediate
boolean
If true, overrides the value of stop and stops the computation immediately
when data stops arriving
disabledPublishLabels
array of string
List of labels associated with the publish() methods you want to disable for this job,
in the form of a JSON array of strings
disableDetectLabels
array of string
List of labels associated with the detect() methods you want to disable for this job,
in the form of a JSON array of strings
Info

The time zone used by start and stop is UTC+0, regardless of the value of timezone.

Execute request examples

Simple request with output streaming to your client via channel-1:

{
"type": "execute",
"channel": "channel-1",
"program": "data('demo.trans.latency').mean(by='demo_customer').stream()"
}

Request with optional arguments, streaming to channel-2. The job starts on May 15, 2019 at 7:10 AM UTC and ends on July 15, 2019 at 7:10 AM UTC. The data resolution is 1 minute.

{
"type": "execute",
"channel": "channel-2",
"program": "data('demo.trans.latency').mean().stream()",
"start": 1557904200000,
"stop": 1563174600000,
"resolution": 60000
}

Detach from a computation

To detach from a computation and stop receiving its output, send a detach message. Include the channel name you specified when you sent the execute message. If the channel is unknown or is no longer receiving data, Splunk Observability Cloud ignores the request.

SignalFlow includes the reason value when it sends a response.

Detach message syntax

{
"type": "detach",
"channel": "<CHANNEL_NAME>",
"reason": "<REASON_MESSAGE>"
}

Detach message properties

Table 3. Detach request: message properties

Property
Data type
Description
type
string
Must be "detach"
channel
string, 16 ASCII characters or less
WebSocket channel name you specified in the "execute" request message
reason
string
Reason for detaching. This value is inserted in WebSocket "detach" messages you
receive from SignalFlow.

Stop a computation

To stop a computation, send a stop request. You can stop a computation even if your client isn’t connected to it. Clients connected to the computation receive an end of stream response message that includes the value of the reason property you put in your request.

The handle property specifies the job handle you receive from Splunk Observability Cloud in the WebSocket response that contains "event": "JOB_START". See WebSocket response messages.

Stop message syntax

{
"type": "stop",
"handle": "<SIGNALFLOW_JOB_HANDLE",
"reason": "<REASON_MESSAGE>"
}

Stop message properties

Table 4. Stop request: message properties

Property
Data type
Description
type
string
Must be "stop"
handle
string
Computation job ID
reason
string
Reason for stopping. This value is inserted in WebSocket "stop" messages you
receive from SignalFlow.