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

[7.17] [Reporting/CSV Export] _id field can not be formatted (#143807) #150609

Merged
merged 7 commits into from
Feb 10, 2023
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 @@ -148,11 +148,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
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,19 @@
{
"attributes": {
"fieldAttrs": "{}",
"fields": "[]",
"runtimeFieldMap": "{}",
"timeFieldName": "timestamp",
"title": "test_elastic",
"typeMeta": "{}"
},
"coreMigrationVersion": "7.17.10",
"id": "0b3ad420-a7d9-11ed-b7bc-4b80fc2e7c64",
"migrationVersion": {
"index-pattern": "7.11.0"
},
"references": [],
"type": "index-pattern",
"updated_at": "2023-02-08T17:50:15.652Z",
"version": "WzExNiwyXQ=="
}

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 @@ -495,5 +495,102 @@ export default function ({ getService }: FtrProviderContext) {
});
});
});

describe('_id field is a big integer, passes through the value without mutation', () => {
let resText: string;
before(async () => {
await kibanaServer.uiSettings.update({
'csv:quoteValues': false,
'dateFormat:tz': 'UTC',
defaultIndex: 'logstash-*',
});
await esArchiver.load('x-pack/test/functional/es_archives/reporting/big_int_id_field');
await kibanaServer.importExport.load(
'x-pack/test/functional/fixtures/kbn_archiver/reporting/big_int_id_field'
);
const {
status: resStatus,
type: resType,
text,
} = (await generateAPI.getCSVFromSearchSource(
getMockJobParams({
browserTimezone: 'UTC',
version: '8.6.0',
searchSource: {
query: { query: '', language: 'kuery' },
fields: [{ field: '*', include_unmapped: 'true' }],
index: '0b3ad420-a7d9-11ed-b7bc-4b80fc2e7c64',
sort: [{ timestamp: 'desc' }],
filter: [
{
meta: {
index: '0b3ad420-a7d9-11ed-b7bc-4b80fc2e7c64',
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: '0b3ad420-a7d9-11ed-b7bc-4b80fc2e7c64',
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;

expect(resStatus).to.eql(200);
expect(resType).to.eql('text/csv');

resText = text;
});

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'
),
]);
});

itIfEs7('(ES 7)', async () => {
expectSnapshot(resText).toMatch();
});

itIfEs8('(ES 8)', async () => {
expectSnapshot(resText).toMatch();
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { FtrProviderContext } from '../ftr_provider_context';

// eslint-disable-next-line import/no-default-export
export default function ({ getService }: FtrProviderContext) {
const log = getService('log');
const kibanaServer = getService('kibanaServer');
const reportingAPI = getService('reportingAPI');
const esVersion = getService('esVersion');

Expand All @@ -21,6 +23,11 @@ export default function ({ getService }: FtrProviderContext) {
before(async () => {
await reportingAPI.initEcommerce();

log.info(`updating Advanced Settings`);
await kibanaServer.uiSettings.update({
'csv:quoteValues': true,
});

const fromTime = '2019-06-20T00:00:00.000Z';
const toTime = '2019-06-24T00:00:00.000Z';

Expand Down