From d9e83639fa28d51f73fb75ca9ed2e6ee01862948 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Tue, 30 Jul 2024 13:17:40 +0300 Subject: [PATCH 01/37] Update contexts request --- src/shared/hooks/useFetchContexts.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/shared/hooks/useFetchContexts.ts b/src/shared/hooks/useFetchContexts.ts index 484c145..c267e9c 100644 --- a/src/shared/hooks/useFetchContexts.ts +++ b/src/shared/hooks/useFetchContexts.ts @@ -3,8 +3,9 @@ import React from 'react'; import { Get } from 'shared/utils/request'; export const getContexts = async (spaceId: string, roomId: string, baseUrl: string) => { - const response = await Get({ path: `/v2/spaces/${spaceId}/rooms/${roomId}/contexts`, baseUrl }); - return response?.data?.results as string[]; + const response = await Get({ path: `/v3/spaces/${spaceId}/rooms/${roomId}/contexts`, baseUrl }); + const { contexts = {} } = response || {} + return Object.keys(contexts) as string[]; }; export const useFetchContexts = (baseUrl: string) => { From a8a73e2f0ba07f48e9f27d3ea7636ee7f1148584 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Tue, 30 Jul 2024 13:52:51 +0300 Subject: [PATCH 02/37] Uopdate nodes request --- src/QueryEditor.tsx | 6 +++--- src/shared/hooks/useFetchNodes.ts | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index 2fbd1a6..ffc722a 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -45,7 +45,7 @@ const QueryEditor: React.FC = ({ datasource, query, onChange, onRunQuery const { allDimensions, groupingByList, filters, units, fetchDimensions } = useFetchDimensions(baseUrl); const filterList = React.useMemo(() => Object.keys(filters).map((s) => ({ label: s, value: s })), [filters]); - const nodeList = React.useMemo(() => nodes?.map((c: any) => ({ label: c.name, value: c.id })), [nodes]); + const nodeList = React.useMemo(() => nodes?.map((c: any) => ({ label: c.nm, value: c.nd })), [nodes]); const { spaceId, roomId, nodes: allNodes, dimensions, groupBy, contextId, filterBy, filterValue } = query; @@ -97,7 +97,7 @@ const QueryEditor: React.FC = ({ datasource, query, onChange, onRunQuery if (allNodes && nodes.length > 0) { const filteredNodes: any[] = []; allNodes.forEach((element) => { - const currentNode: any = nodes.find((n: any) => n.id === element); + const currentNode: any = nodes.find((n: any) => n.nd === element); filteredNodes.push({ label: currentNode?.name, value: currentNode?.id }); }); @@ -111,7 +111,7 @@ const QueryEditor: React.FC = ({ datasource, query, onChange, onRunQuery if (allNodes && nodes.length > 0) { allNodes.forEach((element) => { - const currentNode: any = nodes.find((n: any) => n.id === element); + const currentNode: any = nodes.find((n: any) => n.nd === element); filteredNodes.push({ label: currentNode?.name, value: currentNode?.id }); }); } diff --git a/src/shared/hooks/useFetchNodes.ts b/src/shared/hooks/useFetchNodes.ts index ac43d25..0557e08 100644 --- a/src/shared/hooks/useFetchNodes.ts +++ b/src/shared/hooks/useFetchNodes.ts @@ -1,9 +1,11 @@ import React from 'react'; -import { Get } from 'shared/utils/request'; +import { Post } from 'shared/utils/request'; export const getNodes = async (spaceId: string, roomId: string, baseUrl: string) => { - const response = await Get({ path: `/v2/spaces/${spaceId}/rooms/${roomId}/nodes`, baseUrl }); - return response?.data; + const response = await Post({ path: `/v3/spaces/${spaceId}/rooms/${roomId}/nodes`, baseUrl, data: { scope: { + nodes: [], + } } }); + return response?.nodes; }; export const useFetchNodes = (baseUrl: string) => { From aa0cfb41f075264b517a62e3ea66dcdf64b1bcb9 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Tue, 30 Jul 2024 14:21:08 +0300 Subject: [PATCH 03/37] wip --- src/shared/hooks/useGetChartData.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/hooks/useGetChartData.ts b/src/shared/hooks/useGetChartData.ts index 31fc867..6c9b170 100644 --- a/src/shared/hooks/useGetChartData.ts +++ b/src/shared/hooks/useGetChartData.ts @@ -56,7 +56,7 @@ export const useGetChartData = async ({ } return await Post({ - path: `/v2/spaces/${spaceId}/rooms/${roomId}/data`, + path: `/v3/spaces/${spaceId}/rooms/${roomId}/data`, baseUrl, data: { filter: { From 352e04e1053e91e8b2fcb92522e1dd8e98594f82 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Tue, 30 Jul 2024 14:39:06 +0300 Subject: [PATCH 04/37] Format files --- .prettierrc.js | 2 +- src/shared/hooks/useFetchContexts.ts | 2 +- src/shared/hooks/useFetchNodes.ts | 12 +++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.prettierrc.js b/.prettierrc.js index 263dbd3..b035698 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,3 +1,3 @@ module.exports = { - ...require("./node_modules/@grafana/toolkit/src/config/prettier.plugin.config.json"), + ...require('./node_modules/@grafana/toolkit/src/config/prettier.plugin.config.json'), }; diff --git a/src/shared/hooks/useFetchContexts.ts b/src/shared/hooks/useFetchContexts.ts index c267e9c..12456d9 100644 --- a/src/shared/hooks/useFetchContexts.ts +++ b/src/shared/hooks/useFetchContexts.ts @@ -4,7 +4,7 @@ import { Get } from 'shared/utils/request'; export const getContexts = async (spaceId: string, roomId: string, baseUrl: string) => { const response = await Get({ path: `/v3/spaces/${spaceId}/rooms/${roomId}/contexts`, baseUrl }); - const { contexts = {} } = response || {} + const { contexts = {} } = response || {}; return Object.keys(contexts) as string[]; }; diff --git a/src/shared/hooks/useFetchNodes.ts b/src/shared/hooks/useFetchNodes.ts index 0557e08..5f346ff 100644 --- a/src/shared/hooks/useFetchNodes.ts +++ b/src/shared/hooks/useFetchNodes.ts @@ -2,9 +2,15 @@ import React from 'react'; import { Post } from 'shared/utils/request'; export const getNodes = async (spaceId: string, roomId: string, baseUrl: string) => { - const response = await Post({ path: `/v3/spaces/${spaceId}/rooms/${roomId}/nodes`, baseUrl, data: { scope: { - nodes: [], - } } }); + const response = await Post({ + path: `/v3/spaces/${spaceId}/rooms/${roomId}/nodes`, + baseUrl, + data: { + scope: { + nodes: [], + }, + }, + }); return response?.nodes; }; From 68f24d4681e50cf553deb5300ef9ea0bf43d6cf0 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Tue, 30 Jul 2024 15:34:19 +0300 Subject: [PATCH 05/37] Fix response --- src/shared/hooks/useFetchContexts.ts | 2 +- src/shared/hooks/useFetchNodes.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/hooks/useFetchContexts.ts b/src/shared/hooks/useFetchContexts.ts index 12456d9..e300c5b 100644 --- a/src/shared/hooks/useFetchContexts.ts +++ b/src/shared/hooks/useFetchContexts.ts @@ -4,7 +4,7 @@ import { Get } from 'shared/utils/request'; export const getContexts = async (spaceId: string, roomId: string, baseUrl: string) => { const response = await Get({ path: `/v3/spaces/${spaceId}/rooms/${roomId}/contexts`, baseUrl }); - const { contexts = {} } = response || {}; + const { contexts = {} } = response?.data || {}; return Object.keys(contexts) as string[]; }; diff --git a/src/shared/hooks/useFetchNodes.ts b/src/shared/hooks/useFetchNodes.ts index 5f346ff..a7b697b 100644 --- a/src/shared/hooks/useFetchNodes.ts +++ b/src/shared/hooks/useFetchNodes.ts @@ -11,7 +11,7 @@ export const getNodes = async (spaceId: string, roomId: string, baseUrl: string) }, }, }); - return response?.nodes; + return response?.data?.nodes; }; export const useFetchNodes = (baseUrl: string) => { From f5b5f2f0742e280534941202f93f05fcadfe87a5 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Tue, 30 Jul 2024 17:29:22 +0300 Subject: [PATCH 06/37] Fix contexts request --- src/QueryEditor.tsx | 11 ++++++++--- src/shared/hooks/useFetchContexts.ts | 27 ++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index ffc722a..615a617 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -17,8 +17,13 @@ type Props = QueryEditorProps; const { FormField } = LegacyForms; -const QueryEditor: React.FC = ({ datasource, query, onChange, onRunQuery }) => { +const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRunQuery }) => { const { baseUrl } = datasource; + const from = range!.from.valueOf(); + const to = range!.to.valueOf(); + const after = Math.floor(from / 1000); + const before = Math.floor(to / 1000); + const [selectedSpace, setSelectedSpace] = React.useState(); const [selectedRoom, setSelectedRoom] = React.useState(); const [selectedFilter, setSelectedFilter] = React.useState(); @@ -88,7 +93,7 @@ const QueryEditor: React.FC = ({ datasource, query, onChange, onRunQuery const room = rooms.find((r) => r.value === roomId); setSelectedRoom({ label: room?.label, value: room?.value }); fetchNodes(spaceId || '', roomId); - fetchContexts(spaceId || '', roomId); + fetchContexts(spaceId || '', roomId, after, before); } }, [roomId, rooms, fetchContexts, fetchNodes, spaceId]); @@ -171,7 +176,7 @@ const QueryEditor: React.FC = ({ datasource, query, onChange, onRunQuery setSelectedMethod(Methods[0]); setSelectedAggregations(Aggreagations[0]); - fetchContexts(selectedSpace?.value || '', v.value || ''); + fetchContexts(selectedSpace?.value || '', v.value || '', after, before); fetchNodes(selectedSpace?.value || '', v.value || ''); onChange({ ...query, spaceId: spaceId, roomId: v.value }); onRunQuery(); diff --git a/src/shared/hooks/useFetchContexts.ts b/src/shared/hooks/useFetchContexts.ts index e300c5b..432a2d9 100644 --- a/src/shared/hooks/useFetchContexts.ts +++ b/src/shared/hooks/useFetchContexts.ts @@ -1,9 +1,26 @@ import { Dropdown } from './../types/dropdown.interface'; import React from 'react'; -import { Get } from 'shared/utils/request'; +import { Post } from 'shared/utils/request'; -export const getContexts = async (spaceId: string, roomId: string, baseUrl: string) => { - const response = await Get({ path: `/v3/spaces/${spaceId}/rooms/${roomId}/contexts`, baseUrl }); +export const getContexts = async (spaceId: string, roomId: string, after: number, before: number, baseUrl: string) => { + const response = await Post({ + path: `/v3/spaces/${spaceId}/rooms/${roomId}/contexts`, + baseUrl, + data: { + scope: { + contexts: ['*'], + nodes: [], + }, + selectors: { + contexts: [], + nodes: [], + }, + window: { + after, + before, + }, + }, + }); const { contexts = {} } = response?.data || {}; return Object.keys(contexts) as string[]; }; @@ -13,11 +30,11 @@ export const useFetchContexts = (baseUrl: string) => { const [contexts, setContexts] = React.useState([]); const fetchContexts = React.useCallback( - async (spaceId: string, roomId: string) => { + async (spaceId: string, roomId: string, after: number, before: number) => { setIsError(false); try { - const result = await getContexts(spaceId, roomId, baseUrl); + const result = await getContexts(spaceId, roomId, after, before, baseUrl); setContexts(result.map((c) => ({ label: c, value: c }))); } catch (error) { setIsError(true); From 30a327f62fb08fa8d6a66f03b70999ad68c0ee40 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Tue, 30 Jul 2024 17:31:58 +0300 Subject: [PATCH 07/37] Add missing useEffect dependencies --- src/QueryEditor.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index 615a617..f2a4132 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -95,7 +95,7 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu fetchNodes(spaceId || '', roomId); fetchContexts(spaceId || '', roomId, after, before); } - }, [roomId, rooms, fetchContexts, fetchNodes, spaceId]); + }, [roomId, rooms, fetchContexts, fetchNodes, spaceId, after, before]); React.useEffect(() => { // eslint-disable-line From dfcb3793f259261f3e2ba40fc5111cfaa8412074 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Tue, 30 Jul 2024 17:33:58 +0300 Subject: [PATCH 08/37] Fix failing test --- src/shared/hooks/useFetchContexts.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/hooks/useFetchContexts.test.ts b/src/shared/hooks/useFetchContexts.test.ts index 50958bd..12c60bd 100644 --- a/src/shared/hooks/useFetchContexts.test.ts +++ b/src/shared/hooks/useFetchContexts.test.ts @@ -15,7 +15,7 @@ describe('useFetchContexts', () => { const { result, waitFor } = renderHook(() => hooks.useFetchContexts(baseUrl)); - await result.current.fetchContexts('spaceId', 'roomId'); + await result.current.fetchContexts('spaceId', 'roomId', -900, 0); await waitFor(() => result.current.contexts.length > 0); From a3178042ac70b8eaea5e607944128680db47a237 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Tue, 30 Jul 2024 17:57:51 +0300 Subject: [PATCH 09/37] Transform nodes response --- src/QueryEditor.tsx | 6 +++--- src/shared/hooks/useFetchNodes.ts | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index f2a4132..847a423 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -50,7 +50,7 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu const { allDimensions, groupingByList, filters, units, fetchDimensions } = useFetchDimensions(baseUrl); const filterList = React.useMemo(() => Object.keys(filters).map((s) => ({ label: s, value: s })), [filters]); - const nodeList = React.useMemo(() => nodes?.map((c: any) => ({ label: c.nm, value: c.nd })), [nodes]); + const nodeList = React.useMemo(() => nodes?.map((c: any) => ({ label: c.name, value: c.id })), [nodes]); const { spaceId, roomId, nodes: allNodes, dimensions, groupBy, contextId, filterBy, filterValue } = query; @@ -102,7 +102,7 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu if (allNodes && nodes.length > 0) { const filteredNodes: any[] = []; allNodes.forEach((element) => { - const currentNode: any = nodes.find((n: any) => n.nd === element); + const currentNode: any = nodes.find((n: any) => n.id === element); filteredNodes.push({ label: currentNode?.name, value: currentNode?.id }); }); @@ -116,7 +116,7 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu if (allNodes && nodes.length > 0) { allNodes.forEach((element) => { - const currentNode: any = nodes.find((n: any) => n.nd === element); + const currentNode: any = nodes.find((n: any) => n.id === element); filteredNodes.push({ label: currentNode?.name, value: currentNode?.id }); }); } diff --git a/src/shared/hooks/useFetchNodes.ts b/src/shared/hooks/useFetchNodes.ts index a7b697b..aaecb51 100644 --- a/src/shared/hooks/useFetchNodes.ts +++ b/src/shared/hooks/useFetchNodes.ts @@ -1,6 +1,14 @@ import React from 'react'; import { Post } from 'shared/utils/request'; +type Node = { + nd: string; + nm: string; + [key: string]: any; +}; + +const transformNodes = (nodes: Node[] = []) => nodes.map(({ nd, nm, ...rest }) => ({ id: nd, name: nm, ...rest })); + export const getNodes = async (spaceId: string, roomId: string, baseUrl: string) => { const response = await Post({ path: `/v3/spaces/${spaceId}/rooms/${roomId}/nodes`, @@ -11,6 +19,7 @@ export const getNodes = async (spaceId: string, roomId: string, baseUrl: string) }, }, }); + return response?.data?.nodes; }; @@ -35,7 +44,7 @@ export const useFetchNodes = (baseUrl: string) => { return { isError, - nodes, + nodes: transformNodes(nodes), fetchNodes, }; }; From 320d436cb583fd6d6f849bb3c582321dfddf198b Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Tue, 30 Jul 2024 19:52:21 +0300 Subject: [PATCH 10/37] [DEBUG] --- src/QueryEditor.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index 847a423..7abf77d 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -103,9 +103,10 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu const filteredNodes: any[] = []; allNodes.forEach((element) => { const currentNode: any = nodes.find((n: any) => n.id === element); + console.log({ element, nodes, currentNode }); filteredNodes.push({ label: currentNode?.name, value: currentNode?.id }); }); - + console.log({ allNodes, nodes, filteredNodes }); setSelectedNodes(filteredNodes); } }, [allNodes, nodes]); // eslint-disable-line From 08466770e00ef9dfec1595a8cb8f2ed19f5b6da3 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Wed, 31 Jul 2024 10:32:04 +0300 Subject: [PATCH 11/37] Revert "[DEBUG]" This reverts commit 070b3e74397320e37cbc3abd4917a1a6c5ff6306. --- src/QueryEditor.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index 7abf77d..847a423 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -103,10 +103,9 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu const filteredNodes: any[] = []; allNodes.forEach((element) => { const currentNode: any = nodes.find((n: any) => n.id === element); - console.log({ element, nodes, currentNode }); filteredNodes.push({ label: currentNode?.name, value: currentNode?.id }); }); - console.log({ allNodes, nodes, filteredNodes }); + setSelectedNodes(filteredNodes); } }, [allNodes, nodes]); // eslint-disable-line From 6054b0ce89763dd483146db91afd036102bebb67 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Wed, 31 Jul 2024 10:51:53 +0300 Subject: [PATCH 12/37] Fix node tranformation --- src/shared/hooks/useFetchNodes.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/shared/hooks/useFetchNodes.ts b/src/shared/hooks/useFetchNodes.ts index aaecb51..14dbc68 100644 --- a/src/shared/hooks/useFetchNodes.ts +++ b/src/shared/hooks/useFetchNodes.ts @@ -3,11 +3,13 @@ import { Post } from 'shared/utils/request'; type Node = { nd: string; + mg: string; nm: string; [key: string]: any; }; -const transformNodes = (nodes: Node[] = []) => nodes.map(({ nd, nm, ...rest }) => ({ id: nd, name: nm, ...rest })); +const transformNodes = (nodes: Node[] = []) => + nodes.map(({ nd, mg, nm, ...rest }) => ({ id: nd || mg, name: nm, ...rest })); export const getNodes = async (spaceId: string, roomId: string, baseUrl: string) => { const response = await Post({ From dfd7603c9237240eb40d25f522419ba3861139e0 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Mon, 9 Sep 2024 10:43:24 +0300 Subject: [PATCH 13/37] [DEBUG] --- src/shared/hooks/useGetChartData.ts | 90 ++++++++++++++++++----------- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/src/shared/hooks/useGetChartData.ts b/src/shared/hooks/useGetChartData.ts index 6c9b170..21dfd54 100644 --- a/src/shared/hooks/useGetChartData.ts +++ b/src/shared/hooks/useGetChartData.ts @@ -32,48 +32,68 @@ export const useGetChartData = async ({ from, to, }: UseGetChartDataType) => { - let aggregations = []; + // let aggregations = []; - switch (groupBy) { - case 'node': - aggregations = [ - { method: 'sum', groupBy: ['chart', 'node'] }, - { method, groupBy: ['node'] }, - ]; - break; - case 'dimension': - aggregations = [{ method, groupBy: ['dimension'] }]; - break; - case 'instance': - aggregations = [{ method: 'sum', groupBy: ['chart', 'node'] }]; - break; - default: - aggregations = [ - { method: 'sum', groupBy: ['chart', `label=${groupBy}`] }, - { method: 'avg', groupBy: [`label=${groupBy}`] }, - ]; - break; - } + // switch (groupBy) { + // case 'node': + // aggregations = [ + // { method: 'sum', groupBy: ['chart', 'node'] }, + // { method, groupBy: ['node'] }, + // ]; + // break; + // case 'dimension': + // aggregations = [{ method, groupBy: ['dimension'] }]; + // break; + // case 'instance': + // aggregations = [{ method: 'sum', groupBy: ['chart', 'node'] }]; + // break; + // default: + // aggregations = [ + // { method: 'sum', groupBy: ['chart', `label=${groupBy}`] }, + // { method: 'avg', groupBy: [`label=${groupBy}`] }, + // ]; + // break; + // } return await Post({ path: `/v3/spaces/${spaceId}/rooms/${roomId}/data`, baseUrl, data: { - filter: { - nodeIDs: nodes, - context: contextId, - dimensions, - ...(filterBy && filterValue ? { labels: { [filterBy]: [filterValue] } } : {}), + format: 'json2', + options: ['jsonwrap', 'nonzero', 'flip', 'ms', 'jw-anomaly-rates', 'minify'], + scope: { + contexts: ['mem.thp_details'], + nodes: [ + '01702efd-af72-45b0-8e2f-33d806e5699f', + '0a841ab0-bc12-41a0-894a-e41fd5440eb8', + 'ce0e8300-8270-4171-ae48-c452d3b91ba9', + 'e0d74612-cf5a-4030-959c-de5dee3d793a', + '3ed8bb08-f2d3-4054-b423-67a8313fb130', + 'af4b47bb-d6be-4a46-b6b0-0a735dbc0a4c', + '2626d41a-39f1-407f-8965-c08d146e8c4d', + 'e48415db-3d25-4521-982c-30e9f46c96d2', + '382c7e2a-4b64-46ba-b8a5-f5f75eafa3e9', + '8b9cc340-6d60-47d9-99d5-de43071de8ba', + ], }, - aggregations, - agent_options: ['jsonwrap', 'flip', 'ms'], - points: 335, - format: 'json', - group, - gtime: 0, - after: from, - before: to, - with_metadata: true, + selectors: { + contexts: ['*'], + nodes: ['*'], + instances: ['*'], + dimensions: ['*'], + labels: ['*'], + }, + aggregations: { + metrics: [ + { + group_by: ['dimension'], + group_by_label: [], + aggregation: 'sum', + }, + ], + time: { time_group: 'average', time_resampling: 0 }, + }, + window: { after: 1722412818, before: 1722413718, points: 269 }, }, }); }; From ee23cf31b4460d0623cae17692568e1eb7b3e806 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Mon, 9 Sep 2024 11:06:15 +0300 Subject: [PATCH 14/37] Revert "[DEBUG]" This reverts commit 3020e4bb73d557fb4dc8e76e614b2411bff5b257. --- src/shared/hooks/useGetChartData.ts | 90 +++++++++++------------------ 1 file changed, 35 insertions(+), 55 deletions(-) diff --git a/src/shared/hooks/useGetChartData.ts b/src/shared/hooks/useGetChartData.ts index 21dfd54..6c9b170 100644 --- a/src/shared/hooks/useGetChartData.ts +++ b/src/shared/hooks/useGetChartData.ts @@ -32,68 +32,48 @@ export const useGetChartData = async ({ from, to, }: UseGetChartDataType) => { - // let aggregations = []; + let aggregations = []; - // switch (groupBy) { - // case 'node': - // aggregations = [ - // { method: 'sum', groupBy: ['chart', 'node'] }, - // { method, groupBy: ['node'] }, - // ]; - // break; - // case 'dimension': - // aggregations = [{ method, groupBy: ['dimension'] }]; - // break; - // case 'instance': - // aggregations = [{ method: 'sum', groupBy: ['chart', 'node'] }]; - // break; - // default: - // aggregations = [ - // { method: 'sum', groupBy: ['chart', `label=${groupBy}`] }, - // { method: 'avg', groupBy: [`label=${groupBy}`] }, - // ]; - // break; - // } + switch (groupBy) { + case 'node': + aggregations = [ + { method: 'sum', groupBy: ['chart', 'node'] }, + { method, groupBy: ['node'] }, + ]; + break; + case 'dimension': + aggregations = [{ method, groupBy: ['dimension'] }]; + break; + case 'instance': + aggregations = [{ method: 'sum', groupBy: ['chart', 'node'] }]; + break; + default: + aggregations = [ + { method: 'sum', groupBy: ['chart', `label=${groupBy}`] }, + { method: 'avg', groupBy: [`label=${groupBy}`] }, + ]; + break; + } return await Post({ path: `/v3/spaces/${spaceId}/rooms/${roomId}/data`, baseUrl, data: { - format: 'json2', - options: ['jsonwrap', 'nonzero', 'flip', 'ms', 'jw-anomaly-rates', 'minify'], - scope: { - contexts: ['mem.thp_details'], - nodes: [ - '01702efd-af72-45b0-8e2f-33d806e5699f', - '0a841ab0-bc12-41a0-894a-e41fd5440eb8', - 'ce0e8300-8270-4171-ae48-c452d3b91ba9', - 'e0d74612-cf5a-4030-959c-de5dee3d793a', - '3ed8bb08-f2d3-4054-b423-67a8313fb130', - 'af4b47bb-d6be-4a46-b6b0-0a735dbc0a4c', - '2626d41a-39f1-407f-8965-c08d146e8c4d', - 'e48415db-3d25-4521-982c-30e9f46c96d2', - '382c7e2a-4b64-46ba-b8a5-f5f75eafa3e9', - '8b9cc340-6d60-47d9-99d5-de43071de8ba', - ], + filter: { + nodeIDs: nodes, + context: contextId, + dimensions, + ...(filterBy && filterValue ? { labels: { [filterBy]: [filterValue] } } : {}), }, - selectors: { - contexts: ['*'], - nodes: ['*'], - instances: ['*'], - dimensions: ['*'], - labels: ['*'], - }, - aggregations: { - metrics: [ - { - group_by: ['dimension'], - group_by_label: [], - aggregation: 'sum', - }, - ], - time: { time_group: 'average', time_resampling: 0 }, - }, - window: { after: 1722412818, before: 1722413718, points: 269 }, + aggregations, + agent_options: ['jsonwrap', 'flip', 'ms'], + points: 335, + format: 'json', + group, + gtime: 0, + after: from, + before: to, + with_metadata: true, }, }); }; From fa3df389a751798b64d14f036e106a17d1abf409 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Mon, 9 Sep 2024 11:40:05 +0300 Subject: [PATCH 15/37] [wip] Refactor data payload --- src/shared/hooks/useGetChartData.ts | 126 +++++++++++++++++++++++----- 1 file changed, 103 insertions(+), 23 deletions(-) diff --git a/src/shared/hooks/useGetChartData.ts b/src/shared/hooks/useGetChartData.ts index 6c9b170..d23aae9 100644 --- a/src/shared/hooks/useGetChartData.ts +++ b/src/shared/hooks/useGetChartData.ts @@ -31,27 +31,82 @@ export const useGetChartData = async ({ dimensions = [], from, to, + ...rest }: UseGetChartDataType) => { - let aggregations = []; + console.log({ + baseUrl, + roomId, + nodes, + spaceId, + contextId, + filterBy, + filterValue, + groupBy, + method, + group, + dimensions, + from, + to, + ...rest, + }); + let metrics = []; switch (groupBy) { case 'node': - aggregations = [ - { method: 'sum', groupBy: ['chart', 'node'] }, - { method, groupBy: ['node'] }, + metrics = [ + { + group_by: ['chart', 'node'], + group_by_label: [], + aggregation: 'sum', + }, + { + group_by: ['node'], + group_by_label: [], + aggregation: method, + }, ]; + // metrics = [ + // { method: 'sum', groupBy: ['chart', 'node'] }, + // { method, groupBy: ['node'] }, + // ]; break; case 'dimension': - aggregations = [{ method, groupBy: ['dimension'] }]; + metrics = [ + { + group_by: ['dimension'], + group_by_label: [], + aggregation: method, + }, + ]; + // metrics = [{ method, groupBy: ['dimension'] }]; break; case 'instance': - aggregations = [{ method: 'sum', groupBy: ['chart', 'node'] }]; + metrics = [ + { + group_by: ['chart', 'node'], + group_by_label: [], + aggregation: 'sum', + }, + ]; + // metrics = [{ method: 'sum', groupBy: ['chart', 'node'] }]; break; default: - aggregations = [ - { method: 'sum', groupBy: ['chart', `label=${groupBy}`] }, - { method: 'avg', groupBy: [`label=${groupBy}`] }, + metrics = [ + { + group_by: ['chart'], + group_by_label: groupBy, + aggregation: 'sum', + }, + { + group_by: [], + group_by_label: groupBy, + aggregation: 'avg', + }, ]; + // metrics = [ + // { method: 'sum', groupBy: ['chart', `label=${groupBy}`] }, + // { method: 'avg', groupBy: [`label=${groupBy}`] }, + // ]; break; } @@ -59,21 +114,46 @@ export const useGetChartData = async ({ path: `/v3/spaces/${spaceId}/rooms/${roomId}/data`, baseUrl, data: { - filter: { - nodeIDs: nodes, - context: contextId, - dimensions, - ...(filterBy && filterValue ? { labels: { [filterBy]: [filterValue] } } : {}), + format: 'json2', + options: ['jsonwrap', 'flip', 'ms'], + scope: { + contexts: [contextId], + nodes, }, - aggregations, - agent_options: ['jsonwrap', 'flip', 'ms'], - points: 335, - format: 'json', - group, - gtime: 0, - after: from, - before: to, - with_metadata: true, + selectors: { + contexts: ['*'], + nodes: ['*'], + instances: ['*'], + dimensions: ['*'], + labels: ['*'], + }, + aggregations: { + metrics, + time: { time_group: group, time_resampling: 0 }, + }, + window: { after: from, before: to, points: 269 }, }, }); + + // return await Post({ + // path: `/v3/spaces/${spaceId}/rooms/${roomId}/data`, + // baseUrl, + // data: { + // filter: { + // nodeIDs: nodes, + // context: contextId, + // dimensions, + // ...(filterBy && filterValue ? { labels: { [filterBy]: [filterValue] } } : {}), + // }, + // aggregations, + // agent_options: ['jsonwrap', 'flip', 'ms'], + // points: 335, + // format: 'json', + // group, + // gtime: 0, + // after: from, + // before: to, + // with_metadata: true, + // }, + // }); }; From ad7856b92ee1b8587448f5e867a6ae6585786228 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Tue, 10 Sep 2024 10:33:52 +0300 Subject: [PATCH 16/37] Remove debuging code and add dimensions to scope --- src/shared/hooks/useGetChartData.ts | 49 +---------------------------- 1 file changed, 1 insertion(+), 48 deletions(-) diff --git a/src/shared/hooks/useGetChartData.ts b/src/shared/hooks/useGetChartData.ts index d23aae9..9bd1354 100644 --- a/src/shared/hooks/useGetChartData.ts +++ b/src/shared/hooks/useGetChartData.ts @@ -33,22 +33,6 @@ export const useGetChartData = async ({ to, ...rest }: UseGetChartDataType) => { - console.log({ - baseUrl, - roomId, - nodes, - spaceId, - contextId, - filterBy, - filterValue, - groupBy, - method, - group, - dimensions, - from, - to, - ...rest, - }); let metrics = []; switch (groupBy) { @@ -65,10 +49,6 @@ export const useGetChartData = async ({ aggregation: method, }, ]; - // metrics = [ - // { method: 'sum', groupBy: ['chart', 'node'] }, - // { method, groupBy: ['node'] }, - // ]; break; case 'dimension': metrics = [ @@ -78,7 +58,6 @@ export const useGetChartData = async ({ aggregation: method, }, ]; - // metrics = [{ method, groupBy: ['dimension'] }]; break; case 'instance': metrics = [ @@ -88,7 +67,6 @@ export const useGetChartData = async ({ aggregation: 'sum', }, ]; - // metrics = [{ method: 'sum', groupBy: ['chart', 'node'] }]; break; default: metrics = [ @@ -103,10 +81,6 @@ export const useGetChartData = async ({ aggregation: 'avg', }, ]; - // metrics = [ - // { method: 'sum', groupBy: ['chart', `label=${groupBy}`] }, - // { method: 'avg', groupBy: [`label=${groupBy}`] }, - // ]; break; } @@ -119,6 +93,7 @@ export const useGetChartData = async ({ scope: { contexts: [contextId], nodes, + dimensions, }, selectors: { contexts: ['*'], @@ -134,26 +109,4 @@ export const useGetChartData = async ({ window: { after: from, before: to, points: 269 }, }, }); - - // return await Post({ - // path: `/v3/spaces/${spaceId}/rooms/${roomId}/data`, - // baseUrl, - // data: { - // filter: { - // nodeIDs: nodes, - // context: contextId, - // dimensions, - // ...(filterBy && filterValue ? { labels: { [filterBy]: [filterValue] } } : {}), - // }, - // aggregations, - // agent_options: ['jsonwrap', 'flip', 'ms'], - // points: 335, - // format: 'json', - // group, - // gtime: 0, - // after: from, - // before: to, - // with_metadata: true, - // }, - // }); }; From 054d25db99d507d3afbfdabd1949fdc7df3e735a Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Tue, 10 Sep 2024 11:20:43 +0300 Subject: [PATCH 17/37] Adjust to v3 data response --- src/QueryEditor.tsx | 5 +++-- src/datasource.ts | 5 +++-- src/shared/hooks/useGetChartData.ts | 1 - 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index 847a423..e8731fd 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -55,8 +55,9 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu const { spaceId, roomId, nodes: allNodes, dimensions, groupBy, contextId, filterBy, filterValue } = query; const mySubscriber = (msg: any, data: any) => { - setTotalNodes(data.data.nodes.length); - setTotalInstances(data.data.nodes.reduce((acc: number, node: any) => acc + node.chartIDs.length, 0)); + setTotalNodes(data.data.summary.nodes.length); + //setTotalInstances(data.data.summary.nodes.reduce((acc: number, node: any) => acc + node.chartIDs.length, 0)); + setTotalInstances(data.data.summary.instances.length); }; const isGroupFunctionAvailable = React.useCallback(() => { diff --git a/src/datasource.ts b/src/datasource.ts index e18611e..5f7b4dc 100644 --- a/src/datasource.ts +++ b/src/datasource.ts @@ -61,7 +61,7 @@ export class DataSource extends DataSourceApi { const frame = new MutableDataFrame({ refId, fields: response.data.result.labels.map((id: string, i: number) => { - const node = response.data.nodes.find((n: any) => n.id === id); + const node = response.data.summary.nodes.find((n: any) => n.nd === id); return { name: node?.name || id, type: i === 0 ? FieldType.time : FieldType.number, @@ -70,7 +70,8 @@ export class DataSource extends DataSourceApi { }); response.data.result.data.forEach((point: any) => { - frame.appendRow([...point]); + const [timestamp, ...rest] = point; + frame.appendRow([timestamp, ...rest.map((r: Array) => r[0])]); }); return frame; diff --git a/src/shared/hooks/useGetChartData.ts b/src/shared/hooks/useGetChartData.ts index 9bd1354..775347a 100644 --- a/src/shared/hooks/useGetChartData.ts +++ b/src/shared/hooks/useGetChartData.ts @@ -31,7 +31,6 @@ export const useGetChartData = async ({ dimensions = [], from, to, - ...rest }: UseGetChartDataType) => { let metrics = []; From ef16f7acd3309570987251ec05dd33eb994c7247 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Tue, 10 Sep 2024 11:22:43 +0300 Subject: [PATCH 18/37] Fix type --- src/datasource.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/datasource.ts b/src/datasource.ts index 5f7b4dc..9ae3610 100644 --- a/src/datasource.ts +++ b/src/datasource.ts @@ -71,7 +71,7 @@ export class DataSource extends DataSourceApi { response.data.result.data.forEach((point: any) => { const [timestamp, ...rest] = point; - frame.appendRow([timestamp, ...rest.map((r: Array) => r[0])]); + frame.appendRow([timestamp, ...rest.map((r: any[]) => r[0])]); }); return frame; From 8a32ce13a5c1017664a501f0890d3be7a47123b7 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Tue, 10 Sep 2024 11:38:32 +0300 Subject: [PATCH 19/37] Get value index form point --- src/QueryEditor.tsx | 1 - src/datasource.ts | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index e8731fd..7b092d5 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -56,7 +56,6 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu const mySubscriber = (msg: any, data: any) => { setTotalNodes(data.data.summary.nodes.length); - //setTotalInstances(data.data.summary.nodes.reduce((acc: number, node: any) => acc + node.chartIDs.length, 0)); setTotalInstances(data.data.summary.instances.length); }; diff --git a/src/datasource.ts b/src/datasource.ts index 9ae3610..850bbc6 100644 --- a/src/datasource.ts +++ b/src/datasource.ts @@ -69,9 +69,11 @@ export class DataSource extends DataSourceApi { }), }); + const valueIndex = response.data.result.point.value; + response.data.result.data.forEach((point: any) => { const [timestamp, ...rest] = point; - frame.appendRow([timestamp, ...rest.map((r: any[]) => r[0])]); + frame.appendRow([timestamp, ...rest.map((r: any[]) => r[valueIndex])]); }); return frame; From 87a267d38227970f3dac1d3d2f87378a9110c2d7 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Tue, 10 Sep 2024 22:15:16 +0300 Subject: [PATCH 20/37] wip --- src/QueryEditor.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index 7b092d5..d38a9c9 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -55,8 +55,11 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu const { spaceId, roomId, nodes: allNodes, dimensions, groupBy, contextId, filterBy, filterValue } = query; const mySubscriber = (msg: any, data: any) => { - setTotalNodes(data.data.summary.nodes.length); - setTotalInstances(data.data.summary.instances.length); + const { summary, view } = data?.data || {}; + const { nodes = [], instances = [], labels = [] } = summary || {}; + //const { dimensions, units } = view || {}; + setTotalNodes(nodes.length); + setTotalInstances(instances.length); }; const isGroupFunctionAvailable = React.useCallback(() => { From 159cfa6315d77c676ca6713668d5a3d2334353ff Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Thu, 12 Sep 2024 10:52:36 +0300 Subject: [PATCH 21/37] Update deprecated actions/upload-artifact version --- .github/workflows/ci.yml | 14 +++++++------- .github/workflows/release.yml | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 949ba8f..3cc397a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,16 +17,16 @@ on: default: 'false' type: choice options: - - 'true' - - 'false' + - 'true' + - 'false' ENV: required: true default: 'testing' type: choice options: - - testing - - staging - - production + - testing + - staging + - production env: BRANCH: ${{ github.event.inputs.BRANCH || github.ref }} @@ -44,7 +44,7 @@ jobs: - name: Setup Node.js environment uses: actions/setup-node@v2.1.2 with: - node-version: "14.x" + node-version: '14.x' - name: Get yarn cache directory path id: yarn-cache-dir-path @@ -84,7 +84,7 @@ jobs: zip "netdata-datasource-${{ steps.build_environment.outputs.BUILD_VERSION }}.zip" netdata-datasource -r - name: Upload artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: netdata-datasource-${{ steps.build_environment.outputs.BUILD_VERSION }}.zip path: ./netdata-datasource-${{ steps.build_environment.outputs.BUILD_VERSION }}.zip diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 11bc30c..790273c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,7 @@ name: Release on: push: tags: - - "v*.*.*" + - 'v*.*.*' jobs: release: @@ -17,7 +17,7 @@ jobs: - name: Setup Node.js environment uses: actions/setup-node@v2.1.2 with: - node-version: "14.x" + node-version: '14.x' - name: Get yarn cache directory path id: yarn-cache-dir-path @@ -64,7 +64,7 @@ jobs: export GRAFANA_PLUGIN_TYPE=$(cat dist/plugin.json | jq -r .type) export GRAFANA_PLUGIN_ARTIFACT=${GRAFANA_PLUGIN_ID}-${GRAFANA_PLUGIN_VERSION}.zip export GRAFANA_PLUGIN_ARTIFACT_CHECKSUM=${GRAFANA_PLUGIN_ARTIFACT}.md5 - + echo "plugin-id=${GRAFANA_PLUGIN_ID}" >> $GITHUB_OUTPUT echo "plugin-version=${GRAFANA_PLUGIN_VERSION}" >> $GITHUB_OUTPUT echo "plugin-type=${GRAFANA_PLUGIN_TYPE}" >> $GITHUB_OUTPUT @@ -91,7 +91,7 @@ jobs: echo "checksum=$(cat './${{ steps.metadata.outputs.archive-checksum }}' | cut -d' ' -f1)" >> $GITHUB_OUTPUT - name: Upload artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ${{ steps.metadata.outputs.archive }} path: ./${{ steps.metadata.outputs.archive }} From 55f9ac4c3f055c11a1533306ad60b43d88bde1be Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Thu, 12 Sep 2024 15:29:39 +0300 Subject: [PATCH 22/37] Remove charts/ request --- src/QueryEditor.tsx | 23 ++++++++++++++++------- src/shared/utils/transformations.ts | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 src/shared/utils/transformations.ts diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index d38a9c9..97913b5 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import { Input, LegacyForms, Select } from '@grafana/ui'; import { QueryEditorProps, SelectableValue } from '@grafana/data'; import { DataSource } from './datasource'; @@ -11,6 +11,7 @@ import { useFetchNodes } from 'shared/hooks/useFetchNodes'; import { Aggreagations, GroupByList, Methods } from 'shared/constants'; import { useFetchDimensions } from 'shared/hooks/useFetchDimensions'; import { Dropdown } from 'shared/types/dropdown.interface'; +import { getDimensions, getFilters, getGroupingByList, defaultFilter } from 'shared/utils/transformations'; import PubSub from 'pubsub-js'; type Props = QueryEditorProps; @@ -47,7 +48,11 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu const { rooms, fetchRooms } = useFetchRooms(baseUrl); const { nodes, fetchNodes } = useFetchNodes(baseUrl); const { contexts, fetchContexts } = useFetchContexts(baseUrl); - const { allDimensions, groupingByList, filters, units, fetchDimensions } = useFetchDimensions(baseUrl); + //const { fetchDimensions } = useFetchDimensions(baseUrl); + const [allDimensions, setAllDimension] = useState([]); + const [units, setUnits] = useState(''); + const [filters, setFilters] = useState(defaultFilter); + const [groupingByList, setGroupingByList] = useState(GroupByList); const filterList = React.useMemo(() => Object.keys(filters).map((s) => ({ label: s, value: s })), [filters]); const nodeList = React.useMemo(() => nodes?.map((c: any) => ({ label: c.name, value: c.id })), [nodes]); @@ -57,7 +62,11 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu const mySubscriber = (msg: any, data: any) => { const { summary, view } = data?.data || {}; const { nodes = [], instances = [], labels = [] } = summary || {}; - //const { dimensions, units } = view || {}; + const { dimensions, units } = view || {}; + setFilters(getFilters(labels)); + setGroupingByList(getGroupingByList(labels)); + setAllDimension(getDimensions(dimensions)); + setUnits(units); setTotalNodes(nodes.length); setTotalInstances(instances.length); }; @@ -124,7 +133,7 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu }); } - fetchDimensions({ spaceId, roomId, contextId, nodeIDs: filteredNodes.map((n: any) => n.value) }); + //fetchDimensions({ spaceId, roomId, contextId, nodeIDs: filteredNodes.map((n: any) => n.value) }); } }, [contextId]); // eslint-disable-line @@ -196,7 +205,7 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu setSelectedMethod(Methods[0]); setSelectedAggregations(Aggreagations[0]); - fetchDimensions({ spaceId, roomId, contextId: v.value, nodeIDs: selectedNodes?.map((n: any) => n.value) || [] }); + //fetchDimensions({ spaceId, roomId, contextId: v.value, nodeIDs: selectedNodes?.map((n: any) => n.value) || [] }); onChange({ ...query, contextId: v.value }); onRunQuery(); }; @@ -212,7 +221,7 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu setSelectedMethod(Methods[0]); setSelectedAggregations(Aggreagations[0]); - fetchDimensions({ spaceId, roomId, contextId, nodeIDs: data }); + //fetchDimensions({ spaceId, roomId, contextId, nodeIDs: data }); setSelectedNodes(data); onChange({ ...query, spaceId, roomId, contextId, nodes: data } as MyQuery); onRunQuery(); @@ -239,7 +248,7 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu onChange({ ...query, filterBy: undefined, filterValue: undefined }); onRunQuery(); } else { - setFilterByValues(filters[v?.value || ''].map((v) => ({ label: v, value: v }))); + setFilterByValues(filters[v?.value || ''].map((v: string) => ({ label: v, value: v }))); } }; diff --git a/src/shared/utils/transformations.ts b/src/shared/utils/transformations.ts new file mode 100644 index 0000000..4fba986 --- /dev/null +++ b/src/shared/utils/transformations.ts @@ -0,0 +1,24 @@ +import { GroupByList } from 'shared/constants'; + +export const getDimensions = (dimensions: any) => { + const { ids, names } = dimensions; + if (!ids) return []; + return ids.map((id: string, index: number) => ({ value: id, label: names[index] || id })); +}; + +export const defaultFilter = { 'No filter': [] }; + +export const getFilters = (labels: any[]) => { + if (!labels?.length) return defaultFilter; + return { + ...defaultFilter, + ...labels.reduce((acc: any, label: any) => { + acc[label.id] = (acc.vl || []).map((value: any) => value.id); + return acc; + }, {}), + }; +}; + +export const getGroupingByList = (labels: any) => { + return { ...GroupByList, ...labels.map((label: any) => ({ value: label.id, label: label.id })) }; +}; From fb076448212271755302057c05ab72d4e4bcdd39 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Thu, 12 Sep 2024 15:31:57 +0300 Subject: [PATCH 23/37] Fix linting error --- src/shared/utils/transformations.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/shared/utils/transformations.ts b/src/shared/utils/transformations.ts index 4fba986..7e1a44b 100644 --- a/src/shared/utils/transformations.ts +++ b/src/shared/utils/transformations.ts @@ -2,14 +2,20 @@ import { GroupByList } from 'shared/constants'; export const getDimensions = (dimensions: any) => { const { ids, names } = dimensions; - if (!ids) return []; + if (!ids) { + return []; + } + return ids.map((id: string, index: number) => ({ value: id, label: names[index] || id })); }; export const defaultFilter = { 'No filter': [] }; export const getFilters = (labels: any[]) => { - if (!labels?.length) return defaultFilter; + if (!labels?.length) { + return defaultFilter; + } + return { ...defaultFilter, ...labels.reduce((acc: any, label: any) => { From 3f62e665fed219b7e427017682e60aa8d08a3dae Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Thu, 12 Sep 2024 15:34:18 +0300 Subject: [PATCH 24/37] Remove unused import --- src/QueryEditor.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index 97913b5..50d8a0e 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -9,7 +9,6 @@ import { useFetchRooms } from 'shared/hooks/useFetchRooms'; import { useFetchContexts } from 'shared/hooks/useFetchContexts'; import { useFetchNodes } from 'shared/hooks/useFetchNodes'; import { Aggreagations, GroupByList, Methods } from 'shared/constants'; -import { useFetchDimensions } from 'shared/hooks/useFetchDimensions'; import { Dropdown } from 'shared/types/dropdown.interface'; import { getDimensions, getFilters, getGroupingByList, defaultFilter } from 'shared/utils/transformations'; import PubSub from 'pubsub-js'; From 9741528535cacff5cfbf977c2c00a6fe73ff7a75 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Thu, 12 Sep 2024 15:45:21 +0300 Subject: [PATCH 25/37] [DEBUG] --- src/QueryEditor.tsx | 4 +++- src/shared/utils/transformations.ts | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index 50d8a0e..a54e810 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -63,7 +63,9 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu const { nodes = [], instances = [], labels = [] } = summary || {}; const { dimensions, units } = view || {}; setFilters(getFilters(labels)); - setGroupingByList(getGroupingByList(labels)); + const options = getGroupingByList(labels); + console.log({ labels, options }); + setGroupingByList(options); setAllDimension(getDimensions(dimensions)); setUnits(units); setTotalNodes(nodes.length); diff --git a/src/shared/utils/transformations.ts b/src/shared/utils/transformations.ts index 7e1a44b..eeb65c8 100644 --- a/src/shared/utils/transformations.ts +++ b/src/shared/utils/transformations.ts @@ -26,5 +26,7 @@ export const getFilters = (labels: any[]) => { }; export const getGroupingByList = (labels: any) => { + const groupingByList = { ...GroupByList, ...labels.map((label: any) => ({ value: label.id, label: label.id })) }; + console.log({ labels, groupingByList }); return { ...GroupByList, ...labels.map((label: any) => ({ value: label.id, label: label.id })) }; }; From ec4155976cb055f4facf3d774fe8fa16053d654f Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Thu, 12 Sep 2024 15:50:34 +0300 Subject: [PATCH 26/37] Revert "[DEBUG]" This reverts commit 71a8e807427ce504d613396fae92a4366ae760fb. --- src/QueryEditor.tsx | 4 +--- src/shared/utils/transformations.ts | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index a54e810..50d8a0e 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -63,9 +63,7 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu const { nodes = [], instances = [], labels = [] } = summary || {}; const { dimensions, units } = view || {}; setFilters(getFilters(labels)); - const options = getGroupingByList(labels); - console.log({ labels, options }); - setGroupingByList(options); + setGroupingByList(getGroupingByList(labels)); setAllDimension(getDimensions(dimensions)); setUnits(units); setTotalNodes(nodes.length); diff --git a/src/shared/utils/transformations.ts b/src/shared/utils/transformations.ts index eeb65c8..7e1a44b 100644 --- a/src/shared/utils/transformations.ts +++ b/src/shared/utils/transformations.ts @@ -26,7 +26,5 @@ export const getFilters = (labels: any[]) => { }; export const getGroupingByList = (labels: any) => { - const groupingByList = { ...GroupByList, ...labels.map((label: any) => ({ value: label.id, label: label.id })) }; - console.log({ labels, groupingByList }); return { ...GroupByList, ...labels.map((label: any) => ({ value: label.id, label: label.id })) }; }; From be84d41c64c154208f8f91c54e9e22a16ca634ff Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Thu, 12 Sep 2024 15:51:25 +0300 Subject: [PATCH 27/37] Fix groupingByList options type --- src/shared/utils/transformations.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/utils/transformations.ts b/src/shared/utils/transformations.ts index 7e1a44b..6348ee2 100644 --- a/src/shared/utils/transformations.ts +++ b/src/shared/utils/transformations.ts @@ -26,5 +26,5 @@ export const getFilters = (labels: any[]) => { }; export const getGroupingByList = (labels: any) => { - return { ...GroupByList, ...labels.map((label: any) => ({ value: label.id, label: label.id })) }; + return [...GroupByList, ...labels.map((label: any) => ({ value: label.id, label: label.id }))]; }; From ee7b523b209a3652c21d84d801018018f27e9d70 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Thu, 12 Sep 2024 15:52:21 +0300 Subject: [PATCH 28/37] Remove comments --- src/QueryEditor.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index 50d8a0e..ea55129 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -47,7 +47,6 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu const { rooms, fetchRooms } = useFetchRooms(baseUrl); const { nodes, fetchNodes } = useFetchNodes(baseUrl); const { contexts, fetchContexts } = useFetchContexts(baseUrl); - //const { fetchDimensions } = useFetchDimensions(baseUrl); const [allDimensions, setAllDimension] = useState([]); const [units, setUnits] = useState(''); const [filters, setFilters] = useState(defaultFilter); @@ -131,8 +130,6 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu filteredNodes.push({ label: currentNode?.name, value: currentNode?.id }); }); } - - //fetchDimensions({ spaceId, roomId, contextId, nodeIDs: filteredNodes.map((n: any) => n.value) }); } }, [contextId]); // eslint-disable-line @@ -204,7 +201,6 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu setSelectedMethod(Methods[0]); setSelectedAggregations(Aggreagations[0]); - //fetchDimensions({ spaceId, roomId, contextId: v.value, nodeIDs: selectedNodes?.map((n: any) => n.value) || [] }); onChange({ ...query, contextId: v.value }); onRunQuery(); }; @@ -220,7 +216,6 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu setSelectedMethod(Methods[0]); setSelectedAggregations(Aggreagations[0]); - //fetchDimensions({ spaceId, roomId, contextId, nodeIDs: data }); setSelectedNodes(data); onChange({ ...query, spaceId, roomId, contextId, nodes: data } as MyQuery); onRunQuery(); From 9e17a58f603ef0c4a4e7099e1ec8d5c3d5fa918a Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Thu, 12 Sep 2024 15:58:14 +0300 Subject: [PATCH 29/37] Handle empty labels array --- src/shared/utils/transformations.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/shared/utils/transformations.ts b/src/shared/utils/transformations.ts index 6348ee2..9d91e08 100644 --- a/src/shared/utils/transformations.ts +++ b/src/shared/utils/transformations.ts @@ -25,6 +25,10 @@ export const getFilters = (labels: any[]) => { }; }; -export const getGroupingByList = (labels: any) => { +export const getGroupingByList = (labels: any[]) => { + if (!labels?.length) { + return GroupByList; + } + return [...GroupByList, ...labels.map((label: any) => ({ value: label.id, label: label.id }))]; }; From 413cc319601e067a2ca905be69d1dcbeb9b6d8d9 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Thu, 12 Sep 2024 16:18:42 +0300 Subject: [PATCH 30/37] Fix filters --- src/shared/utils/transformations.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/utils/transformations.ts b/src/shared/utils/transformations.ts index 9d91e08..503a396 100644 --- a/src/shared/utils/transformations.ts +++ b/src/shared/utils/transformations.ts @@ -19,7 +19,7 @@ export const getFilters = (labels: any[]) => { return { ...defaultFilter, ...labels.reduce((acc: any, label: any) => { - acc[label.id] = (acc.vl || []).map((value: any) => value.id); + acc[label.id] = (label.vl || []).map((value: any) => value.id); return acc; }, {}), }; From 189545216d298486c46a014ea10b265128404291 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Thu, 12 Sep 2024 16:25:23 +0300 Subject: [PATCH 31/37] Delete unused useFetchDimensions --- src/shared/hooks/useFetchDimensions.test.ts | 324 -------------------- src/shared/hooks/useFetchDimensions.ts | 58 ---- 2 files changed, 382 deletions(-) delete mode 100644 src/shared/hooks/useFetchDimensions.test.ts delete mode 100644 src/shared/hooks/useFetchDimensions.ts diff --git a/src/shared/hooks/useFetchDimensions.test.ts b/src/shared/hooks/useFetchDimensions.test.ts deleted file mode 100644 index 58a35f5..0000000 --- a/src/shared/hooks/useFetchDimensions.test.ts +++ /dev/null @@ -1,324 +0,0 @@ -import { renderHook } from '@testing-library/react-hooks'; -import * as hooks from './useFetchDimensions'; - -const baseUrl = '/base'; - -const dataMock: Promise = Promise.resolve({ - 'apps.cpu': { - chartLabels: { - _collect_module: ['_none_'], - _collect_plugin: ['apps.plugin'], - _instance_family: ['cpu'], - }, - chartType: 'stacked', - context: 'apps.cpu', - dimensions: { - agent_sd: { - id: 'agent_sd', - name: 'agent_sd', - }, - alertmanager: { - id: 'alertmanager', - name: 'alertmanager', - }, - 'apps.plugin': { - id: 'apps.plugin', - name: 'apps.plugin', - }, - bash: { - id: 'bash', - name: 'bash', - }, - 'cloud-accounts-service': { - id: 'cloud-accounts-service', - name: 'cloud-accounts-service', - }, - 'cloud-agent-data-ctrl-service': { - id: 'cloud-agent-data-ctrl-service', - name: 'cloud-agent-data-ctrl-service', - }, - 'cloud-agent-service': { - id: 'cloud-agent-service', - name: 'cloud-agent-service', - }, - 'cloud-custom-dashboard-service': { - id: 'cloud-custom-dashboard-service', - name: 'cloud-custom-dashboard-service', - }, - 'cloud-iam-agent-service': { - id: 'cloud-iam-agent-service', - name: 'cloud-iam-agent-service', - }, - 'cloud-iam-user-service': { - id: 'cloud-iam-user-service', - name: 'cloud-iam-user-service', - }, - 'cloud-node-mqtt-input-service': { - id: 'cloud-node-mqtt-input-service', - name: 'cloud-node-mqtt-input-service', - }, - 'cloud-node-mqtt-output-service': { - id: 'cloud-node-mqtt-output-service', - name: 'cloud-node-mqtt-output-service', - }, - 'cloud-nodes-service': { - id: 'cloud-nodes-service', - name: 'cloud-nodes-service', - }, - 'cloud-spaceroom-service': { - id: 'cloud-spaceroom-service', - name: 'cloud-spaceroom-service', - }, - containerd: { - id: 'containerd', - name: 'containerd', - }, - 'containerd-shim': { - id: 'containerd-shim', - name: 'containerd-shim', - }, - dockerd: { - id: 'dockerd', - name: 'dockerd', - }, - envoy: { - id: 'envoy', - name: 'envoy', - }, - 'go.d.plugin': { - id: 'go.d.plugin', - name: 'go.d.plugin', - }, - grafana: { - id: 'grafana', - name: 'grafana', - }, - gunicorn: { - id: 'gunicorn', - name: 'gunicorn', - }, - haproxy: { - id: 'haproxy', - name: 'haproxy', - }, - 'haproxy-ingress': { - id: 'haproxy-ingress', - name: 'haproxy-ingress', - }, - 'kube-proxy': { - id: 'kube-proxy', - name: 'kube-proxy', - }, - 'kube-state-metrics': { - id: 'kube-state-metrics', - name: 'kube-state-metrics', - }, - kubelet: { - id: 'kubelet', - name: 'kubelet', - }, - loki: { - id: 'loki', - name: 'loki', - }, - 'metrics-server': { - id: 'metrics-server', - name: 'metrics-server', - }, - mongod: { - id: 'mongod', - name: 'mongod', - }, - netdata: { - id: 'netdata', - name: 'netdata', - }, - nginx: { - id: 'nginx', - name: 'nginx', - }, - node_exporter: { - id: 'node_exporter', - name: 'node_exporter', - }, - other: { - id: 'other', - name: 'other', - }, - pomerium: { - id: 'pomerium', - name: 'pomerium', - }, - 'prometheus-adapter': { - id: 'prometheus-adapter', - name: 'prometheus-adapter', - }, - 'prometheus-pushgateway': { - id: 'prometheus-pushgateway', - name: 'prometheus-pushgateway', - }, - 'prometheus-server': { - id: 'prometheus-server', - name: 'prometheus-server', - }, - promtail: { - id: 'promtail', - name: 'promtail', - }, - python: { - id: 'python', - name: 'python', - }, - 'python.d.plugin': { - id: 'python.d.plugin', - name: 'python.d.plugin', - }, - redis: { - id: 'redis', - name: 'redis', - }, - sshd: { - id: 'sshd', - name: 'sshd', - }, - traefik: { - id: 'traefik', - name: 'traefik', - }, - vernemq: { - id: 'vernemq', - name: 'vernemq', - }, - }, - family: 'cpu', - firstEntry: 1662555061, - lastEntry: 1662969591, - module: '_none_', - nodeIDs: [ - '3d36c8ea-49dc-4191-9010-9a7862fe472d', - '05ce83ea-f62e-4839-868e-90bc81a7114a', - '113074c4-4575-4feb-8abd-7c077b9c5e96', - '2475156b-54a1-4d2f-99d6-7e5f816e5317', - 'ca1c7695-88e4-4124-b54f-804b297e6e9d', - '972c5e17-a341-4aa7-9598-31fd0aef8e26', - '113074c4-4575-4feb-8abd-7c077b9c5e96', - '74ffad89-08c2-42f4-baa3-c653d189b5dc', - 'ca1c7695-88e4-4124-b54f-804b297e6e9d', - 'ca1c7695-88e4-4124-b54f-804b297e6e9d', - '3bd6c73f-888e-4da5-bbe6-6ef0baf9d939', - '05ce83ea-f62e-4839-868e-90bc81a7114a', - '054b5fee-a743-473c-b0d2-8d394c43a333', - '3d36c8ea-49dc-4191-9010-9a7862fe472d', - '2f4360eb-5969-4603-b6d1-5bb22e2334e6', - '113074c4-4575-4feb-8abd-7c077b9c5e96', - '25fe7213-4ff2-44d3-8e81-07b5747b502b', - '2f4360eb-5969-4603-b6d1-5bb22e2334e6', - '2475156b-54a1-4d2f-99d6-7e5f816e5317', - '0fc6e555-1f75-49d9-bd35-70321f6dd2e6', - '3bd6c73f-888e-4da5-bbe6-6ef0baf9d939', - '9535c5e7-eafd-4889-8097-844e536628a6', - '972c5e17-a341-4aa7-9598-31fd0aef8e26', - '054b5fee-a743-473c-b0d2-8d394c43a333', - '25fe7213-4ff2-44d3-8e81-07b5747b502b', - '74ffad89-08c2-42f4-baa3-c653d189b5dc', - '3bd6c73f-888e-4da5-bbe6-6ef0baf9d939', - '9535c5e7-eafd-4889-8097-844e536628a6', - '2f4360eb-5969-4603-b6d1-5bb22e2334e6', - '9535c5e7-eafd-4889-8097-844e536628a6', - '972c5e17-a341-4aa7-9598-31fd0aef8e26', - '0fc6e555-1f75-49d9-bd35-70321f6dd2e6', - '05ce83ea-f62e-4839-868e-90bc81a7114a', - '25fe7213-4ff2-44d3-8e81-07b5747b502b', - '2475156b-54a1-4d2f-99d6-7e5f816e5317', - '3d36c8ea-49dc-4191-9010-9a7862fe472d', - '054b5fee-a743-473c-b0d2-8d394c43a333', - '0fc6e555-1f75-49d9-bd35-70321f6dd2e6', - '74ffad89-08c2-42f4-baa3-c653d189b5dc', - ], - plugin: 'apps.plugin', - priority: 20001, - title: 'Apps CPU Time (100% = 1 core)', - units: 'percentage', - }, -}); - -describe('useFetchDimensions', () => { - it('return correct data', async () => { - jest.spyOn(hooks, 'getDimensions').mockImplementation(() => dataMock); - - const { result, waitFor } = renderHook(() => hooks.useFetchDimensions(baseUrl)); - - await result.current.fetchDimensions({ - spaceId: 'spaceId', - roomId: 'roomId', - contextId: 'apps.cpu', - nodeIDs: ['nodeIDs'], - }); - - await waitFor(() => result.current.allDimensions.length > 0); - - expect(result.current.allDimensions).toBeDefined(); - expect(result.current.allDimensions).toEqual([ - { label: 'agent_sd', value: 'agent_sd' }, - { label: 'alertmanager', value: 'alertmanager' }, - { label: 'apps.plugin', value: 'apps.plugin' }, - { label: 'bash', value: 'bash' }, - { label: 'cloud-accounts-service', value: 'cloud-accounts-service' }, - { label: 'cloud-agent-data-ctrl-service', value: 'cloud-agent-data-ctrl-service' }, - { label: 'cloud-agent-service', value: 'cloud-agent-service' }, - { label: 'cloud-custom-dashboard-service', value: 'cloud-custom-dashboard-service' }, - { label: 'cloud-iam-agent-service', value: 'cloud-iam-agent-service' }, - { label: 'cloud-iam-user-service', value: 'cloud-iam-user-service' }, - { label: 'cloud-node-mqtt-input-service', value: 'cloud-node-mqtt-input-service' }, - { label: 'cloud-node-mqtt-output-service', value: 'cloud-node-mqtt-output-service' }, - { label: 'cloud-nodes-service', value: 'cloud-nodes-service' }, - { label: 'cloud-spaceroom-service', value: 'cloud-spaceroom-service' }, - { label: 'containerd', value: 'containerd' }, - { label: 'containerd-shim', value: 'containerd-shim' }, - { label: 'dockerd', value: 'dockerd' }, - { label: 'envoy', value: 'envoy' }, - { label: 'go.d.plugin', value: 'go.d.plugin' }, - { label: 'grafana', value: 'grafana' }, - { label: 'gunicorn', value: 'gunicorn' }, - { label: 'haproxy', value: 'haproxy' }, - { label: 'haproxy-ingress', value: 'haproxy-ingress' }, - { label: 'kube-proxy', value: 'kube-proxy' }, - { label: 'kube-state-metrics', value: 'kube-state-metrics' }, - { label: 'kubelet', value: 'kubelet' }, - { label: 'loki', value: 'loki' }, - { label: 'metrics-server', value: 'metrics-server' }, - { label: 'mongod', value: 'mongod' }, - { label: 'netdata', value: 'netdata' }, - { label: 'nginx', value: 'nginx' }, - { label: 'node_exporter', value: 'node_exporter' }, - { label: 'other', value: 'other' }, - { label: 'pomerium', value: 'pomerium' }, - { label: 'prometheus-adapter', value: 'prometheus-adapter' }, - { label: 'prometheus-pushgateway', value: 'prometheus-pushgateway' }, - { label: 'prometheus-server', value: 'prometheus-server' }, - { label: 'promtail', value: 'promtail' }, - { label: 'python', value: 'python' }, - { label: 'python.d.plugin', value: 'python.d.plugin' }, - { label: 'redis', value: 'redis' }, - { label: 'sshd', value: 'sshd' }, - { label: 'traefik', value: 'traefik' }, - { label: 'vernemq', value: 'vernemq' }, - ]); - - expect(result.current.filters).toEqual({ - 'No filter': [], - _collect_module: ['_none_'], - _collect_plugin: ['apps.plugin'], - _instance_family: ['cpu'], - }); - expect(result.current.groupingByList).toEqual([ - { label: 'dimension', value: 'dimension' }, - { label: 'node', value: 'node' }, - { label: 'instance', value: 'instance' }, - { label: '_collect_module', value: '_collect_module' }, - { label: '_collect_plugin', value: '_collect_plugin' }, - { label: '_instance_family', value: '_instance_family' }, - ]); - expect(result.current.units).toEqual('percentage'); - }); -}); diff --git a/src/shared/hooks/useFetchDimensions.ts b/src/shared/hooks/useFetchDimensions.ts deleted file mode 100644 index 0ed07e2..0000000 --- a/src/shared/hooks/useFetchDimensions.ts +++ /dev/null @@ -1,58 +0,0 @@ -import React from 'react'; -import { GroupByList } from 'shared/constants'; -import { Dropdown } from 'shared/types/dropdown.interface'; -import { Post } from 'shared/utils/request'; - -export const getDimensions = async ( - spaceId: string, - roomId: string, - contextId: string, - nodeIDs: string[], - baseUrl: string -) => { - const response = await Post({ - path: `/v2/spaces/${spaceId}/rooms/${roomId}/charts/${contextId}`, - baseUrl, - data: { - filter: { nodeIDs }, - }, - }); - return response?.data?.results; -}; - -export const useFetchDimensions = (baseUrl: string) => { - const [isError, setIsError] = React.useState(false); - const [allDimensions, setDimensions] = React.useState([]); - const [filters, setFilters] = React.useState<{ [key in string]: [] }>({}); - const [groupingByList, setGroupingByList] = React.useState(GroupByList); - const [units, setUnits] = React.useState(''); - - const fetchDimensions = async ({ spaceId, roomId, contextId, nodeIDs }: any) => { - setIsError(false); - try { - const result = await getDimensions(spaceId, roomId, contextId, nodeIDs, baseUrl); - setUnits(result?.[contextId].units); - setDimensions(Object.values(result?.[contextId]?.dimensions)?.map((c: any) => ({ label: c.name, value: c.id }))); - setFilters({ 'No filter': [], ...result?.[contextId]?.chartLabels }); - - const groupByData = [ - ...GroupByList, - ...Object.keys(result?.[contextId]?.chartLabels).map((g: any) => ({ label: g, value: g })), - ]; - - setGroupingByList(groupByData); - } catch (error) { - console.log('ERROR (useFetchDimensions): ', error); - setIsError(true); - } - }; - - return { - isError, - allDimensions, - filters, - groupingByList, - units, - fetchDimensions, - }; -}; From ab368c8e0b60b92de7a56239095651d6ddaf8e7b Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Fri, 13 Sep 2024 10:45:54 +0300 Subject: [PATCH 32/37] Reset filter value on each filter change --- src/QueryEditor.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index ea55129..46ff542 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -236,9 +236,9 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu const onFilterByChange = (v: SelectableValue) => { setSelectedFilter(v); + setSelectedFilterValue({}); if (v.value === 'No filter') { - setSelectedFilterValue({}); onChange({ ...query, filterBy: undefined, filterValue: undefined }); onRunQuery(); } else { From 491c3cf72d3f9bb08c57b1a69a96b86fd7870952 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Mon, 24 Mar 2025 15:34:33 +0200 Subject: [PATCH 33/37] Change node name accessor prop --- src/datasource.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/datasource.ts b/src/datasource.ts index 850bbc6..eb38118 100644 --- a/src/datasource.ts +++ b/src/datasource.ts @@ -63,7 +63,7 @@ export class DataSource extends DataSourceApi { fields: response.data.result.labels.map((id: string, i: number) => { const node = response.data.summary.nodes.find((n: any) => n.nd === id); return { - name: node?.name || id, + name: node?.nm || id, type: i === 0 ? FieldType.time : FieldType.number, }; }), From 8b555cf5e7aac439b919003b4ba0c2edc68b3efe Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Mon, 24 Mar 2025 15:42:20 +0200 Subject: [PATCH 34/37] fixup! Change node name accessor prop --- src/datasource.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/datasource.ts b/src/datasource.ts index eb38118..3dad058 100644 --- a/src/datasource.ts +++ b/src/datasource.ts @@ -61,7 +61,7 @@ export class DataSource extends DataSourceApi { const frame = new MutableDataFrame({ refId, fields: response.data.result.labels.map((id: string, i: number) => { - const node = response.data.summary.nodes.find((n: any) => n.nd === id); + const node = response.data.summary.nodes.find((n: any) => n.mg === id); return { name: node?.nm || id, type: i === 0 ? FieldType.time : FieldType.number, From 4c7111b7f3fa1956e9ec2629d4785cda9ed57093 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Mon, 24 Mar 2025 15:51:15 +0200 Subject: [PATCH 35/37] Update major version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2765158..18cf6cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "netdatacloud-netdata-datasource", - "version": "2.0.0", + "version": "3.0.0", "description": "netdata datasource plugin", "scripts": { "build": "grafana-toolkit plugin:build", From 45031ccabe1290c04e0bc9e75d3d288d4b52bc20 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Mon, 24 Mar 2025 16:37:52 +0200 Subject: [PATCH 36/37] Fix licence text --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 8dada3e..f7144cd 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright {yyyy} {name of copyright owner} + Copyright 2025 Netdata Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From 5e5fdc194f6baac87dbac7730c96fa5185212484 Mon Sep 17 00:00:00 2001 From: John Kapantzakis Date: Tue, 22 Apr 2025 15:43:54 +0300 Subject: [PATCH 37/37] Minor change --- src/QueryEditor.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index 46ff542..a8dd98e 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -47,7 +47,7 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu const { rooms, fetchRooms } = useFetchRooms(baseUrl); const { nodes, fetchNodes } = useFetchNodes(baseUrl); const { contexts, fetchContexts } = useFetchContexts(baseUrl); - const [allDimensions, setAllDimension] = useState([]); + const [allDimensions, setAllDimensions] = useState([]); const [units, setUnits] = useState(''); const [filters, setFilters] = useState(defaultFilter); const [groupingByList, setGroupingByList] = useState(GroupByList); @@ -63,7 +63,7 @@ const QueryEditor: React.FC = ({ datasource, query, range, onChange, onRu const { dimensions, units } = view || {}; setFilters(getFilters(labels)); setGroupingByList(getGroupingByList(labels)); - setAllDimension(getDimensions(dimensions)); + setAllDimensions(getDimensions(dimensions)); setUnits(units); setTotalNodes(nodes.length); setTotalInstances(instances.length);