Use alias name in output metric buffer stats

This commit is contained in:
Daniel Nelson 2019-08-21 18:02:51 -07:00
parent 3cdc6c32dd
commit 94f68c06d7
No known key found for this signature in database
GPG Key ID: CAAD59C9444F6155
8 changed files with 73 additions and 80 deletions

View File

@ -32,7 +32,7 @@ type Buffer struct {
} }
// NewBuffer returns a new empty Buffer with the given capacity. // NewBuffer returns a new empty Buffer with the given capacity.
func NewBuffer(name string, capacity int) *Buffer { func NewBuffer(name string, alias string, capacity int) *Buffer {
b := &Buffer{ b := &Buffer{
buf: make([]telegraf.Metric, capacity), buf: make([]telegraf.Metric, capacity),
first: 0, first: 0,
@ -43,27 +43,27 @@ func NewBuffer(name string, capacity int) *Buffer {
MetricsAdded: selfstat.Register( MetricsAdded: selfstat.Register(
"write", "write",
"metrics_added", "metrics_added",
map[string]string{"output": name}, map[string]string{"output": name, "alias": alias},
), ),
MetricsWritten: selfstat.Register( MetricsWritten: selfstat.Register(
"write", "write",
"metrics_written", "metrics_written",
map[string]string{"output": name}, map[string]string{"output": name, "alias": alias},
), ),
MetricsDropped: selfstat.Register( MetricsDropped: selfstat.Register(
"write", "write",
"metrics_dropped", "metrics_dropped",
map[string]string{"output": name}, map[string]string{"output": name, "alias": alias},
), ),
BufferSize: selfstat.Register( BufferSize: selfstat.Register(
"write", "write",
"buffer_size", "buffer_size",
map[string]string{"output": name}, map[string]string{"output": name, "alias": alias},
), ),
BufferLimit: selfstat.Register( BufferLimit: selfstat.Register(
"write", "write",
"buffer_limit", "buffer_limit",
map[string]string{"output": name}, map[string]string{"output": name, "alias": alias},
), ),
} }
b.BufferSize.Set(int64(0)) b.BufferSize.Set(int64(0))

View File

@ -49,7 +49,7 @@ func MetricTime(sec int64) telegraf.Metric {
} }
func BenchmarkAddMetrics(b *testing.B) { func BenchmarkAddMetrics(b *testing.B) {
buf := NewBuffer("test", 10000) buf := NewBuffer("test", "", 10000)
m := Metric() m := Metric()
for n := 0; n < b.N; n++ { for n := 0; n < b.N; n++ {
buf.Add(m) buf.Add(m)
@ -64,14 +64,14 @@ func setup(b *Buffer) *Buffer {
} }
func TestBuffer_LenEmpty(t *testing.T) { func TestBuffer_LenEmpty(t *testing.T) {
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
require.Equal(t, 0, b.Len()) require.Equal(t, 0, b.Len())
} }
func TestBuffer_LenOne(t *testing.T) { func TestBuffer_LenOne(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m) b.Add(m)
require.Equal(t, 1, b.Len()) require.Equal(t, 1, b.Len())
@ -79,7 +79,7 @@ func TestBuffer_LenOne(t *testing.T) {
func TestBuffer_LenFull(t *testing.T) { func TestBuffer_LenFull(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m, m, m, m, m) b.Add(m, m, m, m, m)
require.Equal(t, 5, b.Len()) require.Equal(t, 5, b.Len())
@ -87,7 +87,7 @@ func TestBuffer_LenFull(t *testing.T) {
func TestBuffer_LenOverfill(t *testing.T) { func TestBuffer_LenOverfill(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
setup(b) setup(b)
b.Add(m, m, m, m, m, m) b.Add(m, m, m, m, m, m)
@ -95,14 +95,14 @@ func TestBuffer_LenOverfill(t *testing.T) {
} }
func TestBuffer_BatchLenZero(t *testing.T) { func TestBuffer_BatchLenZero(t *testing.T) {
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
batch := b.Batch(0) batch := b.Batch(0)
require.Len(t, batch, 0) require.Len(t, batch, 0)
} }
func TestBuffer_BatchLenBufferEmpty(t *testing.T) { func TestBuffer_BatchLenBufferEmpty(t *testing.T) {
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
batch := b.Batch(2) batch := b.Batch(2)
require.Len(t, batch, 0) require.Len(t, batch, 0)
@ -110,7 +110,7 @@ func TestBuffer_BatchLenBufferEmpty(t *testing.T) {
func TestBuffer_BatchLenUnderfill(t *testing.T) { func TestBuffer_BatchLenUnderfill(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m) b.Add(m)
batch := b.Batch(2) batch := b.Batch(2)
@ -119,7 +119,7 @@ func TestBuffer_BatchLenUnderfill(t *testing.T) {
func TestBuffer_BatchLenFill(t *testing.T) { func TestBuffer_BatchLenFill(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m, m, m) b.Add(m, m, m)
batch := b.Batch(2) batch := b.Batch(2)
require.Len(t, batch, 2) require.Len(t, batch, 2)
@ -127,7 +127,7 @@ func TestBuffer_BatchLenFill(t *testing.T) {
func TestBuffer_BatchLenExact(t *testing.T) { func TestBuffer_BatchLenExact(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m, m) b.Add(m, m)
batch := b.Batch(2) batch := b.Batch(2)
require.Len(t, batch, 2) require.Len(t, batch, 2)
@ -135,7 +135,7 @@ func TestBuffer_BatchLenExact(t *testing.T) {
func TestBuffer_BatchLenLargerThanBuffer(t *testing.T) { func TestBuffer_BatchLenLargerThanBuffer(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m, m, m, m, m) b.Add(m, m, m, m, m)
batch := b.Batch(6) batch := b.Batch(6)
require.Len(t, batch, 5) require.Len(t, batch, 5)
@ -143,7 +143,7 @@ func TestBuffer_BatchLenLargerThanBuffer(t *testing.T) {
func TestBuffer_BatchWrap(t *testing.T) { func TestBuffer_BatchWrap(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m, m, m, m, m) b.Add(m, m, m, m, m)
batch := b.Batch(2) batch := b.Batch(2)
b.Accept(batch) b.Accept(batch)
@ -153,7 +153,7 @@ func TestBuffer_BatchWrap(t *testing.T) {
} }
func TestBuffer_BatchLatest(t *testing.T) { func TestBuffer_BatchLatest(t *testing.T) {
b := setup(NewBuffer("test", 4)) b := setup(NewBuffer("test", "", 4))
b.Add(MetricTime(1)) b.Add(MetricTime(1))
b.Add(MetricTime(2)) b.Add(MetricTime(2))
b.Add(MetricTime(3)) b.Add(MetricTime(3))
@ -167,7 +167,7 @@ func TestBuffer_BatchLatest(t *testing.T) {
} }
func TestBuffer_BatchLatestWrap(t *testing.T) { func TestBuffer_BatchLatestWrap(t *testing.T) {
b := setup(NewBuffer("test", 4)) b := setup(NewBuffer("test", "", 4))
b.Add(MetricTime(1)) b.Add(MetricTime(1))
b.Add(MetricTime(2)) b.Add(MetricTime(2))
b.Add(MetricTime(3)) b.Add(MetricTime(3))
@ -183,7 +183,7 @@ func TestBuffer_BatchLatestWrap(t *testing.T) {
} }
func TestBuffer_MultipleBatch(t *testing.T) { func TestBuffer_MultipleBatch(t *testing.T) {
b := setup(NewBuffer("test", 10)) b := setup(NewBuffer("test", "", 10))
b.Add(MetricTime(1)) b.Add(MetricTime(1))
b.Add(MetricTime(2)) b.Add(MetricTime(2))
b.Add(MetricTime(3)) b.Add(MetricTime(3))
@ -209,7 +209,7 @@ func TestBuffer_MultipleBatch(t *testing.T) {
} }
func TestBuffer_RejectWithRoom(t *testing.T) { func TestBuffer_RejectWithRoom(t *testing.T) {
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(MetricTime(1)) b.Add(MetricTime(1))
b.Add(MetricTime(2)) b.Add(MetricTime(2))
b.Add(MetricTime(3)) b.Add(MetricTime(3))
@ -232,7 +232,7 @@ func TestBuffer_RejectWithRoom(t *testing.T) {
} }
func TestBuffer_RejectNothingNewFull(t *testing.T) { func TestBuffer_RejectNothingNewFull(t *testing.T) {
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(MetricTime(1)) b.Add(MetricTime(1))
b.Add(MetricTime(2)) b.Add(MetricTime(2))
b.Add(MetricTime(3)) b.Add(MetricTime(3))
@ -255,7 +255,7 @@ func TestBuffer_RejectNothingNewFull(t *testing.T) {
} }
func TestBuffer_RejectNoRoom(t *testing.T) { func TestBuffer_RejectNoRoom(t *testing.T) {
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(MetricTime(1)) b.Add(MetricTime(1))
b.Add(MetricTime(2)) b.Add(MetricTime(2))
@ -284,7 +284,7 @@ func TestBuffer_RejectNoRoom(t *testing.T) {
} }
func TestBuffer_RejectRoomExact(t *testing.T) { func TestBuffer_RejectRoomExact(t *testing.T) {
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(MetricTime(1)) b.Add(MetricTime(1))
b.Add(MetricTime(2)) b.Add(MetricTime(2))
batch := b.Batch(2) batch := b.Batch(2)
@ -308,7 +308,7 @@ func TestBuffer_RejectRoomExact(t *testing.T) {
} }
func TestBuffer_RejectRoomOverwriteOld(t *testing.T) { func TestBuffer_RejectRoomOverwriteOld(t *testing.T) {
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(MetricTime(1)) b.Add(MetricTime(1))
b.Add(MetricTime(2)) b.Add(MetricTime(2))
b.Add(MetricTime(3)) b.Add(MetricTime(3))
@ -333,7 +333,7 @@ func TestBuffer_RejectRoomOverwriteOld(t *testing.T) {
} }
func TestBuffer_RejectPartialRoom(t *testing.T) { func TestBuffer_RejectPartialRoom(t *testing.T) {
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(MetricTime(1)) b.Add(MetricTime(1))
b.Add(MetricTime(2)) b.Add(MetricTime(2))
@ -360,7 +360,7 @@ func TestBuffer_RejectPartialRoom(t *testing.T) {
} }
func TestBuffer_RejectNewMetricsWrapped(t *testing.T) { func TestBuffer_RejectNewMetricsWrapped(t *testing.T) {
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(MetricTime(1)) b.Add(MetricTime(1))
b.Add(MetricTime(2)) b.Add(MetricTime(2))
b.Add(MetricTime(3)) b.Add(MetricTime(3))
@ -403,7 +403,7 @@ func TestBuffer_RejectNewMetricsWrapped(t *testing.T) {
} }
func TestBuffer_RejectWrapped(t *testing.T) { func TestBuffer_RejectWrapped(t *testing.T) {
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(MetricTime(1)) b.Add(MetricTime(1))
b.Add(MetricTime(2)) b.Add(MetricTime(2))
b.Add(MetricTime(3)) b.Add(MetricTime(3))
@ -434,7 +434,7 @@ func TestBuffer_RejectWrapped(t *testing.T) {
} }
func TestBuffer_RejectAdjustFirst(t *testing.T) { func TestBuffer_RejectAdjustFirst(t *testing.T) {
b := setup(NewBuffer("test", 10)) b := setup(NewBuffer("test", "", 10))
b.Add(MetricTime(1)) b.Add(MetricTime(1))
b.Add(MetricTime(2)) b.Add(MetricTime(2))
b.Add(MetricTime(3)) b.Add(MetricTime(3))
@ -482,7 +482,7 @@ func TestBuffer_RejectAdjustFirst(t *testing.T) {
func TestBuffer_AddDropsOverwrittenMetrics(t *testing.T) { func TestBuffer_AddDropsOverwrittenMetrics(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m, m, m, m, m) b.Add(m, m, m, m, m)
b.Add(m, m, m, m, m) b.Add(m, m, m, m, m)
@ -493,7 +493,7 @@ func TestBuffer_AddDropsOverwrittenMetrics(t *testing.T) {
func TestBuffer_AcceptRemovesBatch(t *testing.T) { func TestBuffer_AcceptRemovesBatch(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m, m, m) b.Add(m, m, m)
batch := b.Batch(2) batch := b.Batch(2)
b.Accept(batch) b.Accept(batch)
@ -502,7 +502,7 @@ func TestBuffer_AcceptRemovesBatch(t *testing.T) {
func TestBuffer_RejectLeavesBatch(t *testing.T) { func TestBuffer_RejectLeavesBatch(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m, m, m) b.Add(m, m, m)
batch := b.Batch(2) batch := b.Batch(2)
b.Reject(batch) b.Reject(batch)
@ -511,7 +511,7 @@ func TestBuffer_RejectLeavesBatch(t *testing.T) {
func TestBuffer_AcceptWritesOverwrittenBatch(t *testing.T) { func TestBuffer_AcceptWritesOverwrittenBatch(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m, m, m, m, m) b.Add(m, m, m, m, m)
batch := b.Batch(5) batch := b.Batch(5)
@ -524,7 +524,7 @@ func TestBuffer_AcceptWritesOverwrittenBatch(t *testing.T) {
func TestBuffer_BatchRejectDropsOverwrittenBatch(t *testing.T) { func TestBuffer_BatchRejectDropsOverwrittenBatch(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m, m, m, m, m) b.Add(m, m, m, m, m)
batch := b.Batch(5) batch := b.Batch(5)
@ -537,7 +537,7 @@ func TestBuffer_BatchRejectDropsOverwrittenBatch(t *testing.T) {
func TestBuffer_MetricsOverwriteBatchAccept(t *testing.T) { func TestBuffer_MetricsOverwriteBatchAccept(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m, m, m, m, m) b.Add(m, m, m, m, m)
batch := b.Batch(3) batch := b.Batch(3)
@ -549,7 +549,7 @@ func TestBuffer_MetricsOverwriteBatchAccept(t *testing.T) {
func TestBuffer_MetricsOverwriteBatchReject(t *testing.T) { func TestBuffer_MetricsOverwriteBatchReject(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m, m, m, m, m) b.Add(m, m, m, m, m)
batch := b.Batch(3) batch := b.Batch(3)
@ -561,7 +561,7 @@ func TestBuffer_MetricsOverwriteBatchReject(t *testing.T) {
func TestBuffer_MetricsBatchAcceptRemoved(t *testing.T) { func TestBuffer_MetricsBatchAcceptRemoved(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m, m, m, m, m) b.Add(m, m, m, m, m)
batch := b.Batch(3) batch := b.Batch(3)
@ -573,7 +573,7 @@ func TestBuffer_MetricsBatchAcceptRemoved(t *testing.T) {
func TestBuffer_WrapWithBatch(t *testing.T) { func TestBuffer_WrapWithBatch(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m, m, m) b.Add(m, m, m)
b.Batch(3) b.Batch(3)
@ -584,7 +584,7 @@ func TestBuffer_WrapWithBatch(t *testing.T) {
func TestBuffer_BatchNotRemoved(t *testing.T) { func TestBuffer_BatchNotRemoved(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m, m, m, m, m) b.Add(m, m, m, m, m)
b.Batch(2) b.Batch(2)
require.Equal(t, 5, b.Len()) require.Equal(t, 5, b.Len())
@ -592,7 +592,7 @@ func TestBuffer_BatchNotRemoved(t *testing.T) {
func TestBuffer_BatchRejectAcceptNoop(t *testing.T) { func TestBuffer_BatchRejectAcceptNoop(t *testing.T) {
m := Metric() m := Metric()
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(m, m, m, m, m) b.Add(m, m, m, m, m)
batch := b.Batch(2) batch := b.Batch(2)
b.Reject(batch) b.Reject(batch)
@ -608,7 +608,7 @@ func TestBuffer_AcceptCallsMetricAccept(t *testing.T) {
accept++ accept++
}, },
} }
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(mm, mm, mm) b.Add(mm, mm, mm)
batch := b.Batch(2) batch := b.Batch(2)
b.Accept(batch) b.Accept(batch)
@ -623,7 +623,7 @@ func TestBuffer_AddCallsMetricRejectWhenNoBatch(t *testing.T) {
reject++ reject++
}, },
} }
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
setup(b) setup(b)
b.Add(mm, mm, mm, mm, mm) b.Add(mm, mm, mm, mm, mm)
b.Add(mm, mm) b.Add(mm, mm)
@ -638,7 +638,7 @@ func TestBuffer_AddCallsMetricRejectWhenNotInBatch(t *testing.T) {
reject++ reject++
}, },
} }
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
setup(b) setup(b)
b.Add(mm, mm, mm, mm, mm) b.Add(mm, mm, mm, mm, mm)
batch := b.Batch(2) batch := b.Batch(2)
@ -656,7 +656,7 @@ func TestBuffer_RejectCallsMetricRejectWithOverwritten(t *testing.T) {
reject++ reject++
}, },
} }
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(mm, mm, mm, mm, mm) b.Add(mm, mm, mm, mm, mm)
batch := b.Batch(5) batch := b.Batch(5)
b.Add(mm, mm) b.Add(mm, mm)
@ -673,7 +673,7 @@ func TestBuffer_AddOverwriteAndReject(t *testing.T) {
reject++ reject++
}, },
} }
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(mm, mm, mm, mm, mm) b.Add(mm, mm, mm, mm, mm)
batch := b.Batch(5) batch := b.Batch(5)
b.Add(mm, mm, mm, mm, mm) b.Add(mm, mm, mm, mm, mm)
@ -697,7 +697,7 @@ func TestBuffer_AddOverwriteAndRejectOffset(t *testing.T) {
accept++ accept++
}, },
} }
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
b.Add(mm, mm, mm) b.Add(mm, mm, mm)
b.Add(mm, mm, mm, mm) b.Add(mm, mm, mm, mm)
require.Equal(t, 2, reject) require.Equal(t, 2, reject)
@ -716,7 +716,7 @@ func TestBuffer_AddOverwriteAndRejectOffset(t *testing.T) {
} }
func TestBuffer_RejectEmptyBatch(t *testing.T) { func TestBuffer_RejectEmptyBatch(t *testing.T) {
b := setup(NewBuffer("test", 5)) b := setup(NewBuffer("test", "", 5))
batch := b.Batch(2) batch := b.Batch(2)
b.Add(MetricTime(1)) b.Add(MetricTime(1))
b.Reject(batch) b.Reject(batch)

View File

@ -79,7 +79,7 @@ func NewRunningOutput(
} }
ro := &RunningOutput{ ro := &RunningOutput{
buffer: NewBuffer(config.LogName(), bufferLimit), buffer: NewBuffer(config.Name, config.Alias, bufferLimit),
BatchReady: make(chan time.Time, 1), BatchReady: make(chan time.Time, 1),
Output: output, Output: output,
Config: config, Config: config,
@ -101,13 +101,6 @@ func NewRunningOutput(
return ro return ro
} }
func (c *OutputConfig) LogName() string {
if c.Alias == "" {
return c.Name
}
return c.Name + "::" + c.Alias
}
func (r *RunningOutput) LogName() string { func (r *RunningOutput) LogName() string {
return logName("outputs", r.Config.Name, r.Config.Alias) return logName("outputs", r.Config.Name, r.Config.Alias)
} }

View File

@ -100,7 +100,7 @@ type HTTPConfig struct {
InfluxUintSupport bool `toml:"influx_uint_support"` InfluxUintSupport bool `toml:"influx_uint_support"`
Serializer *influx.Serializer Serializer *influx.Serializer
log telegraf.Logger Log telegraf.Logger
} }
type httpClient struct { type httpClient struct {
@ -176,7 +176,7 @@ func NewHTTPClient(config HTTPConfig) (*httpClient, error) {
}, },
createdDatabases: make(map[string]bool), createdDatabases: make(map[string]bool),
config: config, config: config,
log: config.log, log: config.Log,
} }
return client, nil return client, nil
} }
@ -186,10 +186,6 @@ func (c *httpClient) URL() string {
return c.config.URL.String() return c.config.URL.String()
} }
func (c *httpClient) SetLogger(log telegraf.Logger) {
c.log = log
}
// Database returns the default database that this client connects too. // Database returns the default database that this client connects too.
func (c *httpClient) Database() string { func (c *httpClient) Database() string {
return c.config.Database return c.config.Database

View File

@ -262,6 +262,7 @@ func TestHTTP_Write(t *testing.T) {
config: influxdb.HTTPConfig{ config: influxdb.HTTPConfig{
URL: u, URL: u,
Database: "telegraf", Database: "telegraf",
Log: testutil.Logger{},
}, },
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
require.Equal(t, r.FormValue("db"), "telegraf") require.Equal(t, r.FormValue("db"), "telegraf")
@ -278,6 +279,7 @@ func TestHTTP_Write(t *testing.T) {
Database: "telegraf", Database: "telegraf",
Username: "guy", Username: "guy",
Password: "smiley", Password: "smiley",
Log: testutil.Logger{},
}, },
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
username, password, ok := r.BasicAuth() username, password, ok := r.BasicAuth()
@ -293,6 +295,7 @@ func TestHTTP_Write(t *testing.T) {
URL: u, URL: u,
Database: "telegraf", Database: "telegraf",
UserAgent: "telegraf", UserAgent: "telegraf",
Log: testutil.Logger{},
}, },
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
require.Equal(t, r.Header.Get("User-Agent"), "telegraf") require.Equal(t, r.Header.Get("User-Agent"), "telegraf")
@ -304,6 +307,7 @@ func TestHTTP_Write(t *testing.T) {
config: influxdb.HTTPConfig{ config: influxdb.HTTPConfig{
URL: u, URL: u,
Database: "telegraf", Database: "telegraf",
Log: testutil.Logger{},
}, },
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
require.Equal(t, r.Header.Get("User-Agent"), "Telegraf/1.2.3") require.Equal(t, r.Header.Get("User-Agent"), "Telegraf/1.2.3")
@ -314,6 +318,7 @@ func TestHTTP_Write(t *testing.T) {
name: "default database", name: "default database",
config: influxdb.HTTPConfig{ config: influxdb.HTTPConfig{
URL: u, URL: u,
Log: testutil.Logger{},
}, },
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
require.Equal(t, "telegraf", r.FormValue("db")) require.Equal(t, "telegraf", r.FormValue("db"))
@ -328,6 +333,7 @@ func TestHTTP_Write(t *testing.T) {
"A": "B", "A": "B",
"C": "D", "C": "D",
}, },
Log: testutil.Logger{},
}, },
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
require.Equal(t, r.Header.Get("A"), "B") require.Equal(t, r.Header.Get("A"), "B")
@ -341,6 +347,7 @@ func TestHTTP_Write(t *testing.T) {
URL: u, URL: u,
Database: "telegraf", Database: "telegraf",
RetentionPolicy: "foo", RetentionPolicy: "foo",
Log: testutil.Logger{},
}, },
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
require.Equal(t, "foo", r.FormValue("rp")) require.Equal(t, "foo", r.FormValue("rp"))
@ -353,6 +360,7 @@ func TestHTTP_Write(t *testing.T) {
URL: u, URL: u,
Database: "telegraf", Database: "telegraf",
Consistency: "all", Consistency: "all",
Log: testutil.Logger{},
}, },
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
require.Equal(t, "all", r.FormValue("consistency")) require.Equal(t, "all", r.FormValue("consistency"))
@ -364,6 +372,7 @@ func TestHTTP_Write(t *testing.T) {
config: influxdb.HTTPConfig{ config: influxdb.HTTPConfig{
URL: u, URL: u,
Database: "telegraf", Database: "telegraf",
Log: testutil.Logger{},
}, },
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
@ -378,6 +387,7 @@ func TestHTTP_Write(t *testing.T) {
config: influxdb.HTTPConfig{ config: influxdb.HTTPConfig{
URL: u, URL: u,
Database: "telegraf", Database: "telegraf",
Log: testutil.Logger{},
}, },
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
@ -392,6 +402,7 @@ func TestHTTP_Write(t *testing.T) {
config: influxdb.HTTPConfig{ config: influxdb.HTTPConfig{
URL: u, URL: u,
Database: "telegraf", Database: "telegraf",
Log: testutil.Logger{},
}, },
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
@ -406,6 +417,7 @@ func TestHTTP_Write(t *testing.T) {
config: influxdb.HTTPConfig{ config: influxdb.HTTPConfig{
URL: u, URL: u,
Database: "telegraf", Database: "telegraf",
Log: testutil.Logger{},
}, },
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadGateway) w.WriteHeader(http.StatusBadGateway)
@ -423,6 +435,7 @@ func TestHTTP_Write(t *testing.T) {
config: influxdb.HTTPConfig{ config: influxdb.HTTPConfig{
URL: u, URL: u,
Database: "telegraf", Database: "telegraf",
Log: testutil.Logger{},
}, },
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusServiceUnavailable) w.WriteHeader(http.StatusServiceUnavailable)
@ -472,7 +485,6 @@ func TestHTTP_Write(t *testing.T) {
client, err := influxdb.NewHTTPClient(tt.config) client, err := influxdb.NewHTTPClient(tt.config)
require.NoError(t, err) require.NoError(t, err)
client.SetLogger(testutil.Logger{})
err = client.Write(ctx, metrics) err = client.Write(ctx, metrics)
if tt.errFunc != nil { if tt.errFunc != nil {
tt.errFunc(t, err) tt.errFunc(t, err)
@ -525,6 +537,7 @@ func TestHTTP_WritePathPrefix(t *testing.T) {
config := influxdb.HTTPConfig{ config := influxdb.HTTPConfig{
URL: u, URL: u,
Database: "telegraf", Database: "telegraf",
Log: testutil.Logger{},
} }
client, err := influxdb.NewHTTPClient(config) client, err := influxdb.NewHTTPClient(config)
@ -579,6 +592,7 @@ func TestHTTP_WriteContentEncodingGzip(t *testing.T) {
URL: u, URL: u,
Database: "telegraf", Database: "telegraf",
ContentEncoding: "gzip", ContentEncoding: "gzip",
Log: testutil.Logger{},
} }
client, err := influxdb.NewHTTPClient(config) client, err := influxdb.NewHTTPClient(config)
@ -618,6 +632,7 @@ func TestHTTP_UnixSocket(t *testing.T) {
config: influxdb.HTTPConfig{ config: influxdb.HTTPConfig{
URL: &url.URL{Scheme: "unix", Path: sock}, URL: &url.URL{Scheme: "unix", Path: sock},
Database: "xyzzy", Database: "xyzzy",
Log: testutil.Logger{},
}, },
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
require.Equal(t, `CREATE DATABASE "xyzzy"`, r.FormValue("q")) require.Equal(t, `CREATE DATABASE "xyzzy"`, r.FormValue("q"))

View File

@ -27,7 +27,6 @@ type Client interface {
Database() string Database() string
URL() string URL() string
Close() Close()
SetLogger(telegraf.Logger)
} }
// InfluxDB struct is the primary data structure for the plugin // InfluxDB struct is the primary data structure for the plugin
@ -172,8 +171,6 @@ func (i *InfluxDB) Connect() error {
return err return err
} }
c.SetLogger(i.Log)
i.clients = append(i.clients, c) i.clients = append(i.clients, c)
case "http", "https", "unix": case "http", "https", "unix":
c, err := i.httpClient(ctx, parts, proxy) c, err := i.httpClient(ctx, parts, proxy)
@ -181,8 +178,6 @@ func (i *InfluxDB) Connect() error {
return err return err
} }
c.SetLogger(i.Log)
i.clients = append(i.clients, c) i.clients = append(i.clients, c)
default: default:
return fmt.Errorf("unsupported scheme [%q]: %q", u, parts.Scheme) return fmt.Errorf("unsupported scheme [%q]: %q", u, parts.Scheme)
@ -243,6 +238,7 @@ func (i *InfluxDB) udpClient(url *url.URL) (Client, error) {
URL: url, URL: url,
MaxPayloadSize: int(i.UDPPayload.Size), MaxPayloadSize: int(i.UDPPayload.Size),
Serializer: i.serializer, Serializer: i.serializer,
Log: i.Log,
} }
c, err := i.CreateUDPClientF(config) c, err := i.CreateUDPClientF(config)
@ -276,6 +272,7 @@ func (i *InfluxDB) httpClient(ctx context.Context, url *url.URL, proxy *url.URL)
RetentionPolicy: i.RetentionPolicy, RetentionPolicy: i.RetentionPolicy,
Consistency: i.WriteConsistency, Consistency: i.WriteConsistency,
Serializer: i.serializer, Serializer: i.serializer,
Log: i.Log,
} }
c, err := i.CreateHTTPClientF(config) c, err := i.CreateHTTPClientF(config)

View File

@ -60,6 +60,7 @@ func NewUDPClient(config UDPConfig) (*udpClient, error) {
url: config.URL, url: config.URL,
serializer: serializer, serializer: serializer,
dialer: dialer, dialer: dialer,
log: config.Log,
} }
return client, nil return client, nil
} }
@ -69,18 +70,13 @@ type udpClient struct {
dialer Dialer dialer Dialer
serializer *influx.Serializer serializer *influx.Serializer
url *url.URL url *url.URL
log telegraf.Logger
log telegraf.Logger
} }
func (c *udpClient) URL() string { func (c *udpClient) URL() string {
return c.url.String() return c.url.String()
} }
func (c *udpClient) SetLogger(log telegraf.Logger) {
c.log = log
}
func (c *udpClient) Database() string { func (c *udpClient) Database() string {
return "" return ""
} }

View File

@ -79,7 +79,6 @@ func TestUDP_URL(t *testing.T) {
} }
client, err := influxdb.NewUDPClient(config) client, err := influxdb.NewUDPClient(config)
client.SetLogger(testutil.Logger{})
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, u.String(), client.URL()) require.Equal(t, u.String(), client.URL())
@ -103,7 +102,6 @@ func TestUDP_Simple(t *testing.T) {
}, },
} }
client, err := influxdb.NewUDPClient(config) client, err := influxdb.NewUDPClient(config)
client.SetLogger(testutil.Logger{})
require.NoError(t, err) require.NoError(t, err)
ctx := context.Background() ctx := context.Background()
@ -130,7 +128,6 @@ func TestUDP_DialError(t *testing.T) {
}, },
} }
client, err := influxdb.NewUDPClient(config) client, err := influxdb.NewUDPClient(config)
client.SetLogger(testutil.Logger{})
require.NoError(t, err) require.NoError(t, err)
ctx := context.Background() ctx := context.Background()
@ -160,7 +157,6 @@ func TestUDP_WriteError(t *testing.T) {
}, },
} }
client, err := influxdb.NewUDPClient(config) client, err := influxdb.NewUDPClient(config)
client.SetLogger(testutil.Logger{})
require.NoError(t, err) require.NoError(t, err)
ctx := context.Background() ctx := context.Background()
@ -187,6 +183,7 @@ func TestUDP_ErrorLogging(t *testing.T) {
return conn, nil return conn, nil
}, },
}, },
Log: testutil.Logger{},
}, },
metrics: []telegraf.Metric{getMetric()}, metrics: []telegraf.Metric{getMetric()},
logContains: `could not serialize metric: "cpu": need more space`, logContains: `could not serialize metric: "cpu": need more space`,
@ -201,6 +198,7 @@ func TestUDP_ErrorLogging(t *testing.T) {
return conn, nil return conn, nil
}, },
}, },
Log: testutil.Logger{},
}, },
metrics: []telegraf.Metric{ metrics: []telegraf.Metric{
func() telegraf.Metric { func() telegraf.Metric {
@ -224,7 +222,6 @@ func TestUDP_ErrorLogging(t *testing.T) {
log.SetOutput(&b) log.SetOutput(&b)
client, err := influxdb.NewUDPClient(tt.config) client, err := influxdb.NewUDPClient(tt.config)
client.SetLogger(testutil.Logger{})
require.NoError(t, err) require.NoError(t, err)
ctx := context.Background() ctx := context.Background()
@ -268,7 +265,6 @@ func TestUDP_WriteWithRealConn(t *testing.T) {
URL: u, URL: u,
} }
client, err := influxdb.NewUDPClient(config) client, err := influxdb.NewUDPClient(config)
client.SetLogger(testutil.Logger{})
require.NoError(t, err) require.NoError(t, err)
ctx := context.Background() ctx := context.Background()