Skip to content

Commit

Permalink
initial version of upgrade assistant integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed May 19, 2021
1 parent 37aa7fd commit d649f56
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 8 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/reporting/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const API_BASE_URL = '/api/reporting'; // "Generation URL" from share men
export const API_BASE_GENERATE = `${API_BASE_URL}/generate`;
export const API_LIST_URL = `${API_BASE_URL}/jobs`;
export const API_DIAGNOSE_URL = `${API_BASE_URL}/diagnose`;
export const API_MIGRATE_ILM_POLICY_URL = `${API_BASE_URL}/deprecations/migrate_ilm_policy`;

// hacky endpoint: download CSV without queueing a report
export const API_BASE_URL_V1 = '/api/reporting/v1'; //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { i18n } from '@kbn/i18n';
import { DeprecationsDetails, GetDeprecationsContext } from 'src/core/server';
import { API_MIGRATE_ILM_POLICY_URL } from '../../common/constants';
import { ReportingCore } from '../core';

interface ExtraDependencies {
Expand All @@ -19,10 +20,10 @@ export const migrateExistingIndicesIlmPolicy = async (
): Promise<DeprecationsDetails[]> => {
const store = await reportingCore.getStore();
const reportingIlmPolicy = store.getIlmPolicyName();
const reportingIndexPrefix = store.getIndexPrefix();
const indexPattern = store.getReportingIndexPattern();

const { body: reportingIndicesSettings } = await esClient.asInternalUser.indices.getSettings({
index: `${store.getIndexPrefix()}-*`,
index: indexPattern,
});

const someIndicesNotManagedByReportingIlm = Object.values(reportingIndicesSettings).some(
Expand All @@ -34,12 +35,13 @@ export const migrateExistingIndicesIlmPolicy = async (
{
level: 'warning',
message: i18n.translate('xpack.reporting.deprecations.migrateIndexIlmPolicyActionMessage', {
defaultMessage: `Reporting indices can be managed by a provisioned ILM policy, ${reportingIlmPolicy}. This policy should be used to manage the lifecycle of indices. Please note, this action will target all indices prefixed with "${reportingIndexPrefix}-*".`,
defaultMessage: `All new reporting indices will be managed by a provisioned ILM policy: "${reportingIlmPolicy}". To manage the lifecycle of reports edit the ${reportingIlmPolicy} policy. Please note, this action will target all indices prefixed with "${indexPattern}".`,
}),
documentationUrl: 'WIP', // TODO: Fix this!
correctiveActions: {
api: {
method: 'PUT',
path: `${reportingIndexPrefix}-*/_settings`,
path: API_MIGRATE_ILM_POLICY_URL,
body: {
index: {
lifecycle: {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/reporting/server/lib/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export class ReportingStore {
return this.ilmPolicyName;
}

public getIndexPrefix(): string {
return this.indexPrefix;
public getReportingIndexPattern(): string {
return `${this.indexPrefix}-*`;
}
}
50 changes: 50 additions & 0 deletions x-pack/plugins/reporting/server/routes/deprecations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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 { errors } from '@elastic/elasticsearch';
import { API_MIGRATE_ILM_POLICY_URL } from '../../common/constants';
import { ReportingCore } from '../core';
import { LevelLogger as Logger } from '../lib';

export const registerDeprecationsRoutes = (reporting: ReportingCore, logger: Logger) => {
const { router } = reporting.getPluginSetupDeps();

router.put({ path: API_MIGRATE_ILM_POLICY_URL, validate: false }, async (ctx, req, res) => {
const store = await reporting.getStore();
const { asInternalUser: client } = await reporting.getEsClient();

const indexPattern = store.getReportingIndexPattern();
const reportingIlmPolicy = store.getIlmPolicyName();

try {
await client.indices.putSettings({
index: indexPattern,
body: {
index: {
lifecycle: {
name: reportingIlmPolicy,
},
},
},
});
return res.ok();
} catch (err) {
logger.error(err);

if (err instanceof errors.ResponseError) {
return res.customError({
statusCode: 500,
body: {
message: err.message,
name: err.name,
},
});
}

throw err;
}
});
};
6 changes: 4 additions & 2 deletions x-pack/plugins/reporting/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
*/

import { LevelLogger as Logger } from '../lib';
import { registerDeprecationsRoutes } from './deprecations';
import { registerDiagnosticRoutes } from './diagnostic';
import { registerJobGenerationRoutes } from './generation';
import { registerJobInfoRoutes } from './jobs';
import { ReportingCore } from '../core';
import { registerDiagnosticRoutes } from './diagnostic';

export function registerRoutes(reporting: ReportingCore, logger: Logger) {
registerDeprecationsRoutes(reporting, logger);
registerDiagnosticRoutes(reporting, logger);
registerJobGenerationRoutes(reporting, logger);
registerJobInfoRoutes(reporting);
registerDiagnosticRoutes(reporting, logger);
}

export interface ReportingRequestPre {
Expand Down

0 comments on commit d649f56

Please sign in to comment.