Repository: DataDog/dd-agent

Issue:
List index out of range error with redisdb integration
Started noticing this:

```
2016-06-27 19:11:24 UTC | ERROR | dd.collector | checks.redisdb(__init__.py:767) | Check 'redisdb' instance #0 failed
Traceback (most recent call last):
  File "/opt/datadog-agent/agent/checks/__init__.py", line 750, in run
    self.check(copy.deepcopy(instance))
  File "/opt/datadog-agent/agent/checks.d/redisdb.py", line 356, in check
    self._check_slowlog(instance, custom_tags)
  File "/opt/datadog-agent/agent/checks.d/redisdb.py", line 328, in _check_slowlog
    command_tag = 'command:{0}'.format(slowlog['command'].split()[0])
IndexError: list index out of range
```

Not sure what command it is trying and failing to split on.

My entire redisdb.yaml is:

```
init_config:

instances:
  - host: some-host
    port: 6379
```



Discussion:
Hi @fotinakis, thanks for reporting this issue!

The check is failing when it tries to parse the output of the [slowlog command](http://redis.io/commands/slowlog). Could you send a [flare](https://help.datadoghq.com/hc/en-us/articles/204991415-Send-logs-and-configs-to-Datadog-via-flare-command) to our support team so that we have more information on your setup?

Also, if this error occurs at every run of the collector (i.e. every 15 seconds) could you include the output of the following `redis-cli` command to your support case:

```
slowlog get
```

Thanks!

Could you also include in your support case the version of Redis you're using? Thanks!

Yes it does happen on every run of the collector, so let's start with the slowlog output since that will probably get you enough info (and I can send you a flare if you still need). Redis: `redis_version:2.8.12`

```
> slowlog get
   1) 1) (integer) 45
      2) (integer) 1465519357
      3) (integer) 19583
      4) 
      5) 1) "zcard"
         2) "workers:idle"
   2) 1) (integer) 44
      2) (integer) 1465164262
      3) (integer) 11105
      4) 
      5) 1) "zcard"
         2) "workers:online"
   3) 1) (integer) 43
      2) (integer) 1465013189
      3) (integer) 14911
      4) Complexity info: N:25
      5) 1) "zadd"
         2) "workers:heartbeat"
         3) "1465013189"
         4) "10331"
   4) 1) (integer) 42
      2) (integer) 1464655621
      3) (integer) 738150
      4) 
      5) 1) "zscore"
         2) "workers:online"
         3) "10321"
   5) 1) (integer) 41
      2) (integer) 1464594153
      3) (integer) 11450
      4) 
      5) 1) "zscore"
         2) "workers:online"
         3) "10330"
   6) 1) (integer) 40
      2) (integer) 1464511441
      3) (integer) 523984
      4) 
      5) 1) "zscore"
         2) "workers:online"
         3) "10324"
   7) 1) (integer) 39
      2) (integer) 1464233295
      3) (integer) 15064
      4) 
      5) 1) "zscore"
         2) "workers:online"
         3) "10324"
   8) 1) (integer) 38
      2) (integer) 1464218560
      3) (integer) 19932
      4) 
      5) 1) "brpoplpush"
         2) "worker:10322:runnable"
         3) "worker:10322:running"
         4) "5"
   9) 1) (integer) 37
      2) (integer) 1463599957
      3) (integer) 10419
      4) Complexity info: N:25
      5) 1) "zadd"
         2) "workers:heartbeat"
         3) "1463599957"
         4) "10299"
  10) 1) (integer) 36
      2) (integer) 1463586498
      3) (integer) 11508
      4) 
      5) 1) "INFO"
```

Thanks for the output, it looks like you're using a version of Redis that adds a 5th field to `slowlog` ("Complexity Analysis"), but unfortunately the redis python client that the Agent uses doesn't support this field yet (there's a PR open that isn't merged yet: https://github.com/andymccurdy/redis-py/pull/622).

I'll work on a workaround to avoid having the check fail because of this.

Perfect, thanks! It seems that other redis data is being collected correctly still, so this is not 100% broken for me.


Resolving patch:
diff --git a/checks.d/redisdb.py b/checks.d/redisdb.py
--- a/checks.d/redisdb.py
+++ b/checks.d/redisdb.py
@@ -325,9 +325,16 @@ def _check_slowlog(self, instance, custom_tags):
             if slowlog['start_time'] > max_ts:
                 max_ts = slowlog['start_time']
 
-            command_tag = 'command:{0}'.format(slowlog['command'].split()[0])
+            slowlog_tags = list(tags)
+            command = slowlog['command'].split()
+            # When the "Garantia Data" custom Redis is used, redis-py returns
+            # an empty `command` field
+            # FIXME when https://github.com/andymccurdy/redis-py/pull/622 is released in redis-py
+            if command:
+                slowlog_tags.append('command:{0}'.format(command[0]))
+
             value = slowlog['duration']
-            self.histogram('redis.slowlog.micros', value, tags=tags + [command_tag])
+            self.histogram('redis.slowlog.micros', value, tags=slowlog_tags)
 
         self.last_timestamp_seen[ts_key] = max_ts
 


Test patch: