chore(outputs.amqp): Remove deprecated options from sample config (#15873)

This commit is contained in:
Thomas Casteleyn 2024-09-16 18:25:49 +02:00 committed by GitHub
parent ccdbc4c480
commit 9a8b5022e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 47 deletions

View File

@ -33,10 +33,6 @@ to use them.
```toml @sample.conf
# Publishes metrics to an AMQP broker
[[outputs.amqp]]
## Broker to publish to.
## deprecated in 1.7; use the brokers option
# url = "amqp://localhost:5672/influxdb"
## Brokers to publish to. If multiple brokers are specified a random broker
## will be selected anytime a connection is established. This can be
## helpful for load balancing when not using a dedicated load balancer.
@ -85,14 +81,6 @@ to use them.
## One of "transient" or "persistent".
# delivery_mode = "transient"
## InfluxDB database added as a message header.
## deprecated in 1.7; use the headers option
# database = "telegraf"
## InfluxDB retention policy added as a message header
## deprecated in 1.7; use the headers option
# retention_policy = "default"
## Static headers added to each published message.
# headers = { }
# headers = {"database" = "telegraf", "retention_policy" = "default"}

View File

@ -88,29 +88,27 @@ func (q *AMQP) SetSerializer(serializer serializers.Serializer) {
q.serializer = serializer
}
func (q *AMQP) Connect() error {
if q.config == nil {
clientConfig, err := q.makeClientConfig()
if err != nil {
return err
}
q.config = clientConfig
func (q *AMQP) Init() error {
var err error
q.config, err = q.makeClientConfig()
if err != nil {
return err
}
var err error
q.encoder, err = internal.NewContentEncoder(q.ContentEncoding)
if err != nil {
return err
}
q.client, err = q.connect(q.config)
if err != nil {
return err
}
return nil
}
func (q *AMQP) Connect() error {
var err error
q.client, err = q.connect(q.config)
return err
}
func (q *AMQP) Close() error {
if q.client != nil {
return q.client.Close()
@ -323,13 +321,15 @@ func connect(clientConfig *ClientConfig) (Client, error) {
func init() {
outputs.Add("amqp", func() telegraf.Output {
return &AMQP{
URL: DefaultURL,
ExchangeType: DefaultExchangeType,
AuthMethod: DefaultAuthMethod,
Database: DefaultDatabase,
RetentionPolicy: DefaultRetentionPolicy,
Timeout: config.Duration(time.Second * 5),
connect: connect,
Brokers: []string{DefaultURL},
ExchangeType: DefaultExchangeType,
AuthMethod: DefaultAuthMethod,
Headers: map[string]string{
"database": DefaultDatabase,
"retention_policy": DefaultRetentionPolicy,
},
Timeout: config.Duration(time.Second * 5),
connect: connect,
}
})
}

View File

@ -52,9 +52,11 @@ func TestConnect(t *testing.T) {
ExchangeType: DefaultExchangeType,
ExchangeDurability: "durable",
AuthMethod: DefaultAuthMethod,
Database: DefaultDatabase,
RetentionPolicy: DefaultRetentionPolicy,
Timeout: config.Duration(time.Second * 5),
Headers: map[string]string{
"database": DefaultDatabase,
"retention_policy": DefaultRetentionPolicy,
},
Timeout: config.Duration(time.Second * 5),
connect: func(_ *ClientConfig) (Client, error) {
return NewMockClient(), nil
},
@ -150,6 +152,7 @@ func TestConnect(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require.NoError(t, tt.output.Init())
err := tt.output.Connect()
tt.errFunc(t, tt.output, err)
})

View File

@ -1,9 +1,5 @@
# Publishes metrics to an AMQP broker
[[outputs.amqp]]
## Broker to publish to.
## deprecated in 1.7; use the brokers option
# url = "amqp://localhost:5672/influxdb"
## Brokers to publish to. If multiple brokers are specified a random broker
## will be selected anytime a connection is established. This can be
## helpful for load balancing when not using a dedicated load balancer.
@ -52,14 +48,6 @@
## One of "transient" or "persistent".
# delivery_mode = "transient"
## InfluxDB database added as a message header.
## deprecated in 1.7; use the headers option
# database = "telegraf"
## InfluxDB retention policy added as a message header
## deprecated in 1.7; use the headers option
# retention_policy = "default"
## Static headers added to each published message.
# headers = { }
# headers = {"database" = "telegraf", "retention_policy" = "default"}