Fix internal metrics for output split into multiple lines (#7119)
This commit is contained in:
parent
64fecfa19e
commit
c50b02e58d
|
@ -33,6 +33,11 @@ type Buffer struct {
|
|||
|
||||
// NewBuffer returns a new empty Buffer with the given capacity.
|
||||
func NewBuffer(name string, alias string, capacity int) *Buffer {
|
||||
tags := map[string]string{"output": name}
|
||||
if alias != "" {
|
||||
tags["alias"] = alias
|
||||
}
|
||||
|
||||
b := &Buffer{
|
||||
buf: make([]telegraf.Metric, capacity),
|
||||
first: 0,
|
||||
|
@ -43,27 +48,27 @@ func NewBuffer(name string, alias string, capacity int) *Buffer {
|
|||
MetricsAdded: selfstat.Register(
|
||||
"write",
|
||||
"metrics_added",
|
||||
map[string]string{"output": name, "alias": alias},
|
||||
tags,
|
||||
),
|
||||
MetricsWritten: selfstat.Register(
|
||||
"write",
|
||||
"metrics_written",
|
||||
map[string]string{"output": name, "alias": alias},
|
||||
tags,
|
||||
),
|
||||
MetricsDropped: selfstat.Register(
|
||||
"write",
|
||||
"metrics_dropped",
|
||||
map[string]string{"output": name, "alias": alias},
|
||||
tags,
|
||||
),
|
||||
BufferSize: selfstat.Register(
|
||||
"write",
|
||||
"buffer_size",
|
||||
map[string]string{"output": name, "alias": alias},
|
||||
tags,
|
||||
),
|
||||
BufferLimit: selfstat.Register(
|
||||
"write",
|
||||
"buffer_limit",
|
||||
map[string]string{"output": name, "alias": alias},
|
||||
tags,
|
||||
),
|
||||
}
|
||||
b.BufferSize.Set(int64(0))
|
||||
|
|
|
@ -4,8 +4,10 @@ import (
|
|||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/selfstat"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -412,6 +414,50 @@ func TestRunningOutputWriteFailOrder3(t *testing.T) {
|
|||
assert.Equal(t, expected, m.Metrics())
|
||||
}
|
||||
|
||||
func TestInternalMetrics(t *testing.T) {
|
||||
_ = NewRunningOutput(
|
||||
"test_internal",
|
||||
&mockOutput{},
|
||||
&OutputConfig{
|
||||
Filter: Filter{},
|
||||
Name: "test_name",
|
||||
Alias: "test_alias",
|
||||
},
|
||||
5,
|
||||
10)
|
||||
|
||||
expected := []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"internal_write",
|
||||
map[string]string{
|
||||
"output": "test_name",
|
||||
"alias": "test_alias",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"buffer_limit": 10,
|
||||
"buffer_size": 0,
|
||||
"errors": 0,
|
||||
"metrics_added": 0,
|
||||
"metrics_dropped": 0,
|
||||
"metrics_filtered": 0,
|
||||
"metrics_written": 0,
|
||||
"write_time_ns": 0,
|
||||
},
|
||||
time.Unix(0, 0),
|
||||
),
|
||||
}
|
||||
|
||||
var actual []telegraf.Metric
|
||||
for _, m := range selfstat.Metrics() {
|
||||
output, _ := m.GetTag("output")
|
||||
if m.Name() == "internal_write" && output == "test_name" {
|
||||
actual = append(actual, m)
|
||||
}
|
||||
}
|
||||
|
||||
testutil.RequireMetricsEqual(t, expected, actual, testutil.IgnoreTime())
|
||||
}
|
||||
|
||||
type mockOutput struct {
|
||||
sync.Mutex
|
||||
|
||||
|
|
Loading…
Reference in New Issue