[Reporting] Add warning logs about CSV export type being deprecated (#104025)
* add deprecation logging to csv export type * fix payload.isDeprecated Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
dcd84ea81a
commit
b794e7b7ca
|
@ -65,6 +65,7 @@ export interface ReportSource {
|
||||||
objectType: string;
|
objectType: string;
|
||||||
title: string;
|
title: string;
|
||||||
layout?: LayoutParams;
|
layout?: LayoutParams;
|
||||||
|
isDeprecated?: boolean;
|
||||||
};
|
};
|
||||||
meta: { objectType: string; layout?: string };
|
meta: { objectType: string; layout?: string };
|
||||||
browser_type: string;
|
browser_type: string;
|
||||||
|
@ -128,6 +129,7 @@ export interface ReportApiJSON {
|
||||||
layout?: LayoutParams;
|
layout?: LayoutParams;
|
||||||
title: string;
|
title: string;
|
||||||
browserTimezone?: string;
|
browserTimezone?: string;
|
||||||
|
isDeprecated?: boolean;
|
||||||
};
|
};
|
||||||
meta: {
|
meta: {
|
||||||
layout?: string;
|
layout?: string;
|
||||||
|
|
|
@ -20,6 +20,9 @@ export const createJobFnFactory: CreateJobFnFactory<
|
||||||
const crypto = cryptoFactory(config.get('encryptionKey'));
|
const crypto = cryptoFactory(config.get('encryptionKey'));
|
||||||
|
|
||||||
return async function createJob(jobParams, context, request) {
|
return async function createJob(jobParams, context, request) {
|
||||||
|
logger.warn(
|
||||||
|
`The "/generate/csv" endpoint is deprecated and will be removed in Kibana 8.0. Please recreate the POST URL used to automate this CSV export.`
|
||||||
|
);
|
||||||
const serializedEncryptedHeaders = await crypto.encrypt(request.headers);
|
const serializedEncryptedHeaders = await crypto.encrypt(request.headers);
|
||||||
|
|
||||||
const savedObjectsClient = context.core.savedObjects.client;
|
const savedObjectsClient = context.core.savedObjects.client;
|
||||||
|
@ -29,6 +32,7 @@ export const createJobFnFactory: CreateJobFnFactory<
|
||||||
)) as unknown) as IndexPatternSavedObjectDeprecatedCSV;
|
)) as unknown) as IndexPatternSavedObjectDeprecatedCSV;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
isDeprecated: true,
|
||||||
headers: serializedEncryptedHeaders,
|
headers: serializedEncryptedHeaders,
|
||||||
spaceId: reporting.getSpaceId(request, logger),
|
spaceId: reporting.getSpaceId(request, logger),
|
||||||
indexPatternSavedObject,
|
indexPatternSavedObject,
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { UnwrapPromise } from '@kbn/utility-types';
|
|
||||||
import { i18n } from '@kbn/i18n';
|
|
||||||
import { ResponseError } from '@elastic/elasticsearch/lib/errors';
|
import { ResponseError } from '@elastic/elasticsearch/lib/errors';
|
||||||
|
import { i18n } from '@kbn/i18n';
|
||||||
|
import { UnwrapPromise } from '@kbn/utility-types';
|
||||||
import { ElasticsearchClient } from 'src/core/server';
|
import { ElasticsearchClient } from 'src/core/server';
|
||||||
import { ReportingCore } from '../../';
|
import { ReportingCore } from '../../';
|
||||||
import { ReportDocument } from '../../lib/store';
|
import { ReportDocument } from '../../lib/store';
|
||||||
|
@ -87,6 +87,7 @@ export function jobsQueryFactory(reportingCore: ReportingCore) {
|
||||||
elasticsearchClient.search({ body, index: getIndex() })
|
elasticsearchClient.search({ body, index: getIndex() })
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// FIXME: return the info in ReportApiJSON format;
|
||||||
return response?.body.hits?.hits ?? [];
|
return response?.body.hits?.hits ?? [];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -139,6 +140,7 @@ export function jobsQueryFactory(reportingCore: ReportingCore) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: return the info in ReportApiJSON format;
|
||||||
return response.body.hits.hits[0] as ReportDocument;
|
return response.body.hits.hits[0] as ReportDocument;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@ export { BaseParams };
|
||||||
export interface BasePayload extends BaseParams {
|
export interface BasePayload extends BaseParams {
|
||||||
headers: string;
|
headers: string;
|
||||||
spaceId?: string;
|
spaceId?: string;
|
||||||
|
isDeprecated?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// default fn type for CreateJobFnFactory
|
// default fn type for CreateJobFnFactory
|
||||||
|
|
|
@ -11,7 +11,8 @@ import { FtrProviderContext } from '../ftr_provider_context';
|
||||||
export default function ({ loadTestFile }: FtrProviderContext) {
|
export default function ({ loadTestFile }: FtrProviderContext) {
|
||||||
describe('Reporting API Integration Tests with Security disabled', function () {
|
describe('Reporting API Integration Tests with Security disabled', function () {
|
||||||
this.tags('ciGroup13');
|
this.tags('ciGroup13');
|
||||||
loadTestFile(require.resolve('./job_apis'));
|
loadTestFile(require.resolve('./job_apis_csv'));
|
||||||
|
loadTestFile(require.resolve('./job_apis_csv_deprecated'));
|
||||||
loadTestFile(require.resolve('./ilm_migration_apis'));
|
loadTestFile(require.resolve('./ilm_migration_apis'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,119 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
||||||
* or more contributor license agreements. Licensed under the Elastic License
|
|
||||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
||||||
* 2.0.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import expect from '@kbn/expect';
|
|
||||||
import { forOwn } from 'lodash';
|
|
||||||
import { JOB_PARAMS_RISON_CSV_DEPRECATED } from '../services/fixtures';
|
|
||||||
import { FtrProviderContext } from '../ftr_provider_context';
|
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-default-export
|
|
||||||
export default function ({ getService }: FtrProviderContext) {
|
|
||||||
const esArchiver = getService('esArchiver');
|
|
||||||
const supertestNoAuth = getService('supertestWithoutAuth');
|
|
||||||
const reportingAPI = getService('reportingAPI');
|
|
||||||
|
|
||||||
describe('Job Listing APIs', () => {
|
|
||||||
before(async () => {
|
|
||||||
await esArchiver.load('x-pack/test/functional/es_archives/reporting/logs');
|
|
||||||
await esArchiver.load('x-pack/test/functional/es_archives/logstash_functional');
|
|
||||||
});
|
|
||||||
|
|
||||||
after(async () => {
|
|
||||||
await esArchiver.unload('x-pack/test/functional/es_archives/reporting/logs');
|
|
||||||
await esArchiver.unload('x-pack/test/functional/es_archives/logstash_functional');
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await reportingAPI.deleteAllReports();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Posted CSV job is visible in the job count', async () => {
|
|
||||||
const { status: resStatus, text: resText } = await supertestNoAuth
|
|
||||||
.post(`/api/reporting/generate/csv`)
|
|
||||||
.set('kbn-xsrf', 'xxx')
|
|
||||||
.send({ jobParams: JOB_PARAMS_RISON_CSV_DEPRECATED });
|
|
||||||
|
|
||||||
expect(resStatus).to.be(200);
|
|
||||||
|
|
||||||
const { job: resJob } = JSON.parse(resText);
|
|
||||||
const expectedResJob: Record<string, any> = {
|
|
||||||
attempts: 0,
|
|
||||||
created_by: false,
|
|
||||||
jobtype: 'csv',
|
|
||||||
status: 'pending',
|
|
||||||
};
|
|
||||||
forOwn(expectedResJob, (value: any, key: string) => {
|
|
||||||
expect(resJob[key]).to.eql(value, key);
|
|
||||||
});
|
|
||||||
|
|
||||||
// call the job count api
|
|
||||||
const { text: countText } = await supertestNoAuth
|
|
||||||
.get(`/api/reporting/jobs/count`)
|
|
||||||
.set('kbn-xsrf', 'xxx');
|
|
||||||
|
|
||||||
const countResult = JSON.parse(countText);
|
|
||||||
expect(countResult).to.be(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Posted CSV job is visible in the status check', async () => {
|
|
||||||
const { status: resStatus, text: resText } = await supertestNoAuth
|
|
||||||
.post(`/api/reporting/generate/csv`)
|
|
||||||
.set('kbn-xsrf', 'xxx')
|
|
||||||
.send({ jobParams: JOB_PARAMS_RISON_CSV_DEPRECATED });
|
|
||||||
|
|
||||||
expect(resStatus).to.be(200);
|
|
||||||
|
|
||||||
const { job: resJob } = JSON.parse(resText);
|
|
||||||
// call the single job listing api (status check)
|
|
||||||
const { text: listText } = await supertestNoAuth
|
|
||||||
.get(`/api/reporting/jobs/list?page=0&ids=${resJob.id}`)
|
|
||||||
.set('kbn-xsrf', 'xxx');
|
|
||||||
|
|
||||||
const listingJobs = JSON.parse(listText);
|
|
||||||
|
|
||||||
const expectedListJob: Record<string, any> = {
|
|
||||||
attempts: 0,
|
|
||||||
created_by: false,
|
|
||||||
jobtype: 'csv',
|
|
||||||
};
|
|
||||||
forOwn(expectedListJob, (value: any, key: string) => {
|
|
||||||
expect(listingJobs[0]._source[key]).to.eql(value, key);
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(listingJobs.length).to.be(1);
|
|
||||||
expect(listingJobs[0]._id).to.be(resJob.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Posted CSV job is visible in the first page of jobs listing', async () => {
|
|
||||||
const { status: resStatus, text: resText } = await supertestNoAuth
|
|
||||||
.post(`/api/reporting/generate/csv`)
|
|
||||||
.set('kbn-xsrf', 'xxx')
|
|
||||||
.send({ jobParams: JOB_PARAMS_RISON_CSV_DEPRECATED });
|
|
||||||
|
|
||||||
expect(resStatus).to.be(200);
|
|
||||||
|
|
||||||
const { job: resJob } = JSON.parse(resText);
|
|
||||||
// call the ALL job listing api
|
|
||||||
const { text: listText } = await supertestNoAuth
|
|
||||||
.get(`/api/reporting/jobs/list?page=0`)
|
|
||||||
.set('kbn-xsrf', 'xxx');
|
|
||||||
|
|
||||||
const listingJobs = JSON.parse(listText);
|
|
||||||
const expectedListJob: Record<string, any> = {
|
|
||||||
attempts: 0,
|
|
||||||
created_by: false,
|
|
||||||
jobtype: 'csv',
|
|
||||||
};
|
|
||||||
forOwn(expectedListJob, (value: any, key: string) => {
|
|
||||||
expect(listingJobs[0]._source[key]).to.eql(value, key);
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(listingJobs.length).to.be(1);
|
|
||||||
expect(listingJobs[0]._id).to.be(resJob.id);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -0,0 +1,256 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||||
|
* 2.0.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import expect from '@kbn/expect';
|
||||||
|
import { pick } from 'lodash';
|
||||||
|
import {
|
||||||
|
ReportApiJSON,
|
||||||
|
ReportDocument,
|
||||||
|
ReportSource,
|
||||||
|
} from '../../../plugins/reporting/common/types';
|
||||||
|
import { FtrProviderContext } from '../ftr_provider_context';
|
||||||
|
|
||||||
|
const apiResponseFields = [
|
||||||
|
'attempts',
|
||||||
|
'created_by',
|
||||||
|
'jobtype',
|
||||||
|
'max_attempts',
|
||||||
|
'meta',
|
||||||
|
'payload.isDeprecated',
|
||||||
|
'payload.title',
|
||||||
|
'payload.type',
|
||||||
|
'status',
|
||||||
|
];
|
||||||
|
|
||||||
|
// TODO: clean up the /list and /info endpoints to return ReportApiJSON interface data
|
||||||
|
const documentResponseFields = [
|
||||||
|
'_source.attempts',
|
||||||
|
'_source.created_by',
|
||||||
|
'_source.jobtype',
|
||||||
|
'_source.max_attempts',
|
||||||
|
'_source.meta',
|
||||||
|
'_source.payload.isDeprecated',
|
||||||
|
'_source.payload.title',
|
||||||
|
'_source.payload.type',
|
||||||
|
'_source.status',
|
||||||
|
];
|
||||||
|
|
||||||
|
// eslint-disable-next-line import/no-default-export
|
||||||
|
export default function ({ getService }: FtrProviderContext) {
|
||||||
|
const esArchiver = getService('esArchiver');
|
||||||
|
const supertestNoAuth = getService('supertestWithoutAuth');
|
||||||
|
const reportingAPI = getService('reportingAPI');
|
||||||
|
|
||||||
|
const postJobCSV = async () => {
|
||||||
|
const jobParams =
|
||||||
|
`(browserTimezone:UTC,columns:!('@timestamp',clientip,extension),` +
|
||||||
|
`objectType:search,searchSource:(fields:!((field:'*',include_unmapped:true)),filter:!((meta:(index:'logstash-*',params:()),` +
|
||||||
|
`range:('@timestamp':(format:strict_date_optional_time,gte:'2006-06-21T22:00:57.631Z',lte:'2021-06-21T22:00:57.631Z')))),` +
|
||||||
|
`index:'logstash-*',parent:(filter:!(('$state':(store:appState),meta:(alias:datefilter🥜,disabled:!f,index:'logstash-*',` +
|
||||||
|
`key:'@timestamp',negate:!f,params:(gte:'2015-09-20T10:19:40.307Z',lt:'2015-09-20T10:26:56.221Z'),type:range),` +
|
||||||
|
`range:('@timestamp':(gte:'2015-09-20T10:19:40.307Z',lt:'2015-09-20T10:26:56.221Z')))),highlightAll:!t,index:'logstash-*',` +
|
||||||
|
`query:(language:kuery,query:''),version:!t),sort:!(('@timestamp':desc)),trackTotalHits:!t,version:!t),title:'A Saved Search With a DATE FILTER')`;
|
||||||
|
const { status: resStatus, text: resText } = await supertestNoAuth
|
||||||
|
.post(`/api/reporting/generate/csv_searchsource?jobParams=${encodeURI(jobParams)}`)
|
||||||
|
.set('kbn-xsrf', 'xxx');
|
||||||
|
expect(resStatus).to.be(200);
|
||||||
|
|
||||||
|
const result: { job: ReportApiJSON; path: string } = JSON.parse(resText);
|
||||||
|
expect(result.job.payload.isDeprecated).to.not.be(true);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('Job Listing APIs', () => {
|
||||||
|
before(async () => {
|
||||||
|
await esArchiver.load('x-pack/test/functional/es_archives/reporting/logs');
|
||||||
|
await esArchiver.load('x-pack/test/functional/es_archives/logstash_functional');
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async () => {
|
||||||
|
await esArchiver.unload('x-pack/test/functional/es_archives/reporting/logs');
|
||||||
|
await esArchiver.unload('x-pack/test/functional/es_archives/logstash_functional');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await reportingAPI.deleteAllReports();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Posted CSV job is visible in the job count', async () => {
|
||||||
|
const { job, path }: { job: ReportApiJSON; path: string } = await postJobCSV();
|
||||||
|
expectSnapshot(pick(job, apiResponseFields)).toMatchInline(`
|
||||||
|
Object {
|
||||||
|
"attempts": 0,
|
||||||
|
"created_by": false,
|
||||||
|
"jobtype": "csv_searchsource",
|
||||||
|
"max_attempts": 1,
|
||||||
|
"meta": Object {
|
||||||
|
"objectType": "search",
|
||||||
|
},
|
||||||
|
"payload": Object {
|
||||||
|
"title": "A Saved Search With a DATE FILTER",
|
||||||
|
},
|
||||||
|
"status": "pending",
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
|
||||||
|
// call the job count api
|
||||||
|
const { text: countText } = await supertestNoAuth
|
||||||
|
.get(`/api/reporting/jobs/count`)
|
||||||
|
.set('kbn-xsrf', 'xxx');
|
||||||
|
expect(countText).to.be('1');
|
||||||
|
|
||||||
|
// clean up
|
||||||
|
await reportingAPI.waitForJobToFinish(path);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Posted CSV job is visible in the status check', async () => {
|
||||||
|
// post a job
|
||||||
|
const { job, path }: { job: ReportApiJSON; path: string } = await postJobCSV();
|
||||||
|
expectSnapshot(pick(job, apiResponseFields)).toMatchInline(`
|
||||||
|
Object {
|
||||||
|
"attempts": 0,
|
||||||
|
"created_by": false,
|
||||||
|
"jobtype": "csv_searchsource",
|
||||||
|
"max_attempts": 1,
|
||||||
|
"meta": Object {
|
||||||
|
"objectType": "search",
|
||||||
|
},
|
||||||
|
"payload": Object {
|
||||||
|
"title": "A Saved Search With a DATE FILTER",
|
||||||
|
},
|
||||||
|
"status": "pending",
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
|
||||||
|
// call the listing api
|
||||||
|
const { text: listText } = await supertestNoAuth
|
||||||
|
.get(`/api/reporting/jobs/list?page=0&ids=${job.id}`)
|
||||||
|
.set('kbn-xsrf', 'xxx');
|
||||||
|
|
||||||
|
// verify the top item in the list
|
||||||
|
const listingJobs: ReportDocument[] = JSON.parse(listText);
|
||||||
|
expect(listingJobs[0]._id).to.be(job.id);
|
||||||
|
expectSnapshot(listingJobs.map((j) => pick(j, documentResponseFields))).toMatchInline(`
|
||||||
|
Array [
|
||||||
|
Object {
|
||||||
|
"_source": Object {
|
||||||
|
"attempts": 0,
|
||||||
|
"created_by": false,
|
||||||
|
"jobtype": "csv_searchsource",
|
||||||
|
"max_attempts": 1,
|
||||||
|
"meta": Object {
|
||||||
|
"objectType": "search",
|
||||||
|
},
|
||||||
|
"payload": Object {
|
||||||
|
"title": "A Saved Search With a DATE FILTER",
|
||||||
|
},
|
||||||
|
"status": "pending",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
`);
|
||||||
|
|
||||||
|
// clean up
|
||||||
|
await reportingAPI.waitForJobToFinish(path);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Posted CSV job is visible in the first page of jobs listing', async () => {
|
||||||
|
// post a job
|
||||||
|
const { job, path }: { job: ReportApiJSON; path: string } = await postJobCSV();
|
||||||
|
expectSnapshot(pick(job, apiResponseFields)).toMatchInline(`
|
||||||
|
Object {
|
||||||
|
"attempts": 0,
|
||||||
|
"created_by": false,
|
||||||
|
"jobtype": "csv_searchsource",
|
||||||
|
"max_attempts": 1,
|
||||||
|
"meta": Object {
|
||||||
|
"objectType": "search",
|
||||||
|
},
|
||||||
|
"payload": Object {
|
||||||
|
"title": "A Saved Search With a DATE FILTER",
|
||||||
|
},
|
||||||
|
"status": "pending",
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
|
||||||
|
// call the listing api
|
||||||
|
const { text: listText } = await supertestNoAuth
|
||||||
|
.get(`/api/reporting/jobs/list?page=0`)
|
||||||
|
.set('kbn-xsrf', 'xxx');
|
||||||
|
|
||||||
|
// verify the top item in the list
|
||||||
|
const listingJobs: ReportDocument[] = JSON.parse(listText);
|
||||||
|
expect(listingJobs[0]._id).to.be(job.id);
|
||||||
|
expectSnapshot(listingJobs.map((j) => pick(j, documentResponseFields))).toMatchInline(`
|
||||||
|
Array [
|
||||||
|
Object {
|
||||||
|
"_source": Object {
|
||||||
|
"attempts": 0,
|
||||||
|
"created_by": false,
|
||||||
|
"jobtype": "csv_searchsource",
|
||||||
|
"max_attempts": 1,
|
||||||
|
"meta": Object {
|
||||||
|
"objectType": "search",
|
||||||
|
},
|
||||||
|
"payload": Object {
|
||||||
|
"title": "A Saved Search With a DATE FILTER",
|
||||||
|
},
|
||||||
|
"status": "pending",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
`);
|
||||||
|
|
||||||
|
// clean up
|
||||||
|
await reportingAPI.waitForJobToFinish(path);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Posted CSV job details are visible in the info API', async () => {
|
||||||
|
// post a job
|
||||||
|
const { job, path }: { job: ReportApiJSON; path: string } = await postJobCSV();
|
||||||
|
expectSnapshot(pick(job, apiResponseFields)).toMatchInline(`
|
||||||
|
Object {
|
||||||
|
"attempts": 0,
|
||||||
|
"created_by": false,
|
||||||
|
"jobtype": "csv_searchsource",
|
||||||
|
"max_attempts": 1,
|
||||||
|
"meta": Object {
|
||||||
|
"objectType": "search",
|
||||||
|
},
|
||||||
|
"payload": Object {
|
||||||
|
"title": "A Saved Search With a DATE FILTER",
|
||||||
|
},
|
||||||
|
"status": "pending",
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
|
||||||
|
const { text: infoText } = await supertestNoAuth
|
||||||
|
.get(`/api/reporting/jobs/info/${job.id}`)
|
||||||
|
.set('kbn-xsrf', 'xxx');
|
||||||
|
|
||||||
|
const info: ReportSource = JSON.parse(infoText);
|
||||||
|
expectSnapshot(pick(info, apiResponseFields)).toMatchInline(`
|
||||||
|
Object {
|
||||||
|
"attempts": 0,
|
||||||
|
"created_by": false,
|
||||||
|
"jobtype": "csv_searchsource",
|
||||||
|
"max_attempts": 1,
|
||||||
|
"meta": Object {
|
||||||
|
"objectType": "search",
|
||||||
|
},
|
||||||
|
"payload": Object {
|
||||||
|
"title": "A Saved Search With a DATE FILTER",
|
||||||
|
},
|
||||||
|
"status": "pending",
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
|
||||||
|
await reportingAPI.waitForJobToFinish(path);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,207 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||||
|
* 2.0.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import expect from '@kbn/expect';
|
||||||
|
import { pick } from 'lodash';
|
||||||
|
import {
|
||||||
|
ReportApiJSON,
|
||||||
|
ReportDocument,
|
||||||
|
ReportSource,
|
||||||
|
} from '../../../plugins/reporting/common/types';
|
||||||
|
import { FtrProviderContext } from '../ftr_provider_context';
|
||||||
|
import { JOB_PARAMS_RISON_CSV_DEPRECATED } from '../services/fixtures';
|
||||||
|
|
||||||
|
const apiResponseFields = [
|
||||||
|
'attempts',
|
||||||
|
'created_by',
|
||||||
|
'jobtype',
|
||||||
|
'max_attempts',
|
||||||
|
'meta',
|
||||||
|
'payload.isDeprecated',
|
||||||
|
'payload.title',
|
||||||
|
'payload.type',
|
||||||
|
'status',
|
||||||
|
];
|
||||||
|
|
||||||
|
// TODO: clean up the /list and /info endpoints to return ReportApiJSON interface data
|
||||||
|
const documentResponseFields = [
|
||||||
|
'_source.attempts',
|
||||||
|
'_source.created_by',
|
||||||
|
'_source.jobtype',
|
||||||
|
'_source.max_attempts',
|
||||||
|
'_source.meta',
|
||||||
|
'_source.payload.isDeprecated',
|
||||||
|
'_source.payload.title',
|
||||||
|
'_source.payload.type',
|
||||||
|
'_source.status',
|
||||||
|
];
|
||||||
|
|
||||||
|
// eslint-disable-next-line import/no-default-export
|
||||||
|
export default function ({ getService }: FtrProviderContext) {
|
||||||
|
const esArchiver = getService('esArchiver');
|
||||||
|
const supertestNoAuth = getService('supertestWithoutAuth');
|
||||||
|
const reportingAPI = getService('reportingAPI');
|
||||||
|
|
||||||
|
describe('Job Listing APIs: Deprecated CSV Export', () => {
|
||||||
|
before(async () => {
|
||||||
|
await esArchiver.load('x-pack/test/functional/es_archives/reporting/logs');
|
||||||
|
await esArchiver.load('x-pack/test/functional/es_archives/logstash_functional');
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async () => {
|
||||||
|
await esArchiver.unload('x-pack/test/functional/es_archives/reporting/logs');
|
||||||
|
await esArchiver.unload('x-pack/test/functional/es_archives/logstash_functional');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await reportingAPI.deleteAllReports();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Posted CSV job is visible in the job count', async () => {
|
||||||
|
const { status: resStatus, text: resText } = await supertestNoAuth
|
||||||
|
.post(`/api/reporting/generate/csv`)
|
||||||
|
.set('kbn-xsrf', 'xxx')
|
||||||
|
.send({ jobParams: JOB_PARAMS_RISON_CSV_DEPRECATED });
|
||||||
|
expect(resStatus).to.be(200);
|
||||||
|
|
||||||
|
const { job, path }: { job: ReportApiJSON; path: string } = JSON.parse(resText);
|
||||||
|
expectSnapshot(pick(job, apiResponseFields)).toMatchInline(`
|
||||||
|
Object {
|
||||||
|
"attempts": 0,
|
||||||
|
"created_by": false,
|
||||||
|
"jobtype": "csv",
|
||||||
|
"max_attempts": 1,
|
||||||
|
"meta": Object {},
|
||||||
|
"payload": Object {
|
||||||
|
"isDeprecated": true,
|
||||||
|
"title": "A Saved Search With a DATE FILTER",
|
||||||
|
"type": "search",
|
||||||
|
},
|
||||||
|
"status": "pending",
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
|
||||||
|
// call the job count api
|
||||||
|
const { text: countText } = await supertestNoAuth
|
||||||
|
.get(`/api/reporting/jobs/count`)
|
||||||
|
.set('kbn-xsrf', 'xxx');
|
||||||
|
|
||||||
|
const countResult = JSON.parse(countText);
|
||||||
|
expect(countResult).to.be(1);
|
||||||
|
|
||||||
|
await reportingAPI.waitForJobToFinish(path);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Posted CSV job is visible in the status check', async () => {
|
||||||
|
const { status: resStatus, text: resText } = await supertestNoAuth
|
||||||
|
.post(`/api/reporting/generate/csv`)
|
||||||
|
.set('kbn-xsrf', 'xxx')
|
||||||
|
.send({ jobParams: JOB_PARAMS_RISON_CSV_DEPRECATED });
|
||||||
|
expect(resStatus).to.be(200);
|
||||||
|
|
||||||
|
const { job, path }: { job: ReportApiJSON; path: string } = JSON.parse(resText);
|
||||||
|
// call the single job listing api (status check)
|
||||||
|
const { text: listText } = await supertestNoAuth
|
||||||
|
.get(`/api/reporting/jobs/list?page=0&ids=${job.id}`)
|
||||||
|
.set('kbn-xsrf', 'xxx');
|
||||||
|
|
||||||
|
const listingJobs: ReportDocument[] = JSON.parse(listText);
|
||||||
|
expect(listingJobs[0]._id).to.be(job.id);
|
||||||
|
expectSnapshot(listingJobs.map((j) => pick(j, documentResponseFields))).toMatchInline(`
|
||||||
|
Array [
|
||||||
|
Object {
|
||||||
|
"_source": Object {
|
||||||
|
"attempts": 0,
|
||||||
|
"created_by": false,
|
||||||
|
"jobtype": "csv",
|
||||||
|
"max_attempts": 1,
|
||||||
|
"meta": Object {},
|
||||||
|
"payload": Object {
|
||||||
|
"isDeprecated": true,
|
||||||
|
"title": "A Saved Search With a DATE FILTER",
|
||||||
|
"type": "search",
|
||||||
|
},
|
||||||
|
"status": "pending",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
`);
|
||||||
|
|
||||||
|
await reportingAPI.waitForJobToFinish(path);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Posted CSV job is visible in the first page of jobs listing', async () => {
|
||||||
|
const { status: resStatus, text: resText } = await supertestNoAuth
|
||||||
|
.post(`/api/reporting/generate/csv`)
|
||||||
|
.set('kbn-xsrf', 'xxx')
|
||||||
|
.send({ jobParams: JOB_PARAMS_RISON_CSV_DEPRECATED });
|
||||||
|
expect(resStatus).to.be(200);
|
||||||
|
|
||||||
|
const { job, path }: { job: ReportApiJSON; path: string } = JSON.parse(resText);
|
||||||
|
// call the ALL job listing api
|
||||||
|
const { text: listText } = await supertestNoAuth
|
||||||
|
.get(`/api/reporting/jobs/list?page=0`)
|
||||||
|
.set('kbn-xsrf', 'xxx');
|
||||||
|
|
||||||
|
const listingJobs: ReportDocument[] = JSON.parse(listText);
|
||||||
|
expect(listingJobs[0]._id).to.eql(job.id);
|
||||||
|
expectSnapshot(listingJobs.map((j) => pick(j, documentResponseFields))).toMatchInline(`
|
||||||
|
Array [
|
||||||
|
Object {
|
||||||
|
"_source": Object {
|
||||||
|
"attempts": 0,
|
||||||
|
"created_by": false,
|
||||||
|
"jobtype": "csv",
|
||||||
|
"max_attempts": 1,
|
||||||
|
"meta": Object {},
|
||||||
|
"payload": Object {
|
||||||
|
"isDeprecated": true,
|
||||||
|
"title": "A Saved Search With a DATE FILTER",
|
||||||
|
"type": "search",
|
||||||
|
},
|
||||||
|
"status": "pending",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
`);
|
||||||
|
|
||||||
|
await reportingAPI.waitForJobToFinish(path);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Posted CSV job details are visible in the info API', async () => {
|
||||||
|
const { status: resStatus, text: resText } = await supertestNoAuth
|
||||||
|
.post(`/api/reporting/generate/csv`)
|
||||||
|
.set('kbn-xsrf', 'xxx')
|
||||||
|
.send({ jobParams: JOB_PARAMS_RISON_CSV_DEPRECATED });
|
||||||
|
expect(resStatus).to.be(200);
|
||||||
|
|
||||||
|
const { job, path }: { job: ReportApiJSON; path: string } = JSON.parse(resText);
|
||||||
|
const { text: infoText } = await supertestNoAuth
|
||||||
|
.get(`/api/reporting/jobs/info/${job.id}`)
|
||||||
|
.set('kbn-xsrf', 'xxx');
|
||||||
|
|
||||||
|
const info: ReportSource = JSON.parse(infoText);
|
||||||
|
expectSnapshot(pick(info, apiResponseFields)).toMatchInline(`
|
||||||
|
Object {
|
||||||
|
"attempts": 0,
|
||||||
|
"created_by": false,
|
||||||
|
"jobtype": "csv",
|
||||||
|
"max_attempts": 1,
|
||||||
|
"meta": Object {},
|
||||||
|
"payload": Object {
|
||||||
|
"isDeprecated": true,
|
||||||
|
"title": "A Saved Search With a DATE FILTER",
|
||||||
|
"type": "search",
|
||||||
|
},
|
||||||
|
"status": "pending",
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
|
||||||
|
await reportingAPI.waitForJobToFinish(path);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in a new issue