GoshPosh / grafana-meta-queries

Grafana plugin for calculating time period metrics like week over week, month over month and year over year etc.
Apache License 2.0
284 stars 71 forks source link

bug in arithmetic metaqueries #29

Open gwuillou opened 6 years ago

gwuillou commented 6 years ago

I am doing a sum of 3 queries A + B +C . I get the follow result:

issues_mq

But if I zoom out, there is not anymore this 0 value in the left corner and everything works.

I am using influxdb and grafana 5.1.3.

Gauravshah commented 6 years ago

@gwuillou when zoomed-in are the results correct ? When zoomed out are able to see A,B,C ( without applying A+B+C Query) ?

gwuillou commented 6 years ago

Here different zooms. There is not always the problem apparently!

issues_mq2 issues_mq3 issues_mq4 issues_mq5 issues_mq6

Gauravshah commented 6 years ago

can you send a screenshot of your panel as well ( dashboard config )

gwuillou commented 6 years ago

issues_MQ7.pdf

Gauravshah commented 6 years ago

I think the problem is because metaqueries does not assume null as 0. So for the sections where 1 of the (a,b or c ) value is null then the resultant D is null. You can probably try (((a)? a :0) + ((b)? b :0) + ((c)? c :0))

gwuillou commented 6 years ago

Hello, I have tried your proposition without success: (((A['siesa'])?A['siesa']:0)+((C['djeva'])?C['djeva']:0)+((B['sinergy'])?B['sinergy']:0)) I don’t know if you are other idea?

Thank for your help,

Gaëtan

Le 5 juil. 2018 à 13:19, Gaurav M Shah notifications@github.com a écrit :

I think the problem is because metaqueries does not assume null as 0. So for the sections where 1 of the (a,b or c ) value is null then the resultant D is null. You can probably try (((a)? a :0) + ((b)? b :0) + ((c)? c :0))

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GoshPosh/grafana-meta-queries/issues/29#issuecomment-402690471, or mute the thread https://github.com/notifications/unsubscribe-auth/ATtI571lm1vUwgNc5ricvgPOMDFG2B09ks5uDfYtgaJpZM4VDYl2.

Gauravshah commented 6 years ago

I am not sure, I am unable to reproduce the error on my end. Looks to me that one of the datapoint is throwing the graph off. Can you try plotting a table instead and look at the odd data point ?

gwuillou commented 6 years ago

When I am exporting the csv:

Conso_FMV;2018-07-05T21:00:00+02:00;30.117048 Conso_FMV;2018-07-05T21:15:00+02:00;29.324952 Conso_FMV;2018-07-05T21:30:00+02:00;29.627704 Conso_FMV;2018-07-05T21:45:00+02:00;29.00208 Conso_FMV;2018-07-05T22:00:00+02:00;29.310443999999997 Conso_FMV;2018-07-05T22:15:00+02:00;29.481824 Conso_FMV;2018-07-05T22:30:00+02:00;28.184124 Conso_FMV;2018-07-05T22:45:00+02:00;28.682604 Conso_FMV;2018-07-05T23:00:00+02:00;28.003059999999998 Conso_FMV;2018-07-05T23:15:00+02:00;26.963816 Conso_FMV;2018-07-05T23:30:00+02:00;26.033584000000005 Conso_FMV;2018-07-05T23:45:00+02:00;26.090695999999998 Conso_FMV;2018-07-06T00:00:00+02:00;24.468472 Conso_FMV;2018-06-25T02:00:00+02:00;0 Conso_FMV;2018-07-06T00:15:00+02:00;0 Conso_FMV;2018-07-06T00:30:00+02:00;0 Conso_FMV;2018-07-06T00:45:00+02:00;0 Conso_FMV;2018-07-06T01:00:00+02:00;0 Conso_FMV;2018-07-06T01:15:00+02:00;0 Conso_FMV;2018-07-06T01:30:00+02:00;0 Conso_FMV;2018-07-06T01:45:00+02:00;0 Conso_FMV;2018-07-06T02:00:00+02:00;0 Conso_FMV;2018-07-06T02:15:00+02:00;0 Conso_FMV;2018-07-06T02:30:00+02:00;0

Le 9 juil. 2018 à 11:28, Gaurav M Shah notifications@github.com a écrit :

I am not sure, I am unable to reproduce the error on my end. Looks to me that one of the datapoint is throwing the graph off. Can you try plotting a table instead and look at the odd data point ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GoshPosh/grafana-meta-queries/issues/29#issuecomment-403418030, or mute the thread https://github.com/notifications/unsubscribe-auth/ATtI55md7cMzroWNSsLp9b6K2khbG3oBks5uEyJSgaJpZM4VDYl2.

Gauravshah commented 6 years ago

can you give a try to (((A['siesa'])?Math.round(A['siesa']*100)/100:0)+((C['djeva'])?Math.round(C['djeva']*100)/100:0)+((B['sinergy'])?Math.round(B['sinergy']*100)/100:0))

gwuillou commented 6 years ago

Always the same problem!

Le 9 juil. 2018 à 11:39, Gaurav M Shah notifications@github.com a écrit :

can you give a try to (((A['siesa'])?Math.round(A['siesa']100)/100:0)+((C['djeva'])?Math.round(C['djeva']100)/100:0)+((B['sinergy'])?Math.round(B['sinergy']*100)/100:0))

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GoshPosh/grafana-meta-queries/issues/29#issuecomment-403420994, or mute the thread https://github.com/notifications/unsubscribe-auth/ATtI5_BBN9cnzWG1VrMl6AaNC_xQLdmJks5uEyTigaJpZM4VDYl2.

Gauravshah commented 6 years ago

its hard to debug without that dataset

gwuillou commented 6 years ago

Perhaps it can help you:

Le 9 juil. 2018 à 11:44, Gaurav M Shah notifications@github.com a écrit :

its hard to debug without that dataset

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GoshPosh/grafana-meta-queries/issues/29#issuecomment-403422232, or mute the thread https://github.com/notifications/unsubscribe-auth/ATtI5_nEi4SH7LOHi6Dg3TIRmeneIb2Fks5uEyXggaJpZM4VDYl2.

DerAndereAndi commented 5 years ago

I have similar drawing issues. I can reproduce it when showing 2 datasets with data available in different time intervals and selecting an group by time() interval that is smaller than the first but larger than the second.

E.g. Dataset 1 is available in 10 Minutes interval, dataset 2 in 5 Minutes intervals. using group by time(10m) shows nice graphs, but using group by time (5m) shows issues in the graph. I am not arguing about the sense of this grouping, but to provide an example on how to reproduce graphing issues with MetaQueries.

Hope this helps.

Gauravshah commented 5 years ago

@TheRealKerni yup that scenario makes sense. but I am unsure if we can default numbers to 0. Its more general grafana issue than this plugin itself. I think it behaves in the same way if a datasource itself would have had no points in that location

DerAndereAndi commented 5 years ago

I am not sure what is going on yet, tried to debug a bit but haven't find the cause.

But I have a small example animated gif that may help.

The data source has data that is fetched once a minute, the minimum interval for the chart is set to 5 minutes. When showing the influxDB data, everything is fine, when showing the MetaQuery instead it acts app. I found that the timestamp of the last item when using MetaQuery suddenly changes to the first timestamp in the dataset!

Take a look.

example

Gauravshah commented 5 years ago

@ShilpaSivanesan we should see if this problem exists in a generic fashion. Lets look into this one next week.

tiago-cruz-movile commented 5 years ago

Hello,

I have two timestamps, and I would like to see the difference between using B['dequeuedAt']-A['routedAt']

Sometimes I've got strange negative values, like this:

image

How can I avoid null values?

I've tried (((B['dequeuedAt'])? B['dequeuedAt'] :0) - ((A['routedAt'])? A['routedAt'] :0) and ((B['dequeuedAt'])?Math.round(B['dequeuedAt']*100)/100:0) - ((A['routedAt'])?Math.round(A['routedAt']*100)/100:0)

But without success.

Sometimes the count got really strange like this:

image

Thanks!!

Gauravshah commented 5 years ago

@tiago-cruz-movile you should put it on a table to see what results do you get. also you can try ( (B['dequeuedAt'] && A['routedAt'])? B['dequeuedAt'] - A['routedAt'] : 0 )

aquilax commented 4 years ago

I had similar problem two queries A and B and the B query did not return values for every time interval for which A did. What worked for me was using something like A['key1'] + (B ? B['key2'] : 0) which essentially returns 0 if the B query does not have a value.

ZyanKLee commented 4 years ago

today I noticed a very similar behaviour with a simple A-B logic (well, B-A really):

A: SELECT mean("value") AS "Free" FROM "node_memory_MemFree_bytes" WHERE $timeFilter GROUP BY time($__interval) fill(none) B: SELECT mean("value") AS "Total" FROM "node_memory_MemTotal_bytes" WHERE $timeFilter GROUP BY time($__interval) fill(none) C: B["Total"]-A["Free"]

At first I had the time() set to 10s statically - and when I plotted 13 days or more the effect would look like that:

Bildschirmfoto 2020-02-03 um 17 20 18

then I went back to letting grafana determine the grouping interval and it solved the problem for me. (tested up till 30 days worth of data)

cassiel74 commented 4 years ago

Can't get metaqueries to work like you do... Here's my setup, what I am missing? image

Regards

DerAndereAndi commented 4 years ago

@cassiel74 add the value $col into the big ALIAS BY field.

The problem is that if ALIAS BY is not set, then the actual identifier prepended by values.. The $col value will eliminate this prepending string.

cassiel74 commented 4 years ago

Ah... I put the alias in SQL style :-) Now it's working, using only ALIAS BY and nothing in SELECT statement

Gauravshah commented 4 years ago

thank you @TheRealKerni

frams commented 4 years ago

I was having the same issue I solve mine by grouping by time ($__interval, previous) on both A AN B queries (MYSQL Data Source) and that seems to have fixed the issue. image