Remove outputs blocking inputs when output is slow (#4938)
This commit is contained in:
@@ -14,6 +14,15 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var (
|
||||
lastID uint64
|
||||
)
|
||||
|
||||
func newTrackingID() telegraf.TrackingID {
|
||||
atomic.AddUint64(&lastID, 1)
|
||||
return telegraf.TrackingID(lastID)
|
||||
}
|
||||
|
||||
// Metric defines a single point measurement
|
||||
type Metric struct {
|
||||
Measurement string
|
||||
@@ -23,7 +32,7 @@ type Metric struct {
|
||||
}
|
||||
|
||||
func (p *Metric) String() string {
|
||||
return fmt.Sprintf("%s %v", p.Measurement, p.Fields)
|
||||
return fmt.Sprintf("%s %v %v", p.Measurement, p.Tags, p.Fields)
|
||||
}
|
||||
|
||||
// Accumulator defines a mocked out accumulator
|
||||
@@ -31,11 +40,12 @@ type Accumulator struct {
|
||||
sync.Mutex
|
||||
*sync.Cond
|
||||
|
||||
Metrics []*Metric
|
||||
nMetrics uint64
|
||||
Discard bool
|
||||
Errors []error
|
||||
debug bool
|
||||
Metrics []*Metric
|
||||
nMetrics uint64
|
||||
Discard bool
|
||||
Errors []error
|
||||
debug bool
|
||||
delivered chan telegraf.DeliveryInfo
|
||||
}
|
||||
|
||||
func (a *Accumulator) NMetrics() uint64 {
|
||||
@@ -154,6 +164,33 @@ func (a *Accumulator) AddHistogram(
|
||||
a.AddFields(measurement, fields, tags, timestamp...)
|
||||
}
|
||||
|
||||
func (a *Accumulator) AddMetric(m telegraf.Metric) {
|
||||
a.AddFields(m.Name(), m.Fields(), m.Tags(), m.Time())
|
||||
}
|
||||
|
||||
func (a *Accumulator) WithTracking(maxTracked int) telegraf.TrackingAccumulator {
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *Accumulator) AddTrackingMetric(m telegraf.Metric) telegraf.TrackingID {
|
||||
a.AddMetric(m)
|
||||
return newTrackingID()
|
||||
}
|
||||
|
||||
func (a *Accumulator) AddTrackingMetricGroup(group []telegraf.Metric) telegraf.TrackingID {
|
||||
for _, m := range group {
|
||||
a.AddMetric(m)
|
||||
}
|
||||
return newTrackingID()
|
||||
}
|
||||
|
||||
func (a *Accumulator) Delivered() <-chan telegraf.DeliveryInfo {
|
||||
if a.delivered == nil {
|
||||
a.delivered = make(chan telegraf.DeliveryInfo)
|
||||
}
|
||||
return a.delivered
|
||||
}
|
||||
|
||||
// AddError appends the given error to Accumulator.Errors.
|
||||
func (a *Accumulator) AddError(err error) {
|
||||
if err == nil {
|
||||
|
||||
@@ -41,6 +41,18 @@ func newMetricDiff(metric telegraf.Metric) *metricDiff {
|
||||
return m
|
||||
}
|
||||
|
||||
func MetricEqual(expected, actual telegraf.Metric) bool {
|
||||
var lhs, rhs *metricDiff
|
||||
if expected != nil {
|
||||
lhs = newMetricDiff(expected)
|
||||
}
|
||||
if actual != nil {
|
||||
rhs = newMetricDiff(actual)
|
||||
}
|
||||
|
||||
return cmp.Equal(lhs, rhs)
|
||||
}
|
||||
|
||||
func RequireMetricEqual(t *testing.T, expected, actual telegraf.Metric) {
|
||||
t.Helper()
|
||||
|
||||
@@ -60,11 +72,11 @@ func RequireMetricEqual(t *testing.T, expected, actual telegraf.Metric) {
|
||||
func RequireMetricsEqual(t *testing.T, expected, actual []telegraf.Metric) {
|
||||
t.Helper()
|
||||
|
||||
lhs := make([]*metricDiff, len(expected))
|
||||
lhs := make([]*metricDiff, 0, len(expected))
|
||||
for _, m := range expected {
|
||||
lhs = append(lhs, newMetricDiff(m))
|
||||
}
|
||||
rhs := make([]*metricDiff, len(actual))
|
||||
rhs := make([]*metricDiff, 0, len(actual))
|
||||
for _, m := range actual {
|
||||
rhs = append(rhs, newMetricDiff(m))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user