Add ability to label inputs for logging (#6207)
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -101,12 +100,15 @@ type HTTPConfig struct {
|
||||
|
||||
InfluxUintSupport bool `toml:"influx_uint_support"`
|
||||
Serializer *influx.Serializer
|
||||
log telegraf.Logger
|
||||
}
|
||||
|
||||
type httpClient struct {
|
||||
client *http.Client
|
||||
config HTTPConfig
|
||||
createdDatabases map[string]bool
|
||||
|
||||
log telegraf.Logger
|
||||
}
|
||||
|
||||
func NewHTTPClient(config HTTPConfig) (*httpClient, error) {
|
||||
@@ -174,6 +176,7 @@ func NewHTTPClient(config HTTPConfig) (*httpClient, error) {
|
||||
},
|
||||
createdDatabases: make(map[string]bool),
|
||||
config: config,
|
||||
log: config.log,
|
||||
}
|
||||
return client, nil
|
||||
}
|
||||
@@ -183,6 +186,10 @@ func (c *httpClient) 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.
|
||||
func (c *httpClient) Database() string {
|
||||
return c.config.Database
|
||||
@@ -262,7 +269,7 @@ func (c *httpClient) Write(ctx context.Context, metrics []telegraf.Metric) error
|
||||
if !c.config.SkipDatabaseCreation && !c.createdDatabases[db] {
|
||||
err := c.CreateDatabase(ctx, db)
|
||||
if err != nil {
|
||||
log.Printf("W! [outputs.influxdb] when writing to [%s]: database %q creation failed: %v",
|
||||
c.log.Warnf("when writing to [%s]: database %q creation failed: %v",
|
||||
c.config.URL, db, err)
|
||||
}
|
||||
}
|
||||
@@ -328,7 +335,7 @@ func (c *httpClient) writeBatch(ctx context.Context, db string, metrics []telegr
|
||||
// discarded for being older than the retention policy. Usually this not
|
||||
// a cause for concern and we don't want to retry.
|
||||
if strings.Contains(desc, errStringPointsBeyondRP) {
|
||||
log.Printf("W! [outputs.influxdb]: when writing to [%s]: received error %v",
|
||||
c.log.Warnf("when writing to [%s]: received error %v",
|
||||
c.URL(), desc)
|
||||
return nil
|
||||
}
|
||||
@@ -337,7 +344,7 @@ func (c *httpClient) writeBatch(ctx context.Context, db string, metrics []telegr
|
||||
// correctable at this point and so the point is dropped instead of
|
||||
// retrying.
|
||||
if strings.Contains(desc, errStringPartialWrite) {
|
||||
log.Printf("E! [outputs.influxdb]: when writing to [%s]: received error %v; discarding points",
|
||||
c.log.Errorf("when writing to [%s]: received error %v; discarding points",
|
||||
c.URL(), desc)
|
||||
return nil
|
||||
}
|
||||
@@ -345,7 +352,7 @@ func (c *httpClient) writeBatch(ctx context.Context, db string, metrics []telegr
|
||||
// This error indicates a bug in either Telegraf line protocol
|
||||
// serialization, retries would not be successful.
|
||||
if strings.Contains(desc, errStringUnableToParse) {
|
||||
log.Printf("E! [outputs.influxdb]: when writing to [%s]: received error %v; discarding points",
|
||||
c.log.Errorf("when writing to [%s]: received error %v; discarding points",
|
||||
c.URL(), desc)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user