Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reporting] Fix Generating Reports with long jobParams RISON #45603

Merged
merged 21 commits into from Sep 23, 2019

Conversation

tsullivan
Copy link
Member

@tsullivan tsullivan commented Sep 13, 2019

Summary

Closes #20037

This solves the problem with URLs having long query string being too long to use as a Reportingt POST URL. This uses the same jobParams data as before, but includes it as POST payload data rather than the query string. This fixes the issues because there are fewer limits in network environments around long strings in POST payload versus long strings as a URL query string.

This fix changes a central area of code that all the export types use. In other words, it fixes the bug for:

  • CSV generation from Discover
  • PNG/PDF generation from Dashboard
  • PNG/PDF generation from Visualize (although there were no known problems before)

The generation API now works either way, but the UI's new behavior is the more optimal flow of including jobParams as a field of POST payload data.

Release note: Fixed a bug with Reporting where it would fail to create a job with a large state in the parameters.

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-stack-services

@elasticmachine
Copy link
Contributor

💔 Build Failed

@tsullivan tsullivan requested a review from a team as a code owner September 13, 2019 19:09
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question is whether we want to update the docs. Getting the post url places job params in the query string. Do we need a section here, or in troubleshooting, explaining how jobParams can be put in the body if the URL is too long?

lgtm with green CI
code review, tested in chrome

@tsullivan tsullivan changed the title Reporting/job params as payload [Reporting] Fix Generating Reports with long jobParams RISON Sep 17, 2019
@tsullivan
Copy link
Member Author

One question is whether we want to update the docs

Thanks Nathan! Yes updating the docs is an open and legitimate checkbox for this PR.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@tsullivan
Copy link
Member Author

tsullivan commented Sep 19, 2019

I think it would be fine to write the documentation in a followup PR, that way I can focus on running the docs server against the changes to make sure formatting looks good.

In case it's someone other than me that has to write the documentation, this is my draft:

https://www.elastic.co/guide/en/kibana/current/automating-report-generation.html#_using_watcher

Using Watcher

<Add a note that if the URL query string gets too long, they may not be able to use Watcher. See "Using a Script" below>

https://www.elastic.co/guide/en/kibana/current/automating-report-generation.html#_using_a_script

Using a Script

To automatically generate reports from a script, youÕll make a request to the POST URL and include a POST payload body containing the job parameters for the report.

The request method must be POST and it must include a kbn-version header for Kibana to allow the request.

The following example queues CSV report generation using the POST URL with cURL:

http://0.0.0.0:5601
kbn-version: 8.0.0
POST /api/reporting/generate/csv
{
  "jobParams": "<string of rison>"
}

TODO: how to get the rison

@elasticmachine
Copy link
Contributor

💔 Build Failed

@tsullivan
Copy link
Member Author

As a future enhancement, we can add "Copy as cUrl" to the Share > PDF menu.

image

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@@ -25,13 +26,45 @@ export function registerGenerate(
server.route({
path: `${BASE_GENERATE}/{exportType}`,
method: 'POST',
config: getRouteConfig(request => request.params.exportType),
config: {
...getRouteConfig(request => request.params.exportType),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice I like this method better

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an unrelated small fix I can make to validate the exportType param is registered in the exportTypesRegistry as an ID of one of the types

@@ -158,3 +158,27 @@ export const CSV_RESULT_NANOS = `date,message,"_id"
"2015-01-01T12:10:30.123456789Z","Hello 2",
"2015-01-01T12:10:30","Hello 1",
`;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could use something like the backtick operator with dedent? I've seen that lib used for our dockerfiles and elsewhere. Just a bit more pleasant to work on.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export const JOB_PARAMS_IN_QUERYSTRING =
  dedent`(conflictedTypesFields:!(),fields:!(%27@timestamp%27,clientip,extens
  ion),indexPatternId:%27logstash-*%27,metaFields:!(_source,_id,_type,_index,_scor
  e),searchRequest:(body:(_source:(excludes:!(),includes:!(%27@timestamp%27,client
  ip,extension)),docvalue_fields:!(),query:(bool:(filter:!((match_all:()),(range:(
  %27@timestamp%27:(gte:%272015-09-20T10:19:40.307Z%27,lt:%272015-09-20T10:26:56.2
  21Z%27))),(range:(%27@timestamp%27:(format:strict_date_optional_time,gte:%272004
  -09-17T21:19:34.213Z%27,lte:%272019-09-17T21:19:34.213Z%27)))),must:!(),must_not
  :!(),should:!())),script_fields:(),sort:!((%27@timestamp%27:(order:desc,unmapped
  _type:boolean))),stored_fields:!(%27@timestamp%27,clientip,extension),version:!t
  ),index:%27logstash-*%27),title:%27A%20Saved%20Search%20With%20a%20DATE%20FILTER
  %27,type:search)`;

Copy link
Member Author

@tsullivan tsullivan Sep 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! It turns out dedent still retains the line breaks, so I added in a short little function to act as the template for the string.

I also realized there does not need to be 2 consts here, because the query string one is just the same rison, just URI-encoded.

* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙇

Copy link
Contributor

@joelgriffith joelgriffith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Small comment about using dedent vs string-concatenation for those larger rison URLs

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@tsullivan
Copy link
Member Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@cqliu1 cqliu1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Canvas changes look good 👍

@tsullivan tsullivan merged commit 5fbcfe6 into elastic:master Sep 23, 2019
@tsullivan tsullivan deleted the reporting/job-params-as-payload branch September 23, 2019 23:18
tsullivan added a commit to tsullivan/kibana that referenced this pull request Sep 23, 2019
…ic#45603)

* Rename route file for consistency

* Generate via jobParams allows post payload

* jobParams as post body

* [Reporting] Skip failing test

* fix types

* canvas pdf generation to use post payload

* api test

* tests

* fix a typescript

* fix fn test

* fix tests

* fix tests

* run esArchiver fewer times

* return rison that came in invalid
tsullivan added a commit that referenced this pull request Sep 25, 2019
… (#46404)

* Rename route file for consistency

* Generate via jobParams allows post payload

* jobParams as post body

* [Reporting] Skip failing test

* fix types

* canvas pdf generation to use post payload

* api test

* tests

* fix a typescript

* fix fn test

* fix tests

* fix tests

* run esArchiver fewer times

* return rison that came in invalid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reports cannot be generated using ultra long urls
5 participants