Add prometheus round trip unit tests (#6720)
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package syslog
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/internal"
|
||||
framing "github.com/influxdata/telegraf/internal/syslog"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -14,16 +16,16 @@ var (
|
||||
type testCasePacket struct {
|
||||
name string
|
||||
data []byte
|
||||
wantBestEffort *testutil.Metric
|
||||
wantStrict *testutil.Metric
|
||||
wantBestEffort telegraf.Metric
|
||||
wantStrict telegraf.Metric
|
||||
werr bool
|
||||
}
|
||||
|
||||
type testCaseStream struct {
|
||||
name string
|
||||
data []byte
|
||||
wantBestEffort []testutil.Metric
|
||||
wantStrict []testutil.Metric
|
||||
wantBestEffort []telegraf.Metric
|
||||
wantStrict []telegraf.Metric
|
||||
werr int // how many errors we expect in the strict mode?
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/internal"
|
||||
framing "github.com/influxdata/telegraf/internal/syslog"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
@@ -21,10 +21,16 @@ func getTestCasesForNonTransparent() []testCaseStream {
|
||||
{
|
||||
name: "1st/avg/ok",
|
||||
data: []byte(`<29>1 2016-02-21T04:32:57+00:00 web1 someservice 2341 2 [origin][meta sequence="14125553" service="someservice"] "GET /v1/ok HTTP/1.1" 200 145 "-" "hacheck 0.9.0" 24306 127.0.0.1:40124 575`),
|
||||
wantStrict: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantStrict: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "notice",
|
||||
"facility": "daemon",
|
||||
"hostname": "web1",
|
||||
"appname": "someservice",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"timestamp": time.Unix(1456029177, 0).UnixNano(),
|
||||
"procid": "2341",
|
||||
@@ -36,19 +42,19 @@ func getTestCasesForNonTransparent() []testCaseStream {
|
||||
"severity_code": 5,
|
||||
"facility_code": 3,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "notice",
|
||||
"facility": "daemon",
|
||||
"hostname": "web1",
|
||||
"appname": "someservice",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
wantBestEffort: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantBestEffort: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "notice",
|
||||
"facility": "daemon",
|
||||
"hostname": "web1",
|
||||
"appname": "someservice",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"timestamp": time.Unix(1456029177, 0).UnixNano(),
|
||||
"procid": "2341",
|
||||
@@ -60,75 +66,69 @@ func getTestCasesForNonTransparent() []testCaseStream {
|
||||
"severity_code": 5,
|
||||
"facility_code": 3,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "notice",
|
||||
"facility": "daemon",
|
||||
"hostname": "web1",
|
||||
"appname": "someservice",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
werr: 1,
|
||||
},
|
||||
{
|
||||
name: "1st/min/ok//2nd/min/ok",
|
||||
data: []byte("<1>2 - - - - - -\n<4>11 - - - - - -\n"),
|
||||
wantStrict: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantStrict: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(2),
|
||||
"severity_code": 1,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
defaultTime,
|
||||
),
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "warning",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"version": uint16(11),
|
||||
"severity_code": 4,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "warning",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime.Add(time.Nanosecond),
|
||||
},
|
||||
defaultTime.Add(time.Nanosecond),
|
||||
),
|
||||
},
|
||||
wantBestEffort: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantBestEffort: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(2),
|
||||
"severity_code": 1,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
defaultTime,
|
||||
),
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "warning",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"version": uint16(11),
|
||||
"severity_code": 4,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "warning",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime.Add(time.Nanosecond),
|
||||
},
|
||||
defaultTime.Add(time.Nanosecond),
|
||||
),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -186,13 +186,7 @@ func testStrictNonTransparent(t *testing.T, protocol string, address string, wan
|
||||
if len(acc.Errors) != tc.werr {
|
||||
t.Fatalf("Got unexpected errors. want error = %v, errors = %v\n", tc.werr, acc.Errors)
|
||||
}
|
||||
var got []testutil.Metric
|
||||
for _, metric := range acc.Metrics {
|
||||
got = append(got, *metric)
|
||||
}
|
||||
if !cmp.Equal(tc.wantStrict, got) {
|
||||
t.Fatalf("Got (+) / Want (-)\n %s", cmp.Diff(tc.wantStrict, got))
|
||||
}
|
||||
testutil.RequireMetricsEqual(t, tc.wantStrict, acc.GetTelegrafMetrics())
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -240,14 +234,7 @@ func testBestEffortNonTransparent(t *testing.T, protocol string, address string,
|
||||
acc.Wait(len(tc.wantBestEffort))
|
||||
}
|
||||
|
||||
// Verify
|
||||
var got []testutil.Metric
|
||||
for _, metric := range acc.Metrics {
|
||||
got = append(got, *metric)
|
||||
}
|
||||
if !cmp.Equal(tc.wantBestEffort, got) {
|
||||
t.Fatalf("Got (+) / Want (-)\n %s", cmp.Diff(tc.wantBestEffort, got))
|
||||
}
|
||||
testutil.RequireMetricsEqual(t, tc.wantStrict, acc.GetTelegrafMetrics())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/internal"
|
||||
framing "github.com/influxdata/telegraf/internal/syslog"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
@@ -22,10 +22,16 @@ func getTestCasesForOctetCounting() []testCaseStream {
|
||||
{
|
||||
name: "1st/avg/ok",
|
||||
data: []byte(`188 <29>1 2016-02-21T04:32:57+00:00 web1 someservice 2341 2 [origin][meta sequence="14125553" service="someservice"] "GET /v1/ok HTTP/1.1" 200 145 "-" "hacheck 0.9.0" 24306 127.0.0.1:40124 575`),
|
||||
wantStrict: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantStrict: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "notice",
|
||||
"facility": "daemon",
|
||||
"hostname": "web1",
|
||||
"appname": "someservice",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"timestamp": time.Unix(1456029177, 0).UnixNano(),
|
||||
"procid": "2341",
|
||||
@@ -37,19 +43,19 @@ func getTestCasesForOctetCounting() []testCaseStream {
|
||||
"severity_code": 5,
|
||||
"facility_code": 3,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "notice",
|
||||
"facility": "daemon",
|
||||
"hostname": "web1",
|
||||
"appname": "someservice",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
wantBestEffort: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantBestEffort: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "notice",
|
||||
"facility": "daemon",
|
||||
"hostname": "web1",
|
||||
"appname": "someservice",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"timestamp": time.Unix(1456029177, 0).UnixNano(),
|
||||
"procid": "2341",
|
||||
@@ -61,221 +67,215 @@ func getTestCasesForOctetCounting() []testCaseStream {
|
||||
"severity_code": 5,
|
||||
"facility_code": 3,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "notice",
|
||||
"facility": "daemon",
|
||||
"hostname": "web1",
|
||||
"appname": "someservice",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "1st/min/ok//2nd/min/ok",
|
||||
data: []byte("16 <1>2 - - - - - -17 <4>11 - - - - - -"),
|
||||
wantStrict: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantStrict: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(2),
|
||||
"severity_code": 1,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
defaultTime,
|
||||
),
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "warning",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"version": uint16(11),
|
||||
"severity_code": 4,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "warning",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime.Add(time.Nanosecond),
|
||||
},
|
||||
defaultTime.Add(time.Nanosecond),
|
||||
),
|
||||
},
|
||||
wantBestEffort: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantBestEffort: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(2),
|
||||
"severity_code": 1,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
defaultTime,
|
||||
),
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "warning",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"version": uint16(11),
|
||||
"severity_code": 4,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "warning",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime.Add(time.Nanosecond),
|
||||
},
|
||||
defaultTime.Add(time.Nanosecond),
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "1st/utf8/ok",
|
||||
data: []byte("23 <1>1 - - - - - - hellø"),
|
||||
wantStrict: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantStrict: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"message": "hellø",
|
||||
"severity_code": 1,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
wantBestEffort: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantBestEffort: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"message": "hellø",
|
||||
"severity_code": 1,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "1st/nl/ok", // newline
|
||||
data: []byte("28 <1>3 - - - - - - hello\nworld"),
|
||||
wantStrict: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantStrict: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(3),
|
||||
"message": "hello\nworld",
|
||||
"severity_code": 1,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
wantBestEffort: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantBestEffort: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(3),
|
||||
"message": "hello\nworld",
|
||||
"severity_code": 1,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "1st/uf/ko", // underflow (msglen less than provided octets)
|
||||
data: []byte("16 <1>2"),
|
||||
wantStrict: nil,
|
||||
wantBestEffort: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantBestEffort: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(2),
|
||||
"severity_code": 1,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
werr: 1,
|
||||
},
|
||||
{
|
||||
name: "1st/min/ok",
|
||||
data: []byte("16 <1>1 - - - - - -"),
|
||||
wantStrict: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantStrict: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"severity_code": 1,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
wantBestEffort: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantBestEffort: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"severity_code": 1,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "1st/uf/mf", // The first "underflow" message breaks also the second one
|
||||
data: []byte("16 <1>217 <11>1 - - - - - -"),
|
||||
wantStrict: nil,
|
||||
wantBestEffort: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantBestEffort: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(217),
|
||||
"severity_code": 1,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
werr: 1,
|
||||
},
|
||||
@@ -287,10 +287,16 @@ func getTestCasesForOctetCounting() []testCaseStream {
|
||||
{
|
||||
name: "1st/max/ok",
|
||||
data: []byte(fmt.Sprintf("8192 <%d>%d %s %s %s %s %s - %s", maxP, maxV, maxTS, maxH, maxA, maxPID, maxMID, message7681)),
|
||||
wantStrict: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantStrict: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "debug",
|
||||
"facility": "local7",
|
||||
"hostname": maxH,
|
||||
"appname": maxA,
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": maxV,
|
||||
"timestamp": time.Unix(1514764799, 999999000).UnixNano(),
|
||||
"message": message7681,
|
||||
@@ -299,19 +305,19 @@ func getTestCasesForOctetCounting() []testCaseStream {
|
||||
"facility_code": 23,
|
||||
"severity_code": 7,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "debug",
|
||||
"facility": "local7",
|
||||
"hostname": maxH,
|
||||
"appname": maxA,
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
wantBestEffort: []testutil.Metric{
|
||||
{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantBestEffort: []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "debug",
|
||||
"facility": "local7",
|
||||
"hostname": maxH,
|
||||
"appname": maxA,
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": maxV,
|
||||
"timestamp": time.Unix(1514764799, 999999000).UnixNano(),
|
||||
"message": message7681,
|
||||
@@ -320,14 +326,8 @@ func getTestCasesForOctetCounting() []testCaseStream {
|
||||
"facility_code": 23,
|
||||
"severity_code": 7,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "debug",
|
||||
"facility": "local7",
|
||||
"hostname": maxH,
|
||||
"appname": maxA,
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -386,13 +386,7 @@ func testStrictOctetCounting(t *testing.T, protocol string, address string, want
|
||||
if len(acc.Errors) != tc.werr {
|
||||
t.Fatalf("Got unexpected errors. want error = %v, errors = %v\n", tc.werr, acc.Errors)
|
||||
}
|
||||
var got []testutil.Metric
|
||||
for _, metric := range acc.Metrics {
|
||||
got = append(got, *metric)
|
||||
}
|
||||
if !cmp.Equal(tc.wantStrict, got) {
|
||||
t.Fatalf("Got (+) / Want (-)\n %s", cmp.Diff(tc.wantStrict, got))
|
||||
}
|
||||
testutil.RequireMetricsEqual(t, tc.wantStrict, acc.GetTelegrafMetrics())
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -440,14 +434,7 @@ func testBestEffortOctetCounting(t *testing.T, protocol string, address string,
|
||||
acc.Wait(len(tc.wantBestEffort))
|
||||
}
|
||||
|
||||
// Verify
|
||||
var got []testutil.Metric
|
||||
for _, metric := range acc.Metrics {
|
||||
got = append(got, *metric)
|
||||
}
|
||||
if !cmp.Equal(tc.wantBestEffort, got) {
|
||||
t.Fatalf("Got (+) / Want (-)\n %s", cmp.Diff(tc.wantBestEffort, got))
|
||||
}
|
||||
testutil.RequireMetricsEqual(t, tc.wantBestEffort, acc.GetTelegrafMetrics())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -25,73 +25,79 @@ func getTestCasesForRFC5426() []testCasePacket {
|
||||
{
|
||||
name: "complete",
|
||||
data: []byte("<1>1 - - - - - - A"),
|
||||
wantBestEffort: &testutil.Metric{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantBestEffort: testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"message": "A",
|
||||
"facility_code": 0,
|
||||
"severity_code": 1,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
defaultTime,
|
||||
),
|
||||
wantStrict: testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
wantStrict: &testutil.Metric{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"message": "A",
|
||||
"facility_code": 0,
|
||||
"severity_code": 1,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "one/per/packet",
|
||||
data: []byte("<1>3 - - - - - - A<1>4 - - - - - - B"),
|
||||
wantBestEffort: &testutil.Metric{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantBestEffort: testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(3),
|
||||
"message": "A<1>4 - - - - - - B",
|
||||
"severity_code": 1,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
defaultTime,
|
||||
),
|
||||
wantStrict: testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
wantStrict: &testutil.Metric{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"version": uint16(3),
|
||||
"message": "A<1>4 - - - - - - B",
|
||||
"severity_code": 1,
|
||||
"facility_code": 0,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "average",
|
||||
data: []byte(`<29>1 2016-02-21T04:32:57+00:00 web1 someservice 2341 2 [origin][meta sequence="14125553" service="someservice"] "GET /v1/ok HTTP/1.1" 200 145 "-" "hacheck 0.9.0" 24306 127.0.0.1:40124 575`),
|
||||
wantBestEffort: &testutil.Metric{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantBestEffort: testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "notice",
|
||||
"facility": "daemon",
|
||||
"hostname": "web1",
|
||||
"appname": "someservice",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"timestamp": time.Unix(1456029177, 0).UnixNano(),
|
||||
"procid": "2341",
|
||||
@@ -103,17 +109,17 @@ func getTestCasesForRFC5426() []testCasePacket {
|
||||
"severity_code": 5,
|
||||
"facility_code": 3,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
defaultTime,
|
||||
),
|
||||
wantStrict: testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "notice",
|
||||
"facility": "daemon",
|
||||
"hostname": "web1",
|
||||
"appname": "someservice",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
wantStrict: &testutil.Metric{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"timestamp": time.Unix(1456029177, 0).UnixNano(),
|
||||
"procid": "2341",
|
||||
@@ -125,21 +131,21 @@ func getTestCasesForRFC5426() []testCasePacket {
|
||||
"severity_code": 5,
|
||||
"facility_code": 3,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "notice",
|
||||
"facility": "daemon",
|
||||
"hostname": "web1",
|
||||
"appname": "someservice",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "max",
|
||||
data: []byte(fmt.Sprintf("<%d>%d %s %s %s %s %s - %s", maxP, maxV, maxTS, maxH, maxA, maxPID, maxMID, message7681)),
|
||||
wantBestEffort: &testutil.Metric{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantBestEffort: testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "debug",
|
||||
"facility": "local7",
|
||||
"hostname": maxH,
|
||||
"appname": maxA,
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": maxV,
|
||||
"timestamp": time.Unix(1514764799, 999999000).UnixNano(),
|
||||
"message": message7681,
|
||||
@@ -148,17 +154,17 @@ func getTestCasesForRFC5426() []testCasePacket {
|
||||
"severity_code": 7,
|
||||
"facility_code": 23,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
defaultTime,
|
||||
),
|
||||
wantStrict: testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "debug",
|
||||
"facility": "local7",
|
||||
"hostname": maxH,
|
||||
"appname": maxA,
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
wantStrict: &testutil.Metric{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"version": maxV,
|
||||
"timestamp": time.Unix(1514764799, 999999000).UnixNano(),
|
||||
"message": message7681,
|
||||
@@ -167,64 +173,58 @@ func getTestCasesForRFC5426() []testCasePacket {
|
||||
"severity_code": 7,
|
||||
"facility_code": 23,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "debug",
|
||||
"facility": "local7",
|
||||
"hostname": maxH,
|
||||
"appname": maxA,
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "minimal/incomplete",
|
||||
data: []byte("<1>2"),
|
||||
wantBestEffort: &testutil.Metric{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantBestEffort: testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(2),
|
||||
"facility_code": 0,
|
||||
"severity_code": 1,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
werr: true,
|
||||
},
|
||||
{
|
||||
name: "trim message",
|
||||
data: []byte("<1>1 - - - - - - \tA\n"),
|
||||
wantBestEffort: &testutil.Metric{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
wantBestEffort: testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"message": "\tA",
|
||||
"facility_code": 0,
|
||||
"severity_code": 1,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
defaultTime,
|
||||
),
|
||||
wantStrict: testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
wantStrict: &testutil.Metric{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"message": "\tA",
|
||||
"facility_code": 0,
|
||||
"severity_code": 1,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: defaultTime,
|
||||
},
|
||||
defaultTime,
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -269,19 +269,17 @@ func testRFC5426(t *testing.T, protocol string, address string, bestEffort bool)
|
||||
}
|
||||
|
||||
// Compare
|
||||
var got *testutil.Metric
|
||||
var want *testutil.Metric
|
||||
var got telegraf.Metric
|
||||
var want telegraf.Metric
|
||||
if len(acc.Metrics) > 0 {
|
||||
got = acc.Metrics[0]
|
||||
got = acc.GetTelegrafMetrics()[0]
|
||||
}
|
||||
if bestEffort {
|
||||
want = tc.wantBestEffort
|
||||
} else {
|
||||
want = tc.wantStrict
|
||||
}
|
||||
if !cmp.Equal(want, got) {
|
||||
t.Fatalf("Got (+) / Want (-)\n %s", cmp.Diff(want, got))
|
||||
}
|
||||
testutil.RequireMetricEqual(t, want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -346,23 +344,22 @@ func TestTimeIncrement_udp(t *testing.T) {
|
||||
// Wait
|
||||
acc.Wait(1)
|
||||
|
||||
want := &testutil.Metric{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"facility_code": 0,
|
||||
"severity_code": 1,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: getNow(),
|
||||
}
|
||||
|
||||
if !cmp.Equal(want, acc.Metrics[0]) {
|
||||
t.Fatalf("Got (+) / Want (-)\n %s", cmp.Diff(want, acc.Metrics[0]))
|
||||
want := []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"facility_code": 0,
|
||||
"severity_code": 1,
|
||||
},
|
||||
getNow(),
|
||||
),
|
||||
}
|
||||
testutil.RequireMetricsEqual(t, want, acc.GetTelegrafMetrics())
|
||||
|
||||
// New one with different time
|
||||
atomic.StoreInt64(&i, atomic.LoadInt64(&i)+1)
|
||||
@@ -377,23 +374,22 @@ func TestTimeIncrement_udp(t *testing.T) {
|
||||
// Wait
|
||||
acc.Wait(1)
|
||||
|
||||
want = &testutil.Metric{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"facility_code": 0,
|
||||
"severity_code": 1,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: getNow(),
|
||||
}
|
||||
|
||||
if !cmp.Equal(want, acc.Metrics[0]) {
|
||||
t.Fatalf("Got (+) / Want (-)\n %s", cmp.Diff(want, acc.Metrics[0]))
|
||||
want = []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"facility_code": 0,
|
||||
"severity_code": 1,
|
||||
},
|
||||
getNow(),
|
||||
),
|
||||
}
|
||||
testutil.RequireMetricsEqual(t, want, acc.GetTelegrafMetrics())
|
||||
|
||||
// New one with same time as previous one
|
||||
|
||||
@@ -407,21 +403,20 @@ func TestTimeIncrement_udp(t *testing.T) {
|
||||
// Wait
|
||||
acc.Wait(1)
|
||||
|
||||
want = &testutil.Metric{
|
||||
Measurement: "syslog",
|
||||
Fields: map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"facility_code": 0,
|
||||
"severity_code": 1,
|
||||
},
|
||||
Tags: map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
Time: getNow().Add(time.Nanosecond),
|
||||
}
|
||||
|
||||
if !cmp.Equal(want, acc.Metrics[0]) {
|
||||
t.Fatalf("Got (+) / Want (-)\n %s", cmp.Diff(want, acc.Metrics[0]))
|
||||
want = []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"syslog",
|
||||
map[string]string{
|
||||
"severity": "alert",
|
||||
"facility": "kern",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"version": uint16(1),
|
||||
"facility_code": 0,
|
||||
"severity_code": 1,
|
||||
},
|
||||
getNow().Add(time.Nanosecond),
|
||||
),
|
||||
}
|
||||
testutil.RequireMetricsEqual(t, want, acc.GetTelegrafMetrics())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user