Search code examples
prometheuspromql

Can a prometheus vector be labeled?


I have the following query:

(vector(1) and on() 
    rate(receiver_audio_track_bitrate{pod_name=~"$pod",session_id=~"$session"}[$__rate_interval]) == 0) 
    and on() (rate(sender_audio_track_bitrate{session_id=~"$session"}[$__rate_interval]) > 0)) 
or on() vector(0)

This query is intended to plot a scalar vector with a value of 1 if the receiver's audio track bitrate is zero while the sender's bitrate is non zero. Otherwise it will plot a scalar vector at 0.

The issue is that the scalar vector plotted does not contain the labels of sender_audio_track_bitrate and receiver_audio_track_bitrate. Is there any way to pass through the labels to the vector in this context?

Maybe there is an alternative approach to achieve my goal here?


Solution

  • Try the following PromQL query instead:

    rate(receiver_audio_track_bitrate{pod_name=~"$pod",session_id=~"$session"}[$__rate_interval]) ==bool 0)
      * on() group_left()
    (rate(sender_audio_track_bitrate{session_id=~"$session"}[$__rate_interval]) >bool 0)
    

    It uses bool modifier at comparison operators for converting the results to 0 or 1.