Add Substract a static value dependant on time

I have a metric, in my case from prometheus, which I have to substract a constant from. Easy so far, but this value have to be “20” after Nov 1st, and “10” before Nov 1st :slight_smile:

I’ve tried to connect a local Test-DB and made a CSV like:

time,value
2022-11-01 00:00:00, 10
2022-11-01 00:00:01, 20

But since there are only 2 values at two points in time I cannot work with that.

Any Ideas?

First, what I would do is obtain the epoch timestamp for the date of interest, which is 1667260800 for GMT. Then, you can get the difference between the current time and the timestamp using time() - 1667260800. The PromQL function sgn(...) returns the sign of the parameter, so sgn(time() - 1667260800) returns a step function where it is -1 before Nov. 1, and 1 after Nov. 1. I think you see where this is going now. Now you can manipulate that function to be equal to 10 before Nov. 1 and 20 after Nov. 1. My final function is:

((sgn(time() - 1667260800) * 5) + 15)

Which is a valid instant vector. You can then subtract (or add, multiply, etc.) this from any valid Prometheus query. Let me know if this worked for you!