grafana / grafana

The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
https://grafana.com
GNU Affero General Public License v3.0
65.12k stars 12.15k forks source link

Stacking data series B a with different interval to series A inserts empty intermediate values #43134

Closed erozen closed 2 years ago

erozen commented 2 years ago

What happened: When creating a time series plot with two series using different intervals, when stack series is "off" the lower granularity series links values up as expected, however when set to "normal" the values are reduced to the granularity of the other series, and the intermediate slots are zero-filled.

What you expected to happen: Stacked rendering to occupy the same space as normal

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?: See below screenshots - First shows the expected behaviour - Query B data linked up. Second shows the change when one stack series is set to "normal" (please ignore the US date format, I haven't worked out how to change that yet).

1 Grafana_no-stacking 2 grafana_stacking

Environment:

bossinc commented 2 years ago

I believe this is intended behavior. Stacking graphs is the process of adding every value at each interval. If there is not a value at an interval on graph A but there is on graph B, then only graph B's value will be used.

erozen commented 2 years ago

In the case of stacking queries A and B together, I 100% agree it would be correct behaviour. In this case though only query B is stacked, and it is then overlaid on top of query A. We're not combining the values in any way, so I don't think it makes sense to reaggregate to the same granularity.

I can't think of a use case where you want those intermediate values to be zero, other than when stacking both queries together as you suggest.

dprokop commented 2 years ago

As @bossinc mentioned this is the intended behavior. Let's assume we have two series:

Scenario 1: A: 1,1,1,1,1 B: 2,null,2,null, 2

Stacking these two will result int the follwing chart:

Screen Shot 2022-01-05 at 13 36 09

Now, let's switch the series:

Scenario 2: A: 2,null,2,null, 2 B: 1,1,1,1,1

Screen Shot 2022-01-05 at 13 30 44

The chart indicates the stacking clearly, the missing (null) values are treated as 0 for the stack to work.

Now, if I understand correctly, what you @erozen would expect to happen is to keep the nulls as missing values and do not consider them when accumulating the stacks, which would result in the following charts:

Scenario 1:

Screen Shot 2022-01-05 at 13 35 18

Scenario 2:

Screen Shot 2022-01-05 at 13 34 42

Now, the missing values - even though not rendered as data points - are shown in the stack in a way that can result in misinterpreting the chart.

erozen commented 2 years ago

Hi @dprokop,

I obviously wasn't clear enough as both yourself and @bossinc got the wrong end of the stick - hopefully this comment clears it up.

In the situation you detail, behaviour is correct - however that's not the scenario I'm trying to describe. The two series are NOT being stacked together, only only one series is being stacked.

Take data for example: Series 1: 00:00:00,"z",40 00:30:00,"z",60

Series 2: 00:00:00,"a",20 00:00:00,"b",30 00:10:00,"a",10 00:10:00,"b",20 00:20:00,"a",20 00:20:00,"b",20 00:30:00,"a",30 00:30:00,"b",30

When both these series are overlaid on the same graph, you get lines for "z", "a", and "b" on the same scale with the points joined directly, as per my first screenshot. If you set the second series to stacked but NOT the whole graph ( so "a" and "b" are stacked but "z" is not), you get the nulls incorrectly injected - as per my second screenshot.

The important thing to note is that you are NOT stacking both series - only one. In that case, since they remain separate, the granularity shouldn't be shared.

ivanahuckova commented 2 years ago

@grafana/grafana-bi-squad Could you please have a look at this again. Closing https://github.com/grafana/grafana/issues/43782.

dprokop commented 2 years ago

@erozen thanks for detailing. I've put a sample data that you provided into Grafana, and I think I'm still not getting the results you are describing. Please have a look at the attached dashboard[1], using the TestData datasource.

I've configured the stacking exactly as you have described and IMO this works exactly as it is supposed to work. Stacking configuration: Series 2 (a) and Series 2 (b) stacked, Series 1 not stacked:

image

I've tested the attached dashboard against main version as well as agains 8.3.2 which you report was about.

Could you please share your query results with us? You can get those by exporting CSV from the Panel Inspect. Please make sure Formatted data in Data options is disabled.

[1] dashboard.json ```json { "annotations": { "list": [ { "builtIn": 1, "datasource": "-- Grafana --", "enable": true, "hide": true, "iconColor": "rgba(0, 211, 255, 1)", "name": "Annotations & Alerts", "target": { "limit": 100, "matchAny": false, "tags": [], "type": "dashboard" }, "type": "dashboard" } ] }, "editable": true, "fiscalYearStartMonth": 0, "graphTooltip": 0, "id": 652, "links": [], "liveNow": false, "panels": [ { "fieldConfig": { "defaults": { "color": { "mode": "palette-classic" }, "custom": { "axisLabel": "", "axisPlacement": "auto", "barAlignment": 0, "drawStyle": "line", "fillOpacity": 0, "gradientMode": "none", "hideFrom": { "legend": false, "tooltip": false, "viz": false }, "lineInterpolation": "linear", "lineWidth": 1, "pointSize": 5, "scaleDistribution": { "type": "linear" }, "showPoints": "auto", "spanNulls": false, "stacking": { "group": "A", "mode": "none" }, "thresholdsStyle": { "mode": "off" } }, "mappings": [], "thresholds": { "mode": "absolute", "steps": [ { "color": "green", "value": null }, { "color": "red", "value": 80 } ] } }, "overrides": [ { "matcher": { "id": "byFrameRefID", "options": "B" }, "properties": [ { "id": "custom.stacking", "value": { "group": "A", "mode": "normal" } } ] } ] }, "gridPos": { "h": 8, "w": 12, "x": 0, "y": 0 }, "id": 2, "options": { "legend": { "calcs": [], "displayMode": "list", "placement": "bottom" }, "tooltip": { "mode": "single", "sort": "none" } }, "targets": [ { "csvContent": "\"time\",\"s1\"\n1642394276442,40\n1642415876442,60\n\n", "datasource": { "type": "testdata", "uid": "PD8C576611E62080A" }, "refId": "A", "scenarioId": "csv_content" }, { "csvContent": "\"time\",\"s2(a)\",\"s2(b)\"\n1642394276442,20,30\n1642401476442,10,20\n1642408676442,20,20\n1642415876442,30,30\n\n", "datasource": { "type": "testdata", "uid": "PD8C576611E62080A" }, "hide": false, "refId": "B", "scenarioId": "csv_content" } ], "title": "Panel Title", "type": "timeseries" } ], "refresh": false, "schemaVersion": 34, "style": "dark", "tags": [], "templating": { "list": [] }, "time": { "from": "2022-01-17T03:57:53.351Z", "to": "2022-01-17T10:49:56.639Z" }, "timepicker": {}, "timezone": "", "title": "Stacking debug - 43134", "uid": "x-TlxE1nz", "version": 3, "weekStart": "" } ```
erozen commented 2 years ago

Hi,

Sample data attached, and the config and chart it generates in the screenshot.

grafana-43134-sample-data.csv Screenshot from 2022-01-18 20-53-47

erozen commented 2 years ago

With stacking of query B off, looks like it should Screenshot from 2022-01-18 21-11-59 :

dprokop commented 2 years ago

Thanks @erozen, I'll have a look soon.

dprokop commented 2 years ago

@erozen I finally had a chance to investigate this and see how we can fix the described issue. I've opened this PR https://github.com/grafana/grafana/pull/44324 - please have a look at the attached screenshots in it if this is the expected behaviour.

erozen commented 2 years ago

Hi,

Definite improvement, removing all the bars instead of having them zero makes the line graph and point plot look perfect - the bar is still narrow though, so a perfect fix would probably be to keep the granularity of the original data too. With stacking off they are the full width of the data, but when it's on the bars are reduced to the width of the other, more granular, data set, so there are large gaps between the bars and it looks like they represent smaller time spans than they actually do.

Hopefully that makes sense?