Skip to content

Feature Request: LockingPollingSensor to make HA aware polling sensors #4301

@djha-skin

Description

@djha-skin

Copying @armab on this.

SUMMARY

As discussed here, as a feature request, please create a LockingSensor and LockingPollingSensor class that I would be able to override much like we are presently able to do with the Sensor and PollingSensor classes.

Both sensor classes would start up, obtain a lock from the coordination backend, and continue to renew the lock (in perhaps the case of the pollinglockingsensor) using the tooz library, as it already does for other non-sensor things.

BUT WHY

When I was creating my StackStorm high availability instance, I wanted to do an Active/Active setup. In order to set this up, I set up a three-node mongodb cluster with fourth node as arbiter, a three-node zookeeper coordination cluster, and a three-node rabbitmq cluster. I chose to run every service -- st2web, st2api, st2sensorcontainer, etc. -- on both nodes behind the usual nginx reverse proxy. SSL termination and load balancing is taken care of by a load balancer in front of both nodes.

High availability totally works in an active/active set up like this for our use case, except the problem of making sensors active/active HA-ready. Sensor partitioning would not work, because the setup is active/active and I need webhooks to work in our environment. Say we have nodes A and B. If I used partioning, some of the webhooks would run on A and some on B. However, in an active/active setup, if a webhook call came in for a webhook which was running on A, but the request was actually routed by the load balancer to B, then the webhook wouldn't work. This is a sort of deal-breaker in my environment.

The solution to this problem in our environment was to simply run all sensors from both nodes. The webhooks would then work as intended; however, the PollingSensors that we are writing will need extra work to make them HA-aware. We will have to override Sensor instead of PollingSensor, and basically write a PollingSensor class by hand, except we will also have to incorporate some sort of lock to make sure only one sensor has the right to conduct polls at any given time. The feature that this ticket describes would really help make better HA-aware sensors.

ISSUE TYPE
  • Feature Idea
STACKSTORM VERSION

Paste the output of st2 --version:

[root@my-ha-host-01 ~]# st2 --version
st2 2.8.1, on Python 2.7.5
OS / ENVIRONMENT / INSTALL METHOD

Custom install using Chef and the StackStorm RPM repository on RHEL 7.

STEPS TO REPRODUCE

The new classes might be used like this:

The python code would be almost the exact same as for PollingSensor in the case of LockingPollingSensor:

from st2reactor.sensor.base import LockingPollingSensor

class MyHAAwareSensor(LockingPollingSensor):
    def setup(self):
        pass
    def poll(self):
        # poll is conducted here
        # LockingPollingSensor is basically a drop-in replacement for PollingSensor

The sensor config might have new config items, lease_interval and lease_duration, in addition to poll interval, which might specify how often the sensor should re-obtain the lease and how long leases should last.

---
    class_name: "HAAwareSensor"
    entry_point: "haaware_sensor.py"
    poll_interval: 600
    lease_interval: 30
    lease_duration: 30
EXPECTED RESULTS

The LockingPollingSensor would obtain a lock every lease_interval seconds. the lease would hopefully last lease_duration seconds, and would conduct a poll every poll_interval seconds.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions