Skip to content

Commit

Permalink
PMM-12710: Api Breaking Changes (#742)
Browse files Browse the repository at this point in the history
* Actions, Services , Agents, Nodes Apis changes

* Update ServicesService

* Backups, Alerting, User services api updates

* ScheduledBakups, BackupInventory, Backup service

* LocationsService api changes

* RoleService, DumpsService, RestoreHistoryService api changes

* PlatformService api changes

* Nodes, Agents , CheckService API changes

* Modified ChangeScheduled api

* Platform, Entitlements service API

* Management services APIs

* Discover services APIs

* Typescript fixes

* PMM-12710 Extend api helper

* PMM-12710 Reintroduce cancel token

* PMM-12710 Update settings api calls

* PMM-12710 Use correct url for backups

* PMM-12710 Fix & ajdust inventory api connections

* PMM-12710 Fix advisors

* PMM-12710 Update service types

* PMM-12710 Update PT Summary

* PMM-12710 Refactor query parameters

* PMM-12710 Update betterer file

* PMM-12710 Correctly handle custom labels edit

* PMM-12710 Update betterrer results

* PMM-12710 Update ignore files

* Fixed backups api call

* Fix after PR review

* Fixed prettier

* Fixed tests

* Fixed prettier

* Fixed test in AddRemoteInstance.service.test

* Fixed after review

* Removed the body from InventoryService

* Added payload back to the AlertRule list API

* Force true to removeNode

* PMM-12710 Remove identifier prefixes

* PMM-12710 run prettier

* Fixed payload for AlertRuleTemplate and Check services

* PMM-12710 Remove redundant variable

* Fixed APIs after testing

* Fixed prettier

* Added force to Service services

* Fixed error message banner

* Revert changes

* Fixed error message banner

* Modify the backup mode enum

* Fixed DataModel enum

* Check if axios is cancel, don't show the error

---------

Co-authored-by: Matej Kubinec <[email protected]>
Co-authored-by: Yash Sartanpara <[email protected]>
  • Loading branch information
3 people authored Jul 18, 2024
1 parent 6dedda3 commit fe75a73
Show file tree
Hide file tree
Showing 74 changed files with 508 additions and 594 deletions.
6 changes: 6 additions & 0 deletions .betterer.results.json
Original file line number Diff line number Diff line change
Expand Up @@ -5366,6 +5366,12 @@
"count": 1
}
],
"/public/app/percona/integrated-alerting/components/TemplateForm/EvaluateEvery/EvaluateEvery.styles.ts": [
{
"message": "Styles should be written using objects.",
"count": 1
}
],
"/public/app/plugins/datasource/alertmanager/DataSource.ts": [
{
"message": "Unexpected any. Specify a different type.",
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,6 @@ public/app/plugins/**/dist/
# Ignore transpiled JavaScript resulting from the generate-transformations.ts script.
/public/app/features/transformers/docs/*.js
/scripts/docs/generate-transformations.js

# NX
.nx/cache
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.nx
.git
.github
.yarn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('AddRemoteInstanceService:: ', () => {
},
add_node: {
node_name: 'localhost',
node_type: 'REMOTE_NODE',
node_type: 'NODE_TYPE_REMOTE_NODE',
},
listen_port: '80',
metrics_mode: 1,
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('AddRemoteInstanceService:: ', () => {
},
add_node: {
node_name: 'localhost',
node_type: 'REMOTE_NODE',
node_type: 'NODE_TYPE_REMOTE_NODE',
},
pmm_agent_id: 'pmm-server',
port: '80',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,69 +24,67 @@ import {
HaProxyPayload,
ProxySQLPayload,
MongoDBPayload,
AddServicePayload,
} from './AddRemoteInstance.types';

const BASE_URL = '/services';

class AddRemoteInstanceService {
static async addMysql(body: MySQLPayload, token?: CancelToken) {
return apiManagement.post<MySQLInstanceResponse | ErrorResponse, RemoteInstancePayload>(
'/MySQL/Add',
body,
return apiManagement.post<MySQLInstanceResponse | ErrorResponse, AddServicePayload>(
BASE_URL,
{ mysql: body },
false,
token
);
}

static async addPostgresql(body: PostgreSQLPayload, token?: CancelToken) {
return apiManagement.post<PostgreSQLInstanceResponse | ErrorResponse, RemoteInstancePayload>(
'/PostgreSQL/Add',
body,
return apiManagement.post<PostgreSQLInstanceResponse | ErrorResponse, AddServicePayload>(
BASE_URL,
{ postgresql: body },
false,
token
);
}

static async addProxysql(body: ProxySQLPayload, token?: CancelToken) {
return apiManagement.post<ProxySQLInstanceResponse | ErrorResponse, RemoteInstancePayload>(
'/ProxySQL/Add',
body,
return apiManagement.post<ProxySQLInstanceResponse | ErrorResponse, AddServicePayload>(
BASE_URL,
{ proxysql: body },
false,
token
);
}

static async addHaproxy(body: HaProxyPayload, token?: CancelToken) {
return apiManagement.post<AddHaProxyResponse | ErrorResponse, RemoteInstancePayload>(
'/HAProxy/Add',
body,
return apiManagement.post<AddHaProxyResponse | ErrorResponse, AddServicePayload>(
BASE_URL,
{ haproxy: body },
false,
token
);
}

static async addMongodb(body: MongoDBPayload, token?: CancelToken) {
return apiManagement.post<AddMongoDbResponse | ErrorResponse, RemoteInstancePayload>(
'/MongoDB/Add',
body,
return apiManagement.post<AddMongoDbResponse | ErrorResponse, AddServicePayload>(
BASE_URL,
{ mongodb: body },
false,
token
);
}

static async addRDS(body: RDSPayload, token?: CancelToken) {
return apiManagement.post<AddRDSResponse | ErrorResponse, RemoteInstancePayload>('/RDS/Add', body, false, token);
return apiManagement.post<AddRDSResponse | ErrorResponse, AddServicePayload>(BASE_URL, { rds: body }, false, token);
}

static async addAzure(body: MSAzurePayload, token?: CancelToken) {
return apiManagement.post<{} | ErrorResponse, RemoteInstancePayload>(
'/azure/AzureDatabase/Add',
body,
false,
token
);
return apiManagement.post<{} | ErrorResponse, RemoteInstancePayload>(`${BASE_URL}/azure`, body, false, token);
}

static async addExternal(body: ExternalPayload, token?: CancelToken) {
return apiManagement.post<AddExternalResponse, ExternalPayload>('/External/Add', body, false, token);
return apiManagement.post<AddExternalResponse, AddServicePayload>(BASE_URL, { external: body }, false, token);
}

static addRemote(type: InstanceAvailableType, data: RemoteInstancePayload, token?: CancelToken) {
Expand Down Expand Up @@ -147,7 +145,7 @@ export const toPayload = (values: any, discoverName?: string, type?: InstanceAva
if (!values.isAzure && data.add_node === undefined) {
data.add_node = {
node_name: data.service_name,
node_type: 'REMOTE_NODE',
node_type: 'NODE_TYPE_REMOTE_NODE',
};
}

Expand Down Expand Up @@ -214,7 +212,7 @@ export const toExternalServicePayload = (values: any): ExternalPayload => {
if (data.add_node === undefined) {
data.add_node = {
node_name: data.service_name,
node_type: 'REMOTE_NODE',
node_type: 'NODE_TYPE_REMOTE_NODE',
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Databases } from 'app/percona/shared/core';

import { DiscoverRDSEngine } from '../Discovery/Discovery.types';

import { getInstanceData } from './AddRemoteInstance.tools';

describe('Get instance data:: ', () => {
Expand Down Expand Up @@ -41,7 +43,7 @@ describe('Get instance data:: ', () => {
};
const testInstance = {
instanceType: 'PostgreSQL',
discoverName: 'DISCOVER_RDS_POSTGRESQL',
discoverName: DiscoverRDSEngine.POSTGRESQL,
remoteInstanceCredentials: {
isRDS: true,
address: 'test address',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Databases } from 'app/percona/shared/core';
import { logger } from 'app/percona/shared/helpers/logger';

import { InstanceAvailableType, INSTANCE_TYPES_LABELS } from '../../panel.types';
import { DiscoverAzureDatabaseType, DiscoverRDSEngine } from '../Discovery/Discovery.types';

import { DEFAULT_PORTS } from './AddRemoteInstance.constants';
import { InstanceData } from './AddRemoteInstance.types';
Expand Down Expand Up @@ -31,19 +32,19 @@ const getAzureCredentials = (credentials: any, instanceType: string) => {
switch (instanceType) {
case Databases.postgresql:
instance.instanceType = INSTANCE_TYPES_LABELS[Databases.postgresql];
instance.discoverName = 'DISCOVER_AZURE_DATABASE_TYPE_POSTGRESQL';
instance.discoverName = DiscoverAzureDatabaseType.POSTGRESQL;
instance.remoteInstanceCredentials.port =
instance.remoteInstanceCredentials.port || DEFAULT_PORTS[Databases.postgresql];
break;
case Databases.mysql:
instance.instanceType = INSTANCE_TYPES_LABELS[Databases.mysql];
instance.discoverName = 'DISCOVER_AZURE_DATABASE_TYPE_MYSQL';
instance.discoverName = DiscoverAzureDatabaseType.MYSQL;
instance.remoteInstanceCredentials.port =
instance.remoteInstanceCredentials.port || DEFAULT_PORTS[Databases.mysql];
break;
case Databases.mariadb:
instance.instanceType = INSTANCE_TYPES_LABELS[Databases.mariadb];
instance.discoverName = 'DISCOVER_AZURE_DATABASE_TYPE_MARIADB';
instance.discoverName = DiscoverAzureDatabaseType.MARIADB;
instance.remoteInstanceCredentials.port =
instance.remoteInstanceCredentials.port || DEFAULT_PORTS[Databases.mysql];
break;
Expand Down Expand Up @@ -72,13 +73,13 @@ const getRDSCredentials = (credentials: any, instanceType: InstanceAvailableType
switch (instanceType) {
case Databases.postgresql:
instance.instanceType = INSTANCE_TYPES_LABELS[Databases.postgresql];
instance.discoverName = 'DISCOVER_RDS_POSTGRESQL';
instance.discoverName = DiscoverRDSEngine.POSTGRESQL;
instance.remoteInstanceCredentials.port =
instance.remoteInstanceCredentials.port || DEFAULT_PORTS[Databases.postgresql];
break;
case Databases.mysql:
instance.instanceType = INSTANCE_TYPES_LABELS[Databases.mysql];
instance.discoverName = 'DISCOVER_RDS_MYSQL';
instance.discoverName = DiscoverRDSEngine.MYSQL;
instance.remoteInstanceCredentials.port =
instance.remoteInstanceCredentials.port || DEFAULT_PORTS[Databases.mysql];
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ export type RemoteInstancePayload =
| MongoDBPayload
| ExternalPayload;

export type AddServicePayload = {
mysql?: MySQLPayload;
mongodb?: MongoDBPayload;
postgresql?: PostgreSQLPayload;
proxysql?: ProxySQLPayload;
haproxy?: HaProxyPayload;
external?: ExternalPayload;
rds?: RDSPayload;
};

export interface ErrorResponse {
error: string;
code: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DiscoveryService {
token?: CancelToken
) {
return apiManagement.post<AzureDatabaseInstances, AzureCredentialsForm>(
'/azure/AzureDatabase/Discover',
'/services:discoverAzure',
{
azure_client_id,
azure_client_secret,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Button } from '@grafana/ui';
import { InstanceAvailableType, SelectInstance } from 'app/percona/add-instance/panel.types';
import { DATABASE_LABELS, Databases } from 'app/percona/shared/core';

import { DiscoverAzureDatabaseType } from '../../../Discovery/Discovery.types';
import { Instance } from '../../Discovery.types';
import { AzureCredentialsForm } from '../Credentials/Credentials.types';

Expand All @@ -13,13 +14,13 @@ import { styles } from './Instances.styles';

const getEngineType = (type?: string) => {
switch (type) {
case 'DISCOVER_AZURE_DATABASE_TYPE_MYSQL':
case DiscoverAzureDatabaseType.MYSQL:
return DATABASE_LABELS[Databases.mysql];
case 'DISCOVER_AZURE_DATABASE_TYPE_MARIADB':
case DiscoverAzureDatabaseType.MARIADB:
return DATABASE_LABELS[Databases.mariadb];
case 'DISCOVER_AZURE_DATABASE_TYPE_POSTGRESQL':
case DiscoverAzureDatabaseType.POSTGRESQL:
return DATABASE_LABELS[Databases.postgresql];
case 'DISCOVER_AZURE_DATABASE_INVALID':
case DiscoverAzureDatabaseType.INVALID:
return 'Unknown type';
default:
return 'Unknown type';
Expand All @@ -28,10 +29,10 @@ const getEngineType = (type?: string) => {

const getDatabaseType = (type?: string): InstanceAvailableType => {
switch (type) {
case 'DISCOVER_AZURE_DATABASE_TYPE_MYSQL':
case 'DISCOVER_AZURE_DATABASE_TYPE_MARIADB':
case DiscoverAzureDatabaseType.MYSQL:
case DiscoverAzureDatabaseType.MARIADB:
return Databases.mysql;
case 'DISCOVER_AZURE_DATABASE_TYPE_POSTGRESQL':
case DiscoverAzureDatabaseType.POSTGRESQL:
return Databases.postgresql;
default:
return '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DiscoveryService {
) {
return apiManagement
.post<RDSInstances, RDSCredentialsForm>(
'/RDS/Discover',
'/services:discoverRDS',
{
aws_access_key,
aws_secret_key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,16 @@ export interface Instance {
export interface RDSInstances {
rds_instances: Instance[];
}

export enum DiscoverRDSEngine {
POSTGRESQL = 'DISCOVER_RDS_ENGINE_POSTGRESQL',
MYSQL = 'DISCOVER_RDS_ENGINE_MYSQL',
UNSPECIFIED = 'DISCOVER_RDS_ENGINE_UNSPECIFIED',
}

export enum DiscoverAzureDatabaseType {
POSTGRESQL = 'DISCOVER_AZURE_DATABASE_TYPE_POSTGRESQL',
MYSQL = 'DISCOVER_AZURE_DATABASE_TYPE_MYSQL',
MARIADB = 'DISCOVER_AZURE_DATABASE_TYPE_MARIADB',
INVALID = 'DISCOVER_AZURE_DATABASE_INVALID',
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import { Button } from '@grafana/ui';
import { SelectInstance } from 'app/percona/add-instance/panel.types';
import { DATABASE_LABELS, Databases } from 'app/percona/shared/core';

import { Instance } from '../../Discovery.types';
import { DiscoverRDSEngine, Instance } from '../../Discovery.types';
import { RDSCredentialsForm } from '../Credentials/Credentials.types';

import { styles } from './Instances.styles';

const getEngineType = (type?: string) => {
switch (type) {
case 'DISCOVER_RDS_MYSQL':
case DiscoverRDSEngine.MYSQL:
return DATABASE_LABELS[Databases.mysql];
case 'DISCOVER_RDS_POSTGRESQL':
case DiscoverRDSEngine.POSTGRESQL:
return DATABASE_LABELS[Databases.postgresql];
case 'DISCOVER_RDS_INVALID':
case DiscoverRDSEngine.UNSPECIFIED:
return 'Unknown type';
default:
return 'Unknown type';
Expand All @@ -25,9 +25,9 @@ const getEngineType = (type?: string) => {

const getDatabaseType = (type?: string) => {
switch (type) {
case 'DISCOVER_RDS_MYSQL':
case DiscoverRDSEngine.MYSQL:
return Databases.mysql;
case 'DISCOVER_RDS_POSTGRESQL':
case DiscoverRDSEngine.POSTGRESQL:
return Databases.postgresql;
default:
return '';
Expand Down
8 changes: 4 additions & 4 deletions public/app/percona/backup/Backup.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getCronStringFromValues } from '../shared/helpers/cron/cron';
import { BackupMode, BackupType, DataModel, RetryMode } from './Backup.types';
import { AddBackupFormProps } from './components/AddBackupPage/AddBackupPage.types';

const BASE_URL = '/v1/management/backup/Backups';
const BASE_URL = '/v1/backups';

export const BackupService = {
backup(values: AddBackupFormProps, token?: CancelToken) {
Expand Down Expand Up @@ -98,7 +98,7 @@ export const BackupService = {
token?: CancelToken
) {
return api.post(
`${BASE_URL}/Start`,
`${BASE_URL}:start`,
{
service_id: serviceId,
location_id: locationId,
Expand Down Expand Up @@ -127,7 +127,7 @@ export const BackupService = {
dataModel: DataModel,
folder: string
) {
return api.post(`${BASE_URL}/Schedule`, {
return api.post(`${BASE_URL}:schedule`, {
service_id: serviceId,
location_id: locationId,
cron_expression: cronExpression,
Expand All @@ -152,7 +152,7 @@ export const BackupService = {
retryTimes: number,
retention: number
) {
return api.post(`${BASE_URL}/ChangeScheduled`, {
return api.put(`${BASE_URL}:changeScheduled`, {
scheduled_backup_id: id,
enabled,
cron_expression: cronExpression,
Expand Down
Loading

0 comments on commit fe75a73

Please sign in to comment.