datasweet / kibana-datasweet-formula

This Kibana plugin allows calculated metrics on any standard kibana visualizations.
Apache License 2.0
121 stars 34 forks source link

Error in visualization #43

Closed MrKuip closed 5 years ago

MrKuip commented 5 years ago

I get a popup when I run a vizualisation that has a datasweet formula. The message is:

Error in visualisation Cannot read property '0' or undefined.

The vizualization is a horizontal barchart with a datasweet formula: "100" (So just a number). It happens with the following 2 circumstances (both must be true):

  1. I select a time range that has 0 (zero) documents.
  2. I have a terms-bucket

I do NOT get an error when (either of the 2)

  1. I select a time range with more than 0 (zero) documents.
  2. I do not have a terms-bucket (or if I change the terms-bucket into an range-bucket)

I'm using elasticsearch/ kibana 6.6.2

lfroment-datasweet commented 5 years ago

Hi, Datasweet Formula is intended only to compute some stuff from another metric or bucket set in your viz. You are trying to make it work without any reference to another metric/bucket, am I right?

MrKuip commented 5 years ago

No, i have 2 metrics defined. I changed the formula from '(agg1 / agg3) * 1000' to '1000' because I wanted to see if the formula was the problem. Did you try it the way I described? Should I post the export of my visualization? It happens with a term bucket and a timerange that results in 0 documents

lfroment-datasweet commented 5 years ago

OK, I reproduced. Indeed in a "no document found" situation, Kibana throws "no result found" if a bucket split is active, and a "0" if no bucket split is active (or Range bucket split). Same problem with or without Datasweet-Formula implied. So in the first case, Formula cannot calculate anything based on a "nil", thus, you got an error. In the second case, Formula does its job : 0/1000=0.

MrKuip commented 5 years ago

Are you saying that the problem is in Kibana and not in datasweet?

I still think it is in datasweet. I only get the error if I add an aggregation of type 'Datasweet Formula'. Any other agregation does not produce this error

I think the execution of the formula throws the error.

lfroment-datasweet commented 5 years ago

The error is generated by the plugin, because Kibana output is a "no result found". When Kibana output is a zero, the plugin does its job.

MrKuip commented 5 years ago

I never ever programmed in javascript but I think I solved the problem.

In file './decorators/lib/apply_formula.js' I changed a line in function 'mutate'. This is the original line: const isRowValue = isObject(table.rows[0][0]); I changed it in: const isRowValue = isObject(table.rows[0]) && isObject(table.rows[0][0]);

The now get a nice 'no results found' message in my visualization.

lfroment-datasweet commented 5 years ago

@tcharlot-datasweet