Skip to content

Commit

Permalink
Reuse connections in redis info metricset (elastic#12950)
Browse files Browse the repository at this point in the history
Reuse connections in redis info metricset, and log close
errors at the debug level.
  • Loading branch information
jsoriano committed Jul 18, 2019
1 parent 192f523 commit 4d207e7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- PdhExpandWildCardPathW will not expand counter paths in 32 bit windows systems, workaround will use a different function.{issue}12590[12590]{pull}12622[12622]
- In the elasticsearch/node_stats metricset, if xpack is enabled, make parsing of ES node load average optional as ES on Windows doesn't report load average. {pull}12866[12866]
- Ramdisk is not filtered out when collecting disk performance counters in diskio metricset {issue}12814[12814] {pull}12829[12829]
- Fix connections leak in redis module {pull}12914[12914]
- Fix connections leak in redis module {pull}12914[12914] {pull}12950[12950]
- Fix wrong uptime reporting by system/uptime metricset under Windows. {pull}12915[12915]
- Print errors that were being omitted in vSphere metricsets {pull}12816[12816]

Expand Down
8 changes: 6 additions & 2 deletions metricbeat/module/redis/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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()
defer func() {
if err := conn.Close(); err != nil {
m.Logger().Debug(errors.Wrapf(err, "failed to release connection"))
}
}()

// Fetch default INFO.
info, err := redis.FetchRedisInfo("default", conn)
Expand All @@ -76,7 +80,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error {
}
}

slowLogLength, err := redis.FetchSlowLogLength(m.Connection())
slowLogLength, err := redis.FetchSlowLogLength(conn)
if err != nil {
return errors.Wrap(err, "failed to fetch slow log length")

Expand Down
6 changes: 5 additions & 1 deletion metricbeat/module/redis/key/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ 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()
defer func() {
if err := conn.Close(); err != nil {
m.Logger().Debug(errors.Wrapf(err, "failed to release connection"))
}
}()

for _, p := range m.patterns {
if err := redis.Select(conn, p.Keyspace); err != nil {
Expand Down
6 changes: 5 additions & 1 deletion metricbeat/module/redis/keyspace/keyspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,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()
defer func() {
if err := conn.Close(); err != nil {
m.Logger().Debug(errors.Wrapf(err, "failed to release connection"))
}
}()

// Fetch default INFO.
info, err := redis.FetchRedisInfo("keyspace", conn)
Expand Down

0 comments on commit 4d207e7

Please sign in to comment.