forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added minor fixes (handling 404 from ES) and added API integration tests
- Loading branch information
1 parent
7f4b518
commit 508c947
Showing
4 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
x-pack/test/reporting_api_integration/reporting_without_security/ilm_migration_apis.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* 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 { JOB_PARAMS_RISON_CSV_DEPRECATED } from '../services/fixtures'; | ||
import { FtrProviderContext } from '../ftr_provider_context'; | ||
|
||
import { ILM_POLICY_NAME } from '../../../plugins/reporting/common/constants'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default function ({ getService }: FtrProviderContext) { | ||
const esArchiver = getService('esArchiver'); | ||
const es = getService('es'); | ||
const supertestNoAuth = getService('supertestWithoutAuth'); | ||
const reportingAPI = getService('reportingAPI'); | ||
|
||
describe('ILM policy migration 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(); | ||
await reportingAPI.migrateReportingIndices(); // ensure that the ILM policy exists | ||
}); | ||
|
||
it('detects when no migration is needed', async () => { | ||
expect(await reportingAPI.checkIlmMigrationStatus()).to.eql('ok'); | ||
|
||
// try creating a report | ||
await supertestNoAuth | ||
.post(`/api/reporting/generate/csv`) | ||
.set('kbn-xsrf', 'xxx') | ||
.send({ jobParams: JOB_PARAMS_RISON_CSV_DEPRECATED }); | ||
|
||
expect(await reportingAPI.checkIlmMigrationStatus()).to.eql('ok'); | ||
}); | ||
|
||
it('detects when reporting indices should be migrated due to missing ILM policy', async () => { | ||
await reportingAPI.makeAllReportingPoliciesUnmanaged(); | ||
// TODO: Remove "any" when no longer through type issue "policy_id" missing | ||
await es.ilm.deleteLifecycle({ policy: ILM_POLICY_NAME } as any); | ||
|
||
await supertestNoAuth | ||
.post(`/api/reporting/generate/csv`) | ||
.set('kbn-xsrf', 'xxx') | ||
.send({ jobParams: JOB_PARAMS_RISON_CSV_DEPRECATED }); | ||
|
||
expect(await reportingAPI.checkIlmMigrationStatus()).to.eql('policy-not-found'); | ||
// assert that migration fixes this | ||
await reportingAPI.migrateReportingIndices(); | ||
expect(await reportingAPI.checkIlmMigrationStatus()).to.eql('ok'); | ||
}); | ||
|
||
it('detects when reporting indices should be migrated due to unmanaged indices', async () => { | ||
await reportingAPI.makeAllReportingPoliciesUnmanaged(); | ||
await supertestNoAuth | ||
.post(`/api/reporting/generate/csv`) | ||
.set('kbn-xsrf', 'xxx') | ||
.send({ jobParams: JOB_PARAMS_RISON_CSV_DEPRECATED }); | ||
|
||
expect(await reportingAPI.checkIlmMigrationStatus()).to.eql('indices-not-managed-by-policy'); | ||
// assert that migration fixes this | ||
await reportingAPI.migrateReportingIndices(); | ||
expect(await reportingAPI.checkIlmMigrationStatus()).to.eql('ok'); | ||
}); | ||
|
||
it('does not override an existing ILM policy', async () => { | ||
const customLifecycle = { | ||
policy: { | ||
phases: { | ||
hot: { | ||
min_age: '0ms', | ||
actions: {}, | ||
}, | ||
delete: { | ||
min_age: '0ms', | ||
actions: { | ||
delete: { | ||
delete_searchable_snapshot: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
// customize the lifecycle policy | ||
await es.ilm.putLifecycle({ | ||
policy: ILM_POLICY_NAME, | ||
body: customLifecycle, | ||
}); | ||
|
||
await reportingAPI.migrateReportingIndices(); | ||
|
||
const { | ||
body: { | ||
[ILM_POLICY_NAME]: { policy }, | ||
}, | ||
} = await es.ilm.getLifecycle({ policy: ILM_POLICY_NAME }); | ||
|
||
expect(policy).to.eql(customLifecycle.policy); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters