Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Generating report directly from dashboard don't work #355

Open
iget-master opened this issue Apr 6, 2021 · 6 comments
Open

Generating report directly from dashboard don't work #355

iget-master opened this issue Apr 6, 2021 · 6 comments
Labels
question Further information is requested

Comments

@iget-master
Copy link

iget-master commented Apr 6, 2021

Steps to reproduce:

  1. Open a dashboard. Select any relative date like "last 7 days"
  2. Click on Reporting
  3. Click on Download PDF
  4. Nothing happens

Investigating the issue, found that an error is logged at browser console:

opendistroReportsKibana.plugin.js:1 Uncaught TypeError: Cannot read property 'diff' of undefined
at getTimeFieldsFromUrl (opendistroReportsKibana.plugin.js:1)
at HTMLButtonElement. (opendistroReportsKibana.plugin.js:1)
at HTMLDocument.dispatch (kbn-ui-shared-deps.js:404)
at HTMLDocument.m.handle (kbn-ui-shared-deps.js:404)

Note that if using an absolute date, it outputs the PDF but shows a lot of error alerts:

rison decoder error: missing ':'
Seems to happens because and bad formatted url: elastic/kibana#75957

@zhongnansu
Copy link
Member

Hi did you save the dashboard/visualization after you change the timerange or anything on the dashboard?

@zhongnansu zhongnansu added the question Further information is requested label Apr 7, 2021
@iget-master
Copy link
Author

No, I changed the timerange and pressed Download PDF. Using the timerange saved in the dashboard works (just open dashboard and press Download, works)

@zhongnansu
Copy link
Member

I realized this should work whether you saved the dashboard or not, becuase the url is changed after you changed the time filter. We took that url and covert to absolutte start and end time for reporting. This is a pretty basic case that we support for generating report. I just tested locally and it works fine. Could you test with the sample dataset as well and let us know? Meantime, we'll also look at the error you provided.

@iget-master
Copy link
Author

I think that with sample dataset it will work, something in my environment or data is causing this. I'm investigating the issue:

The error occurs on getTimeFieldsFromUrl() of context_menu_helper.ts: "cannot read diff of undefined". Going to that line:

  const timeDuration = moment.duration(
    dateMath.parse(toDateString).diff(dateMath.parse(fromDateString))
  );

In order to the return of parse() be null, the toDateString must be invalid. The variable is set at

const toDateFormat = dateMath.parse(toDateString);

Doing some tests on console (with the "broken" dashboard opened):

> const timeRangeMatcher = /time:\(from:(.+?),to:(.+?)\)/;
> const url = window.location.href;
> let [, fromDateString, toDateString] = url.match(timeRangeMatcher);
> console.log(toDateString)
Outputs: "now%2Fd"

Doing some tests, I've figured out that, when using the default time range for dashboard (here is always "last 15 minutes" ), and this range in DateMath is: from now-15m to now. Note that theres no slashes in this DateMath expression, but when doing any date maths including a slash (for example now/d), it will fail since the slash is URL encoded 😄

So the problem here is that we need to decode the URL before parsing the date. I'll send a PR with the fix for this issue.

@iget-master
Copy link
Author

Also noticed that using an absolute time range is not working properly.

Try setting from:'2021-04-08T03:00:00.000Z',to:'2021-04-09T02:30:00.000Z' in the url. The output report doesn't match with the shown on dashboard. But it seems not to be related with the getTimeFieldsFromUrl() function, since it outputs the correct value in this situation:

// url = "http://localhost:5601/app/dashboards#/view/a1ba51f0-9255-11eb-a80c-b9eee5294774?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:'2021-04-08T03:00:00.000Z',to:'2021-04-09T02:30:00.000Z'))&_a=(description:'',filters:!(),fullScreenMode:!f,options:(hidePanelTitles:!f,useMargins:!t),query:(language:kuery,query:''),timeRestore:!f,title:'Sample%20Dashboard',viewMode:view)";
const { time_from, time_to, time_duration } = getTimeFieldsFromUrl()
console.log(time_from, time_to, time_duration);
Moment<2021-04-07T20:00:00-07:00> Moment<2021-04-08T19:30:00-07:00> 'PT23H30M'

@iget-master
Copy link
Author

Doing the same test above with now/d to now/d will result in a weird result:

// Note that I'm using a fixed version of `getTimeFieldsFromUrl` that accepts encoded url components and fix another issue with end timestamp not being round up, I'll explain later
// const url = "http://localhost:5601/app/dashboards#/view/a1ba51f0-9255-11eb-a80c-b9eee5294774?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now%2Fd,to:now%2Fd))&_a=(description:'',filters:!(),fullScreenMode:!f,options:(hidePanelTitles:!f,useMargins:!t),query:(language:kuery,query:''),timeRestore:!f,title:'Sample%20Dashboard',viewMode:view)";
const { time_from, time_to, time_duration } = getTimeFieldsFromUrl()
console.log(time_from, time_to, time_duration);
Moment<2021-01-01T00:00:00-08:00> Moment<2021-01-01T23:59:59-08:00> 'P0D'

Note the P0D exposing the fragility of using ISO Duration to represent this range: It doesn't support miliseconds, and momentjs implementation weirdly round down the period to zero days instead of 23H59M59S.

I'm doing a series of tests with this plugin, and as you can see in latest issues, I'm founding a lot of issues related with the decision to use ISO Duration instead of sticking with kibanas/elasticsearch deafult Date Math

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants