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/27 12:06:11 UTC
[skywalking-grafana-plugins] 01/04: refactor: update
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 516c85c52b5762f995a108fcd080e934de25a5ac
Author: Fine0830 <fa...@gmail.com>
AuthorDate: Tue Apr 25 19:02:43 2023 +0800
refactor: update
---
src/components/QueryEditor.tsx | 1 -
src/constant.ts | 9 ++++++++-
src/datasource.ts | 21 +++++----------------
3 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/src/components/QueryEditor.tsx b/src/components/QueryEditor.tsx
index 16a25fb..7acf083 100644
--- a/src/components/QueryEditor.tsx
+++ b/src/components/QueryEditor.tsx
@@ -13,7 +13,6 @@ export function QueryEditor({ query, onChange, onRunQuery }: Props) {
const onRunQueryText = () => {
onRunQuery();
};
-
const { queryText } = query;
return (
diff --git a/src/constant.ts b/src/constant.ts
index 03eda2d..4b60de8 100644
--- a/src/constant.ts
+++ b/src/constant.ts
@@ -1,5 +1,12 @@
-export const fragments = {
+export const Fragments = {
serviceTopolgy: "query queryData($serviceId: ID!, $duration: Duration!) {\n topology: getServiceTopology(serviceId: $serviceId, 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 }}",
globalTopology: "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 }}",
services: "query queryServices($duration: Duration!,$keyword: String!) {\n services: getAllServices(duration: $duration, group: $keyword) {\n id\n name\n group\n }\n }",
};
+// proxy route
+export const RoutePath = '/graphql';
+export enum TimeType {
+ MINUTE_TIME = "MINUTE",
+ HOUR_TIME = "HOUR",
+ DAY_TIME = "DAY",
+}
diff --git a/src/datasource.ts b/src/datasource.ts
index 470ca68..012334d 100644
--- a/src/datasource.ts
+++ b/src/datasource.ts
@@ -13,17 +13,7 @@ import timezone from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";
import { MyQuery, MyDataSourceOptions, DEFAULT_QUERY } from './types';
-import {fragments } from "./constant";
-
-// proxy route
-const routePath = '/graphql';
-enum TimeType {
- MINUTE_TIME = "MINUTE",
- HOUR_TIME = "HOUR",
- DAY_TIME = "DAY",
-}
-
-
+import {Fragments, RoutePath, TimeType } from "./constant";
export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
URL: string;
@@ -50,17 +40,16 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
end: this.dateFormatStep(dates.end, dates.step),
step: dates.step,
};
- // Return a constant for each query.
const promises = options.targets.map(async (target) => {
const query = defaults(target, DEFAULT_QUERY);
const serviceName = getTemplateSrv().replace(query.queryText, options.scopedVars);
let t: any = {
- query: fragments.globalTopology,
+ query: Fragments.globalTopology,
variables: {duration},
};
if (serviceName) {
const s = {
- query: fragments.services,
+ query: Fragments.services,
variables: {duration, keyword: ""},
};
// fetch services from api
@@ -68,7 +57,7 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
const serviceObj = (resp.data.services || []).find((d: {name: string, id: string}) => d.name === serviceName);
if(serviceObj) {
t = {
- query: fragments.serviceTopolgy,
+ query: Fragments.serviceTopolgy,
variables: {serviceId: serviceObj.id, duration},
};
}
@@ -116,7 +105,7 @@ 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, {headers: {
+ const result = getBackendSrv().post(`${this.URL}${RoutePath}`, params, {headers: {
'Content-Type': 'application/json'
} });