Skip to content
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/CSV Export] _id field can not be formatted #143807

Merged
merged 2 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Is it possible to test this feature using a unit test, instead of a functional test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vadimkibana this is a great point. We also talked offline about how functional tests should be used to enhance a body of unit tests, and that unit test coverage should be greater than functional coverage. I admit I developed a habit of adding functional tests by default, but just for CSV export and not for other features, so that is irrational.

Going forward, I'll use unit tests and ensure this area of code fits the pattern of greater coverage of unit tests.

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