mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-30 07:40:06 +01:00
fb90a56de2
This commit adds only JSON support - https://docs.datadoghq.com/api/latest/metrics/#submit-metrics , while recent versions of DataDog Agent send data to /api/v2/series in undocumented Protobuf format. The support for this format will be added later. Thanks to @AndrewChubatiuk for the initial implementation at https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5094 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4451
78 lines
1.3 KiB
Go
78 lines
1.3 KiB
Go
package datadogv2
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestRequestUnmarshalJSONFailure(t *testing.T) {
|
|
f := func(s string) {
|
|
t.Helper()
|
|
var req Request
|
|
if err := UnmarshalJSON(&req, []byte(s)); err == nil {
|
|
t.Fatalf("expecting non-nil error for Unmarshal(%q)", s)
|
|
}
|
|
}
|
|
f("")
|
|
f("foobar")
|
|
f(`{"series":123`)
|
|
f(`1234`)
|
|
f(`[]`)
|
|
}
|
|
|
|
func TestRequestUnmarshalJSONSuccess(t *testing.T) {
|
|
f := func(s string, reqExpected *Request) {
|
|
t.Helper()
|
|
var req Request
|
|
if err := UnmarshalJSON(&req, []byte(s)); err != nil {
|
|
t.Fatalf("unexpected error in Unmarshal(%q): %s", s, err)
|
|
}
|
|
if !reflect.DeepEqual(&req, reqExpected) {
|
|
t.Fatalf("unexpected row;\ngot\n%+v\nwant\n%+v", &req, reqExpected)
|
|
}
|
|
}
|
|
f("{}", &Request{})
|
|
f(`
|
|
{
|
|
"series": [
|
|
{
|
|
"metric": "system.load.1",
|
|
"type": 0,
|
|
"points": [
|
|
{
|
|
"timestamp": 1636629071,
|
|
"value": 0.7
|
|
}
|
|
],
|
|
"resources": [
|
|
{
|
|
"name": "dummyhost",
|
|
"type": "host"
|
|
}
|
|
],
|
|
"tags": ["environment:test"]
|
|
}
|
|
]
|
|
}
|
|
`, &Request{
|
|
Series: []Series{{
|
|
Metric: "system.load.1",
|
|
Points: []Point{
|
|
{
|
|
Timestamp: 1636629071,
|
|
Value: 0.7,
|
|
},
|
|
},
|
|
Resources: []Resource{
|
|
{
|
|
Name: "dummyhost",
|
|
Type: "host",
|
|
},
|
|
},
|
|
Tags: []string{
|
|
"environment:test",
|
|
},
|
|
}},
|
|
})
|
|
}
|