OpenTSDB: Fix type mismatch with counterMax and counterResetValue (#113835)
* fix * update test
This commit is contained in:
@@ -60,8 +60,8 @@ type QueryModel struct {
|
|||||||
Tags map[string]interface{} `json:"tags"`
|
Tags map[string]interface{} `json:"tags"`
|
||||||
ShouldComputeRate bool `json:"shouldComputeRate"`
|
ShouldComputeRate bool `json:"shouldComputeRate"`
|
||||||
IsCounter bool `json:"isCounter"`
|
IsCounter bool `json:"isCounter"`
|
||||||
CounterMax float64 `json:"counterMax"`
|
CounterMax string `json:"counterMax"`
|
||||||
CounterResetValue float64 `json:"counterResetValue"`
|
CounterResetValue string `json:"counterResetValue"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func newInstanceSettings(httpClientProvider *httpclient.Provider) datasource.InstanceFactoryFunc {
|
func newInstanceSettings(httpClientProvider *httpclient.Provider) datasource.InstanceFactoryFunc {
|
||||||
@@ -311,15 +311,27 @@ func (s *Service) buildMetric(query backend.DataQuery) map[string]any {
|
|||||||
rateOptions := make(map[string]any)
|
rateOptions := make(map[string]any)
|
||||||
rateOptions["counter"] = model.IsCounter
|
rateOptions["counter"] = model.IsCounter
|
||||||
|
|
||||||
if model.CounterMax != 0 {
|
var counterMax *float64
|
||||||
rateOptions["counterMax"] = model.CounterMax
|
if model.CounterMax != "" {
|
||||||
|
if val, err := strconv.ParseFloat(model.CounterMax, 64); err == nil {
|
||||||
|
counterMax = &val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if counterMax != nil {
|
||||||
|
rateOptions["counterMax"] = *counterMax
|
||||||
}
|
}
|
||||||
|
|
||||||
if model.CounterResetValue != 0 {
|
var counterResetValue *float64
|
||||||
rateOptions["resetValue"] = model.CounterResetValue
|
if model.CounterResetValue != "" {
|
||||||
|
if val, err := strconv.ParseFloat(model.CounterResetValue, 64); err == nil {
|
||||||
|
counterResetValue = &val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if counterResetValue != nil {
|
||||||
|
rateOptions["resetValue"] = *counterResetValue
|
||||||
}
|
}
|
||||||
|
|
||||||
if model.CounterMax == 0 && (model.CounterResetValue == 0) {
|
if counterMax == nil && (counterResetValue == nil || *counterResetValue == 0) {
|
||||||
rateOptions["dropResets"] = true
|
rateOptions["dropResets"] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -377,8 +377,8 @@ func TestOpenTsdbExecutor(t *testing.T) {
|
|||||||
"disableDownsampling": true,
|
"disableDownsampling": true,
|
||||||
"shouldComputeRate": true,
|
"shouldComputeRate": true,
|
||||||
"isCounter": true,
|
"isCounter": true,
|
||||||
"counterMax": 45,
|
"counterMax": "45",
|
||||||
"counterResetValue": 60,
|
"counterResetValue": "60",
|
||||||
"tags": {
|
"tags": {
|
||||||
"env": "prod",
|
"env": "prod",
|
||||||
"app": "grafana"
|
"app": "grafana"
|
||||||
@@ -388,6 +388,7 @@ func TestOpenTsdbExecutor(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
metric := service.buildMetric(query)
|
metric := service.buildMetric(query)
|
||||||
|
t.Log(metric)
|
||||||
|
|
||||||
require.Len(t, metric, 5)
|
require.Len(t, metric, 5)
|
||||||
require.Equal(t, "cpu.average.percent", metric["metric"])
|
require.Equal(t, "cpu.average.percent", metric["metric"])
|
||||||
|
|||||||
Reference in New Issue
Block a user