diff --git a/packages/kbn-generate-csv/src/generate_csv.ts b/packages/kbn-generate-csv/src/generate_csv.ts index 16cce7afb62ad..dcd2b3116c0b9 100644 --- a/packages/kbn-generate-csv/src/generate_csv.ts +++ b/packages/kbn-generate-csv/src/generate_csv.ts @@ -383,7 +383,7 @@ export class CsvGenerator { // apply timezone from the job to all date field formatters try { index.fields.getByType('date').forEach(({ name }) => { - logger.debug(`Setting timezone on ${name}`); + logger.debug(`Setting ${timezone} timezone on ${name}`); const format: FieldFormatConfig = { ...index.fieldFormatMap[name], id: index.fieldFormatMap[name]?.id || 'date', // allow id: date_nanos diff --git a/x-pack/test/functional/apps/dashboard/group3/reporting/__snapshots__/download_csv.snap b/x-pack/test/functional/apps/dashboard/group3/reporting/__snapshots__/download_csv.snap index 126947dd748b1..25fe46458602c 100644 --- a/x-pack/test/functional/apps/dashboard/group3/reporting/__snapshots__/download_csv.snap +++ b/x-pack/test/functional/apps/dashboard/group3/reporting/__snapshots__/download_csv.snap @@ -707,12 +707,6 @@ exports[`dashboard Reporting Download CSV Default Saved Search Data Downloads a " `; -exports[`dashboard Reporting Download CSV Field Formatters and Scripted Fields Download CSV export of a saved search panel 1`] = ` -"date,\\"_id\\",name,gender,value,year,\\"years_ago\\",\\"date_informal\\" -\\"Jan 1, 1982 @ 00:00:00.000\\",\\"1982-Fethany-F\\",Fethany,F,780,1982,\\"37.00000000000000000000\\",\\"Jan 1st 82\\" -" -`; - exports[`dashboard Reporting Download CSV Filtered Saved Search Downloads filtered Discover saved search report 1`] = ` "\\"order_date\\",category,\\"order_id\\",\\"customer_full_name\\",\\"taxful_total_price\\",currency \\"Jun 25, 2019 @ 00:00:00.000\\",\\"Women's Clothing\\",569144,\\"Betty Perkins\\",\\"61.969\\",EUR diff --git a/x-pack/test/functional/apps/dashboard/group3/reporting/download_csv.ts b/x-pack/test/functional/apps/dashboard/group3/reporting/download_csv.ts index c23f991f69f07..52e702502cada 100644 --- a/x-pack/test/functional/apps/dashboard/group3/reporting/download_csv.ts +++ b/x-pack/test/functional/apps/dashboard/group3/reporting/download_csv.ts @@ -171,38 +171,5 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { expectSnapshot(csvFile).toMatch(); }); }); - - describe('Field Formatters and Scripted Fields', () => { - const dashboardWithScriptedFieldsSearch = 'names dashboard'; - - before(async () => { - await reporting.initLogs(); - await esArchiver.load('x-pack/test/functional/es_archives/reporting/hugedata'); - - await navigateToDashboardApp(); - await PageObjects.dashboard.loadSavedDashboard(dashboardWithScriptedFieldsSearch); - await PageObjects.timePicker.setAbsoluteRange( - 'Nov 26, 1981 @ 21:54:15.526', - 'Mar 5, 1982 @ 18:17:44.821' - ); - - await PageObjects.common.sleep(1000); - await filterBar.addFilter({ field: 'name.keyword', operation: 'is', value: 'Fethany' }); - await PageObjects.common.sleep(1000); - }); - - after(async () => { - await reporting.teardownLogs(); - await esArchiver.unload('x-pack/test/functional/es_archives/reporting/hugedata'); - }); - - it('Download CSV export of a saved search panel', async () => { - await clickActionsMenu('namessearch'); - await clickDownloadCsv(); - - const csvFile = await getDownload(getCsvPath('namessearch')); - expectSnapshot(csvFile).toMatch(); - }); - }); }); } diff --git a/x-pack/test/reporting_api_integration/reporting_and_security/__snapshots__/download_csv_dashboard.snap b/x-pack/test/reporting_api_integration/reporting_and_security/__snapshots__/download_csv_dashboard.snap index 73c7a6ef4b542..7fc931daf2fda 100644 --- a/x-pack/test/reporting_api_integration/reporting_and_security/__snapshots__/download_csv_dashboard.snap +++ b/x-pack/test/reporting_api_integration/reporting_and_security/__snapshots__/download_csv_dashboard.snap @@ -175,6 +175,12 @@ exports[`Reporting APIs CSV Generation from SearchSource non-timebased With filt " `; +exports[`Reporting APIs CSV Generation from SearchSource scripted fields years_ago field calculates the number of years to 2019 1`] = ` +"\\"_id\\",\\"_index\\",\\"_score\\",date,\\"date_informal\\",gender,\\"gender.keyword\\",name,\\"name.keyword\\",percent,value,year,\\"years_ago\\" +\\"1980-Fethany-F\\",babynames,\\"-\\",\\"Jan 1, 1980 @ 00:00:00.000\\",\\"Jan 1st 80\\",F,F,Fethany,Fethany,0,702,1980,\\"39.00000000000000000000\\" +" +`; + exports[`Reporting APIs CSV Generation from SearchSource unquoted values Exports CSV with all fields when using defaults 1`] = ` "_id,_index,_score,category,category.keyword,currency,customer_first_name,customer_first_name.keyword,customer_full_name,customer_full_name.keyword,customer_gender,customer_id,customer_last_name,customer_last_name.keyword,customer_phone,day_of_week,day_of_week_i,email,geoip.city_name,geoip.continent_name,geoip.country_iso_code,geoip.location,geoip.region_name,manufacturer,manufacturer.keyword,order_date,order_id,products._id,products._id.keyword,products.base_price,products.base_unit_price,products.category,products.category.keyword,products.created_on,products.discount_amount,products.discount_percentage,products.manufacturer,products.manufacturer.keyword,products.min_price,products.price,products.product_id,products.product_name,products.product_name.keyword,products.quantity,products.sku,products.tax_amount,products.taxful_price,products.taxless_price,products.unit_discount_amount,sku,taxful_total_price,taxless_total_price,total_quantity,total_unique_products,type,user 9AMtOW0BH63Xcmy432DJ,ecommerce,-,Men's Clothing,Men's Clothing,EUR,Boris,Boris,Boris Bradley,Boris Bradley,MALE,36,Bradley,Bradley,(empty),Wednesday,2,boris@bradley-family.zzz,-,Europe,GB,POINT (-0.1 51.5),-,Microlutions, Elitelligence,Microlutions, Elitelligence,Jun 25, 2019 @ 00:00:00.000,568397,sold_product_568397_24419, sold_product_568397_20207,sold_product_568397_24419, sold_product_568397_20207,33, 28.984,33, 28.984,Men's Clothing, Men's Clothing,Men's Clothing, Men's Clothing,Dec 14, 2016 @ 00:00:00.000, Dec 14, 2016 @ 00:00:00.000,0, 0,0, 0,Microlutions, Elitelligence,Microlutions, Elitelligence,17.484, 13.922,33, 28.984,24,419, 20,207,Cargo trousers - oliv, Trousers - black,Cargo trousers - oliv, Trousers - black,1, 1,ZO0112101121, ZO0530405304,0, 0,33, 28.984,33, 28.984,0, 0,ZO0112101121, ZO0530405304,61.969,61.969,2,2,order,boris diff --git a/x-pack/test/reporting_api_integration/reporting_and_security/download_csv_dashboard.ts b/x-pack/test/reporting_api_integration/reporting_and_security/download_csv_dashboard.ts index bd389cd49ea87..8053a18c9d2ee 100644 --- a/x-pack/test/reporting_api_integration/reporting_and_security/download_csv_dashboard.ts +++ b/x-pack/test/reporting_api_integration/reporting_and_security/download_csv_dashboard.ts @@ -283,6 +283,64 @@ export default function ({ getService }: FtrProviderContext) { }); }); + describe('scripted fields', () => { + before(async () => { + await reportingAPI.initLogs(); + await esArchiver.load('x-pack/test/functional/es_archives/reporting/hugedata'); + }); + + after(async () => { + await reportingAPI.teardownLogs(); + await esArchiver.unload('x-pack/test/functional/es_archives/reporting/hugedata'); + }); + + it('years_ago field calculates the number of years to 2019', async () => { + const res = (await generateAPI.getCSVFromSearchSource( + getMockJobParams({ + browserTimezone: 'UTC', + version: '8.13.0', + searchSource: { + query: { query: '', language: 'kuery' }, + fields: [{ field: '*', include_unmapped: 'true' }], + index: '89655130-5013-11e9-bce7-4dabcb8bef24', + sort: [{ date: { order: 'desc', format: 'strict_date_optional_time' } }], + filter: [ + { + query: { match_phrase: { 'name.keyword': 'Fethany' } }, + }, + ], + parent: { + query: { query: '', language: 'kuery' }, + filter: [], + parent: { + filter: [ + { + query: { + range: { + date: { + format: 'strict_date_optional_time', + gte: '1979-09-01T05:31:57.572Z', + lte: '1980-04-18T10:47:57.709Z', + }, + }, + }, + }, + ], + }, + }, + }, + columns: [], + title: 'years_ago', + }) + )) as supertest.Response; + const { status: resStatus, text: resText, type: resType } = res; + + expect(resStatus).to.eql(200); + expect(resType).to.eql('text/csv'); + expectSnapshot(resText).toMatch(); + }); + }); + describe('nanosecond formatting', () => { before(async () => { await esArchiver.load('x-pack/test/functional/es_archives/reporting/nanos');