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:12 UTC

[skywalking-grafana-plugins] 02/04: fix: add authorization to request header

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 cbce587faa8c561f8b5d75eb4c54628fdbf98ea8
Author: Fine0830 <fa...@gmail.com>
AuthorDate: Wed Apr 26 11:47:21 2023 +0800

    fix: add authorization to request header
---
 src/components/QueryEditor.tsx |  4 ++--
 src/datasource.ts              | 16 +++++++++++-----
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/components/QueryEditor.tsx b/src/components/QueryEditor.tsx
index 7acf083..872a423 100644
--- a/src/components/QueryEditor.tsx
+++ b/src/components/QueryEditor.tsx
@@ -17,8 +17,8 @@ export function QueryEditor({ query, onChange, onRunQuery }: Props) {
 
   return (
     <div className="gf-form">
-      <InlineField label="Query Text" labelWidth={16} tooltip="Not used yet">
-        <Input onBlur={onRunQueryText} onChange={onQueryTextChange} value={queryText || ''} />
+      <InlineField label="Query Text"  tooltip="Not used yet">
+        <Input onBlur={onRunQueryText} onChange={onQueryTextChange} value={queryText || ''} width={40} />
       </InlineField>
     </div>
   );
diff --git a/src/datasource.ts b/src/datasource.ts
index 012334d..9584b85 100644
--- a/src/datasource.ts
+++ b/src/datasource.ts
@@ -42,19 +42,20 @@ 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 str = getTemplateSrv().replace(query.queryText, options.scopedVars);
+      this.validate(str);
       let t: any = {
         query: Fragments.globalTopology,
         variables: {duration},
       };
-      if (serviceName) {
+      if (str) {
         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 === serviceName);
+        const serviceObj = (resp.data.services || []).find((d: {name: string, id: string}) => d.name === str);
         if(serviceObj) {
           t = {
             query: Fragments.serviceTopolgy,
@@ -106,13 +107,18 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
     // 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: {
-      'Content-Type': 'application/json'
+      'Content-Type': 'application/json',
+      'Authorization': 'Basic c2t5d2Fsa2luZzpza3l3YWxraW5n',
     } });
 
     return result;
   }
 
-   timeFormat (time: Date[]) {
+  validate(param: string) {
+    console.log(param);
+  }
+
+  timeFormat(time: Date[]) {
     let step: TimeType;
     const unix = Math.round(time[1].getTime()) - Math.round(time[0].getTime());
     if (unix <= 60 * 60 * 1000) {