Skip to content

Commit

Permalink
[Reporting] New UI for migrating reporting indices ILM policy (#103853)
Browse files Browse the repository at this point in the history
* revert revert

* wip; first iteration of server-side functionality

* wip; public side code started. using the new ilm policy status endpoint

* * refactored ReportingIlmPolicyManager -> IlmReportingManager
* restructured files for the policy manager code
* re-added the IlmPolicyStatusResponse interface

* added the ability to use useRequest

* * removed extra server-side endpoint, we do both migration steps
  in one
* added ilm policy context and context for api client
* added es ui shared so we can use userequest

* added working link to ILM policy

* refactor of the migration route response (again), added logic for determining when to show ilm-policy link

* fix type issues and refactor to use testbed pattern for report listing component

* added tests for base cases of ilm policy banner

* remove non-existent prop

* added minor fixes (handling 404 from ES) and added API integration tests

* resolve merge conflict and remove unused file

* update toast error message

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
jloleysens and kibanamachine authored Jul 5, 2021
1 parent 8d84c2f commit 4c448c9
Show file tree
Hide file tree
Showing 31 changed files with 11,129 additions and 756 deletions.
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

0 comments on commit 4c448c9

Please sign in to comment.