You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by qi...@apache.org on 2023/04/25 01:58:09 UTC
[skywalking-grafana-plugins] branch main updated (5844ed1 -> b673948)
This is an automated email from the ASF dual-hosted git repository.
qiuxiafan pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-grafana-plugins.git
from 5844ed1 feat: update query
new 3b2513c fix: update query header
new ef586ff feat: add utc
new f48901c fix: update utc
new b673948 feat: add node and edge frame
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/datasource.ts | 79 ++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 63 insertions(+), 16 deletions(-)
[skywalking-grafana-plugins] 02/04: feat: add utc
Posted by qi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
qiuxiafan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-grafana-plugins.git
commit ef586ffefc211be77b391593d49bf92ddc55f270
Author: Fine0830 <fa...@gmail.com>
AuthorDate: Mon Apr 24 19:00:18 2023 +0800
feat: add utc
---
src/datasource.ts | 38 ++++++++++++++++++++++++++++++--------
1 file changed, 30 insertions(+), 8 deletions(-)
diff --git a/src/datasource.ts b/src/datasource.ts
index edbbc35..3e0169f 100644
--- a/src/datasource.ts
+++ b/src/datasource.ts
@@ -8,6 +8,9 @@ import {
FieldType,
} from '@grafana/data';
import { getBackendSrv, getTemplateSrv } from '@grafana/runtime';
+import dayjs from "dayjs";
+import timezone from "dayjs/plugin/timezone";
+import utc from "dayjs/plugin/utc";
import { MyQuery, MyDataSourceOptions, DEFAULT_QUERY } from './types';
@@ -19,25 +22,33 @@ enum TimeType {
DAY_TIME = "DAY",
}
+
+
export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
URL: string;
constructor(instanceSettings: DataSourceInstanceSettings<MyDataSourceOptions>) {
super(instanceSettings);
// proxy url
this.URL = instanceSettings.url || '';
+ dayjs.extend(utc)
+ dayjs.extend(timezone)
}
async query(options: DataQueryRequest<MyQuery>): Promise<DataQueryResponse> {
const { range } = options;
const from = range!.from.valueOf();
const to = range!.to.valueOf();
- const dates = this.timeFormat([new Date(from), new Date(to)]);
+ let utc = -(new Date().getTimezoneOffset() / 60) + ":0";
+
+ if (options.timezone !== "browser") {
+ utc = dayjs().tz(options.timezone).utcOffset() / 60 + ":0";
+ }
+ const dates = this.timeFormat([this.getLocalTime(utc, new Date(from)), this.getLocalTime(utc, new Date(to))]);
const duration = {
start: this.dateFormatStep(dates.start, dates.step),
end: this.dateFormatStep(dates.end, dates.step),
step: dates.step,
};
-
// Return a constant for each query.
const data = options.targets.map(async (target) => {
const query = defaults(target, DEFAULT_QUERY);
@@ -48,13 +59,13 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
};
// fetch services from api
await this.doRequest(s);
- // console.log(services);
- // const t = {
- // query: "query queryData($duration: Duration!, $serviceIds: [ID!]!) {\n topology: getServicesTopology(duration: $duration, serviceIds: $serviceIds) {\n nodes {\n id\n name\n type\n isReal\n }\n calls {\n id\n source\n detectPoints\n target\n }\n }}",
- // variables: JSON.stringify({duration,serviceIds:["YWdlbnQ6OnNvbmdz.1","YWdlbnQ6OnJlY29tbWVuZGF0aW9u.1","YWdlbnQ6OmFwcA==.1","YWdlbnQ6OmdhdGV3YXk=.1","YWdlbnQ6OmZyb250ZW5k.1"]}),
- // };
+ const t = {
+ query: "query queryData($duration: Duration!) {\n topology: getGlobalTopology(duration: $duration) {\n nodes {\n id\n name\n type\n isReal\n }\n calls {\n id\n source\n detectPoints\n target\n }\n }}",
+ // variables: {duration: {"start":"2023-04-23 1503","end":"2023-04-23 1603","step":"MINUTE"}},
+ variables: {duration},
+ };
// fetch topology data from api
- // await this.doRequest(t);
+ await this.doRequest(t);
return new MutableDataFrame({
refId: target.refId,
fields: [
@@ -133,6 +144,17 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
}
return "";
}
+ getLocalTime(utc: string, time: Date): Date {
+ const utcArr = utc.split(":");
+ const utcHour = isNaN(Number(utcArr[0])) ? 0 : Number(utcArr[0]);
+ const utcMin = isNaN(Number(utcArr[1])) ? 0 : Number(utcArr[1]);
+ const d = new Date(time);
+ const len = d.getTime();
+ const offset = d.getTimezoneOffset() * 60000;
+ const utcTime = len + offset;
+
+ return new Date(utcTime + 3600000 * utcHour + utcMin * 60000);
+ };
async testDatasource() {
// Implement a health check for your data source.
[skywalking-grafana-plugins] 04/04: feat: add node and edge frame
Posted by qi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
qiuxiafan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-grafana-plugins.git
commit b6739489fe5c5a7006c00f0632add273b43696b1
Author: Fine0830 <fa...@gmail.com>
AuthorDate: Tue Apr 25 09:50:46 2023 +0800
feat: add node and edge frame
---
src/datasource.ts | 45 ++++++++++++++++++++++++++++++++++++---------
1 file changed, 36 insertions(+), 9 deletions(-)
diff --git a/src/datasource.ts b/src/datasource.ts
index 02cebb0..2ebc6d3 100644
--- a/src/datasource.ts
+++ b/src/datasource.ts
@@ -50,32 +50,59 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
step: dates.step,
};
// Return a constant for each query.
- const data = options.targets.map(async (target) => {
+ const promises = options.targets.map(async (target) => {
const query = defaults(target, DEFAULT_QUERY);
getTemplateSrv().replace(query.queryText, options.scopedVars);
const s = {
query: "query queryServices($duration: Duration!,$keyword: String!) {\n services: getAllServices(duration: $duration, group: $keyword) {\n key: id\n label: name\n group\n }\n }",
- variables: {duration},
+ variables: {duration, keyword: ""},
};
// fetch services from api
- await this.doRequest(s);
+ await this.doRequest(s)
const t = {
- query: "query queryData($duration: Duration!) {\n topology: getGlobalTopology(duration: $duration) {\n nodes {\n id\n name\n type\n isReal\n }\n calls {\n id\n source\n detectPoints\n target\n }\n }}",
+ query: "query queryData($duration: Duration!) {\n topology: getGlobalTopology(duration: $duration) {\n nodes {\n id\n name: title\n type\n isReal\n }\n calls {\n id\n source\n detectPoints\n target\n }\n }}",
variables: {duration},
};
// fetch topology data from api
- await this.doRequest(t);
- return new MutableDataFrame({
+ const res = await this.doRequest(t);
+ const nodes = res.data.topology.nodes || [];
+ const calls = res.data.topology.calls || [];
+ const nodeFrame = new MutableDataFrame({
+ name: 'Nodes',
+ refId: target.refId,
+ fields: [
+ { name: 'id', type: FieldType.string },
+ { name: 'title', type: FieldType.string },
+ ],
+ meta: {
+ preferredVisualisationType: 'nodeGraph',
+ }
+ });
+ const edgeFrame = new MutableDataFrame({
+ name: 'Edges',
refId: target.refId,
fields: [
- { name: 'Time', values: [from, to], type: FieldType.time },
- { name: 'Value', values: [target.constant, target.constant], type: FieldType.number },
+ { name: 'id', type: FieldType.string },
+ { name: 'source', type: FieldType.string },
+ { name: 'target', type: FieldType.string },
],
+ meta: {
+ preferredVisualisationType: 'nodeGraph',
+ }
});
+ console.log(res.data.topology);
+ for (const node of nodes) {
+ nodeFrame.add({id: node.id, title: node.title});
+ }
+ for (const call of calls) {
+ nodeFrame.add({id: call.id, target: call.target, source: call.source});
+ }
+ return [nodeFrame, edgeFrame];
});
- return { data };
+ return Promise.all(promises).then(data => ({ data: data[0] }));
}
+
async doRequest(params?: Record<string, any>) {
// Do the request on proxy; the server will replace url + routePath with the url
// defined in plugin.json
[skywalking-grafana-plugins] 03/04: fix: update utc
Posted by qi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
qiuxiafan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-grafana-plugins.git
commit f48901c621d614ba94c8da96b27076d2960b174b
Author: Fine0830 <fa...@gmail.com>
AuthorDate: Mon Apr 24 19:05:59 2023 +0800
fix: update utc
---
src/datasource.ts | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/src/datasource.ts b/src/datasource.ts
index 3e0169f..02cebb0 100644
--- a/src/datasource.ts
+++ b/src/datasource.ts
@@ -38,10 +38,10 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
const { range } = options;
const from = range!.from.valueOf();
const to = range!.to.valueOf();
- let utc = -(new Date().getTimezoneOffset() / 60) + ":0";
+ let utc = -(new Date().getTimezoneOffset() / 60);
if (options.timezone !== "browser") {
- utc = dayjs().tz(options.timezone).utcOffset() / 60 + ":0";
+ utc = dayjs().tz(options.timezone).utcOffset() / 60;
}
const dates = this.timeFormat([this.getLocalTime(utc, new Date(from)), this.getLocalTime(utc, new Date(to))]);
const duration = {
@@ -55,13 +55,12 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
getTemplateSrv().replace(query.queryText, options.scopedVars);
const s = {
query: "query queryServices($duration: Duration!,$keyword: String!) {\n services: getAllServices(duration: $duration, group: $keyword) {\n key: id\n label: name\n group\n }\n }",
- variables: {duration, keyword:""},
+ variables: {duration},
};
// fetch services from api
await this.doRequest(s);
const t = {
query: "query queryData($duration: Duration!) {\n topology: getGlobalTopology(duration: $duration) {\n nodes {\n id\n name\n type\n isReal\n }\n calls {\n id\n source\n detectPoints\n target\n }\n }}",
- // variables: {duration: {"start":"2023-04-23 1503","end":"2023-04-23 1603","step":"MINUTE"}},
variables: {duration},
};
// fetch topology data from api
@@ -144,16 +143,13 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
}
return "";
}
- getLocalTime(utc: string, time: Date): Date {
- const utcArr = utc.split(":");
- const utcHour = isNaN(Number(utcArr[0])) ? 0 : Number(utcArr[0]);
- const utcMin = isNaN(Number(utcArr[1])) ? 0 : Number(utcArr[1]);
+ getLocalTime(utc: number, time: Date): Date {
const d = new Date(time);
const len = d.getTime();
const offset = d.getTimezoneOffset() * 60000;
const utcTime = len + offset;
- return new Date(utcTime + 3600000 * utcHour + utcMin * 60000);
+ return new Date(utcTime + 3600000 * utc);
};
async testDatasource() {
[skywalking-grafana-plugins] 01/04: fix: update query header
Posted by qi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
qiuxiafan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-grafana-plugins.git
commit 3b2513cc1f9bfa5016d39570e00eaa53dbeb40ea
Author: Fine0830 <fa...@gmail.com>
AuthorDate: Mon Apr 24 12:00:58 2023 +0800
fix: update query header
---
src/datasource.ts | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/datasource.ts b/src/datasource.ts
index 489a84d..edbbc35 100644
--- a/src/datasource.ts
+++ b/src/datasource.ts
@@ -69,7 +69,9 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
async doRequest(params?: Record<string, any>) {
// Do the request on proxy; the server will replace url + routePath with the url
// defined in plugin.json
- const result = getBackendSrv().post(`${this.URL}${routePath}`, params);
+ const result = getBackendSrv().post(`${this.URL}${routePath}`, params, {headers: {
+ 'Content-Type': 'application/json'
+ } });
return result;
}