Skip to content

Commit

Permalink
[Reporting/CSV Export] _id field can not be formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Oct 25, 2022
1 parent 8b01521 commit 63bf78e
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,16 @@ export class CsvGenerator {
cell = '-';
}

try {
// expected values are a string of JSON where the value(s) is in an array
cell = JSON.parse(cell);
} catch (e) {
// ignore
const isIdField = tableColumn === '_id'; // _id field can not be formatted or mutated
if (!isIdField) {
try {
// unwrap the value
// expected values are a string of JSON where the value(s) is in an array
// examples: "[""Jan 1, 2020 @ 04:00:00.000""]","[""username""]"
cell = JSON.parse(cell);
} catch (e) {
// ignore
}
}

// We have to strip singular array values out of their array wrapper,
Expand Down Expand Up @@ -381,6 +386,7 @@ export class CsvGenerator {
break; // empty report with just the header
}

// FIXME: make tabifyDocs handle the formatting, to get the same formatting logic as Discover?
const formatters = this.getFormatters(table);
await this.generateRows(columns, table, builder, formatters, settings);

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type": "index",
"value": {
"aliases": {
},
"index": "test_elastic",
"mappings": {
"properties": {
"timestamp": {
"format": "yyyyMMddHHmmss||yyyyMMddHHmmssZ||strict_date_optional_time||epoch_millis",
"type": "date"
},
"message_type": {
"type": "keyword"
}
}
},
"settings": {
"index": {
"number_of_replicas": "1",
"number_of_shards": "1"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"attributes": {
"fieldAttrs": "{}",
"fieldFormatMap": "{}",
"fields": "[]",
"name": "test_elastic*",
"runtimeFieldMap": "{}",
"sourceFilters": "[]",
"timeFieldName": "timestamp",
"title": "test_elastic*",
"typeMeta": "{}"
},
"coreMigrationVersion": "8.6.0",
"created_at": "2022-10-25T20:55:46.970Z",
"id": "c424ce04-f440-4f48-aa0c-534da84d06f6",
"migrationVersion": {
"index-pattern": "8.0.0"
},
"references": [],
"type": "index-pattern",
"updated_at": "2022-10-25T20:55:46.970Z",
"version": "WzIxOCwxXQ=="
}

{
"attributes": {
"columns": [],
"description": "",
"grid": {},
"hideChart": false,
"isTextBasedQuery": false,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"query\":{\"query\":\"\",\"language\":\"kuery\"},\"filter\":[],\"indexRefName\":\"kibanaSavedObjectMeta.searchSourceJSON.index\"}"
},
"sort": [
[
"timestamp",
"desc"
]
],
"timeRestore": false,
"title": "testsearch"
},
"coreMigrationVersion": "8.6.0",
"created_at": "2022-10-25T20:57:39.872Z",
"id": "a984aeb0-54a7-11ed-b3f3-41d5096a3cfd",
"migrationVersion": {
"search": "8.0.0"
},
"references": [
{
"id": "c424ce04-f440-4f48-aa0c-534da84d06f6",
"name": "kibanaSavedObjectMeta.searchSourceJSON.index",
"type": "index-pattern"
}
],
"type": "search",
"updated_at": "2022-10-25T20:57:39.872Z",
"version": "WzI2MCwxXQ=="
}

{
"attributes": {
"description": "",
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"query\":{\"query\":\"\",\"language\":\"kuery\"},\"filter\":[]}"
},
"optionsJSON": "{\"useMargins\":true,\"syncColors\":false,\"syncCursor\":true,\"syncTooltips\":false,\"hidePanelTitles\":false}",
"panelsJSON": "[{\"version\":\"8.6.0\",\"type\":\"search\",\"gridData\":{\"x\":0,\"y\":0,\"w\":48,\"h\":18,\"i\":\"7307be50-603d-4091-b4b9-e76a96c6a33a\"},\"panelIndex\":\"7307be50-603d-4091-b4b9-e76a96c6a33a\",\"embeddableConfig\":{\"enhancements\":{}},\"panelRefName\":\"panel_7307be50-603d-4091-b4b9-e76a96c6a33a\"}]",
"refreshInterval": {
"pause": true,
"value": 0
},
"timeFrom": "now-15y",
"timeRestore": true,
"timeTo": "2022-10-30T00:00:00.000Z",
"title": "rbbaf",
"version": 1
},
"coreMigrationVersion": "8.6.0",
"created_at": "2022-10-25T21:01:17.780Z",
"id": "b78b1350-54a7-11ed-b3f3-41d5096a3cfd",
"migrationVersion": {
"dashboard": "8.6.0"
},
"references": [
{
"id": "a984aeb0-54a7-11ed-b3f3-41d5096a3cfd",
"name": "7307be50-603d-4091-b4b9-e76a96c6a33a:panel_7307be50-603d-4091-b4b9-e76a96c6a33a",
"type": "search"
}
],
"type": "dashboard",
"updated_at": "2022-10-25T21:01:17.780Z",
"version": "WzMzNiwxXQ=="
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,85 @@ export default function ({ getService }: FtrProviderContext) {
});
});

describe('_id field is a big integer', () => {
before(async () => {
await Promise.all([
esArchiver.load('x-pack/test/functional/es_archives/reporting/big_int_id_field'),
kibanaServer.importExport.load(
'x-pack/test/functional/fixtures/kbn_archiver/reporting/big_int_id_field'
),
]);
});

after(async () => {
await Promise.all([
esArchiver.unload('x-pack/test/functional/es_archives/reporting/big_int_id_field'),
kibanaServer.importExport.unload(
'x-pack/test/functional/fixtures/kbn_archiver/reporting/big_int_id_field'
),
]);
});
it('passes through the value without mutation', async () => {
const { text } = (await generateAPI.getCSVFromSearchSource(
getMockJobParams({
browserTimezone: 'UTC',
version: '8.6.0',
searchSource: {
query: { query: '', language: 'kuery' },
fields: [{ field: '*', include_unmapped: 'true' }],
index: 'c424ce04-f440-4f48-aa0c-534da84d06f6',
sort: [{ timestamp: 'desc' }],
filter: [
{
meta: {
index: 'c424ce04-f440-4f48-aa0c-534da84d06f6',
params: {},
field: 'timestamp',
},
query: {
range: {
timestamp: {
format: 'strict_date_optional_time',
gte: '2007-10-25T21:18:23.905Z',
lte: '2022-10-30T00:00:00.000Z',
},
},
},
},
],
parent: {
query: { query: '', language: 'kuery' },
filter: [],
parent: {
filter: [
{
meta: {
index: 'c424ce04-f440-4f48-aa0c-534da84d06f6',
params: {},
field: 'timestamp',
},
query: {
range: {
timestamp: {
format: 'strict_date_optional_time',
gte: '2007-10-25T21:18:23.905Z',
lte: '2022-10-30T00:00:00.000Z',
},
},
},
},
],
},
},
},
columns: [],
title: 'testsearch',
})
)) as supertest.Response;
expectSnapshot(text).toMatch();
});
});

describe('validation', () => {
it('Return a 404', async () => {
const { body } = (await generateAPI.getCSVFromSearchSource(
Expand Down

0 comments on commit 63bf78e

Please sign in to comment.