提交 af31c496 编写于 作者: U Ulric Qin

datasource checker for loki

上级 d541ec7f
......@@ -137,12 +137,11 @@ func DatasourceCheck(ds models.Datasource) error {
if ds.PluginType == models.PROMETHEUS {
subPath := "/api/v1/query"
query := url.Values{}
// if strings.Contains(fullURL, "loki") {
// subPath = "/api/v1/labels"
// } else {
// query.Add("query", "1+1")
// }
query.Add("query", "mock_metric_name")
if ds.HTTPJson.IsLoki() {
subPath = "/api/v1/labels"
} else {
query.Add("query", "1+1")
}
fullURL = fmt.Sprintf("%s%s?%s", ds.HTTPJson.Url, subPath, query.Encode())
req, err = http.NewRequest("GET", fullURL, nil)
......
......@@ -51,6 +51,21 @@ type HTTP struct {
Headers map[string]string `json:"headers"`
}
func (h HTTP) IsLoki() bool {
if strings.Contains(h.Url, "loki") {
return true
}
for k := range h.Headers {
tmp := strings.ToLower(k)
if strings.Contains(tmp, "loki") {
return true
}
}
return false
}
type TLS struct {
SkipTlsVerify bool `json:"skip_tls_verify"`
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册