CorpGlory / grafana-graph-panel

Webpack copy of Grafana default panel
MIT License
11 stars 5 forks source link

Modification to histogram function not working as expected #6

Closed FrancescoC87 closed 6 years ago

FrancescoC87 commented 6 years ago

Hello,

i'm trying to create my own panel using this one as base.

I'm doing some test with the histogram feature of the graph; i just perform a simple modification on the histogram.ts function and i got a very strange result.

I edited histogram.ts function, changing

for (let i = 0; i < values.length; i++) { let bound = getBucketBound(values[i], bucketSize); if (histogram[bound]) { histogram[bound] = histogram[bound] + 1; } else { histogram[bound] = 1; } }

with

histogram[1] = 10; histogram[2] = 20; histogram[3] = 30; histogram[4] = 40;

and removing (no more used)

function getBucketBound(value: number, bucketSize: number): number { return Math.floor(value / bucketSize) * bucketSize; }

So i would like that my histogram always shows four bucket placed at 1, 2, 3, 4 with values 10, 20, 30, 40, instead of automatically calculate them with the data coming from the datasource.

I'm using the windows versions of Grafana 5.0.4, and the default random metric (Test Data: random walk)

The histogram showed by this panel are equals to the ones obtained if the histogram.ts function is not modified as shown above. Specifically first Grafana correctly render the four hard coded bucket, but then the graph is overwritten with the value coming from the default histogram.ts function.

Attached you can find some image showing this problem.

As you can see:

1) The variable histogram inside prepareXAxis function is correctly defined (equal to the hardcoded buckets); 2) Stepping over with the debug (F10), after running callPlot inside render_panel the histogram is correctly showed; 3) Stepping over again with the debug (F10), the graph is overwritten (at the point showed in the third image).

It seems that Grafana, at point 3, redraw the graph using the code (already compiled) of the default graph, instead of the code of this plugin.

I tried different ways to solve this problem, but i was not able to fix it; it always fall back to the default behaviors.

correct histogram first render correctly histogram overwritten

FrancescoC87 commented 6 years ago

I found a drastic way to stop the redraw: throwing an exception after callPlot inside render_panel.

Of course its not an elegant solution and i'm not sure if it can break something.; alternatives to solve this problem are welcome.

jonyrock commented 6 years ago

@Francesco-Cocchioni There are knows bug directive collides with default directive https://github.com/CorpGlory/grafana-graph-panel/blob/master/src/graph.ts#L711

We don't have time to fix it now and study your case better . Please contact us ping{at}corpglory.com if it is very urgent for you.

FrancescoC87 commented 6 years ago

After more testing i found that this plugin has bigger compatibility problem than the one reported above.

For example if in the same dashboard a user put the default Grafana Graph Panel and this plugin panel, the code of tthis plugin is never called, and all the panel use the default Grafana Graph code.

I think that the description of this plugin should report that its is currently highly incompatible.

jonyrock commented 6 years ago

@Francesco-Cocchioni Sorry to hear that you are experiencing problems. There is indeed a hack https://github.com/CorpGlory/grafana-graph-panel/commit/a3325ccae51af3b909d13fe4382e39c152998e3b which is removed now

It happend because of https://github.com/grafana/grafana/pull/11448

I fixed all names collisions, Please see new readme here: https://github.com/CorpGlory/grafana-graph-panel

Please close the task if you it`s solved

FrancescoC87 commented 6 years ago

@jonyrock Thank you very much. Your changes fixed all the problems, including the one initially reported.