Skip to content

Commit

Permalink
Rename max to limit
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano committed Dec 19, 2018
1 parent 32881d4 commit 9621ba2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions metricbeat/module/redis/key/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
------------------------------------------------------------------------------
10 changes: 5 additions & 5 deletions metricbeat/module/redis/key/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions metricbeat/module/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}
Expand Down

0 comments on commit 9621ba2

Please sign in to comment.