Skip to content

Commit

Permalink
Pmm-12710: Api fixes (#763)
Browse files Browse the repository at this point in the history
* Fix scheduled backups deletion

* Fixed restores:start

* Fixed edit scheduled backup page

* Added the type to the locationService

* Fixed the wrong settings payload

* PMM Dump fix

* PMM-12710 Fix updates check

* Fixed the interval for Security Advisors

* Replace restoreId with artefactId

* Fixed prettier

* Fixed PMMDump.tsx prettier

* PMM-12710 Fix backup editing

* PMM-12710 Fix AddBackupPage unit tests

---------

Co-authored-by: Matej Kubinec <[email protected]>
  • Loading branch information
doracretu3pillar and matejkubinec authored Sep 30, 2024
1 parent 89a0db3 commit f551f2b
Show file tree
Hide file tree
Showing 18 changed files with 226 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { Router } from 'react-router-dom';

import { locationService } from '@grafana/runtime';
import { getRouteComponentProps } from 'app/core/navigation/__mocks__/routeProps';
import { wrapWithGrafanaContextMock } from 'app/percona/shared/helpers/testUtils';
import { configureStore } from 'app/store/configureStore';
import { StoreState } from 'app/types';

import { BackupType } from '../../Backup.types';
import { LocationType } from '../StorageLocations/StorageLocations.types';

import AddBackupPage from './AddBackupPage';
Expand All @@ -18,8 +20,8 @@ jest.mock('../BackupInventory/BackupInventory.service');
jest.mock('./AddBackupPage.service');
jest.mock('app/percona/backup/components/StorageLocations/StorageLocations.service');

const AddBackupPageWrapper: FC<PropsWithChildren> = ({ children }) => {
return (
const AddBackupPageWrapper: FC<PropsWithChildren> = ({ children }) =>
wrapWithGrafanaContextMock(
<Provider
store={configureStore({
percona: {
Expand All @@ -46,7 +48,6 @@ const AddBackupPageWrapper: FC<PropsWithChildren> = ({ children }) => {
<Router history={locationService.getHistory()}>{children}</Router>
</Provider>
);
};

describe('AddBackupPage', () => {
it('should render fields', async () => {
Expand Down Expand Up @@ -77,7 +78,7 @@ describe('AddBackupPage', () => {
<AddBackupPageWrapper>
<AddBackupPage
{...getRouteComponentProps({
match: { params: { type: 'scheduled_task_id', id: '' }, isExact: true, path: '', url: '' },
match: { params: { type: BackupType.SCHEDULED, id: '' }, isExact: true, path: '', url: '' },
})}
/>
</AddBackupPageWrapper>
Expand All @@ -94,7 +95,7 @@ describe('AddBackupPage', () => {
<AddBackupPageWrapper>
<AddBackupPage
{...getRouteComponentProps({
match: { params: { type: 'scheduled_task_id', id: '' }, isExact: true, path: '', url: '' },
match: { params: { type: BackupType.SCHEDULED, id: '' }, isExact: true, path: '', url: '' },
})}
/>
</AddBackupPageWrapper>
Expand Down Expand Up @@ -124,7 +125,7 @@ describe('AddBackupPage', () => {
<AddBackupPageWrapper>
<AddBackupPage
{...getRouteComponentProps({
match: { params: { type: 'scheduled_task_id', id: '' }, isExact: true, path: '', url: '' },
match: { params: { type: BackupType.SCHEDULED, id: '' }, isExact: true, path: '', url: '' },
})}
/>
</AddBackupPageWrapper>
Expand Down Expand Up @@ -157,7 +158,7 @@ describe('AddBackupPage', () => {
<AddBackupPageWrapper>
<AddBackupPage
{...getRouteComponentProps({
match: { params: { type: 'scheduled_task_id', id: '' }, isExact: true, path: '', url: '' },
match: { params: { type: BackupType.SCHEDULED, id: '' }, isExact: true, path: '', url: '' },
})}
/>
</AddBackupPageWrapper>
Expand Down
343 changes: 173 additions & 170 deletions public/app/percona/backup/components/AddBackupPage/AddBackupPage.tsx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const BackupInventoryService = {
},
async restore(serviceId: string, artifactId: string, pitrTimestamp?: string, token?: CancelToken) {
return api.post(
`${BASE_URL}/restore:start`,
`${BASE_URL}/restores:start`,
{
service_id: serviceId,
artifact_id: artifactId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export const BackupInventory: FC = () => {

const onBackupClick = (backup: BackupRow | null) => {
if (backup) {
locationService.push(`/backup/${backup.id}/edit`);
locationService.push(`/backup/${backup.type}/${backup.id}/edit`);
} else {
locationService.push(NEW_BACKUP_URL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export const RestoreHistoryService = {
})
);
},
async getLogs(restoreId: string, offset: number, limit: number, cancelToken?: CancelToken): Promise<BackupLogs> {
async getLogs(artefactId: string, offset: number, limit: number, cancelToken?: CancelToken): Promise<BackupLogs> {
const { logs = [], end } = await api.get<BackupLogResponse, { offset: number; limit: number }>(
`${BASE_URL}/${restoreId}/logs`,
`${BASE_URL}/${artefactId}/logs`,
false,
{ cancelToken, params: { offset, limit } }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export const RestoreHistory: FC = () => {

const getLogs = useCallback(
async (startingChunk: number, offset: number, token?: CancelToken) =>
RestoreHistoryService.getLogs(selectedRestore!.id, startingChunk, offset, token),
RestoreHistoryService.getLogs(selectedRestore!.artifactId, startingChunk, offset, token),
[selectedRestore]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ export const ScheduledBackupsService = {
return api.put(`${BASE_URL}:changeScheduled`, { scheduled_backup_id: id, enabled });
},
async delete(id: string) {
return api.delete(`${BASE_URL}/scheduled/${id}`);
return api.delete(`${BASE_URL}/${id}`);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { locationService } from '@grafana/runtime';
import { LinkButton, useStyles } from '@grafana/ui';
import { appEvents } from 'app/core/app_events';
import { Page } from 'app/core/components/Page/Page';
import { BackupType } from 'app/percona/backup/Backup.types';
import { DeleteModal } from 'app/percona/shared/components/Elements/DeleteModal';
import { FeatureLoader } from 'app/percona/shared/components/Elements/FeatureLoader';
import { ExtendedColumn, FilterFieldTypes, Table } from 'app/percona/shared/components/Elements/Table';
Expand Down Expand Up @@ -241,7 +242,7 @@ export const ScheduledBackups: FC = () => {
};

const onEditClick = (backup: ScheduledBackup) => {
locationService.push(`/backup${backup.id}/edit`);
locationService.push(`/backup/${BackupType.SCHEDULED}/${backup.id}/edit`);
};

const getCellProps = useCallback(
Expand Down
10 changes: 5 additions & 5 deletions public/app/percona/check/__mocks__/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const allChecksStub: CheckDetails[] = [
name: 'test1',
summary: 'Test 1',
description: 'Test number 1',
interval: 'STANDARD',
interval: 'ADVISOR_CHECK_INTERVAL_STANDARD',
readMoreUrl: 'https://example.com',
category: '',
family: 'ADVISOR_CHECK_FAMILY_MONGODB',
Expand All @@ -177,15 +177,15 @@ export const allChecksStub: CheckDetails[] = [
name: 'test2',
summary: 'Test 2',
description: 'Test number 2',
interval: 'RARE',
interval: 'ADVISOR_CHECK_INTERVAL_RARE',
category: '',
family: 'ADVISOR_CHECK_FAMILY_MONGODB',
},
{
name: 'test3',
summary: 'Test 3',
description: 'Test number 3',
interval: 'STANDARD',
interval: 'ADVISOR_CHECK_INTERVAL_STANDARD',
disabled: true,
readMoreUrl: 'https://example.com',
category: '',
Expand All @@ -194,15 +194,15 @@ export const allChecksStub: CheckDetails[] = [
{
name: 'test4',
summary: 'Test 4',
interval: 'FREQUENT',
interval: 'ADVISOR_CHECK_INTERVAL_FREQUENT',
category: '',
family: 'ADVISOR_CHECK_FAMILY_MONGODB',
},
{
name: 'test5',
summary: 'Test 5',
disabled: true,
interval: 'STANDARD',
interval: 'ADVISOR_CHECK_INTERVAL_STANDARD',
category: '',
family: 'ADVISOR_CHECK_FAMILY_MONGODB',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const STATUS_OPTIONS: Array<SelectableValue<string>> = [
];
export const INTERVAL_OPTIONS: Array<SelectableValue<Interval | string>> = [
{ value: 'all', label: 'All' },
{ value: Interval.FREQUENT, label: Interval.FREQUENT },
{ value: Interval.STANDARD, label: Interval.STANDARD },
{ value: Interval.RARE, label: Interval.RARE },
{ value: Interval.ADVISOR_CHECK_INTERVAL_FREQUENT, label: Interval.ADVISOR_CHECK_INTERVAL_FREQUENT },
{ value: Interval.ADVISOR_CHECK_INTERVAL_STANDARD, label: Interval.ADVISOR_CHECK_INTERVAL_STANDARD },
{ value: Interval.ADVISOR_CHECK_INTERVAL_RARE, label: Interval.ADVISOR_CHECK_INTERVAL_RARE },
{ value: Interval.ADVISOR_CHECK_INTERVAL_UNSPECIFIED, label: Interval.ADVISOR_CHECK_INTERVAL_UNSPECIFIED },
];
16 changes: 10 additions & 6 deletions public/app/percona/check/components/AllChecksTab/AllChecksTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,20 @@ export const AllChecksTab: FC<GrafanaRouteComponentProps<{ category: string }>>
type: FilterFieldTypes.DROPDOWN,
options: [
{
label: Interval.STANDARD,
value: Interval.STANDARD,
label: Interval.ADVISOR_CHECK_INTERVAL_STANDARD,
value: Interval.ADVISOR_CHECK_INTERVAL_STANDARD,
},
{
label: Interval.RARE,
value: Interval.RARE,
label: Interval.ADVISOR_CHECK_INTERVAL_RARE,
value: Interval.ADVISOR_CHECK_INTERVAL_RARE,
},
{
label: Interval.FREQUENT,
value: Interval.FREQUENT,
label: Interval.ADVISOR_CHECK_INTERVAL_FREQUENT,
value: Interval.ADVISOR_CHECK_INTERVAL_FREQUENT,
},
{
label: Interval.ADVISOR_CHECK_INTERVAL_UNSPECIFIED,
value: Interval.ADVISOR_CHECK_INTERVAL_UNSPECIFIED,
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jest.mock('app/core/app_events', () => {
const TEST_CHECK: CheckDetails = {
summary: 'Test',
name: 'test',
interval: 'STANDARD',
interval: 'ADVISOR_CHECK_INTERVAL_STANDARD',
description: 'test description',
disabled: false,
category: '',
Expand Down
7 changes: 4 additions & 3 deletions public/app/percona/check/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ export enum AlertState {
}

export enum Interval {
STANDARD = 'Standard',
RARE = 'Rare',
FREQUENT = 'Frequent',
ADVISOR_CHECK_INTERVAL_STANDARD = 'Standard',
ADVISOR_CHECK_INTERVAL_RARE = 'Rare',
ADVISOR_CHECK_INTERVAL_FREQUENT = 'Frequent',
ADVISOR_CHECK_INTERVAL_UNSPECIFIED = 'Unspecified',
}

export interface CheckDetails {
Expand Down
10 changes: 7 additions & 3 deletions public/app/percona/pmm-dump/PMMDump.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { DumpStatus, DumpStatusColor, DumpStatusText, PMMDumpServices } from 'ap
import { DetailsRow } from 'app/percona/shared/components/Elements/DetailsRow/DetailsRow';
import { Action } from 'app/percona/shared/components/Elements/MultipleActions';
import { ExtendedColumn, FilterFieldTypes, Table } from 'app/percona/shared/components/Elements/Table';
import { usePerconaNavModel } from 'app/percona/shared/components/hooks/perconaNavModel';
import { PMM_DUMP_PAGE } from 'app/percona/shared/components/PerconaBootstrapper/PerconaNavigation';
import {
deletePmmDumpAction,
downloadPmmDumpAction,
Expand Down Expand Up @@ -44,7 +44,6 @@ export const PMMDump = () => {
const [selectedDump, setSelectedDump] = useState<PMMDumpServices | null>(null);
const [isSendToSupportModalOpened, setIsSendToSupportModalOpened] = useState(false);
const [logsModalVisible, setLogsModalVisible] = useState(false);
const navModel = usePerconaNavModel('pmm-dump');

const loadData = useCallback(async () => {
try {
Expand Down Expand Up @@ -280,7 +279,12 @@ export const PMMDump = () => {
);

return (
<Page navId="pmmdump" navModel={navModel}>
<Page
navModel={{
main: PMM_DUMP_PAGE,
node: PMM_DUMP_PAGE,
}}
>
<Page.Contents>
<div className={styles.createDatasetArea}>
{selectedRows.length > 0 ? (
Expand Down
2 changes: 1 addition & 1 deletion public/app/percona/settings/Settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const SettingsService = {

const toModel = (response: SettingsPayload): Settings => ({
awsPartitions: response.aws_partitions.values,
updatesEnabled: response.enable_updates,
updatesEnabled: response.updates_enabled,
telemetryEnabled: response.telemetry_enabled,
telemetrySummaries: response.telemetry_summaries || [],
metricsResolutions: response.metrics_resolutions,
Expand Down
2 changes: 1 addition & 1 deletion public/app/percona/settings/Settings.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export interface SettingsPayload
values: string[];
};
platform_email: string;
enable_updates: boolean;
updates_enabled: boolean;
telemetry_enabled: boolean;
advisor_enabled: boolean;
alerting_enabled: boolean;
Expand Down
6 changes: 3 additions & 3 deletions public/app/percona/shared/services/updates/Updates.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { api } from '../../helpers/api';

import { CheckUpdatesBody, CheckUpdatesResponse } from './Updates.types';
import { CheckUpdatesParams, CheckUpdatesResponse } from './Updates.types';

export const UpdatesService = {
getCurrentVersion: (body: CheckUpdatesBody = { force: false }) =>
api.post<CheckUpdatesResponse, CheckUpdatesBody>('/v1/Updates/Check', body, true),
getCurrentVersion: (params: CheckUpdatesParams = { force: false }) =>
api.get<CheckUpdatesResponse, CheckUpdatesParams>('/v1/server/updates', true, { params }),
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface CheckUpdatesBody {
export interface CheckUpdatesParams {
force: boolean;
only_installed_version?: boolean;
}
Expand Down

0 comments on commit f551f2b

Please sign in to comment.