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
tsullivan
merged 21 commits into
elastic:master
from
tsullivan:reporting/job-params-as-payload
Sep 23, 2019
Merged
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7791970
Rename route file for consistency
tsullivan 0640cab
Generate via jobParams allows post payload
tsullivan 8dd3241
jobParams as post body
tsullivan df344d0
[Reporting] Skip failing test
tsullivan 2cbfe96
Merge branch 'master' into reporting/job-params-as-payload
tsullivan 68db0d4
fix types
tsullivan fc7fbe5
Merge branch 'master' into reporting/job-params-as-payload
tsullivan 1b7b3d8
canvas pdf generation to use post payload
tsullivan 411178e
api test
tsullivan 7039ee2
tests
tsullivan a6d2df2
Merge branch 'master' into reporting/job-params-as-payload
tsullivan d3fba77
fix a typescript
tsullivan 317212b
fix fn test
tsullivan ce9433c
fix tests
tsullivan 451e80a
Merge branch 'master' into reporting/job-params-as-payload
tsullivan 9319e87
fix tests
tsullivan 1703ccb
run esArchiver fewer times
tsullivan 074982f
Merge branch 'master' into reporting/job-params-as-payload
tsullivan 547c59d
Merge branch 'master' into reporting/job-params-as-payload
tsullivan 5e6735b
return rison that came in invalid
tsullivan 0419325
Merge branch 'master' into reporting/job-params-as-payload
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
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. 🙇 |
||
import expect from '@kbn/expect'; | ||
import supertest from 'supertest'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default function({ getService }: { getService: any }) { | ||
const esArchiver = getService('esArchiver'); | ||
const supertestSvc = getService('supertest'); | ||
const generateAPI = { | ||
getCsvFromParamsInPayload: async (jobParams: object = {}) => { | ||
return await supertestSvc | ||
.post(`/api/reporting/generate/csv`) | ||
.set('kbn-xsrf', 'xxx') | ||
.send(jobParams); | ||
}, | ||
getCsvFromParamsInQueryString: async (jobParams: string = '') => { | ||
return await supertestSvc | ||
.post(`/api/reporting/generate/csv${jobParams}`) | ||
.set('kbn-xsrf', 'xxx') | ||
.send(jobParams); | ||
}, | ||
}; | ||
|
||
describe('Generation from Job Params', () => { | ||
it('Rejects bogus jobParams', async () => { | ||
// load test data that contains a saved search and documents | ||
await esArchiver.load('reporting/logs'); | ||
|
||
const { status: resStatus, text: resText } = (await generateAPI.getCsvFromParamsInPayload({ | ||
jobParams: 0, | ||
})) as supertest.Response; | ||
|
||
expect(resStatus).to.eql(400); | ||
expect(resText).to.match(/\\\"jobParams\\\" must be a string/); | ||
|
||
await esArchiver.unload('reporting/logs'); | ||
}); | ||
|
||
it('Rejects empty jobParams', async () => { | ||
// load test data that contains a saved search and documents | ||
await esArchiver.load('reporting/logs'); | ||
|
||
const { | ||
status: resStatus, | ||
text: resText, | ||
} = (await generateAPI.getCsvFromParamsInPayload()) as supertest.Response; | ||
|
||
expect(resStatus).to.eql(400); | ||
expect(resText).to.match(/jobParams RISON string is required/); | ||
|
||
await esArchiver.unload('reporting/logs'); | ||
}); | ||
|
||
it('Accepts jobParams in POST payload', async () => { | ||
// load test data that contains a saved search and documents | ||
await esArchiver.load('reporting/logs'); | ||
const { status: resStatus } = (await generateAPI.getCsvFromParamsInPayload({ | ||
jobParams: | ||
"(conflictedTypesFields:!(),fields:!('@date',_id,_index,_score,_type,country,metric,name),indexPatternId:b6a10720-ce76-11e9-aa85-47efb3fa905c,metaFields:!(_source,_id,_type,_index,_score),searchRequest:(body:(_source:(excludes:!()),docvalue_fields:!((field:'@date',format:date_time)),query:(bool:(filter:!((match_all:()),(range:('@date':(format:strict_date_optional_time,gte:'2004-01-01T07:00:00.000Z',lte:'2019-09-13T00:43:32.540Z')))),must:!(),must_not:!(),should:!())),script_fields:(),sort:!(('@date':(order:desc,unmapped_type:boolean))),stored_fields:!('*'),version:!t),index:tests),title:'New Saved Search 4',type:search)", | ||
})) as supertest.Response; | ||
expect(resStatus).to.eql(200); | ||
await esArchiver.unload('reporting/logs'); | ||
}); | ||
|
||
it('Accepts jobParams in query string', async () => { | ||
// load test data that contains a saved search and documents | ||
await esArchiver.load('reporting/logs'); | ||
const { status: resStatus } = (await generateAPI.getCsvFromParamsInQueryString( | ||
'?jobParams=(conflictedTypesFields:!(),fields:!(%27@date%27,_id,_index,_score,_type,country,metric,name),indexPatternId:b6a10720-ce76-11e9-aa85-47efb3fa905c,metaFields:!(_source,_id,_type,_index,_score),searchRequest:(body:(_source:(excludes:!()),docvalue_fields:!((field:%27@date%27,format:date_time)),query:(bool:(filter:!((match_all:()),(range:(%27@date%27:(format:strict_date_optional_time,gte:%272004-01-01T07:00:00.000Z%27,lte:%272019-09-13T00:43:32.540Z%27)))),must:!(),must_not:!(),should:!())),script_fields:(),sort:!((%27@date%27:(order:desc,unmapped_type:boolean))),stored_fields:!(%27*%27),version:!t),index:tests),title:%27New%20Saved%20Search%204%27,type:search)' | ||
)) as supertest.Response; | ||
expect(resStatus).to.eql(200); | ||
await esArchiver.unload('reporting/logs'); | ||
}); | ||
}); | ||
} |
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
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.
Nice I like this method better
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 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