Skip to content

Commit d89b850

Browse files
authored
Merge pull request #28 from netdata/agent-v2-update
Agent v2 updates
2 parents 030c39b + 5e5fdc1 commit d89b850

File tree

14 files changed

+183
-448
lines changed

14 files changed

+183
-448
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ on:
1717
default: 'false'
1818
type: choice
1919
options:
20-
- 'true'
21-
- 'false'
20+
- 'true'
21+
- 'false'
2222
ENV:
2323
required: true
2424
default: 'testing'
2525
type: choice
2626
options:
27-
- testing
28-
- staging
29-
- production
27+
- testing
28+
- staging
29+
- production
3030

3131
env:
3232
BRANCH: ${{ github.event.inputs.BRANCH || github.ref }}
@@ -44,7 +44,7 @@ jobs:
4444
- name: Setup Node.js environment
4545
uses: actions/[email protected]
4646
with:
47-
node-version: "14.x"
47+
node-version: '14.x'
4848

4949
- name: Get yarn cache directory path
5050
id: yarn-cache-dir-path
@@ -84,7 +84,7 @@ jobs:
8484
zip "netdata-datasource-${{ steps.build_environment.outputs.BUILD_VERSION }}.zip" netdata-datasource -r
8585
8686
- name: Upload artifacts
87-
uses: actions/upload-artifact@v2
87+
uses: actions/upload-artifact@v4
8888
with:
8989
name: netdata-datasource-${{ steps.build_environment.outputs.BUILD_VERSION }}.zip
9090
path: ./netdata-datasource-${{ steps.build_environment.outputs.BUILD_VERSION }}.zip

.github/workflows/release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Release
33
on:
44
push:
55
tags:
6-
- "v*.*.*"
6+
- 'v*.*.*'
77

88
jobs:
99
release:
@@ -17,7 +17,7 @@ jobs:
1717
- name: Setup Node.js environment
1818
uses: actions/[email protected]
1919
with:
20-
node-version: "14.x"
20+
node-version: '14.x'
2121

2222
- name: Get yarn cache directory path
2323
id: yarn-cache-dir-path
@@ -64,7 +64,7 @@ jobs:
6464
export GRAFANA_PLUGIN_TYPE=$(cat dist/plugin.json | jq -r .type)
6565
export GRAFANA_PLUGIN_ARTIFACT=${GRAFANA_PLUGIN_ID}-${GRAFANA_PLUGIN_VERSION}.zip
6666
export GRAFANA_PLUGIN_ARTIFACT_CHECKSUM=${GRAFANA_PLUGIN_ARTIFACT}.md5
67-
67+
6868
echo "plugin-id=${GRAFANA_PLUGIN_ID}" >> $GITHUB_OUTPUT
6969
echo "plugin-version=${GRAFANA_PLUGIN_VERSION}" >> $GITHUB_OUTPUT
7070
echo "plugin-type=${GRAFANA_PLUGIN_TYPE}" >> $GITHUB_OUTPUT
@@ -91,7 +91,7 @@ jobs:
9191
echo "checksum=$(cat './${{ steps.metadata.outputs.archive-checksum }}' | cut -d' ' -f1)" >> $GITHUB_OUTPUT
9292
9393
- name: Upload artifacts
94-
uses: actions/upload-artifact@v2
94+
uses: actions/upload-artifact@v4
9595
with:
9696
name: ${{ steps.metadata.outputs.archive }}
9797
path: ./${{ steps.metadata.outputs.archive }}

.prettierrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
...require("./node_modules/@grafana/toolkit/src/config/prettier.plugin.config.json"),
2+
...require('./node_modules/@grafana/toolkit/src/config/prettier.plugin.config.json'),
33
};

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright 2025 Netdata
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "netdatacloud-netdata-datasource",
3-
"version": "2.0.0",
3+
"version": "3.0.0",
44
"description": "netdata datasource plugin",
55
"scripts": {
66
"build": "grafana-toolkit plugin:build",

src/QueryEditor.tsx

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import { Input, LegacyForms, Select } from '@grafana/ui';
33
import { QueryEditorProps, SelectableValue } from '@grafana/data';
44
import { DataSource } from './datasource';
@@ -9,16 +9,21 @@ import { useFetchRooms } from 'shared/hooks/useFetchRooms';
99
import { useFetchContexts } from 'shared/hooks/useFetchContexts';
1010
import { useFetchNodes } from 'shared/hooks/useFetchNodes';
1111
import { Aggreagations, GroupByList, Methods } from 'shared/constants';
12-
import { useFetchDimensions } from 'shared/hooks/useFetchDimensions';
1312
import { Dropdown } from 'shared/types/dropdown.interface';
13+
import { getDimensions, getFilters, getGroupingByList, defaultFilter } from 'shared/utils/transformations';
1414
import PubSub from 'pubsub-js';
1515

1616
type Props = QueryEditorProps<DataSource, MyQuery, MyDataSourceOptions>;
1717

1818
const { FormField } = LegacyForms;
1919

20-
const QueryEditor: React.FC<Props> = ({ datasource, query, onChange, onRunQuery }) => {
20+
const QueryEditor: React.FC<Props> = ({ datasource, query, range, onChange, onRunQuery }) => {
2121
const { baseUrl } = datasource;
22+
const from = range!.from.valueOf();
23+
const to = range!.to.valueOf();
24+
const after = Math.floor(from / 1000);
25+
const before = Math.floor(to / 1000);
26+
2227
const [selectedSpace, setSelectedSpace] = React.useState<Dropdown>();
2328
const [selectedRoom, setSelectedRoom] = React.useState<Dropdown>();
2429
const [selectedFilter, setSelectedFilter] = React.useState<Dropdown>();
@@ -42,16 +47,26 @@ const QueryEditor: React.FC<Props> = ({ datasource, query, onChange, onRunQuery
4247
const { rooms, fetchRooms } = useFetchRooms(baseUrl);
4348
const { nodes, fetchNodes } = useFetchNodes(baseUrl);
4449
const { contexts, fetchContexts } = useFetchContexts(baseUrl);
45-
const { allDimensions, groupingByList, filters, units, fetchDimensions } = useFetchDimensions(baseUrl);
50+
const [allDimensions, setAllDimensions] = useState([]);
51+
const [units, setUnits] = useState('');
52+
const [filters, setFilters] = useState<any>(defaultFilter);
53+
const [groupingByList, setGroupingByList] = useState<Dropdown[]>(GroupByList);
4654

4755
const filterList = React.useMemo(() => Object.keys(filters).map((s) => ({ label: s, value: s })), [filters]);
4856
const nodeList = React.useMemo(() => nodes?.map((c: any) => ({ label: c.name, value: c.id })), [nodes]);
4957

5058
const { spaceId, roomId, nodes: allNodes, dimensions, groupBy, contextId, filterBy, filterValue } = query;
5159

5260
const mySubscriber = (msg: any, data: any) => {
53-
setTotalNodes(data.data.nodes.length);
54-
setTotalInstances(data.data.nodes.reduce((acc: number, node: any) => acc + node.chartIDs.length, 0));
61+
const { summary, view } = data?.data || {};
62+
const { nodes = [], instances = [], labels = [] } = summary || {};
63+
const { dimensions, units } = view || {};
64+
setFilters(getFilters(labels));
65+
setGroupingByList(getGroupingByList(labels));
66+
setAllDimensions(getDimensions(dimensions));
67+
setUnits(units);
68+
setTotalNodes(nodes.length);
69+
setTotalInstances(instances.length);
5570
};
5671

5772
const isGroupFunctionAvailable = React.useCallback(() => {
@@ -88,9 +103,9 @@ const QueryEditor: React.FC<Props> = ({ datasource, query, onChange, onRunQuery
88103
const room = rooms.find((r) => r.value === roomId);
89104
setSelectedRoom({ label: room?.label, value: room?.value });
90105
fetchNodes(spaceId || '', roomId);
91-
fetchContexts(spaceId || '', roomId);
106+
fetchContexts(spaceId || '', roomId, after, before);
92107
}
93-
}, [roomId, rooms, fetchContexts, fetchNodes, spaceId]);
108+
}, [roomId, rooms, fetchContexts, fetchNodes, spaceId, after, before]);
94109

95110
React.useEffect(() => {
96111
// eslint-disable-line
@@ -115,8 +130,6 @@ const QueryEditor: React.FC<Props> = ({ datasource, query, onChange, onRunQuery
115130
filteredNodes.push({ label: currentNode?.name, value: currentNode?.id });
116131
});
117132
}
118-
119-
fetchDimensions({ spaceId, roomId, contextId, nodeIDs: filteredNodes.map((n: any) => n.value) });
120133
}
121134
}, [contextId]); // eslint-disable-line
122135

@@ -171,7 +184,7 @@ const QueryEditor: React.FC<Props> = ({ datasource, query, onChange, onRunQuery
171184
setSelectedMethod(Methods[0]);
172185
setSelectedAggregations(Aggreagations[0]);
173186

174-
fetchContexts(selectedSpace?.value || '', v.value || '');
187+
fetchContexts(selectedSpace?.value || '', v.value || '', after, before);
175188
fetchNodes(selectedSpace?.value || '', v.value || '');
176189
onChange({ ...query, spaceId: spaceId, roomId: v.value });
177190
onRunQuery();
@@ -188,7 +201,6 @@ const QueryEditor: React.FC<Props> = ({ datasource, query, onChange, onRunQuery
188201
setSelectedMethod(Methods[0]);
189202
setSelectedAggregations(Aggreagations[0]);
190203

191-
fetchDimensions({ spaceId, roomId, contextId: v.value, nodeIDs: selectedNodes?.map((n: any) => n.value) || [] });
192204
onChange({ ...query, contextId: v.value });
193205
onRunQuery();
194206
};
@@ -204,7 +216,6 @@ const QueryEditor: React.FC<Props> = ({ datasource, query, onChange, onRunQuery
204216
setSelectedMethod(Methods[0]);
205217
setSelectedAggregations(Aggreagations[0]);
206218

207-
fetchDimensions({ spaceId, roomId, contextId, nodeIDs: data });
208219
setSelectedNodes(data);
209220
onChange({ ...query, spaceId, roomId, contextId, nodes: data } as MyQuery);
210221
onRunQuery();
@@ -225,13 +236,13 @@ const QueryEditor: React.FC<Props> = ({ datasource, query, onChange, onRunQuery
225236

226237
const onFilterByChange = (v: SelectableValue<string>) => {
227238
setSelectedFilter(v);
239+
setSelectedFilterValue({});
228240

229241
if (v.value === 'No filter') {
230-
setSelectedFilterValue({});
231242
onChange({ ...query, filterBy: undefined, filterValue: undefined });
232243
onRunQuery();
233244
} else {
234-
setFilterByValues(filters[v?.value || ''].map((v) => ({ label: v, value: v })));
245+
setFilterByValues(filters[v?.value || ''].map((v: string) => ({ label: v, value: v })));
235246
}
236247
};
237248

src/datasource.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,19 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
6161
const frame = new MutableDataFrame({
6262
refId,
6363
fields: response.data.result.labels.map((id: string, i: number) => {
64-
const node = response.data.nodes.find((n: any) => n.id === id);
64+
const node = response.data.summary.nodes.find((n: any) => n.mg === id);
6565
return {
66-
name: node?.name || id,
66+
name: node?.nm || id,
6767
type: i === 0 ? FieldType.time : FieldType.number,
6868
};
6969
}),
7070
});
7171

72+
const valueIndex = response.data.result.point.value;
73+
7274
response.data.result.data.forEach((point: any) => {
73-
frame.appendRow([...point]);
75+
const [timestamp, ...rest] = point;
76+
frame.appendRow([timestamp, ...rest.map((r: any[]) => r[valueIndex])]);
7477
});
7578

7679
return frame;

src/shared/hooks/useFetchContexts.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('useFetchContexts', () => {
1515

1616
const { result, waitFor } = renderHook(() => hooks.useFetchContexts(baseUrl));
1717

18-
await result.current.fetchContexts('spaceId', 'roomId');
18+
await result.current.fetchContexts('spaceId', 'roomId', -900, 0);
1919

2020
await waitFor(() => result.current.contexts.length > 0);
2121

src/shared/hooks/useFetchContexts.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
11
import { Dropdown } from './../types/dropdown.interface';
22
import React from 'react';
3-
import { Get } from 'shared/utils/request';
3+
import { Post } from 'shared/utils/request';
44

5-
export const getContexts = async (spaceId: string, roomId: string, baseUrl: string) => {
6-
const response = await Get({ path: `/v2/spaces/${spaceId}/rooms/${roomId}/contexts`, baseUrl });
7-
return response?.data?.results as string[];
5+
export const getContexts = async (spaceId: string, roomId: string, after: number, before: number, baseUrl: string) => {
6+
const response = await Post({
7+
path: `/v3/spaces/${spaceId}/rooms/${roomId}/contexts`,
8+
baseUrl,
9+
data: {
10+
scope: {
11+
contexts: ['*'],
12+
nodes: [],
13+
},
14+
selectors: {
15+
contexts: [],
16+
nodes: [],
17+
},
18+
window: {
19+
after,
20+
before,
21+
},
22+
},
23+
});
24+
const { contexts = {} } = response?.data || {};
25+
return Object.keys(contexts) as string[];
826
};
927

1028
export const useFetchContexts = (baseUrl: string) => {
1129
const [isError, setIsError] = React.useState(false);
1230
const [contexts, setContexts] = React.useState<Dropdown[]>([]);
1331

1432
const fetchContexts = React.useCallback(
15-
async (spaceId: string, roomId: string) => {
33+
async (spaceId: string, roomId: string, after: number, before: number) => {
1634
setIsError(false);
1735

1836
try {
19-
const result = await getContexts(spaceId, roomId, baseUrl);
37+
const result = await getContexts(spaceId, roomId, after, before, baseUrl);
2038
setContexts(result.map((c) => ({ label: c, value: c })));
2139
} catch (error) {
2240
setIsError(true);

0 commit comments

Comments
 (0)