[Reporting] Rewrite addForceNowQuerystring to getFullUrls#44851
Conversation
|
Pinging @elastic/kibana-stack-services |
There was a problem hiding this comment.
See also: the create_job compatibility shim, which is now the only place that parses saved objects by ID into Kibana URLs
There was a problem hiding this comment.
Correction: this wasn't actually parsing saved objects by ID, but it was handling a structure of data that isn't relevant to the create_job outputs for PDF and PNG. (worth double checking that)
All references to saved objects in the PDF export type should only be in the compatibility shim of create_job. This is because after job creation, only URL paths are dealt with. Multi-page PDF (canvas worksheet) would not be possible otherwise.
💔 Build Failed |
3c81e8b to
73e7992
Compare
💔 Build Failed |
73e7992 to
08bee7f
Compare
There was a problem hiding this comment.
A lot of the tests had mock data like this: job params that don't line up to existing features. The csv export type doesn't use savedObjectId and savedObjectType as jobParams. See JobParamsDiscoverCsv is the actual definition. Invalid mocks were part of the reason Typescripting is taking awhile.
There was a problem hiding this comment.
Apologies on that -- I believe I wrote these a while ago. You're dead-on about TS taking so long: I believe I originally wrote these mocks with little TS input, so they were likely incorrect. In any case, sorry!
There was a problem hiding this comment.
Ha, it's not problem. Mostly I write these things down because I learn as I go
There was a problem hiding this comment.
putting a custom logo on a CSV export would make no sense
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
This is from basePath being removed from JobDocPayload which all the different JobDocPayload types extend from.
There was a problem hiding this comment.
Removing all these makes me so happy :) The urls one was just because of unnecessary mutation in addNowForceQueryString.
There was a problem hiding this comment.
New test! Multi-page PDF URLs!
08bee7f to
acd5d04
Compare
There was a problem hiding this comment.
The main JobParams type should go away. Nothing (correctly) uses it or extends it as the export types have each gotten their own definitions.
💔 Build Failed |
| } | ||
|
|
||
| throw new Error(i18n.translate('xpack.reporting.exportTypes.printablePdf.compShim.unableToGenerateReportErrorMessage', { | ||
| defaultMessage: `Unable to generate report for url {savedObjUrl}, it's not a Kibana URL`, |
There was a problem hiding this comment.
Absolute URLs are derived in execute_job, so I'm not sure how this error would happen now. There's no new analogy for this error in the changes in this PR.
💚 Build Succeeded |
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import url from 'url'; |
There was a problem hiding this comment.
Removing execute_job/compatibility_shim means that Reporting won't be able to convert job params created from older version. That functionality is enabled by create_job and still works after this PR. After this PR though, this scenario won't work: (Call it Scenario A)
- Use Kibana 5.x to queue a report
- Before the report is executed, upgrade the Elastic Stack to 7.5.0
- Kibana 7.5.0 tries to execute the job that was created with 6.8, and it won't work. As of this PR, execute_job doesn't convert the legacy params of Saved Object Type and ID into a Kibana path.
The following scenario is why we have create_job/compatibility_shim, and it will still work: (Call it Scenario B)
- Use Kibana 5.x to generate a POST URL
- Trigger the POST URL with external automation
- Upgrade the Elastic Stack to 7.5.0
- New jobs come in with 6.x job params
create_job/compatibility_shimconverts the legacy params into a format thatexecute_job/indexis able to handle
There was a problem hiding this comment.
cc @kobelb I think you've pointed out this kind of thing before
There was a problem hiding this comment.
Reading my earlier comment, I don't know if Scenario A from above was expected to work in the previous code.
There was a problem hiding this comment.
I think there are actually some good solutions for upgrade complications:
A migration to update the pending job documents so they'll be ready for the next major- NOPE: We need to migrate Reporting to use Saved Objects before we can make migrations for the jobs.
- Add documentation in the upgrade guide to explain: make sure you do not have pending reports when you start the upgrade
💚 Build Succeeded |
| const parsed: UrlWithParsedQuery = urlParse(jobUrl, true); | ||
| if (parsed.hash == null) { | ||
| throw new Error( | ||
| 'No valid hash in the URL! A hash is expected for the application to route to the intended visualization.' |
There was a problem hiding this comment.
I think the purpose of this code is finally making sense :)
Compare these additions to the removal of export_types/common/execute_job/add_force_now_query_string.ts
|
Removed WIP, ready for review (again) |
| } | ||
|
|
||
| const parsed: any = url.parse(jobUrl, true); | ||
| const hash: any = url.parse(parsed.hash.replace(/^#/, ''), true); |
There was a problem hiding this comment.
It was easy to get a meaningless error from here if the parsed URL has was null. I'm not sure if that has ever happened though
| import { LayoutInstance } from '../common/layouts/layout'; | ||
| import { ConditionalHeaders, KbnServer, JobDocPayload } from '../../types'; | ||
|
|
||
| // NOTE: this does not extend the main Params |
There was a problem hiding this comment.
The comment was removed because it is moot - none of the type extend from the main params, so there probably shouldn't even be a main params. Separate issue.
| @@ -17,6 +17,18 @@ export interface JobParamsPDF { | |||
| layout: LayoutInstance; | |||
There was a problem hiding this comment.
JobParamsPDF should not have relativeUrl: string, it should have relativeUrls: string[]. Knowing that helps relativeUrl: undefined in JobDocPayloadPDF make more sense. That is a separate issue, created from a mistake in #44130
💚 Build Succeeded |
| map(omitBlacklistedHeaders), | ||
| map(getConditionalHeaders), | ||
| mergeMap(addForceNowQuerystring), | ||
| mergeMap(getFullUrls), |
There was a problem hiding this comment.
It was still surprisingly hard to come up with ;)
joelgriffith
left a comment
There was a problem hiding this comment.
Sorry for the red herring tests there. IIRC I quickly put those in to get CI builds green again :/ Goes to show how much good types help
💚 Build Succeeded |
) * this is the one * this could break a job nbd * get_full_url to observe PNG and PDF job payload types * fix typescripts * fix ts in tests * fix more types * cosmetic * remove PDF execute compatibility shim test -- that stuff is handled in now PDF executeJob * fix unit test * remove old strings * Remove pdf execute compatibility shim entirely * combine the 2 maps * More reject matchers in the test
…-to-np-ready * 'master' of github.com:elastic/kibana: (138 commits) [Canvas] i18n work on workpad header (and a few header CTAs) and convert to typescript (elastic#44943) update close/delete system index modals (elastic#45037) TS return type of createIndexPatternSelect (elastic#45107) [ML] Fix focus chart updating. (elastic#45146) [ML] Data frame transform: Fix progress in wizard create step. (elastic#45116) [Graph] Re-enable functional test (elastic#44683) [SIEM] unique table id for each top talkers table (elastic#45014) [SIEM] ip details heading draggable (elastic#45179) [Maps][File upload] Set complete on index pattern creation (elastic#44423) [Maps] unmount map embeddable component on destroy (elastic#45183) [SIEM] Adds error toasts to MapEmbeddable component (elastic#45088) fix redirect to maintain search query string (elastic#45184) [APM] One-line trace summary (elastic#44842) [Infra UI] Display non-metric details on Node Detail page (elastic#43551) [Maps][File upload] Removing bbox from parsed file pending upstream lib fix (elastic#45194) [Logs UI] Improve live streaming behavior when scrolling (elastic#44923) [APM] Fix indefinite loading state in agent settings for unauthorized user roles (elastic#44970) [Reporting] Rewrite addForceNowQuerystring to getFullUrls (elastic#44851) [Reporting/ESQueue] Improve logging of doc-update events (elastic#45077) [Reporting] Make screenshot capture less noisy by default (elastic#45185) ...
…45205) * this is the one * this could break a job nbd * get_full_url to observe PNG and PDF job payload types * fix typescripts * fix ts in tests * fix more types * cosmetic * remove PDF execute compatibility shim test -- that stuff is handled in now PDF executeJob * fix unit test * remove old strings * Remove pdf execute compatibility shim entirely * combine the 2 maps * More reject matchers in the test
Summary
This adds some semantics to the execute steps of PNG and PDF jobs (export types).
Both the types create jobs with relative URLs stored in the job documents, and convert the URLs to absolute when executing the job.
The PDF export type was nearly converting its URLs to absolute in two different places of the execute step: in the compatibility shim, and in
addForceNowQueryString.The important behavior being done in
addForceNowQueryStringwas being obscured by its name. It adds aforceNowparam to the URL when applicable, but the main thing it does is convert relative URLs to absolute.The compatibility shim of
execute_job(PDF only) is mostly eliminated now. It was handling object fields that aren't relevant to 7.x job doc payloads: all theexecute_jobfunctions only need to consume their type of data returned bycreate_job.This PR does not change the interface between data returned from
create_joband sent toexecute_job.This PR also adds some extra specificity to the
JobDocPayloadtype, which is becoming just a base type for any type of payload from any of the export types, which each have their differences. This helpedgetFullUrlsget a better understanding of what should be coming in and going out. That meant removing several fields from the main JobDocPayload and re-inserting them only on the extensions that need it. That had a lot of impact in this code change, mostly code removal (CSV types do not need basePath, for example).Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.[ ] This was checked for cross-browser compatibility, including a check against IE11[ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support[ ] Documentation was added for features that require explanation or tutorials[ ] This was checked for keyboard-only and screenreader accessibility