Commit bb50fc59 by Arve Knudsen Committed by GitHub

pkg/tsdb: Check errors (#19837)

Check errors in pkg/tsdb.
parent 79cbe191
...@@ -169,10 +169,13 @@ func (e *AzureMonitorDatasource) executeQuery(ctx context.Context, query *AzureM ...@@ -169,10 +169,13 @@ func (e *AzureMonitorDatasource) executeQuery(ctx context.Context, query *AzureM
defer span.Finish() defer span.Finish()
opentracing.GlobalTracer().Inject( if err := opentracing.GlobalTracer().Inject(
span.Context(), span.Context(),
opentracing.HTTPHeaders, opentracing.HTTPHeaders,
opentracing.HTTPHeadersCarrier(req.Header)) opentracing.HTTPHeadersCarrier(req.Header)); err != nil {
queryResult.Error = err
return queryResult, AzureMonitorResponse{}, nil
}
azlog.Debug("AzureMonitor", "Request ApiURL", req.URL.String()) azlog.Debug("AzureMonitor", "Request ApiURL", req.URL.String())
res, err := ctxhttp.Do(ctx, e.httpClient, req) res, err := ctxhttp.Do(ctx, e.httpClient, req)
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/tsdb" "github.com/grafana/grafana/pkg/tsdb"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
...@@ -402,13 +403,13 @@ func httpClientScenario(t *testing.T, desc string, ds *models.DataSource, fn sce ...@@ -402,13 +403,13 @@ func httpClientScenario(t *testing.T, desc string, ds *models.DataSource, fn sce
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
sc.request = r sc.request = r
buf, err := ioutil.ReadAll(r.Body) buf, err := ioutil.ReadAll(r.Body)
if err != nil { require.Nil(t, err)
t.Fatalf("Failed to read request body, err=%v", err)
}
sc.requestBody = bytes.NewBuffer(buf) sc.requestBody = bytes.NewBuffer(buf)
rw.Header().Add("Content-Type", "application/json") rw.Header().Add("Content-Type", "application/json")
rw.Write([]byte(sc.responseBody)) _, err = rw.Write([]byte(sc.responseBody))
require.Nil(t, err)
rw.WriteHeader(sc.responseStatus) rw.WriteHeader(sc.responseStatus)
})) }))
ds.Url = ts.URL ds.Url = ts.URL
......
...@@ -82,10 +82,12 @@ func (e *GraphiteExecutor) Query(ctx context.Context, dsInfo *models.DataSource, ...@@ -82,10 +82,12 @@ func (e *GraphiteExecutor) Query(ctx context.Context, dsInfo *models.DataSource,
defer span.Finish() defer span.Finish()
opentracing.GlobalTracer().Inject( if err := opentracing.GlobalTracer().Inject(
span.Context(), span.Context(),
opentracing.HTTPHeaders, opentracing.HTTPHeaders,
opentracing.HTTPHeadersCarrier(req.Header)) opentracing.HTTPHeadersCarrier(req.Header)); err != nil {
return nil, err
}
res, err := ctxhttp.Do(ctx, httpClient, req) res, err := ctxhttp.Do(ctx, httpClient, req)
if err != nil { if err != nil {
......
...@@ -14,9 +14,10 @@ func TestInfluxdbResponseParser(t *testing.T) { ...@@ -14,9 +14,10 @@ func TestInfluxdbResponseParser(t *testing.T) {
parser := &ResponseParser{} parser := &ResponseParser{}
cfg := setting.NewCfg() cfg := setting.NewCfg()
cfg.Load(&setting.CommandLineArgs{ err := cfg.Load(&setting.CommandLineArgs{
HomePath: "../../../", HomePath: "../../../",
}) })
So(err, ShouldBeNil)
response := &Response{ response := &Response{
Results: []Result{ Results: []Result{
......
...@@ -11,9 +11,10 @@ import ( ...@@ -11,9 +11,10 @@ import (
func TestInterval(t *testing.T) { func TestInterval(t *testing.T) {
Convey("Default interval ", t, func() { Convey("Default interval ", t, func() {
cfg := setting.NewCfg() cfg := setting.NewCfg()
cfg.Load(&setting.CommandLineArgs{ err := cfg.Load(&setting.CommandLineArgs{
HomePath: "../../", HomePath: "../../",
}) })
So(err, ShouldBeNil)
calculator := NewIntervalCalculator(&IntervalOptions{}) calculator := NewIntervalCalculator(&IntervalOptions{})
......
...@@ -382,7 +382,8 @@ func TestMSSQL(t *testing.T) { ...@@ -382,7 +382,8 @@ func TestMSSQL(t *testing.T) {
if exist, err := sess.IsTableExist(metric_values{}); err != nil || exist { if exist, err := sess.IsTableExist(metric_values{}); err != nil || exist {
So(err, ShouldBeNil) So(err, ShouldBeNil)
sess.DropTable(metric_values{}) err = sess.DropTable(metric_values{})
So(err, ShouldBeNil)
} }
err := sess.CreateTable(metric_values{}) err := sess.CreateTable(metric_values{})
So(err, ShouldBeNil) So(err, ShouldBeNil)
......
...@@ -46,7 +46,9 @@ func newMysqlQueryEndpoint(datasource *models.DataSource) (tsdb.TsdbQueryEndpoin ...@@ -46,7 +46,9 @@ func newMysqlQueryEndpoint(datasource *models.DataSource) (tsdb.TsdbQueryEndpoin
if tlsConfig.RootCAs != nil || len(tlsConfig.Certificates) > 0 { if tlsConfig.RootCAs != nil || len(tlsConfig.Certificates) > 0 {
tlsConfigString := fmt.Sprintf("ds%d", datasource.Id) tlsConfigString := fmt.Sprintf("ds%d", datasource.Id)
mysql.RegisterTLSConfig(tlsConfigString, tlsConfig) if err := mysql.RegisterTLSConfig(tlsConfigString, tlsConfig); err != nil {
return nil, err
}
cnnstr += "&tls=" + tlsConfigString cnnstr += "&tls=" + tlsConfigString
} }
......
...@@ -68,7 +68,8 @@ func TestMySQL(t *testing.T) { ...@@ -68,7 +68,8 @@ func TestMySQL(t *testing.T) {
Convey("Given a table with different native data types", func() { Convey("Given a table with different native data types", func() {
if exists, err := sess.IsTableExist("mysql_types"); err != nil || exists { if exists, err := sess.IsTableExist("mysql_types"); err != nil || exists {
So(err, ShouldBeNil) So(err, ShouldBeNil)
sess.DropTable("mysql_types") err = sess.DropTable("mysql_types")
So(err, ShouldBeNil)
} }
sql := "CREATE TABLE `mysql_types` (" sql := "CREATE TABLE `mysql_types` ("
...@@ -181,7 +182,8 @@ func TestMySQL(t *testing.T) { ...@@ -181,7 +182,8 @@ func TestMySQL(t *testing.T) {
if exist, err := sess.IsTableExist(metric{}); err != nil || exist { if exist, err := sess.IsTableExist(metric{}); err != nil || exist {
So(err, ShouldBeNil) So(err, ShouldBeNil)
sess.DropTable(metric{}) err = sess.DropTable(metric{})
So(err, ShouldBeNil)
} }
err := sess.CreateTable(metric{}) err := sess.CreateTable(metric{})
So(err, ShouldBeNil) So(err, ShouldBeNil)
...@@ -413,7 +415,8 @@ func TestMySQL(t *testing.T) { ...@@ -413,7 +415,8 @@ func TestMySQL(t *testing.T) {
if exist, err := sess.IsTableExist(metric_values{}); err != nil || exist { if exist, err := sess.IsTableExist(metric_values{}); err != nil || exist {
So(err, ShouldBeNil) So(err, ShouldBeNil)
sess.DropTable(metric_values{}) err = sess.DropTable(metric_values{})
So(err, ShouldBeNil)
} }
err := sess.CreateTable(metric_values{}) err := sess.CreateTable(metric_values{})
So(err, ShouldBeNil) So(err, ShouldBeNil)
...@@ -788,7 +791,8 @@ func TestMySQL(t *testing.T) { ...@@ -788,7 +791,8 @@ func TestMySQL(t *testing.T) {
if exist, err := sess.IsTableExist(event{}); err != nil || exist { if exist, err := sess.IsTableExist(event{}); err != nil || exist {
So(err, ShouldBeNil) So(err, ShouldBeNil)
sess.DropTable(event{}) err = sess.DropTable(event{})
So(err, ShouldBeNil)
} }
err := sess.CreateTable(event{}) err := sess.CreateTable(event{})
So(err, ShouldBeNil) So(err, ShouldBeNil)
......
...@@ -392,7 +392,8 @@ func TestPostgres(t *testing.T) { ...@@ -392,7 +392,8 @@ func TestPostgres(t *testing.T) {
if exist, err := sess.IsTableExist(metric_values{}); err != nil || exist { if exist, err := sess.IsTableExist(metric_values{}); err != nil || exist {
So(err, ShouldBeNil) So(err, ShouldBeNil)
sess.DropTable(metric_values{}) err = sess.DropTable(metric_values{})
So(err, ShouldBeNil)
} }
err := sess.CreateTable(metric_values{}) err := sess.CreateTable(metric_values{})
So(err, ShouldBeNil) So(err, ShouldBeNil)
...@@ -721,7 +722,8 @@ func TestPostgres(t *testing.T) { ...@@ -721,7 +722,8 @@ func TestPostgres(t *testing.T) {
if exist, err := sess.IsTableExist(event{}); err != nil || exist { if exist, err := sess.IsTableExist(event{}); err != nil || exist {
So(err, ShouldBeNil) So(err, ShouldBeNil)
sess.DropTable(event{}) err = sess.DropTable(event{})
So(err, ShouldBeNil)
} }
err := sess.CreateTable(event{}) err := sess.CreateTable(event{})
So(err, ShouldBeNil) So(err, ShouldBeNil)
......
...@@ -303,10 +303,13 @@ func (e *StackdriverExecutor) executeQuery(ctx context.Context, query *Stackdriv ...@@ -303,10 +303,13 @@ func (e *StackdriverExecutor) executeQuery(ctx context.Context, query *Stackdriv
defer span.Finish() defer span.Finish()
opentracing.GlobalTracer().Inject( if err := opentracing.GlobalTracer().Inject(
span.Context(), span.Context(),
opentracing.HTTPHeaders, opentracing.HTTPHeaders,
opentracing.HTTPHeadersCarrier(req.Header)) opentracing.HTTPHeadersCarrier(req.Header)); err != nil {
queryResult.Error = err
return queryResult, StackdriverResponse{}, nil
}
res, err := ctxhttp.Do(ctx, e.httpClient, req) res, err := ctxhttp.Do(ctx, e.httpClient, req)
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment