Skip to content

Commit

Permalink
Cherry-pick #12914 to 7.2: Release connections in metricbeat redis mo…
Browse files Browse the repository at this point in the history
…dule (#12948)

Release pooled connections in metricbeat redis module when they are not
needed anymore so they can be reused.

(cherry picked from commit 129d2ee)
  • Loading branch information
jsoriano committed Jul 18, 2019
1 parent 2290594 commit 3b00358
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ https://github.com/elastic/beats/compare/v7.2.0...7.2[Check the HEAD diff]

*Metricbeat*

- Fix connections leak in redis module {pull}12914[12914]

*Packetbeat*

*Winlogbeat*
Expand Down
5 changes: 4 additions & 1 deletion metricbeat/module/redis/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {

// Fetch fetches metrics from Redis by issuing the INFO command.
func (m *MetricSet) Fetch(r mb.ReporterV2) error {
conn := m.Connection()
defer conn.Close()

// Fetch default INFO.
info, err := redis.FetchRedisInfo("default", m.Connection())
info, err := redis.FetchRedisInfo("default", conn)
if err != nil {
return errors.Wrap(err, "failed to fetch redis info")
}
Expand Down
2 changes: 2 additions & 0 deletions metricbeat/module/redis/key/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
// Fetch fetches information from Redis keys
func (m *MetricSet) Fetch(r mb.ReporterV2) error {
conn := m.Connection()
defer conn.Close()

for _, p := range m.patterns {
if err := redis.Select(conn, p.Keyspace); err != nil {
msg := errors.Wrapf(err, "Failed to select keyspace %d", p.Keyspace)
Expand Down
5 changes: 4 additions & 1 deletion metricbeat/module/redis/keyspace/keyspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {

// Fetch fetches metrics from Redis by issuing the INFO command.
func (m *MetricSet) Fetch(r mb.ReporterV2) error {
conn := m.Connection()
defer conn.Close()

// Fetch default INFO.
info, err := redis.FetchRedisInfo("keyspace", m.Connection())
info, err := redis.FetchRedisInfo("keyspace", conn)
if err != nil {
return errors.Wrap(err, "Failed to fetch redis info for keyspaces")
}
Expand Down

0 comments on commit 3b00358

Please sign in to comment.