-
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] Fix ability to export CSV on searched data with frozen indices #109976
Merged
tsullivan
merged 6 commits into
elastic:master
from
tsullivan:reporting/fix-csvsearchsource-frozen-idxes
Aug 25, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c8d3e24
use include frozen setting in csv export
tsullivan a7cfc82
add api integration test
tsullivan e55ba57
add fixes
tsullivan 61d4f61
Update x-pack/test/reporting_api_integration/reporting_and_security/s…
tsullivan bb2585b
test polish
tsullivan 9a89f14
update per feedback
tsullivan 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
127 changes: 127 additions & 0 deletions
127
x-pack/test/reporting_api_integration/reporting_and_security/search_frozen_indices.ts
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,127 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { FtrProviderContext } from '../ftr_provider_context'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default function ({ getService }: FtrProviderContext) { | ||
const kibanaServer = getService('kibanaServer'); | ||
const supertestSvc = getService('supertest'); | ||
const esSupertest = getService('esSupertest'); | ||
const indexPatternId = 'cool-test-index-pattern'; | ||
|
||
async function callExportAPI() { | ||
const job = { | ||
browserTimezone: 'UTC', | ||
columns: ['@timestamp', 'ip', 'utilization'], | ||
searchSource: { | ||
fields: [{ field: '*', include_unmapped: 'true' }], | ||
filter: [ | ||
{ | ||
meta: { field: '@timestamp', index: indexPatternId, params: {} }, | ||
range: { | ||
'@timestamp': { | ||
format: 'strict_date_optional_time', | ||
gte: '2020-08-24T00:00:00.000Z', | ||
lte: '2022-08-24T21:40:48.346Z', | ||
}, | ||
}, | ||
}, | ||
], | ||
index: indexPatternId, | ||
parent: { filter: [], index: indexPatternId, query: { language: 'kuery', query: '' } }, | ||
sort: [{ '@timestamp': 'desc' }], | ||
trackTotalHits: true, | ||
}, | ||
title: 'Test search', | ||
}; | ||
|
||
return await supertestSvc | ||
.post(`/api/reporting/v1/generate/immediate/csv_searchsource`) | ||
.set('kbn-xsrf', 'xxx') | ||
.send(job); | ||
} | ||
|
||
describe('Frozen indices search', () => { | ||
const reset = async () => { | ||
await kibanaServer.uiSettings.replace({ 'search:includeFrozen': false }); | ||
try { | ||
await esSupertest.delete('/test1,test2,test3'); | ||
await kibanaServer.savedObjects.delete({ type: 'index-pattern', id: indexPatternId }); | ||
} catch (err) { | ||
// ignore 404 error | ||
} | ||
}; | ||
|
||
before(reset); | ||
after(reset); | ||
|
||
it('Search includes frozen indices based on Advanced Setting', async () => { | ||
await kibanaServer.uiSettings.update({ 'csv:quoteValues': true }); | ||
|
||
// setup: add multiple indices of test data | ||
await Promise.all([ | ||
esSupertest | ||
.post('/test1/_doc') | ||
.send({ '@timestamp': '2021-08-24T21:36:40Z', ip: '43.98.8.183', utilization: 18725 }), | ||
esSupertest | ||
.post('/test2/_doc') | ||
.send({ '@timestamp': '2021-08-21T09:36:40Z', ip: '63.91.103.79', utilization: 8480 }), | ||
esSupertest | ||
.post('/test3/_doc') | ||
.send({ '@timestamp': '2021-08-17T21:36:40Z', ip: '139.108.162.171', utilization: 3078 }), | ||
]); | ||
await esSupertest.post('/test*/_refresh'); | ||
|
||
// setup: create index pattern | ||
const indexPatternCreateResponse = await kibanaServer.savedObjects.create({ | ||
type: 'index-pattern', | ||
id: indexPatternId, | ||
overwrite: true, | ||
attributes: { title: 'test*', timeFieldName: '@timestamp' }, | ||
}); | ||
expect(indexPatternCreateResponse.id).to.be(indexPatternId); | ||
|
||
// 1. check the initial data with a CSV export | ||
const initialSearch = await callExportAPI(); | ||
expectSnapshot(initialSearch.text).toMatchInline(` | ||
"\\"@timestamp\\",ip,utilization | ||
\\"Aug 24, 2021 @ 21:36:40.000\\",\\"43.98.8.183\\",\\"18,725\\" | ||
\\"Aug 21, 2021 @ 09:36:40.000\\",\\"63.91.103.79\\",\\"8,480\\" | ||
\\"Aug 17, 2021 @ 21:36:40.000\\",\\"139.108.162.171\\",\\"3,078\\" | ||
" | ||
`); | ||
|
||
// 2. freeze an index in the pattern | ||
await esSupertest.post('/test3/_freeze').expect(200); | ||
await esSupertest.post('/test*/_refresh').expect(200); | ||
|
||
// 3. recheck the search results | ||
const afterFreezeSearch = await callExportAPI(); | ||
expectSnapshot(afterFreezeSearch.text).toMatchInline(` | ||
"\\"@timestamp\\",ip,utilization | ||
\\"Aug 24, 2021 @ 21:36:40.000\\",\\"43.98.8.183\\",\\"18,725\\" | ||
\\"Aug 21, 2021 @ 09:36:40.000\\",\\"63.91.103.79\\",\\"8,480\\" | ||
" | ||
`); | ||
|
||
// 4. update setting to allow searching frozen data | ||
await kibanaServer.uiSettings.update({ 'search:includeFrozen': true }); | ||
|
||
// 5. recheck the search results | ||
const afterAllowSearch = await callExportAPI(); | ||
expectSnapshot(afterAllowSearch.text).toMatchInline(` | ||
"\\"@timestamp\\",ip,utilization | ||
\\"Aug 24, 2021 @ 21:36:40.000\\",\\"43.98.8.183\\",\\"18,725\\" | ||
\\"Aug 21, 2021 @ 09:36:40.000\\",\\"63.91.103.79\\",\\"8,480\\" | ||
\\"Aug 17, 2021 @ 21:36:40.000\\",\\"139.108.162.171\\",\\"3,078\\" | ||
" | ||
`); | ||
}); | ||
}); | ||
} |
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.
cc @lukasolson shouldn't this setting be respected inside
search
service ? (and as such we should not need to set it 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.
Filed: #110679
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.
Looks like this setting is only respected with the
ESE_SEARCH_STRATEGY
. Unfortunately, CSV export can not use that search strategy because it doesn't supportscroll
queries: #110679 (comment)