-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Rewrite addForceNowQuerystring to getFullUrls #44851
[Reporting] Rewrite addForceNowQuerystring to getFullUrls #44851
Conversation
Pinging @elastic/kibana-stack-services |
export function compatibilityShimFactory(server) { | ||
const getAbsoluteUrl = getAbsoluteUrlFactory(server); | ||
|
||
const getSavedObjectAbsoluteUrl = (job, savedObject) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
savedObjectId: 'abc-123', | ||
isImmediate: false, | ||
savedObjectType: 'search', | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, it's not problem. Mostly I write these things down because I learn as I go
savedObjectType: 'search', | ||
}, | ||
basePath: jobBasePath, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
putting a custom logo on a CSV export would make no sense
}); | ||
|
||
// why 2 maps | ||
const urls = absoluteUrls.map((jobUrl: string) => { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
@@ -94,7 +94,6 @@ function createJobFn(server: KbnServer): CreateJobFn { | |||
}); | |||
|
|||
return { | |||
basePath: req.getBasePath(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is from basePath being removed from JobDocPayload
which all the different JobDocPayload types extend from.
title: string; | ||
type: string | null; | ||
urls?: string[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing all these makes me so happy :) The urls
one was just because of unnecessary mutation in addNowForceQueryString
.
server: mockServer, | ||
}); | ||
|
||
expect(urls[0]).toEqual('http://localhost:5601/sbp/app/kibana#/something'); | ||
}); | ||
|
||
test(`adds forceNow to each of multiple urls`, async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New test! Multi-page PDF URLs!
08bee7f
to
acd5d04
Compare
|
||
// NOTE: this does not extend the main Params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_shim
converts the legacy params into a format thatexecute_job/index
is able to handle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @kobelb I think you've pointed out this kind of thing before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -8,7 +8,7 @@ import { Request } from 'hapi'; | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
@@ -40,7 +40,7 @@ function executeJobFn(server) { | |||
}), | |||
map(omitBlacklistedHeaders), | |||
map(getConditionalHeaders), | |||
mergeMap(addForceNowQuerystring), | |||
mergeMap(getFullUrls), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice rename here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was still surprisingly hard to come up with ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
addForceNowQueryString
was being obscured by its name. It adds aforceNow
param 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_job
functions only need to consume their type of data returned bycreate_job
.This PR does not change the interface between data returned from
create_job
and sent toexecute_job
.This PR also adds some extra specificity to the
JobDocPayload
type, which is becoming just a base type for any type of payload from any of the export types, which each have their differences. This helpedgetFullUrls
get 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