Open ralphbean opened 9 years ago
:+1: This would be fun and tricky as well. But, it's definitely the way to go. However, we'll need some kind of datastore, still, in the plugins, so that all the states are dumped to the datastore and the apps remain stateless. We'll be able to easily scale, then.
We need to give more thought on it, though. I will package the current statscache for deployment, first before jumping into the rewrite.
@rtnpro In my idea above (in the log), dumping data out to the data store would be the responsibility of the callback functions. So the plugins would only ever return a data structure. Importantly, they (as @ralphbean mentioned) would never side-effect to actually store the data somewhere.
So, using the volume/by_topic
plugin as an example, we'd have callback functions for each of the following:
handle
function does from line 34 to 48The plugin would contain whatever the current handle
function does line 28 to 32, and then return that result as part of its object structure that it returns.
The biggest problem I see here is that if the plugin depends on some kind of previously stored data to do its job. Like if there is a plugin that needs to reach out to the database, grab a number, and add that to some field in whatever triggered that plugin to be run. In Haskell, I'd fix this by using the Reader
monad, but I don't know of the cleanest Python way. However, this also gives preference to one backend store which seems counterintuitive -- it says "if you need data, get it from this hardcoded source, as opposed to this one over here" which seems bad/limiting. Maybe it's better to enforce that plugins aren't aware of the current datastore state, but can still signal that they want to modify it. So a plugin can say, for example, "I don't know what the current value of the data store is, but I know I want to increment it by 1."
But then we're reinventing statsd.
Basically, it would be awesome if we could dispatch the output of all our wonderful plugins to other different systems -- in particular, to statsd.
Currently, we can't do this as all of our plugins hardcode their interaction with sqlalchemy to store their data (read: side-effects).
Instead, we should have the plugins
return
their data and then have the calling code dispatch that data to different handlers/callbacks/etc.. which then store the data in postgres, or send it to statsd, or memcached, or wherever.The tricky part here will be to make some kind of common data object that can represent both the time-series information from the volume plugin and the singleton information from the releng plugins.
Full IRC log of the conversation that brought this up: