-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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] add version to all export types job params #106137
Merged
tsullivan
merged 62 commits into
elastic:master
from
tsullivan:reporting/csv-searchsource-version-param
Aug 2, 2021
Merged
Changes from all commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
de232ba
add version to csv params
tsullivan 915fa9c
fix ts
tsullivan 1482d03
Merge branch 'master' into reporting/csv-searchsource-version-param
tsullivan 141a174
fix api tests
tsullivan dfa0e56
use kibana version from packageInfo
tsullivan f80097e
use kibana version from packageInfo
tsullivan 9b592f6
clean up ide warnings
tsullivan b37a238
Merge branch 'master' into reporting/csv-searchsource-version-param
tsullivan 02688b7
utility to log and set a default params version
tsullivan 793618c
fix baseparams ts
tsullivan 96d0dff
update snapshot
tsullivan 8ff2152
check version in enqueue job
tsullivan 27f1181
Merge branch 'master' into reporting/csv-searchsource-version-param
tsullivan 732c891
Merge branch 'master' into reporting/csv-searchsource-version-param
tsullivan 8d59bd4
add temporary ts-ignore for canvas
tsullivan a44cf64
clarify comment
tsullivan 9c522d4
Merge branch 'master' into reporting/csv-searchsource-version-param
tsullivan bc1a8ad
fix hardcoded version in png_pdf_panel
tsullivan 86ef317
clarify the UNVERSIONED_VERSION variable with a comment
tsullivan cd65714
fix canvas jest test
tsullivan ce87467
fix ts in example app
tsullivan e11a0a0
Merge branch 'master' into reporting/csv-searchsource-version-param
kibanamachine fe67dc6
fix types
tsullivan 9cde23f
Merge branch 'master' into reporting/csv-searchsource-version-param
kibanamachine 8f37970
Merge branch 'master' into reporting/csv-searchsource-version-param
tsullivan 839b01e
send version param to canvas util for job params
tsullivan 79c4507
update jest snapshot
tsullivan 061ef07
Update utils.test.ts
tsullivan 685eaec
Merge branch 'master' into reporting/csv-searchsource-version-param
tsullivan 1af338f
fix snapshot
tsullivan cfb7f12
remove browserTimezone and version from integration boilerplate
tsullivan dd529e8
wip ensure version is always populated in job params inside of the se…
tsullivan c8e140c
wip2
tsullivan a90a701
wip3
tsullivan b767a75
wip4
tsullivan 4024f9c
wip5
tsullivan ed3f8ae
wip6
tsullivan e8185d7
Merge branch 'master' into reporting/csv-searchsource-version-param
tsullivan 23409f4
update note
tsullivan 31349c1
update example plugin
tsullivan d9536b4
wip7
tsullivan 472ae85
improve tests
tsullivan 43bdd21
fix dynamic job params
tsullivan 64f54f5
better testing
tsullivan 7795958
improve enqueue_job test
tsullivan 56f0393
more tests
tsullivan c24c44e
fix types
tsullivan 3f4a582
fix types
tsullivan dcfda41
fix example ts
tsullivan 8ca7cfc
simplify props
tsullivan 0dca459
fix test
tsullivan f753f76
--wip-- [skip ci]
tsullivan 300ba45
consolidate baseparams back into one interface
tsullivan f4710b7
Merge branch 'master' into reporting/csv-searchsource-version-param
kibanamachine 0c85dab
Merge branch 'master' into reporting/csv-searchsource-version-param
tsullivan a6e34b0
fix rison encoding of apiClient param
tsullivan 87dc4ba
clean up
tsullivan d74cc9e
reorganize imports
tsullivan 1c96876
back out functional change
tsullivan 47329a1
Merge branch 'master' into reporting/csv-searchsource-version-param
tsullivan dd06b40
fix 400 error in download csv
tsullivan abdd0e6
Merge branch 'master' into reporting/csv-searchsource-version-param
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,34 +6,45 @@ | |
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import moment from 'moment'; | ||
import { stringify } from 'query-string'; | ||
import rison from 'rison-node'; | ||
import { HttpSetup } from 'src/core/public'; | ||
import rison, { RisonObject } from 'rison-node'; | ||
import { HttpSetup, IUiSettingsClient } from 'src/core/public'; | ||
import { | ||
API_BASE_GENERATE, | ||
API_BASE_URL, | ||
API_GENERATE_IMMEDIATE, | ||
API_LIST_URL, | ||
API_MIGRATE_ILM_POLICY_URL, | ||
REPORTING_MANAGEMENT_HOME, | ||
} from '../../../common/constants'; | ||
import { DownloadReportFn, JobId, ManagementLinkFn, ReportApiJSON } from '../../../common/types'; | ||
import { | ||
BaseParams, | ||
DownloadReportFn, | ||
JobId, | ||
ManagementLinkFn, | ||
ReportApiJSON, | ||
} from '../../../common/types'; | ||
import { add } from '../../notifier/job_completion_notifications'; | ||
import { Job } from '../job'; | ||
|
||
/* | ||
* For convenience, apps do not have to provide the browserTimezone and Kibana version. | ||
* Those fields are added in this client as part of the service. | ||
* TODO: export a type like this to other plugins: https://github.com/elastic/kibana/issues/107085 | ||
*/ | ||
type AppParams = Omit<BaseParams, 'browserTimezone' | 'version'>; | ||
|
||
export interface DiagnoseResponse { | ||
help: string[]; | ||
success: boolean; | ||
logs: string; | ||
} | ||
|
||
interface JobParams { | ||
[paramName: string]: any; | ||
} | ||
|
||
interface IReportingAPI { | ||
// Helpers | ||
getReportURL(jobId: string): string; | ||
getReportingJobPath(exportType: string, jobParams: JobParams): string; // Return a URL to queue a job, with the job params encoded in the query string of the URL. Used for copying POST URL | ||
getReportingJobPath<T>(exportType: string, jobParams: BaseParams & T): string; // Return a URL to queue a job, with the job params encoded in the query string of the URL. Used for copying POST URL | ||
createReportingJob(exportType: string, jobParams: any): Promise<Job>; // Sends a request to queue a job, with the job params in the POST body | ||
getServerBasePath(): string; // Provides the raw server basePath to allow it to be stripped out from relativeUrls in job params | ||
|
||
|
@@ -57,11 +68,11 @@ interface IReportingAPI { | |
} | ||
|
||
export class ReportingAPIClient implements IReportingAPI { | ||
private http: HttpSetup; | ||
|
||
constructor(http: HttpSetup) { | ||
this.http = http; | ||
} | ||
constructor( | ||
private http: HttpSetup, | ||
private uiSettings: IUiSettingsClient, | ||
private kibanaVersion: string | ||
) {} | ||
|
||
public getReportURL(jobId: string) { | ||
const apiBaseUrl = this.http.basePath.prepend(API_LIST_URL); | ||
|
@@ -132,13 +143,15 @@ export class ReportingAPIClient implements IReportingAPI { | |
return reports.map((report) => new Job(report)); | ||
} | ||
|
||
public getReportingJobPath(exportType: string, jobParams: JobParams) { | ||
const params = stringify({ jobParams: rison.encode(jobParams) }); | ||
public getReportingJobPath(exportType: string, jobParams: BaseParams) { | ||
const risonObject: RisonObject = jobParams as Record<string, any>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need this additional casting now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is pretty much moving the casting down from the local type which was removed: |
||
const params = stringify({ jobParams: rison.encode(risonObject) }); | ||
return `${this.http.basePath.prepend(API_BASE_GENERATE)}/${exportType}?${params}`; | ||
} | ||
|
||
public async createReportingJob(exportType: string, jobParams: any) { | ||
const jobParamsRison = rison.encode(jobParams); | ||
public async createReportingJob(exportType: string, jobParams: BaseParams) { | ||
const risonObject: RisonObject = jobParams as Record<string, any>; | ||
const jobParamsRison = rison.encode(risonObject); | ||
const resp: { job: ReportApiJSON } = await this.http.post( | ||
`${API_BASE_GENERATE}/${exportType}`, | ||
{ | ||
|
@@ -154,6 +167,27 @@ export class ReportingAPIClient implements IReportingAPI { | |
return new Job(resp.job); | ||
} | ||
|
||
public async createImmediateReport(baseParams: BaseParams) { | ||
const { objectType: _objectType, ...params } = baseParams; // objectType is not needed for immediate download api | ||
return this.http.post(`${API_GENERATE_IMMEDIATE}`, { body: JSON.stringify(params) }); | ||
} | ||
|
||
public getDecoratedJobParams<T extends AppParams>(baseParams: T): BaseParams { | ||
// If the TZ is set to the default "Browser", it will not be useful for | ||
// server-side export. We need to derive the timezone and pass it as a param | ||
// to the export API. | ||
const browserTimezone: string = | ||
this.uiSettings.get('dateFormat:tz') === 'Browser' | ||
? moment.tz.guess() | ||
: this.uiSettings.get('dateFormat:tz'); | ||
|
||
return { | ||
browserTimezone, | ||
version: this.kibanaVersion, | ||
...baseParams, | ||
}; | ||
} | ||
|
||
public getManagementLink: ManagementLinkFn = () => | ||
this.http.basePath.prepend(REPORTING_MANAGEMENT_HOME); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
worth opening an issue for this, adding a blocker label to it and a version in which the appBasePath will be removed
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.
#107254