【问题标题】:No Host in request URL for Grafana datasource plugin tutorial - Add authenticationGrafana 数据源插件教程的请求 URL 中没有主机 - 添加身份验证
【发布时间】:2021-11-12 10:34:09
【问题描述】:

我正在尝试按照示例从 Grafana 开发数据源插件。最终我希望我的插件使用 Oauth,但即使只有基本的 Grafana 数据源代理示例,我似乎也遇到了问题。 我已经更新了我的 plugin.json、类和构造函数。

我已经设置了这个硬编码示例。

在 plugin.json 中

      {
        "path": "grafana",
        "url": "https://github.com"
      }
    ],

还有一个示例 testDataSource()

  async testDatasource() {
    return getBackendSrv()
      .datasourceRequest({
        url: this.url + '/grafana/grafana',
        method: 'GET',
      })
      .then(response => {
        if (response.status === 200) {
          return { status: 'success', message: 'Data source is working', title: 'Success' };
        } else {
          return { status: 'failure', message: 'Data source is not working: ' + response.status, title: 'Failure' };
        }
      });
  }

当我尝试保存/测试此数据源以调用该方法时,我在前端 HTTP 错误 网关错误 在日志中

t=2021-09-17T14:31:22+0000 lvl=eror msg="数据代理错误" logger=data-proxy-log userId=1 orgId=1 uname=admin path=/api/datasources/proxy /9/grafana/grafana remote_addr=172.17.0.1 referer=http://localhost:3000/datasources/edit/9/error="http: proxy error: http: no Host in request URL"

我本来希望将请求路由到数据源代理并为此向 github 发出请求,但似乎 Grafana 正在向 /api/datasources/proxy/9/grafana/grafana 发出请求,但什么都没有捡起来?

【问题讨论】:

    标签: authentication plugins proxy datasource grafana


    【解决方案1】:

    通过 API 查找我的数据源,没有为 URL 列出任何内容。 您需要在 ConfigEditor.tsx

    中呈现它
    <DataSourceHttpSettings
      defaultUrl="http://localhost:8080"
      dataSourceConfig={options}
      onChange={onOptionsChange}
    />
    

    这将为您提供您在大多数插件上看到的带有 URL、白名单、身份验证选项的基本表单。我猜那里的 URL 应该与您的路线中的 URL 相匹配。

    【讨论】:

      猜你喜欢
      • 2018-12-04
      • 2017-04-04
      • 2021-07-30
      • 2015-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多