diff --git a/pmm-app/src/pmm-pt-summary/datasource/PTSummary.service.ts b/pmm-app/src/pmm-pt-summary/datasource/PTSummary.service.ts deleted file mode 100644 index 61b70183b7..0000000000 --- a/pmm-app/src/pmm-pt-summary/datasource/PTSummary.service.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { getTemplateSrv } from '@grafana/runtime'; -import { apiRequestManagement } from 'shared/components/helpers/api'; -import { PTSummaryRequest, PTSummaryResponse, DatabaseSummaryRequest } from './PTSummary.types'; - -export const PTSummaryService = { - async getPTSummary(variableName) { - const body: PTSummaryRequest = { node_id: getTemplateSrv().replace(`$${variableName || 'node_id'}`) }; - - return apiRequestManagement.post('/Actions/StartPTSummary', body, true); - }, - async getMysqlPTSummary(variableName) { - const body: DatabaseSummaryRequest = { - service_id: getTemplateSrv().replace(`$${variableName || 'service_name'}`), - }; - - return apiRequestManagement.post('/Actions/StartPTMySQLSummary', body, true); - }, - async getPostgresqlPTSummary(variableName) { - const body: DatabaseSummaryRequest = { - service_id: getTemplateSrv().replace(`$${variableName || 'service_name'}`), - }; - - return apiRequestManagement.post('/Actions/StartPTPgSummary', body, true); - }, - async getMongodbPTSummary(variableName) { - const body: DatabaseSummaryRequest = { - service_id: getTemplateSrv().replace(`$${variableName || 'service-name'}`), - }; - - return apiRequestManagement.post('/Actions/StartPTMongoDBSummary', body, true); - }, -}; diff --git a/pmm-app/src/pmm-pt-summary/datasource/PTSummary.types.ts b/pmm-app/src/pmm-pt-summary/datasource/PTSummary.types.ts deleted file mode 100644 index 2015f4c2db..0000000000 --- a/pmm-app/src/pmm-pt-summary/datasource/PTSummary.types.ts +++ /dev/null @@ -1,19 +0,0 @@ -export interface PTSummaryRequest { - node_id: string; -} - -export interface DatabaseSummaryRequest { - service_id: string; -} - -export interface PTSummaryResponse { - action_id: string; - pmm_agent_id: string; -} - -export enum DatasourceType { - postgresql = 'postgresql', - mongodb = 'mongodb', - mysql = 'mysql', - node = 'node', -} diff --git a/pmm-app/src/pmm-pt-summary/datasource/PTSummaryDataSource.test.ts b/pmm-app/src/pmm-pt-summary/datasource/PTSummaryDataSource.test.ts deleted file mode 100644 index af60825e51..0000000000 --- a/pmm-app/src/pmm-pt-summary/datasource/PTSummaryDataSource.test.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { FieldType, MutableDataFrame } from '@grafana/data'; -import { ActionResult } from 'shared/components/Actions'; -import { PTSummaryDataSource } from './PTSummaryDataSource'; -import { PTSummaryService } from './PTSummary.service'; - -jest.mock('shared/components/helpers/notification-manager'); -jest.mock('@grafana/runtime', () => ({ - getTemplateSrv: () => ({ - replace: () => 'node', - }), -})); -jest.mock('shared/components/Actions/Actions.utils', () => ({ - getActionResult: async (): Promise => new Promise((resolve) => { - resolve({ - loading: false, - value: 'Test data', - error: '', - }); - }), -})); - -describe('PTSummaryDatasource::', () => { - it('Returns correct data for Node summary', async () => { - const expected = { - data: [ - new MutableDataFrame({ - fields: [{ name: 'summary', values: ['Test data'], type: FieldType.string }], - }), - ], - }; - const instance = new PTSummaryDataSource({}); - - PTSummaryService.getPTSummary = jest.fn().mockResolvedValueOnce({ value: 'Test data' }); - - const result = await instance.query({ - targets: [{ refId: 'A', queryType: { type: 'node', variableName: undefined } }], - } as any); - - expect(result).toEqual(expected); - }); - - it('Returns correct data for MySQL summary', async () => { - const expected = { - data: [ - new MutableDataFrame({ - fields: [{ name: 'summary', values: ['Test data'], type: FieldType.string }], - }), - ], - }; - const instance = new PTSummaryDataSource({}); - - PTSummaryService.getMysqlPTSummary = jest.fn().mockResolvedValueOnce({ value: 'Test data' }); - - const result = await instance.query({ - targets: [{ refId: 'A', queryType: { type: 'mysql', variableName: undefined } }], - } as any); - - expect(result).toEqual(expected); - }); - - it('Returns correct data for MongoDB summary', async () => { - const expected = { - data: [ - new MutableDataFrame({ - fields: [{ name: 'summary', values: ['Test data'], type: FieldType.string }], - }), - ], - }; - const instance = new PTSummaryDataSource({}); - - PTSummaryService.getMongodbPTSummary = jest.fn().mockResolvedValueOnce({ value: 'Test data' }); - - const result = await instance.query({ - targets: [{ refId: 'A', queryType: { type: 'mongodb', variableName: undefined } }], - } as any); - - expect(result).toEqual(expected); - }); - - it('Returns correct data for PostgreSQL summary', async () => { - const expected = { - data: [ - new MutableDataFrame({ - fields: [{ name: 'summary', values: ['Test data'], type: FieldType.string }], - }), - ], - }; - const instance = new PTSummaryDataSource({}); - - PTSummaryService.getPostgresqlPTSummary = jest.fn().mockResolvedValueOnce({ value: 'Test data' }); - - const result = await instance.query({ - targets: [{ refId: 'A', queryType: { type: 'postgresql', variableName: undefined } }], - } as any); - - expect(result).toEqual(expected); - }); -}); diff --git a/pmm-app/src/pmm-pt-summary/datasource/PTSummaryDataSource.ts b/pmm-app/src/pmm-pt-summary/datasource/PTSummaryDataSource.ts deleted file mode 100644 index 35d9cf102e..0000000000 --- a/pmm-app/src/pmm-pt-summary/datasource/PTSummaryDataSource.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { - DataQueryResponse, DataSourceApi, MutableDataFrame, FieldType, -} from '@grafana/data'; -import { getActionResult } from 'shared/components/Actions'; -import { PTSummaryService } from './PTSummary.service'; -import { DatasourceType, PTSummaryResponse } from './PTSummary.types'; - -/* eslint-disable no-useless-constructor, class-methods-use-this */ -export class PTSummaryDataSource extends DataSourceApi { - constructor(instanceSettings: any) { - super(instanceSettings); - } - - async query(options): Promise { - const { variableName, type } = options.targets[0]?.queryType || {}; - - const getRequest = (type) => { - switch (type) { - case DatasourceType.node: - return PTSummaryService.getPTSummary(variableName); - case DatasourceType.mysql: - return PTSummaryService.getMysqlPTSummary(variableName); - case DatasourceType.mongodb: - return PTSummaryService.getMongodbPTSummary(variableName); - case DatasourceType.postgresql: - return PTSummaryService.getPostgresqlPTSummary(variableName); - default: - return PTSummaryService.getPTSummary(variableName); - } - }; - - return getRequest(type) - .then(async (response) => { - const result = await getActionResult((response as PTSummaryResponse).action_id); - - return this.newDataFrame(result.value ? result.value : result.error); - }) - .catch((error) => this.newDataFrame(error.response.data.message)); - } - - async testDatasource() { - return { - status: 'success', - message: 'Success', - }; - } - - newDataFrame(value: string) { - return { - data: [ - new MutableDataFrame({ - fields: [ - { - name: 'summary', - values: [value], - type: FieldType.string, - }, - ], - }), - ], - }; - } -} diff --git a/pmm-app/src/pmm-pt-summary/datasource/QueryEditor/QueryEditor.constants.ts b/pmm-app/src/pmm-pt-summary/datasource/QueryEditor/QueryEditor.constants.ts deleted file mode 100644 index f037c78beb..0000000000 --- a/pmm-app/src/pmm-pt-summary/datasource/QueryEditor/QueryEditor.constants.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { Messages } from './QueryEditor.messages'; -import { DatasourceType } from '../PTSummary.types'; - -export const DATASOURCES = [ - { - value: DatasourceType.node, - label: Messages.labels.nodePTSummary, - }, - { - value: DatasourceType.mysql, - label: Messages.labels.mysqlPTSummary, - }, - { - value: DatasourceType.postgresql, - label: Messages.labels.postgresqlPTSummary, - }, - { - value: DatasourceType.mongodb, - label: Messages.labels.mongodbPTSummary, - }, -]; diff --git a/pmm-app/src/pmm-pt-summary/datasource/QueryEditor/QueryEditor.messages.ts b/pmm-app/src/pmm-pt-summary/datasource/QueryEditor/QueryEditor.messages.ts deleted file mode 100644 index 201280281c..0000000000 --- a/pmm-app/src/pmm-pt-summary/datasource/QueryEditor/QueryEditor.messages.ts +++ /dev/null @@ -1,15 +0,0 @@ -export const Messages = { - labels: { - postgresqlPTSummary: 'PostgreSQL PT Summary', - mongodbPTSummary: 'MongoDB PT Summary', - mysqlPTSummary: 'MySQL PT Summary', - nodePTSummary: 'Node PT Summary', - field: { - datasourceType: 'Datasource type', - variableName: 'Grafana variable name', - }, - }, - placeholders: { - variableName: 'Variable name', - }, -}; diff --git a/pmm-app/src/pmm-pt-summary/datasource/QueryEditor/QueryEditor.tsx b/pmm-app/src/pmm-pt-summary/datasource/QueryEditor/QueryEditor.tsx deleted file mode 100644 index cddac07ddf..0000000000 --- a/pmm-app/src/pmm-pt-summary/datasource/QueryEditor/QueryEditor.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import { SelectableValue } from '@grafana/data'; -import { Select, Field, FieldSet } from '@grafana/ui'; -import { getTemplateSrv } from '@grafana/runtime'; -import { Messages } from './QueryEditor.messages'; -import { DATASOURCES } from './QueryEditor.constants'; - -export const QueryEditor = (props) => { - const { query: { queryType }, onChange } = props; - - const variablesOptions = getTemplateSrv() - .getVariables() - .map((variable) => ({ value: variable.name, label: variable.label || undefined })); - - const selectedOption = variablesOptions.find((variable) => variable.value === queryType?.variableName); - const selectedTypeOption = DATASOURCES.find((datasource) => datasource.value === queryType?.type); - - const [selectedVariable, selectVariable] = useState | undefined>(selectedOption); - const [type, setType] = useState>(selectedTypeOption || DATASOURCES[0]); - - useEffect(() => { - const newQuery = { ...queryType }; - - if (selectedVariable?.value) { - newQuery.variableName = selectedVariable?.value; - } - - if (type?.value) { - newQuery.type = type?.value; - } - - onChange({ - queryType: newQuery, - }); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [selectedVariable, type]); - - return ( - <> -
-
- - - -
-
- - ); -}; - -export default QueryEditor; diff --git a/pmm-app/src/pmm-pt-summary/datasource/module.ts b/pmm-app/src/pmm-pt-summary/datasource/module.ts deleted file mode 100644 index 40f3588d25..0000000000 --- a/pmm-app/src/pmm-pt-summary/datasource/module.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { DataSourcePlugin } from '@grafana/data'; -import { PTSummaryDataSource } from './PTSummaryDataSource'; -import { QueryEditor } from './QueryEditor/QueryEditor'; - -export const plugin = new DataSourcePlugin(PTSummaryDataSource) - .setQueryEditor(QueryEditor); - // .setConfigEditor(ConfigEditor); diff --git a/pmm-app/src/pmm-pt-summary/datasource/plugin.json b/pmm-app/src/pmm-pt-summary/datasource/plugin.json deleted file mode 100644 index d525a76e1f..0000000000 --- a/pmm-app/src/pmm-pt-summary/datasource/plugin.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "type": "datasource", - "name": "PTSummary", - "id": "pmm-pt-summary-datasource", - "metrics": true -} diff --git a/pmm-app/src/pmm-pt-summary/panel/PTSummary.styles.ts b/pmm-app/src/pmm-pt-summary/panel/PTSummary.styles.ts deleted file mode 100644 index ab8f8b37b6..0000000000 --- a/pmm-app/src/pmm-pt-summary/panel/PTSummary.styles.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { stylesFactory } from '@grafana/ui'; -import { GrafanaTheme } from '@grafana/data'; -import { css } from '@emotion/css'; - -export const getStyles = stylesFactory((theme: GrafanaTheme) => ({ - ptSummaryWrapper: css` - background: ${theme.palette.dark2}; - border: ${theme.border.width.sm} solid ${theme.colors.pageHeaderBorder}; - border-radius: ${theme.border.radius.sm}; - font-size: ${theme.typography.size.sm}; - height: 100%; - `, - ptSummary: css` - background: ${theme.palette.dark2}; - border: none; - color: ${theme.palette.white}; - height: 100%; - margin: 0; - `, -})); diff --git a/pmm-app/src/pmm-pt-summary/panel/PTSummary.test.tsx b/pmm-app/src/pmm-pt-summary/panel/PTSummary.test.tsx deleted file mode 100644 index 886fef0a68..0000000000 --- a/pmm-app/src/pmm-pt-summary/panel/PTSummary.test.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import React from 'react'; -import { mount } from 'enzyme'; -import { PTSummaryPanel } from './PTSummary'; - -describe('PTSummaryPanel::', () => { - it('Renders correctly with props', () => { - const props: any = { - data: { - series: [{ fields: [{ name: 'summary', values: { buffer: ['Test data'] } }] }], - }, - }; - const root = mount(); - - expect(root.find('pre').text()).toBe('Test data'); - }); - - it('Renders correctly without data', () => { - const props: any = { - data: { - series: [], - }, - }; - const root = mount(); - - expect(root.find('pre').text()).toEqual(''); - }); -}); diff --git a/pmm-app/src/pmm-pt-summary/panel/PTSummary.tsx b/pmm-app/src/pmm-pt-summary/panel/PTSummary.tsx deleted file mode 100644 index c63aa66fc2..0000000000 --- a/pmm-app/src/pmm-pt-summary/panel/PTSummary.tsx +++ /dev/null @@ -1,18 +0,0 @@ -import React, { FC } from 'react'; -import { PanelProps } from '@grafana/data'; -import { useTheme } from '@grafana/ui'; -import { getStyles } from './PTSummary.styles'; - -export const PTSummaryPanel: FC = ({ data }) => { - const theme = useTheme(); - const styles = getStyles(theme); - const series = data.series[0]; - const summary: any = series?.fields.find((f) => f.name === 'summary'); - const fingerprint = summary?.values.buffer[0]; - - return ( -
-
{fingerprint}
-
- ); -}; diff --git a/pmm-app/src/pmm-pt-summary/panel/module.ts b/pmm-app/src/pmm-pt-summary/panel/module.ts deleted file mode 100644 index 7e99c579a5..0000000000 --- a/pmm-app/src/pmm-pt-summary/panel/module.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { PanelPlugin } from '@grafana/data'; -import { PTSummaryPanel } from './PTSummary'; - -export const plugin = new PanelPlugin(PTSummaryPanel); diff --git a/pmm-app/src/pmm-pt-summary/panel/plugin.json b/pmm-app/src/pmm-pt-summary/panel/plugin.json deleted file mode 100755 index d41521cb61..0000000000 --- a/pmm-app/src/pmm-pt-summary/panel/plugin.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "type": "panel", - "name": "PTSummary", - "id": "pmm-pt-summary-panel" -}