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:30 UTC
[skywalking-grafana-plugins] 01/03: feat: add service topology
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 || [];