Writing prometheus test with metric operations/function

42 views
Skip to first unread message

Belmark Caday

unread,
Apr 2, 2020, 10:27:05 PM4/2/20
to Prometheus Users

Brian Candler

unread,
Apr 3, 2020, 3:02:45 AM4/3/20
to Prometheus Users
Expression 1 uses a range vector (data over a 1 hour time window) with predict_linear.  However if you only provide one data point, then there's no way it can do linear regression to fit a line.

Expression 2 performs an operation between two different metrics, but you've only provided a data point for one metric.

Belmark Caday

unread,
Apr 3, 2020, 2:02:04 PM4/3/20
to Prometheus Users


On Friday, April 3, 2020 at 3:02:45 PM UTC+8, Brian Candler wrote:
Expression 1 uses a range vector (data over a 1 hour time window) with predict_linear.  However if you only provide one data point, then there's no way it can do linear regression to fit a line.
 

       I already changed the time window to 1m, still it fails the test. can you give me example how to test it? 

Brian Candler

unread,
Apr 4, 2020, 5:05:49 AM4/4/20
to Prometheus Users
Put at least two data points in the time series.
Message has been deleted

Belmark Caday

unread,
Apr 4, 2020, 5:43:27 AM4/4/20
to Prometheus Users
Here are the udpdated tests : 

 - series: 'node_filesystem_free{fstype="ext4"}'
   values: '1+0x120'

 - expr: 'predict_linear(node_filesystem_free{fstype!~"tmpfs"}[1h], 4 * 3600) > 0'                                                                                                                                    
   eval_time: 1m                                                                                                                                                                                                      
   exp_samples:                                                                                                                                                                                                        
     - labels: 'node_filesystem_free{fstype="ext4"}'                                                                                                                                                                      
       value: 1          

And here is the error message I get: 

  FAILED:
    expr: "predict_linear(node_filesystem_free{fstype!~\"tmpfs\"}[1h], 4 * 3600) > 0", time: 1m0s,
        exp:"{__name__=\"node_filesystem_free\", fstype=\"ext4\"} 1E+00"
        got:"{fstype=\"ext4\"} 1E+00"

Brian Candler

unread,
Apr 4, 2020, 8:41:17 AM4/4/20
to Prometheus Users
Good: the error message tells you exactly what the problem is.  You said the expected result is

node_filesystem_free{fstype="ext4"} 1

but the actual result was

{fstype="ext4"} 1

That is correct: the output of the predict_linear() function is a timeseries with no metric name.

If you go to the prometheus GUI (normally on port 9090) and try these two promQL expressions, you'll see the difference:

node_filesystem_free_bytes{fstype!~"tmpfs"}

predict_linear(node_filesystem_free_bytes{fstype!~"tmpfs"}[1h], 4 * 3600)

HTH,

Brian.
Reply all
Reply to author
Forward
0 new messages