Browse Source

Merge pull request #11689 from mjtrangoni/fix-ineffassign-issues

pkg/tsdb: fix ineffassign isues
Carl Bergquist 7 years ago
parent
commit
6315142d00

+ 1 - 1
pkg/tsdb/cloudwatch/cloudwatch.go

@@ -271,7 +271,7 @@ func parseQuery(model *simplejson.Json) (*CloudWatchQuery, error) {
 		}
 		}
 	}
 	}
 
 
-	period := 300
+	var period int
 	if regexp.MustCompile(`^\d+$`).Match([]byte(p)) {
 	if regexp.MustCompile(`^\d+$`).Match([]byte(p)) {
 		period, err = strconv.Atoi(p)
 		period, err = strconv.Atoi(p)
 		if err != nil {
 		if err != nil {

+ 3 - 0
pkg/tsdb/influxdb/model_parser.go

@@ -40,6 +40,9 @@ func (qp *InfluxdbQueryParser) Parse(model *simplejson.Json, dsInfo *models.Data
 	}
 	}
 
 
 	parsedInterval, err := tsdb.GetIntervalFrom(dsInfo, model, time.Millisecond*1)
 	parsedInterval, err := tsdb.GetIntervalFrom(dsInfo, model, time.Millisecond*1)
+	if err != nil {
+		return nil, err
+	}
 
 
 	return &Query{
 	return &Query{
 		Measurement:  measurement,
 		Measurement:  measurement,

+ 2 - 3
pkg/tsdb/influxdb/query.go

@@ -62,9 +62,8 @@ func (query *Query) renderTags() []string {
 			}
 			}
 		}
 		}
 
 
-		textValue := ""
-
 		// quote value unless regex or number
 		// quote value unless regex or number
+		var textValue string
 		if tag.Operator == "=~" || tag.Operator == "!~" {
 		if tag.Operator == "=~" || tag.Operator == "!~" {
 			textValue = tag.Value
 			textValue = tag.Value
 		} else if tag.Operator == "<" || tag.Operator == ">" {
 		} else if tag.Operator == "<" || tag.Operator == ">" {
@@ -107,7 +106,7 @@ func (query *Query) renderSelectors(queryContext *tsdb.TsdbQuery) string {
 }
 }
 
 
 func (query *Query) renderMeasurement() string {
 func (query *Query) renderMeasurement() string {
-	policy := ""
+	var policy string
 	if query.Policy == "" || query.Policy == "default" {
 	if query.Policy == "" || query.Policy == "default" {
 		policy = ""
 		policy = ""
 	} else {
 	} else {

+ 4 - 0
pkg/tsdb/opentsdb/opentsdb.go

@@ -83,6 +83,10 @@ func (e *OpenTsdbExecutor) createRequest(dsInfo *models.DataSource, data OpenTsd
 	u.Path = path.Join(u.Path, "api/query")
 	u.Path = path.Join(u.Path, "api/query")
 
 
 	postData, err := json.Marshal(data)
 	postData, err := json.Marshal(data)
+	if err != nil {
+		plog.Info("Failed marshalling data", "error", err)
+		return nil, fmt.Errorf("Failed to create request. error: %v", err)
+	}
 
 
 	req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(string(postData)))
 	req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(string(postData)))
 	if err != nil {
 	if err != nil {