Add telegraf version to User-Agent header (#4838)
Header is added in influxdb, influxdb_v2, and http outputs.
This commit is contained in:
committed by
Daniel Nelson
parent
502d9ab499
commit
44fd74d688
@@ -27,10 +27,8 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
defaultRequestTimeout = time.Second * 5
|
||||
defaultDatabase = "telegraf"
|
||||
defaultUserAgent = "telegraf"
|
||||
|
||||
defaultRequestTimeout = time.Second * 5
|
||||
defaultDatabase = "telegraf"
|
||||
errStringDatabaseNotFound = "database not found"
|
||||
errStringHintedHandoffNotEmpty = "hinted handoff queue not empty"
|
||||
errStringPartialWrite = "partial write"
|
||||
@@ -138,7 +136,7 @@ func NewHTTPClient(config *HTTPConfig) (*httpClient, error) {
|
||||
|
||||
userAgent := config.UserAgent
|
||||
if userAgent == "" {
|
||||
userAgent = defaultUserAgent
|
||||
userAgent = "Telegraf/" + internal.Version()
|
||||
}
|
||||
|
||||
var headers = make(map[string]string, len(config.Headers)+1)
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/internal"
|
||||
"github.com/influxdata/telegraf/metric"
|
||||
"github.com/influxdata/telegraf/plugins/outputs/influxdb"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -246,6 +247,8 @@ func TestHTTP_Write(t *testing.T) {
|
||||
u, err := url.Parse(fmt.Sprintf("http://%s", ts.Listener.Addr().String()))
|
||||
require.NoError(t, err)
|
||||
|
||||
internal.SetVersion("1.2.3")
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
config *influxdb.HTTPConfig
|
||||
@@ -295,6 +298,17 @@ func TestHTTP_Write(t *testing.T) {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "default user agent",
|
||||
config: &influxdb.HTTPConfig{
|
||||
URL: u,
|
||||
Database: "telegraf",
|
||||
},
|
||||
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
||||
require.Equal(t, r.Header.Get("User-Agent"), "Telegraf/1.2.3")
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "default database",
|
||||
config: &influxdb.HTTPConfig{
|
||||
|
||||
Reference in New Issue
Block a user