-
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
script field support, fix field formatters #33910
Changes from 6 commits
6b1e2e0
e6d7266
63dad94
4145f0d
9598544
2ea3013
1fff2a5
ebf2b38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,15 @@ interface CsvResultFromSearch { | |
} | ||
|
||
type EndpointCaller = (method: string, params: any) => Promise<any>; | ||
type FormatsMap = Map<string, any>; | ||
type FormatsMap = Map< | ||
string, | ||
{ | ||
id: string; | ||
params: { | ||
pattern: string; | ||
}; | ||
} | ||
>; | ||
|
||
interface GenerateCsvParams { | ||
searchRequest: SearchRequest; | ||
|
@@ -103,6 +111,13 @@ const getTimebasedParts = ( | |
return { combinedFilter, includes, timezone }; | ||
}; | ||
|
||
interface IndexPatternField { | ||
scripted: boolean; | ||
lang?: string; | ||
script?: string; | ||
name: string; | ||
} | ||
|
||
export async function generateCsvSearch( | ||
req: Request, | ||
server: KbnServer, | ||
|
@@ -132,6 +147,19 @@ export async function generateCsvSearch( | |
const esQueryConfig = await getEsQueryConfig(uiConfig); | ||
const [sortField, sortOrder] = savedSearchObjectAttr.sort; | ||
|
||
const scriptFields = indexPatternSavedObject.fields | ||
.filter((f: IndexPatternField) => f.scripted === true) | ||
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.
|
||
.reduce((accum: any, curr: IndexPatternField) => { | ||
return { | ||
...accum, | ||
[curr.name]: { | ||
script: { | ||
source: curr.script, | ||
lang: curr.lang, | ||
}, | ||
}, | ||
}; | ||
}, {}); | ||
const searchRequest: SearchRequest = { | ||
index: indexPatternSavedObject.title, | ||
body: { | ||
|
@@ -143,7 +171,7 @@ export async function generateCsvSearch( | |
combinedFilter, | ||
esQueryConfig | ||
), | ||
script_fields: {}, | ||
script_fields: scriptFields, | ||
sort: [{ [sortField]: { order: sortOrder } }], | ||
}, | ||
}; | ||
|
@@ -152,9 +180,9 @@ export async function generateCsvSearch( | |
const callCluster = (...params: any[]) => callWithRequest(req, ...params); | ||
const config = server.config(); | ||
const [formatsMap, uiSettings] = await Promise.all([ | ||
fieldFormatServiceFactory(uiConfig).then((fieldFormats: any) => | ||
fieldFormatMapFactory(indexPatternSavedObject, fieldFormats) | ||
), | ||
fieldFormatServiceFactory(uiConfig).then((fieldFormats: any) => { | ||
return fieldFormatMapFactory(indexPatternSavedObject, fieldFormats); | ||
}), | ||
getUiSettings(uiConfig), | ||
]); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,19 +42,16 @@ export async function getDataSource( | |
} | ||
} | ||
try { | ||
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. Nice cleanup here. |
||
const { attributes: indexPatternAttributes } = await savedObjectsClient.get( | ||
'index-pattern', | ||
indexPatternId | ||
); | ||
let fields = '[]'; | ||
let fieldFormatMap = '{}'; | ||
if (indexPatternAttributes.fields) { | ||
fields = JSON.parse(indexPatternAttributes.fields); | ||
} | ||
if (indexPatternAttributes.fieldFormatMap) { | ||
fieldFormatMap = JSON.parse(indexPatternAttributes.fieldFormatMap); | ||
} | ||
indexPatternSavedObject = { ...indexPatternAttributes, fields, fieldFormatMap }; | ||
const { attributes } = await savedObjectsClient.get('index-pattern', indexPatternId); | ||
const { fields, title, timeFieldName } = attributes; | ||
const parsedFields = fields ? JSON.parse(fields) : []; | ||
|
||
indexPatternSavedObject = { | ||
fields: parsedFields, | ||
title, | ||
timeFieldName, | ||
attributes, | ||
}; | ||
} catch (err) { | ||
throw new Error(`Could not get index pattern saved object! ${err}`); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,12 +76,18 @@ export interface SavedObject { | |
references: SavedObjectReference[]; | ||
} | ||
|
||
/* This object is passed to different helpers in different parts of the code | ||
- packages/kbn-es-query/src/es_query/build_es_query | ||
- x-pack/plugins/reporting/export_types/csv/server/lib/field_format_map | ||
The structure has redundant parts and json-parsed / json-unparsed versions of the same data | ||
*/ | ||
export interface IndexPatternSavedObject { | ||
title: string; | ||
timeFieldName: string; | ||
fields: any[]; | ||
fieldFormatMap: { | ||
[key: string]: { id: string; params: { pattern: string } }; | ||
attributes: { | ||
fieldFormatMap: string; | ||
fields: string; | ||
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. There was some structure tweaks to this type made, after realizing that |
||
}; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,7 @@ import { | |
InfraOpsGraphQLProvider | ||
} from './services'; | ||
|
||
export default async function ({ readConfigFile }) { | ||
|
||
export async function getApiIntegrationConfig({ readConfigFile }) { | ||
const kibanaAPITestsConfig = await readConfigFile(require.resolve('../../../test/api_integration/config.js')); | ||
const xPackFunctionalTestsConfig = await readConfigFile(require.resolve('../functional/config.js')); | ||
const kibanaCommonConfig = await readConfigFile(require.resolve('../../../test/common/config.js')); | ||
|
@@ -47,3 +46,5 @@ export default async function ({ readConfigFile }) { | |
esTestCluster: xPackFunctionalTestsConfig.get('esTestCluster'), | ||
}; | ||
} | ||
|
||
export default getApiIntegrationConfig; | ||
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. Just a little trick I saw in another test file to get my test config to "extend" this one in an easier way. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -304,8 +304,6 @@ | |
{ | ||
"type": "index", | ||
"value": { | ||
"aliases": { | ||
}, | ||
"index": "sales", | ||
"mappings": { | ||
"properties": { | ||
|
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.
Nitpick:
The logic here can part from Discover
, for some reason I have a hard time reading this. Does this mean that the logic here can be separated from Discover? IE right now it's closely coupled to it?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'll fix the comment, but this is meaning that the logic can part ways with Discover, even though they do much of the same thing. That becomes the cause of bugs like #25068