fix(outputs.yandex_cloud_monitoring): catch int64 values (#12156)
This commit is contained in:
parent
a3424a982f
commit
f2b49ce39c
|
|
@ -12,6 +12,7 @@ import (
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/config"
|
"github.com/influxdata/telegraf/config"
|
||||||
|
"github.com/influxdata/telegraf/internal"
|
||||||
"github.com/influxdata/telegraf/plugins/outputs"
|
"github.com/influxdata/telegraf/plugins/outputs"
|
||||||
"github.com/influxdata/telegraf/selfstat"
|
"github.com/influxdata/telegraf/selfstat"
|
||||||
)
|
)
|
||||||
|
|
@ -122,13 +123,19 @@ func (a *YandexCloudMonitoring) Write(metrics []telegraf.Metric) error {
|
||||||
var yandexCloudMonitoringMetrics []yandexCloudMonitoringMetric
|
var yandexCloudMonitoringMetrics []yandexCloudMonitoringMetric
|
||||||
for _, m := range metrics {
|
for _, m := range metrics {
|
||||||
for _, field := range m.FieldList() {
|
for _, field := range m.FieldList() {
|
||||||
|
value, err := internal.ToFloat64(field.Value)
|
||||||
|
if err != nil {
|
||||||
|
a.Log.Errorf("skipping value: %w", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
yandexCloudMonitoringMetrics = append(
|
yandexCloudMonitoringMetrics = append(
|
||||||
yandexCloudMonitoringMetrics,
|
yandexCloudMonitoringMetrics,
|
||||||
yandexCloudMonitoringMetric{
|
yandexCloudMonitoringMetric{
|
||||||
Name: field.Key,
|
Name: field.Key,
|
||||||
Labels: m.Tags(),
|
Labels: m.Tags(),
|
||||||
TS: fmt.Sprint(m.Time().Format(time.RFC3339)),
|
TS: fmt.Sprint(m.Time().Format(time.RFC3339)),
|
||||||
Value: field.Value.(float64),
|
Value: value,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,16 @@ package yandex_cloud_monitoring
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/influxdata/telegraf"
|
|
||||||
"github.com/influxdata/telegraf/testutil"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/influxdata/telegraf"
|
||||||
|
"github.com/influxdata/telegraf/testutil"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWrite(t *testing.T) {
|
func TestWrite(t *testing.T) {
|
||||||
|
|
@ -74,6 +75,48 @@ func TestWrite(t *testing.T) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "int64 metric is converted to json value",
|
||||||
|
plugin: &YandexCloudMonitoring{},
|
||||||
|
metrics: []telegraf.Metric{
|
||||||
|
testutil.MustMetric(
|
||||||
|
"cluster",
|
||||||
|
map[string]string{},
|
||||||
|
map[string]interface{}{
|
||||||
|
"value": int64(9223372036854775806),
|
||||||
|
},
|
||||||
|
time.Unix(0, 0),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
handler: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
||||||
|
message := readBody(r)
|
||||||
|
require.Len(t, message.Metrics, 1)
|
||||||
|
require.Equal(t, "value", message.Metrics[0].Name)
|
||||||
|
require.Equal(t, float64(9.223372036854776e+18), message.Metrics[0].Value)
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "int metric is converted to json value",
|
||||||
|
plugin: &YandexCloudMonitoring{},
|
||||||
|
metrics: []telegraf.Metric{
|
||||||
|
testutil.MustMetric(
|
||||||
|
"cluster",
|
||||||
|
map[string]string{},
|
||||||
|
map[string]interface{}{
|
||||||
|
"value": 9226,
|
||||||
|
},
|
||||||
|
time.Unix(0, 0),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
handler: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
||||||
|
message := readBody(r)
|
||||||
|
require.Len(t, message.Metrics, 1)
|
||||||
|
require.Equal(t, "value", message.Metrics[0].Name)
|
||||||
|
require.Equal(t, float64(9226), message.Metrics[0].Value)
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue