mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Azure: Insights Analytics, fix possible panics and return error body (#26361)
missing return statements can result in panic
This commit is contained in:
parent
21971a4df8
commit
c980f37509
@ -104,7 +104,7 @@ func (e *InsightsAnalyticsDatasource) executeQuery(ctx context.Context, query *I
|
|||||||
|
|
||||||
req, err := e.createRequest(ctx, e.dsInfo)
|
req, err := e.createRequest(ctx, e.dsInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
queryResultError(err)
|
return queryResultError(err)
|
||||||
}
|
}
|
||||||
req.URL.Path = path.Join(req.URL.Path, "query")
|
req.URL.Path = path.Join(req.URL.Path, "query")
|
||||||
req.URL.RawQuery = query.Params.Encode()
|
req.URL.RawQuery = query.Params.Encode()
|
||||||
@ -128,30 +128,30 @@ func (e *InsightsAnalyticsDatasource) executeQuery(ctx context.Context, query *I
|
|||||||
azlog.Debug("ApplicationInsights", "Request URL", req.URL.String())
|
azlog.Debug("ApplicationInsights", "Request URL", req.URL.String())
|
||||||
res, err := ctxhttp.Do(ctx, e.httpClient, req)
|
res, err := ctxhttp.Do(ctx, e.httpClient, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
queryResultError(err)
|
return queryResultError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
queryResultError(err)
|
return queryResultError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.StatusCode/100 != 2 {
|
if res.StatusCode/100 != 2 {
|
||||||
azlog.Debug("Request failed", "status", res.Status, "body", string(body))
|
azlog.Debug("Request failed", "status", res.Status, "body", string(body))
|
||||||
queryResultError(fmt.Errorf("Request failed status: %v", res.Status))
|
return queryResultError(fmt.Errorf("Request failed status: %v %w", res.Status, fmt.Errorf(string(body))))
|
||||||
}
|
}
|
||||||
var logResponse AzureLogAnalyticsResponse
|
var logResponse AzureLogAnalyticsResponse
|
||||||
d := json.NewDecoder(bytes.NewReader(body))
|
d := json.NewDecoder(bytes.NewReader(body))
|
||||||
d.UseNumber()
|
d.UseNumber()
|
||||||
err = d.Decode(&logResponse)
|
err = d.Decode(&logResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
queryResultError(err)
|
return queryResultError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t, err := logResponse.GetPrimaryResultTable()
|
t, err := logResponse.GetPrimaryResultTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
queryResultError(err)
|
return queryResultError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
frame, err := LogTableToFrame(t)
|
frame, err := LogTableToFrame(t)
|
||||||
|
Loading…
Reference in New Issue
Block a user