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 10:44:29 UTC

[skywalking-grafana-plugins] branch main updated (c45ce4d -> e474f7c)

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 c45ce4d  fix: frame data
     new dfbcfb4  feat: add service topology
     new 1a1ee77  feat: update service topolgy
     new e474f7c  fix: mock data

The 3 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/components/QueryEditor.tsx | 12 +++---------
 src/constant.ts                |  5 +++++
 src/datasource.ts              | 29 ++++++++++++++++++++---------
 3 files changed, 28 insertions(+), 18 deletions(-)
 create mode 100644 src/constant.ts


[skywalking-grafana-plugins] 02/03: feat: update service topolgy

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 1a1ee77eeb700cdb4817eaf5e5969620beee81a0
Author: Fine0830 <fa...@gmail.com>
AuthorDate: Tue Apr 25 18:22:39 2023 +0800

    feat: update service topolgy
---
 src/components/QueryEditor.tsx |  4 +++-
 src/constant.ts                |  2 +-
 src/datasource.ts              | 24 ++++++++++++------------
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/src/components/QueryEditor.tsx b/src/components/QueryEditor.tsx
index 0b9723d..16a25fb 100644
--- a/src/components/QueryEditor.tsx
+++ b/src/components/QueryEditor.tsx
@@ -9,6 +9,8 @@ type Props = QueryEditorProps<DataSource, MyQuery, MyDataSourceOptions>;
 export function QueryEditor({ query, onChange, onRunQuery }: Props) {
   const onQueryTextChange = (event: ChangeEvent<HTMLInputElement>) => {
     onChange({ ...query, queryText: event.target.value });
+  };
+  const onRunQueryText = () => {
     onRunQuery();
   };
 
@@ -17,7 +19,7 @@ export function QueryEditor({ query, onChange, onRunQuery }: Props) {
   return (
     <div className="gf-form">
       <InlineField label="Query Text" labelWidth={16} tooltip="Not used yet">
-        <Input onChange={onQueryTextChange} value={queryText || ''} />
+        <Input onBlur={onRunQueryText} onChange={onQueryTextChange} value={queryText || ''} />
       </InlineField>
     </div>
   );
diff --git a/src/constant.ts b/src/constant.ts
index 5d66052..03eda2d 100644
--- a/src/constant.ts
+++ b/src/constant.ts
@@ -1,5 +1,5 @@
 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      key: id\n      label: name\n      group\n    }\n  }",
+  services: "query queryServices($duration: Duration!,$keyword: String!) {\n    services: getAllServices(duration: $duration, group: $keyword) {\n      id\n      name\n      group\n    }\n  }",
 };
diff --git a/src/datasource.ts b/src/datasource.ts
index aa17698..653086e 100644
--- a/src/datasource.ts
+++ b/src/datasource.ts
@@ -36,7 +36,6 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
   }
 
   async query(options: DataQueryRequest<MyQuery>): Promise<DataQueryResponse> {
-    console.log(options);
     const { range } = options;
     const from = range!.from.valueOf();
     const to = range!.to.valueOf();
@@ -55,23 +54,24 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
     const promises = options.targets.map(async (target) => {
       const query = defaults(target, DEFAULT_QUERY);
       const serviceName = getTemplateSrv().replace(query.queryText, options.scopedVars);
-      const  s =  {
-        query: fragments.services,
-        variables: {duration, keyword: ""},
-      };
-      // fetch services from api
-      const resp = await this.doRequest(s);
-      console.log(resp);
       let t: any = {
         query: fragments.globalTopology,
         variables: {duration},
       };
       if (serviceName) {
-        const serviceObj = resp.data.data.services.find((d: {name: string, id: string}) => d.name === serviceName);
-        t = {
-          query: fragments.serviceTopolgy,
-          variables: {serviceId: serviceObj.id, duration},
+        const  s =  {
+          query: fragments.services,
+          variables: {duration, keyword: ""},
         };
+        // fetch services from api
+        const resp = await this.doRequest(s);
+        const serviceObj = (resp.data.services || []).find((d: {name: string, id: string}) => d.name === "agent::recommendation");
+        if(serviceObj) {
+          t = {
+            query: fragments.serviceTopolgy,
+            variables: {serviceId: serviceObj.id, duration},
+          };
+        }
       }
       
       // fetch topology data from api


[skywalking-grafana-plugins] 03/03: fix: mock data

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 e474f7c235fb7b7e79c6d03f6ab2a35e10a0e60d
Author: Fine0830 <fa...@gmail.com>
AuthorDate: Tue Apr 25 18:33:08 2023 +0800

    fix: mock data
---
 src/datasource.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/datasource.ts b/src/datasource.ts
index 653086e..470ca68 100644
--- a/src/datasource.ts
+++ b/src/datasource.ts
@@ -65,7 +65,7 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
         };
         // fetch services from api
         const resp = await this.doRequest(s);
-        const serviceObj = (resp.data.services || []).find((d: {name: string, id: string}) => d.name === "agent::recommendation");
+        const serviceObj = (resp.data.services || []).find((d: {name: string, id: string}) => d.name === serviceName);
         if(serviceObj) {
           t = {
             query: fragments.serviceTopolgy,


[skywalking-grafana-plugins] 01/03: feat: add service topology

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 dfbcfb4800e42d7484607875fad90aaadc4a90f7
Author: Fine0830 <fa...@gmail.com>
AuthorDate: Tue Apr 25 17:23:43 2023 +0800

    feat: add service topology
---
 src/components/QueryEditor.tsx | 10 +---------
 src/constant.ts                |  5 +++++
 src/datasource.ts              | 21 ++++++++++++++++-----
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/src/components/QueryEditor.tsx b/src/components/QueryEditor.tsx
index f9b0647..0b9723d 100644
--- a/src/components/QueryEditor.tsx
+++ b/src/components/QueryEditor.tsx
@@ -9,21 +9,13 @@ type Props = QueryEditorProps<DataSource, MyQuery, MyDataSourceOptions>;
 export function QueryEditor({ query, onChange, onRunQuery }: Props) {
   const onQueryTextChange = (event: ChangeEvent<HTMLInputElement>) => {
     onChange({ ...query, queryText: event.target.value });
-  };
-
-  const onConstantChange = (event: ChangeEvent<HTMLInputElement>) => {
-    onChange({ ...query, constant: parseFloat(event.target.value) });
-    // executes the query
     onRunQuery();
   };
 
-  const { queryText, constant } = query;
+  const { queryText } = query;
 
   return (
     <div className="gf-form">
-      <InlineField label="Constant">
-        <Input onChange={onConstantChange} value={constant} width={8} type="number" step="0.1" />
-      </InlineField>
       <InlineField label="Query Text" labelWidth={16} tooltip="Not used yet">
         <Input onChange={onQueryTextChange} value={queryText || ''} />
       </InlineField>
diff --git a/src/constant.ts b/src/constant.ts
new file mode 100644
index 0000000..5d66052
--- /dev/null
+++ b/src/constant.ts
@@ -0,0 +1,5 @@
+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      key: id\n      label: name\n      group\n    }\n  }",
+};
diff --git a/src/datasource.ts b/src/datasource.ts
index 319f88b..aa17698 100644
--- a/src/datasource.ts
+++ b/src/datasource.ts
@@ -13,6 +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';
@@ -35,6 +36,7 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
   }
 
   async query(options: DataQueryRequest<MyQuery>): Promise<DataQueryResponse> {
+    console.log(options);
     const { range } = options;
     const from = range!.from.valueOf();
     const to = range!.to.valueOf();
@@ -52,17 +54,26 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
     // Return a constant for each query.
     const promises = options.targets.map(async (target) => {
       const query = defaults(target, DEFAULT_QUERY);
-      getTemplateSrv().replace(query.queryText, options.scopedVars);
+      const serviceName = 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  }",
+        query: fragments.services,
         variables: {duration, keyword: ""},
       };
       // 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  }}",
+      const resp = await this.doRequest(s);
+      console.log(resp);
+      let t: any = {
+        query: fragments.globalTopology,
         variables: {duration},
       };
+      if (serviceName) {
+        const serviceObj = resp.data.data.services.find((d: {name: string, id: string}) => d.name === serviceName);
+        t = {
+          query: fragments.serviceTopolgy,
+          variables: {serviceId: serviceObj.id, duration},
+        };
+      }
+      
       // fetch topology data from api
       const res = await this.doRequest(t);
       const nodes = res.data.topology.nodes || [];