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

PMM-12710: API breaking changes #1594

Merged
merged 14 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getExample = async ({
tables,
};

return apiRequestQAN.post<QueryExampleResponse, any>('/ObjectDetails/GetQueryExample', data);
return apiRequestQAN.post<QueryExampleResponse, any>('/query:getExample', data);
};

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const fetchExplains = async (
};

const [classicResult, jsonResult] = await Promise.all([
mysqlMethods.getExplainTraditional(payload).then(getActionResult),
mysqlMethods.getExplain(payload).then(getActionResult),
mysqlMethods.getExplainJSON(payload).then(getActionResult),
]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { apiRequestQAN } from 'shared/components/helpers/api';
import { apiRequest } from 'shared/components/helpers/api';
import { getLabelQueryParams } from 'pmm-qan/panel/QueryAnalytics.tools';
import { HistogramRequest, HistogramResponse } from './Metrics.types';

Expand All @@ -15,7 +15,7 @@ export const getMetrics = async ({
totals,
};

return apiRequestQAN.post<any, any>('/ObjectDetails/GetMetrics', body);
return apiRequest.post<any, any>('/v1/qan:getMetrics', body);
};

export const getHistogram = async ({
Expand All @@ -28,7 +28,7 @@ export const getHistogram = async ({
period_start_to: to,
};

return apiRequestQAN.post<HistogramResponse, HistogramRequest>('/ObjectDetails/GetHistogram', body);
return apiRequest.post<HistogramResponse, HistogramRequest>('/v1/qan:getHistogram', body);
};

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const PlanService = {
};

return apiRequestQAN
.post<QueryPlanResponse, QueryPlanRequest>('/ObjectDetails/GetQueryPlan', body)
.get<QueryPlanResponse, QueryPlanRequest>(`/query/${body.queryid}/plan`)
.then(({ planid, query_plan }) => (
planid && query_plan ? { id: planid, plan: query_plan } : undefined
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const mongodbMethods = {
query: example.example,
});

return result.action_id;
return result.mongodb_explain.action_id;
} catch (e) {
console.error(e);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { apiRequestManagement } from 'shared/components/helpers/api';
import { apiRequest } from 'shared/components/helpers/api';

export default {
getTraditionalExplainJSONMongo(body) {
return apiRequestManagement.post<any, any>('/Actions/StartMongoDBExplain', body);
const requestBody = { mongodb_explain: body };

return apiRequest.post<any, any>('/v1/actions:startServiceAction', requestBody);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const mysqlMethods = {
service_id: example.service_id,
});

return result.action_id;
return result.mysql_show_create_table.action_id;
},

getIndexes: async ({ example, tableName, database }) => {
Expand All @@ -27,7 +27,7 @@ export const mysqlMethods = {
service_id: example.service_id,
});

return result.action_id;
return result.mysql_show_index.action_id;
},

getStatuses: async ({ example, tableName, database }) => {
Expand All @@ -41,30 +41,30 @@ export const mysqlMethods = {
service_id: example.service_id,
});

return result.action_id;
return result.mysql_show_table_status.action_id;
},

getExplainJSON: async ({ example, queryId, placeholders }) => {
try {
const payload = getExplainPayload(example, queryId, placeholders);

const result = await MysqlDatabaseService.getTraditionalExplainJSONMysql(payload);
const result = await MysqlDatabaseService.getExplainJSON(payload);

return result.action_id;
return result.mysql_explain_json.action_id;
} catch (e) {
console.error(e);

return null;
}
},

getExplainTraditional: async ({ example, queryId, placeholders }) => {
getExplain: async ({ example, queryId, placeholders }) => {
try {
const payload = getExplainPayload(example, queryId, placeholders);

const result = await MysqlDatabaseService.getTraditionalExplainMysql(payload);
const result = await MysqlDatabaseService.getExplain(payload);

return result.action_id;
return result.mysql_explain.action_id;
} catch (e) {
console.error(e);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import { apiRequestManagement } from 'shared/components/helpers/api';
import { apiRequest } from 'shared/components/helpers/api';

export default {
getShowCreateTableMySQL(body) {
return apiRequestManagement.post<any, any>('/Actions/StartMySQLShowCreateTable', body);
matejkubinec marked this conversation as resolved.
Show resolved Hide resolved
const requestBody = { mysql_show_create_table: body };

return apiRequest.post<any, any>('/v1/actions:startServiceAction', requestBody);
},

getMysqlTableStatus(body) {
return apiRequestManagement.post<any, any>('/Actions/StartMySQLShowTableStatus', body);
const requestBody = { mysql_show_table_status: body };

return apiRequest.post<any, any>('/v1/actions:startServiceAction', requestBody);
},

getMysqlIndex(body) {
return apiRequestManagement.post<any, any>('/Actions/StartMySQLShowIndex', body);
const requestBody = { mysql_show_index: body };

return apiRequest.post<any, any>('/v1/actions:startServiceAction', requestBody);
},

getTraditionalExplainJSONMysql(body) {
return apiRequestManagement.post<any, any>('/Actions/StartMySQLExplainJSON', body);
getExplainJSON(body) {
const requestBody = { mysql_explain_json: body };

return apiRequest.post<any, any>('/v1/actions:startServiceAction', requestBody);
},

getTraditionalExplainMysql(body) {
return apiRequestManagement.post<any, any>('/Actions/StartMySQLExplain', body);
getExplain(body) {
const requestBody = { mysql_explain: body };

return apiRequest.post<any, any>('/v1/actions:startServiceAction', requestBody);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const postgresqlMethods = {
database,
});

return result.action_id;
return result.postgresql_show_create_table.action_id;
},
getIndexes: async ({ example, tableName, database }) => {
if (!tableName) {
Expand All @@ -25,6 +25,6 @@ export const postgresqlMethods = {
database,
});

return result.action_id;
return result.postgresql_show_index.action_id;
},
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { apiRequestManagement } from 'shared/components/helpers/api';
import { apiRequest } from 'shared/components/helpers/api';

export default {
getPostgreSQLIndex(body) {
return apiRequestManagement.post<any, any>('/Actions/StartPostgreSQLShowIndex', body);
const requestBody = { postgres_show_index: body };

return apiRequest.post<any, any>('/v1/actions:startServiceAction', requestBody);
},
getShowCreateTablePostgreSQL(body) {
return apiRequestManagement.post<any, any>('/Actions/StartPostgreSQLShowCreateTable', body);
const requestBody = { postgres_show_create_table: body };

return apiRequest.post<any, any>('/v1/actions:startServiceAction', requestBody);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const markCheckedLabels = (labels, paramLabels) => {

export default {
getQueryOverviewFiltersList: async (paramLabels, from, to, mainMetric) => {
const { labels } = await apiRequestQAN.post<any, any>('/Filters/Get', {
const { labels } = await apiRequestQAN.post<any, any>('/metrics:getFilters', {
labels: getLabelQueryParams(paramLabels),
main_metric_name: mainMetric,
period_start_from: from,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export default {
search: body.dimensionSearchText,
};

return apiRequestQAN.post<any, any>('/GetReport', request);
return apiRequestQAN.post<any, any>('/metrics:getReport', request);
},
};
4 changes: 2 additions & 2 deletions pmm-app/src/shared/components/Actions/Actions.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { apiRequestManagement } from '../helpers/api';
import { apiRequest } from '../helpers/api';
import { ActionRequest, ActionResponse } from './Actions.types';

export const ActionsService = {
getActionResult(body: ActionRequest): Promise<ActionResponse> {
return apiRequestManagement.post<any, any>('/Actions/Get', body);
return apiRequest.get<any, any>(`/v1/actions/${body.action_id}`);
},
};
2 changes: 1 addition & 1 deletion pmm-app/src/shared/components/helpers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class ApiRequest {
}

export const apiRequest = new ApiRequest({});
export const apiRequestQAN = new ApiRequest({ baseURL: '/v0/qan' });
export const apiRequestQAN = new ApiRequest({ baseURL: '/v1/qan' });
export const apiRequestManagement = new ApiRequest({ baseURL: '/v1/management' });
export const apiRequestInventory = new ApiRequest({ baseURL: '/v1/inventory' });
export const apiRequestSettings = new ApiRequest({ baseURL: '/v1/Settings' });
6 changes: 3 additions & 3 deletions pmm-app/src/shared/core/Settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { API } from './constants';
import { Settings, SettingsAPIResponse, SettingsPayload } from './types';

export const SettingsService = {
async getSettings(disableNotifications = false): Promise<Settings> {
const { settings } = await apiRequest.post(API.SETTINGS, {}, disableNotifications) as SettingsAPIResponse;
async getSettings(): Promise<Settings> {
const { settings } = await apiRequest.get(API.SETTINGS) as SettingsAPIResponse;
matejkubinec marked this conversation as resolved.
Show resolved Hide resolved

return toModel(settings);
},
};

const toModel = (response: SettingsPayload): Settings => ({
updatesDisabled: response.updates_disabled,
updatesEnabled: response.updates_enabled,
});
2 changes: 1 addition & 1 deletion pmm-app/src/shared/core/__mocks__/Settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { Settings } from '../types';

export const SettingsService = {
async getSettings(): Promise<Settings> {
return Promise.resolve({ updatesDisabled: false });
return Promise.resolve({ updatesEnabled: true });
},
};
3 changes: 1 addition & 2 deletions pmm-app/src/shared/core/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Databases } from './types';

export const API = {
ALERTMANAGER: '/alertmanager/api/v2',
SETTINGS: '/v1/Settings/Get',
SETTINGS: '/v1/server/settings',
};

export const DATABASE_LABELS = {
Expand Down
4 changes: 2 additions & 2 deletions pmm-app/src/shared/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ export enum Databases {
}

export interface Settings {
updatesDisabled?: boolean;
updatesEnabled?: boolean;
}

export interface SettingsAPIResponse {
settings: SettingsPayload;
}

export interface SettingsPayload {
updates_disabled: boolean;
updates_enabled: boolean;
}

export interface PaginatedPayload {
Expand Down
9 changes: 3 additions & 6 deletions setup-page/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ export function App() {
setLoading(true);

try {
const response = await fetch('/v1/AWSInstanceCheck', {
method: 'POST',
const response = await fetch(`/v1/server/AWSInstance?instance_id${instanceId.trim()}`, {
matejkubinec marked this conversation as resolved.
Show resolved Hide resolved
method: 'GET',
credentials: "include",
cache: "no-cache",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
instance_id: instanceId.trim(),
}),
}
});

if (!response.ok) {
Expand Down
Loading