tempodb / tempodb-python

Python client for TempoDB
MIT License
28 stars 19 forks source link

FR: Get Latest Value #19

Closed platinummonkey closed 2 years ago

platinummonkey commented 11 years ago

It would be great to only retrieve a single-value on demand instead of pulling a time-range and just picking off the last datapoint(s).

For example, currently you would pull some arbitrary amount of time history, check if the length of the returned dataset contains at least 1 point, then use that one point: dataset = client.read_key(<key>, <weekago>, <now>) if len(dataset.data) > 0: lastdp = list(dataset.data)[-1] # who knows how many points are in here?!

As you can tell, there could potentially be a lot of waste. Ideally, it would be great to retrieve just a single value (or set amount of values) like the following: dataset = client.read_key_latest(<key>, <weekago>, <now>, <numDatapointsToSend=1>) if len(dataset.data) > 0: lastdp = list(dataset.data)[0] # we know there are exactly 1 points now.

The other, but very similar case of retrieving the First value could also be of potential use to someone out there.

ajcronk commented 11 years ago

Thanks for the note, Cody. Yes, this is in our pipeline. Here is our current best thinking on how to generalize this feature, let me know what you think:

Last value is a special case of retrieving a single value. So we are designing an endpoint where you specify a point in time, and can say "find the closest previous value in time" or "find the closest next value in time". If you don't specify a point in time, we return the last value for the series.

Make sense? Would the generalized single value endpoint be useful beyond last value?

platinummonkey commented 11 years ago

I think that's a great idea to generalize it!

mjm-cycronix commented 11 years ago

Has there been any progress on adding this feature? This would be incredibly handy - it is very inefficient to trial-and-error your way thru data to find limits.