Plugins

The service supports the system of plugins. Plugins must be written in the Python programming language.

Plugin types

There are two sorts of plugins:

  • On event plugin. The plugin is triggered when an event occurs. The plugin should implement a callback function. This function is called on each event of the corresponding type. The set of event types is defined by the service developers.

    event type

    description

    monitoring_event

    Event contains monitoring points for sending to a custom monitoring system

    Monitoring plugin example:

    Module request monitoring plugin example

    class cow.plugins.plugin_examples.request_monitoring_plugin_example.BaseRequestMonitoringPlugin(app)[source]

    Base class for requests monitoring.

    abstractmethod async flushPointToMonitoring(point, logger)[source]

    All plugins must realize this method.

    This function call after end of request

    Parameters:
    • point (TypeVar(MonitoringPoint)) – point for monitoring

    • logger – logger

    Return type:

    None

    async handleEvent(points, logger)[source]

    Handle event

    Parameters:
    • *args – positional arg for event handler function

    • **kwargs – named arg for event handler function

    class cow.plugins.plugin_examples.request_monitoring_plugin_example.RequestMonitoringPlugin(app)[source]

    Example plugin sends a request data for monitoring to third-party source. Only one instance of this class exist during the program execution.

    async close()[source]

    Stop plugin.

    Close all open connections and ect

    async flushPointToMonitoring(point, logger)[source]

    Callback for sending a request monitoring data.

    Parameters:
    • point (TypeVar(MonitoringPoint)) – point for monitoring

    • logger – logger

    Return type:

    None

    async initialize()[source]

    Initialize plugin.

    Close all open connections and ect

    This plugin demonstrates the sending of a request monitoring data to another service. All monitoring plugins must implement the BaseRequestMonitoringPlugin abstract class.

  • Background plugin. This sort of plugin is intended for background work.

    The background plugin can implement:

    • custom route

    • background monitoring of service resources

    • collaboration of an event plugin and a background plugin (batching monitoring points)

    • connection to other data sources (Redis, RabbitMQ) and their data processing

      Module realizes background plugin example

      class cow.plugins.plugin_examples.background_plugin_example.BackgroundPluginExample(app)[source]

      Background plugin example.

      Create background task and add a route.

      async close()[source]

      Stop background process Returns:

      async initialize()[source]

      Initialize plugin

      async start()[source]

      Run background process

      Warning

      The function suppose that the process is handle in this coroutine. The coroutine must start the process only without awaiting a end of the process

      async usefulJob()[source]

      Some useful async work

      class cow.plugins.plugin_examples.background_plugin_example.HandlerExample[source]

      Handler example

      async get(request)[source]

      Method get example.

      Returns:

      response

      cow.plugins.plugin_examples.background_plugin_example.anotherHandlerExample(request)[source]

      Standalone handler example

    This plugin demonstrates background work and implements a route. All background plugins must implement the BaseRequestMonitoringPlugin abstract class.

Enable plugin

If the user implements a plugin, the file with the plugin should be added to the luna_video_agent/plugins directory of the service. The plugin filename should be added to the LUNA_VIDEO_AGENT_ACTIVE_PLUGINS configuration setting.