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

[Reporting] New UI for migrating reporting indices ILM policy #103853

Merged
merged 18 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3f56f07
revert revert
jloleysens Jun 29, 2021
68b9d19
wip; first iteration of server-side functionality
jloleysens Jun 14, 2021
73d0972
wip; public side code started. using the new ilm policy status endpoint
jloleysens Jun 14, 2021
3a8b218
* refactored ReportingIlmPolicyManager -> IlmReportingManager
jloleysens Jun 28, 2021
ad145c8
added the ability to use useRequest
jloleysens Jun 28, 2021
df25813
* removed extra server-side endpoint, we do both migration steps
jloleysens Jun 28, 2021
4abd092
added working link to ILM policy
jloleysens Jun 29, 2021
93c5c03
refactor of the migration route response (again), added logic for det…
jloleysens Jun 29, 2021
ee87c68
fix type issues and refactor to use testbed pattern for report listin…
jloleysens Jun 29, 2021
bbda9f9
added tests for base cases of ilm policy banner
jloleysens Jun 29, 2021
619f315
Merge branch 'master' into reporting/ilm-policy-2
kibanamachine Jun 30, 2021
7f4b518
remove non-existent prop
jloleysens Jun 30, 2021
508c947
added minor fixes (handling 404 from ES) and added API integration tests
jloleysens Jun 30, 2021
3797167
Merge branch 'master' of github.com:elastic/kibana into reporting/ilm…
jloleysens Jun 30, 2021
3579254
resolve merge conflict and remove unused file
jloleysens Jul 1, 2021
9ab2f28
Merge branch 'master' into reporting/ilm-policy-2
kibanamachine Jul 1, 2021
4b26074
Merge branch 'master' into reporting/ilm-policy-2
kibanamachine Jul 5, 2021
9c2773b
update toast error message
jloleysens Jul 5, 2021
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
6 changes: 6 additions & 0 deletions x-pack/plugins/reporting/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ 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_GET_ILM_POLICY_STATUS = `${API_BASE_URL}/ilm_policy_status`;
export const API_CREATE_ILM_POLICY_URL = `${API_BASE_URL}/ilm_policy`;
export const API_MIGRATE_ILM_POLICY_URL = `${API_BASE_URL}/deprecations/migrate_ilm_policy`;

export const ILM_POLICY_NAME = 'kibana-reporting';

// hacky endpoint: download CSV without queueing a report
export const API_BASE_URL_V1 = '/api/reporting/v1'; //
export const API_GENERATE_IMMEDIATE = `${API_BASE_URL_V1}/generate/immediate/csv_searchsource`;
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/reporting/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,9 @@ export type DownloadReportFn = (jobId: JobId) => DownloadLink;

type ManagementLink = string;
export type ManagementLinkFn = () => ManagementLink;

export type IlmPolicyMigrationStatus = 'policy-not-found' | 'indices-not-managed-by-policy' | 'ok';

export interface IlmPolicyStatusResponse {
status: IlmPolicyMigrationStatus;
}
1 change: 1 addition & 0 deletions x-pack/plugins/reporting/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"configPath": ["xpack", "reporting"],
"requiredPlugins": [
"data",
"esUiShared",
"home",
"management",
"licensing",
Expand Down
43 changes: 43 additions & 0 deletions x-pack/plugins/reporting/public/lib/ilm_policy_status_context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 type { FunctionComponent } from 'react';
import React, { createContext, useContext } from 'react';

import { IlmPolicyStatusResponse } from '../../common/types';

import { useCheckIlmPolicyStatus } from './reporting_api_client';

type UseCheckIlmPolicyStatus = ReturnType<typeof useCheckIlmPolicyStatus>;

interface ContextValue {
status: undefined | IlmPolicyStatusResponse['status'];
isLoading: UseCheckIlmPolicyStatus['isLoading'];
recheckStatus: UseCheckIlmPolicyStatus['resendRequest'];
}

const IlmPolicyStatusContext = createContext<undefined | ContextValue>(undefined);

export const IlmPolicyStatusContextProvider: FunctionComponent = ({ children }) => {
const { isLoading, data, resendRequest: recheckStatus } = useCheckIlmPolicyStatus();

return (
<IlmPolicyStatusContext.Provider value={{ isLoading, status: data?.status, recheckStatus }}>
{children}
</IlmPolicyStatusContext.Provider>
);
};

export type UseIlmPolicyStatusReturn = ReturnType<typeof useIlmPolicyStatus>;

export const useIlmPolicyStatus = (): ContextValue => {
const ctx = useContext(IlmPolicyStatusContext);
if (!ctx) {
throw new Error('"useIlmPolicyStatus" can only be used inside of "IlmPolicyStatusContext"');
}
return ctx;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 type { HttpSetup } from 'src/core/public';
import type { FunctionComponent } from 'react';
import React, { createContext, useContext } from 'react';

import type { ReportingAPIClient } from './reporting_api_client';

interface ContextValue {
http: HttpSetup;
apiClient: ReportingAPIClient;
}

const InternalApiClientContext = createContext<undefined | ContextValue>(undefined);

export const InternalApiClientClientProvider: FunctionComponent<{
http: HttpSetup;
apiClient: ReportingAPIClient;
}> = ({ http, apiClient, children }) => {
return (
<InternalApiClientContext.Provider value={{ http, apiClient }}>
{children}
</InternalApiClientContext.Provider>
);
};

export const useInternalApiClient = (): ContextValue => {
const ctx = useContext(InternalApiClientContext);
if (!ctx) {
throw new Error('"useInternalApiClient" can only be used inside of "InternalApiClientContext"');
}
return ctx;
};
18 changes: 18 additions & 0 deletions x-pack/plugins/reporting/public/lib/reporting_api_client/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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 { useRequest, UseRequestResponse } from '../../shared_imports';
import { IlmPolicyStatusResponse } from '../../../common/types';

import { API_GET_ILM_POLICY_STATUS } from '../../../common/constants';

import { useInternalApiClient } from './context';

export const useCheckIlmPolicyStatus = (): UseRequestResponse<IlmPolicyStatusResponse> => {
const { http } = useInternalApiClient();
return useRequest(http, { path: API_GET_ILM_POLICY_STATUS, method: 'get' });
};
12 changes: 12 additions & 0 deletions x-pack/plugins/reporting/public/lib/reporting_api_client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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.
*/

export * from './reporting_api_client';

export * from './hooks';

export { InternalApiClientClientProvider, useInternalApiClient } from './context';
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ import {
API_BASE_GENERATE,
API_BASE_URL,
API_LIST_URL,
API_MIGRATE_ILM_POLICY_URL,
REPORTING_MANAGEMENT_HOME,
} from '../../common/constants';
} from '../../../common/constants';
import {
DownloadReportFn,
JobId,
ManagementLinkFn,
ReportApiJSON,
ReportDocument,
ReportSource,
} from '../../common/types';
import { add } from '../notifier/job_completion_notifications';
} from '../../../common/types';
import { add } from '../../notifier/job_completion_notifications';

export interface JobQueueEntry {
_id: string;
Expand Down Expand Up @@ -167,4 +168,8 @@ export class ReportingAPIClient {
this.http.post(`${API_BASE_URL}/diagnose/screenshot`, {
asSystemRequest: true,
});

public migrateReportingIndicesIlmPolicy = (): Promise<void> => {
return this.http.put(`${API_MIGRATE_ILM_POLICY_URL}`);
};
}
Loading
Loading