diff --git a/metricbeat/module/redis/key/_meta/docs.asciidoc b/metricbeat/module/redis/key/_meta/docs.asciidoc index 89dfcc03658..b81ba13c166 100644 --- a/metricbeat/module/redis/key/_meta/docs.asciidoc +++ b/metricbeat/module/redis/key/_meta/docs.asciidoc @@ -7,7 +7,7 @@ length when available, and its ttl. Patterns are configured as a list containing these fields: * `pattern` (required): pattern for key names, as accepted by the Redis `KEYS` or `SCAN` commands. -* `max` (optional): safeguard when using patterns with wildcards to avoid +* `limit` (optional): safeguard when using patterns with wildcards to avoid collecting too many keys (Default: 0, no limit) * `keyspace` (optional): Identifier of the database to use to look for the keys (Default: 0) @@ -21,5 +21,5 @@ whose name starts with `pipeline-*`, with a limit of 20 keys. metricsets: ['key'] key.patterns: - name: 'pipeline-*' - max: 20 + limit: 20 ------------------------------------------------------------------------------ diff --git a/metricbeat/module/redis/key/key.go b/metricbeat/module/redis/key/key.go index 9c04a424050..86943729dca 100644 --- a/metricbeat/module/redis/key/key.go +++ b/metricbeat/module/redis/key/key.go @@ -49,7 +49,7 @@ type MetricSet struct { type KeyPattern struct { Keyspace uint `config:"keyspace"` Pattern string `config:"pattern" validate:"required"` - Max uint `config:"max"` + Limit uint `config:"limit"` } // New creates new instance of MetricSet @@ -88,14 +88,14 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) { continue } - keys, err := redis.FetchKeys(conn, p.Pattern, p.Max) + keys, err := redis.FetchKeys(conn, p.Pattern, p.Limit) if err != nil { logp.Err("Failed to fetch list of keys in keyspace %d with pattern '%s': %s", p.Keyspace, p.Pattern, err) continue } - if p.Max > 0 && len(keys) > int(p.Max) { - debugf("Collecting stats for %d keys, but there are more available for pattern '%s' in keyspace %d", p.Max) - keys = keys[:p.Max] + if p.Limit > 0 && len(keys) > int(p.Limit) { + debugf("Collecting stats for %d keys, but there are more available for pattern '%s' in keyspace %d", p.Limit) + keys = keys[:p.Limit] } for _, key := range keys { diff --git a/metricbeat/module/redis/redis.go b/metricbeat/module/redis/redis.go index 0f6c01d0aec..0746fc64305 100644 --- a/metricbeat/module/redis/redis.go +++ b/metricbeat/module/redis/redis.go @@ -137,11 +137,12 @@ func FetchKeyInfo(c rd.Conn, key string) (map[string]interface{}, error) { return info, nil } -// FetchKeys gets a list of keys based on a pattern using SCAN, `max` is a +// FetchKeys gets a list of keys based on a pattern using SCAN, `limit` is a // safeguard to limit the number of commands executed and the number of keys -// returned, it is not a hard-limit to the length of the string. Setting -// `max` to 0 disables the limit. -func FetchKeys(c rd.Conn, pattern string, max uint) ([]string, error) { +// returned, if more than `limit` keys are being collected the method stops +// and returns the keys already collected. Setting `limit` to ' disables this +// limit. +func FetchKeys(c rd.Conn, pattern string, limit uint) ([]string, error) { cursor := 0 var keys []string for { @@ -158,7 +159,7 @@ func FetchKeys(c rd.Conn, pattern string, max uint) ([]string, error) { keys = append(keys, scanKeys...) - if cursor == 0 || (max > 0 && len(keys) > int(max)) { + if cursor == 0 || (limit > 0 && len(keys) > int(limit)) { break } }