Skip to content

Modules

Tim Paine edited this page Mar 12, 2025 · 1 revision

Table Of Contents

AddChannelsToGraphOutput

Documentation coming soon!

Initialize

Documentation coming soon!

LogChannels

LogChannels is a simple GatewayModule to log channel ticks to a logger.

Configuration

log_channels:
  _target_: csp_gateway.LogChannels
  selection:
    include:
      - channel_one
      - channel_two
  log_states: false
  log_level: DEBUG
  log_name: MyCoolLogger

Tip

You can instantiate multiple different instances.

Mirror

Documentation coming soon!

MountAPIKeyMiddleware

MountAPIKeyMiddleware is a GatewayModule to add API Key based authentication to the Gateway REST API, Websocket API, and UI.

Configuration

modules:
  mount_api_key_middleware:
    _target_: csp_gateway.MountAPIKeyMiddleware
    api_key_timeout: 60:00:00 # Cookie timeout
    unauthorized_status_message: unauthorized

Usage

Server

When you instantiate your Gateway, ensure that the GatewaySettings instance has authenticate=True. By default, a unique token will be generated and displayed in the logging output, similar to how Jupyter works by default. To customize, change the GatewaySettings instance's api_key to whatever you like:

E.g. in configuration:

gateway:
  settings:
    AUTHENTICATE: True
    API_KEY: my-secret-api-key

Or from the CLI

csp-gateway-start <your arguments> ++gateway.settings.AUTHENTICATE=True ++gateway.settings.API_KEY=my-secret-api-key

API

For REST and Websocket APIs, append the token query parameter for all requests to authenticate.

Client

When instantiating your Python client, pass in the same arguments as the server:

config = GatewayClientConfig(
    host="localhost",
    port=8000,
    authenticate=True,
    api_key="my-secret-api-key"
)
client = GatewayClient(config)

The client will automatically include the API Key on all requests.

MountChannelsGraph

MountChannelsGraph adds a small UI for visualizing your csp-gateway graph, available by default at /channels_graph.

Configuration

modules:
  mount_channels_graph:
    _target_: csp_gateway.MountChannelsGraph

MountControls

MountControls adds additional REST utilities for various application-oriented functionality.

Configuration

modules:
  mount_outputs:
    _target_: csp_gateway.MountOutputsFolder

Functionality

This adds an additional top-level REST API group controls. By default, it contains 3 subroutes:

  • heartbeat: check if the csp graph is still alive and running
  • stats: collect some host information including cpu usage, memory usage, csp time, wall time, active threads, username, etc
  • shutdown: initiate a shutdown of the running server, used in the "Big Red Button"

MountFieldRestRoutes

Documentation coming soon!

MountOutputsFolder

MountOutputsFolder adds a small UI for visualizing your log outputs and your hydra configuration graph, available by default at /outputs.

Configuration

modules:
  mount_outputs:
    _target_: csp_gateway.MountOutputsFolder

MountPerspectiveTables

MountPerspectiveTables enables Perspective in the UI.

Configuration

modules:
  mount_perspective_tables:
    _target_: csp_gateway.MountPerspectiveTables
    layouts:
      Server Defined Layout: "<a custom layout JSON>"
    update_interval: 00:00:02

Additional configuration is available:

  • limits (Dict[str, int] = {}): configuration of Perspective table limits
  • indexes (Dict[str, str] = {}): configuration of Perspective table indexes
  • update_interval (timedelta = Field(default=timedelta(seconds=2)): default perspective table update interval
  • default_index (Optional[str]): default index on all perspective tables, e.g. id
  • perspective_field (str): Optional field to allow a perspective.Server to be mounted on a GatewayChannels instance, to allow GatewayModules to interact with Perspective independent of this module

MountRestRoutes

MountRestRoutes enables the REST API.

Note

The REST API is launched when starting the Gateway instance with rest=True

Configuration

modules:
  mount_rest_routes:
    _target_: csp_gateway.MountRestRoutes
    force_mount_all: True

Warning

force_mount_all: True force mounts all channels as read/write. This is convenient for debugging, but might not be ideal in production.

API endpoints can also be configured individually:

  • mount_last (ChannelSelection): channels to include in last routes
  • mount_next (ChannelSelection): channels to include in next routes
  • mount_send (ChannelSelection): channels to include in send routes
  • mount_state (ChannelSelection): channels to include in state routes
  • mount_lookup (ChannelSelection): channels to include in lookup routes

Important

send is only available if a GatewayModule has called add_send_channel or force_mount_all is True.

MountWebSocketRoutes

MountWebSocketRoutes enables the Websocket API.

Note

The REST API is launched when starting the Gateway instance with rest=True

Configuration

modules:
  mount_websocket_routes:
    _target_: csp_gateway.MountRestRoutes

It has a few additional configuration options:

  • readonly (bool=False): disallow sending in data back to the Gateway
  • ping_time_s (int=1): configure the default websocket ping (keepalive) interval in seconds

PrintChannels

PrintChannels is a simple GatewayModule to print channel ticks to stdout.

Configuration

print_channels:
  _target_: csp_gateway.PrintChannels
  selection:
    include:
      - channel_one
      - channel_two

PublishDatadog

Documentation coming soon!

PublishOpsGenie

Documentation coming soon!

PublishSQLA

Documentation coming soon!

PublishSymphony

Documentation coming soon!

ReplayEngineJSON

Documentation coming soon!

ReplayEngineKafka

Documentation coming soon!