snap_plugin.v1.plugin module

class snap_plugin.v1.plugin.Meta(type, name, version, concurrency_count=5, routing_strategy=<RoutingStrategy.lru: 0>, exclusive=False, cache_ttl=None, rpc_type=<RPCType.grpc: 2>, rpc_version=1, unsecure=True)

Bases: object

Snap plugin meta

Parameters:
  • type (PluginType) – Plugin type
  • name (string) – Plugin name
  • version (int) – Plugin version
  • concurrency_count (int) – ConcurrencyCount is the max number concurrent calls the plugin may take. If there are 5 tasks using the plugin and concurrency count is 2 there will be 3 plugins running.
  • routing_strategy (RoutingStrategy) – RoutingStrategy will override the routing strategy this plugin requires. The default routing strategy is least-recently-used.
  • exclusive (bool) – Exclusive results in a single instance of the plugin running regardless the number of tasks using the plugin.
  • cache_ttl (int) – CacheTTL will override the default cache TTL for the provided plugin and the metrics it exposes (default=500ms).
  • rpc_type (RPCType) –
  • rpc_version (int) – RPC version
  • unsecure (bool) – Unsecure
class snap_plugin.v1.plugin.Plugin

Bases: object

Abstract base class for Collector, Processor and Publisher plugins.

Plugin authoris shoud not inherit directly from this class rather they should inherit from snap_plugin.v1.collector.Collector, snap_plugin.v1.processor.Processor or snap_plugin.v1.publisher.Publisher.

get_config_policy()

Returns the config policy for a plugin.

The config policy for a plugin includes config value types (Integer, (Float, String and Bool) and rules which includes default values and min and max constraints for Float and Integery value types.

Parameters:None
Returns:snap_plugin.v1.config_policy.ConfigPolicy
last_ping()

Returns the epoch time when the last ping was received

ping()

Ping responds to clients providing proof of life

The Snap framework will ping plugins every 1.5s to confirm they are not hung.

start_plugin()

Starts the Plugin

Starting a plugin includes:
  • Finding an available port
  • Starting the gRPC server
  • Printing to STDOUT data (JSON) for handshaking with Snap
stop_plugin()

Stops the plugin

class snap_plugin.v1.plugin.PluginResponseState

Bases: enum.Enum

Plugin response states

plugin_failure = 1
plugin_success = 0
class snap_plugin.v1.plugin.PluginType

Bases: enum.Enum

Plugin types

collector = 0
processor = 1
publisher = 2
class snap_plugin.v1.plugin.RPCType

Bases: enum.Enum

Snap RPC types

grpc = 2
json = 1
native = 0
class snap_plugin.v1.plugin.RoutingStrategy

Bases: enum.Enum

Plugin routing strategies

  • lru (default): Least recently used
    Calls are routed to the least recently called plugin instance.
  • sticky: Sticky based routing
    Calls are routed to the same instance of the running plugin. See Meta its attribute concurrency_count.
  • config: Config based routing
    Calls are routed based on the configuration matching. In this case multiple tasks could be configured with the same configuration in which case the framework will route calls to only those running instances with a configuration matching the task that is firing.
config = 2
lru = 0
sticky = 1