Skip to content

Commit

Permalink
chore(outputs.amqp): Remove deprecated options from sample config (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
Hipska authored Sep 16, 2024
1 parent ccdbc4c commit 9a8b502
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 45 deletions.
12 changes: 0 additions & 12 deletions plugins/outputs/amqp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"}
Expand Down
36 changes: 18 additions & 18 deletions plugins/outputs/amqp/amqp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.encoder, err = internal.NewContentEncoder(q.ContentEncoding)
q.config, err = q.makeClientConfig()
if err != nil {
return err
}

q.client, err = q.connect(q.config)
q.encoder, err = internal.NewContentEncoder(q.ContentEncoding)
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()
Expand Down Expand Up @@ -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,
}
})
}
9 changes: 6 additions & 3 deletions plugins/outputs/amqp/amqp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down Expand Up @@ -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)
})
Expand Down
12 changes: 0 additions & 12 deletions plugins/outputs/amqp/sample.conf
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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"}
Expand Down

0 comments on commit 9a8b502

Please sign in to comment.