DrMemCS / drmem

Full source tree for the DrMem control system
MIT License
3 stars 4 forks source link

Add history limit parameter #24

Closed rneswold closed 1 year ago

rneswold commented 1 year ago

The Problem

The simple backend only saves the last value of each device. The redis backend can save historical data until the system runs out of memory. Any future backend will also be saving an unbounded amount of data.

The Solution

This issue proposes we add a parameter to the driver configuration, max_history. This property will be an integer and represents the number of historical entries that will be saved for that driver instance (all devices created by that driver instance will have the same history size limit.) If there are more than this number of entries, the oldest ones will be dropped.

For instance:

[[driver]]
name = "cycle"
prefix = "square-wave"
max_history = 1000
cfg = { millis = 1000, enabled = true }

This would make the driver provide history size information to the backend so, at most, 1000 entries will be saved (in this example.)

This parameter will be ignored by the simple backend, since it can only save one entry. Redis has built-in support for capping the total number of saved entries, so we'll leverage that feature.

"Good First Issue" Help

This is fairly straight forward, even though it requires changes in several crates:

I'm sure I'm missing some details, but that should be enough to get the compiler to point out the other spots that need to be fixed.