Any way to provide default value when there's no data for table?

I’m a newbie with grafana so please be patient with me. I will try to fill out the template as much as I can.

  • What Grafana version and what operating system are you using?
    Grafana v10.2.2

  • What are you trying to achieve?
    I am using a table with the following query to get pod status and use it like an indicator:
    kube_pod_status_phase{namespace=“nuix-neo-tenant”, pod=~“investigate-deploy-.*”} == 1
    And depending on the value I set the cell colour. For example, Running is green, Failed is Red…etc.

The problem is before the pod exists, the table will show “No Data” and I want to see if there’s a way to have a default value so that I can actually colour it with some colour. Rather than just showing “No Data” with the default colour.

  • How are you trying to achieve it?
    The problem is I don’t know how to achieve it. I know I can set the text with “No Value” field but that’s not really defaulting it to a value that can be used by value mapping.

I also read somewhere that some people uses “on() vector(0)” to set some default value but this didn’t work in my case.

  • What happened?

  • What did you expect to happen?

  • Can you copy/paste the configuration(s) that you are having problems with?

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

  • Did you follow any online instructions? If so, what is the URL?

Hello @ashiue01

I just tried using the doc and find a really easy way.
Go to value mapping, Add a mapping value then select special. From there you are able to pick up NULL value, which should work!

Regards

Hi @codi639 ,

Thanks a lot for the reply. I tried what you suggested that but it did not work for me. I even used both Null + NaN, then hit refresh button but still it shows no data and the colour is still the normal background.

Well, in PromQL (looks like that’s what you are using?), there’s no explicit value for an “empty value”… Can you try the last special option Empty string?

Thanks for the reply. I tried it as well, same result, nothing changed.

Okay, last guess I make: if it don’t work I’ll not be able to help you furthermore… :neutral_face:

Try to put a value mapping using the string “Absent” or “absent” (something like this).
Hope it works!

1 Like

Doesn’t work either, thanks a lot for your help. I will do a bit more research.

Thank you for your response but I also tried it and it’s still the same, the value mappings did not change the colour even if I set the “No value” field.

I gave you answer for your topic title “Any way to provide default value when there’s no data for table” - No value setting doesn’t change value actually (it just mask it visually), so you can’t use Value mapping setting to change color.

If you want: “Any way to provide default value AND COLOR when there’s no data for table”, then:
create promql query (*), which return some special value, which metric can’t have (e.g. -1) when metric doesn’t exist and use that value in Value mapping (-1 => text: text, color: red)

* How to write that promql is another topic - you need “if else” in promql: prometheus - PromQL if/else like expression - Stack Overflow - so develop that query for your case

1 Like

Yep, sorry about my misleading title. It’s more like actually change the value rather than just showing something. I’m new to grafana so I don’t even know how to write the PromQL properly and have been just using the builder. Thanks for your response and I will check out how to write if-else expression with PromQL.

Thanks a lot for the link to the post for if-else express for PromQL. I was able to achieve what I wanted via the PromQL. I marked your answer as the solution. Thanks again.

For others who might want to do the same thing as what I’m doing. Here’s the sample PromQL that I used to set values based on the phase metric and also has a case in case there’s “no data”:

(vector(1) and on() (kube_pod_status_phase{namespace="tenant", pod=~"app-.*", phase="Running"}==1)) or
(vector(2) and on() (kube_pod_status_phase{namespace="tenant", pod=~"app-.*", phase="Pending"}==1)) or
(vector(3) and on() (kube_pod_status_phase{namespace="tenant", pod=~"app-.*", phase="Failed"}==1)) or
on() vector(0)

Then I use the value mapping to change the display text and set the background colour.

It will be nice if you post that developed PromQL query here.