integrations-core icon indicating copy to clipboard operation
integrations-core copied to clipboard

kube-state-metrics timing out with agent v6.1.0-6.1.4 / v5.23.0

Open cknowles opened this issue 8 years ago • 55 comments

We've just switched from agent v5 using our own YAML to v6.1.0 using the Helm chart and we appear to have hit the same problem as https://github.com/kubernetes/charts/issues/1466. We deploy kube-state-metrics separately rather than bundle it as a helm dependency. For that we're on 1.2.0.

After the upgrade, most things are working ok but kube state metrics are not coming through any more when non of the rest of the system has changed.

This is what we see in the logs:

datadog-master-rcd8v datadog [ AGENT ] 2018-04-05 04:33:04 UTC | ERROR | (runner.go:276 in work) | Error running check kubernetes_state: [{"message": "HTTPConnectionPool(host='10.2.13.182', port=8080): Read timed out. (read timeout=1)", "traceback": "Traceback (most recent call last):\n  File \"/opt/datadog-agent/bin/agent/dist/checks/__init__.py\", line 332, in run\n    self.check(copy.deepcopy(self.instances[0]))\n  File \"/opt/datadog-agent/embedded/lib/python2.7/site-packages/datadog_checks/kubernetes_state/kubernetes_state.py\", line 196, in check\n    self.process(endpoint, send_histograms_buckets=send_buckets, instance=instance)\n  File \"/opt/datadog-agent/embedded/lib/python2.7/site-packages/datadog_checks/checks/prometheus/mixins.py\", line 350, in process\n    for metric in self.scrape_metrics(endpoint):\n  File \"/opt/datadog-agent/embedded/lib/python2.7/site-packages/datadog_checks/checks/prometheus/mixins.py\", line 314, in scrape_metrics\n    response = self.poll(endpoint)\n  File \"/opt/datadog-agent/embedded/lib/python2.7/site-packages/datadog_checks/checks/prometheus/mixins.py\", line 467, in poll\n    response = requests.get(endpoint, headers=headers, stream=True, timeout=1, cert=cert, verify=verify)\n  File \"/opt/datadog-agent/embedded/lib/python2.7/site-packages/requests/api.py\", line 72, in get\n    return request('get', url, params=params, **kwargs)\n  File \"/opt/datadog-agent/embedded/lib/python2.7/site-packages/requests/api.py\", line 58, in request\n    return session.request(method=method, url=url, **kwargs)\n  File \"/opt/datadog-agent/embedded/lib/python2.7/site-packages/requests/sessions.py\", line 508, in request\n    resp = self.send(prep, **send_kwargs)\n  File \"/opt/datadog-agent/embedded/lib/python2.7/site-packages/requests/sessions.py\", line 618, in send\n    r = adapter.send(request, **kwargs)\n  File \"/opt/datadog-agent/embedded/lib/python2.7/site-packages/requests/adapters.py\", line 521, in send\n    raise ReadTimeout(e, request=request)\nReadTimeout: HTTPConnectionPool(host='10.2.13.182', port=8080): Read timed out. (read timeout=1)\n"}]

I've confirmed 10.2.13.182 is the correct pod IP address; as mentioned none of that side of things has changed so the AD seems to still be working.

I went to the datadog pod in question and did a little investigation on the timing:

time curl -v --silent --output /dev/null --show-error --fail 10.2.13.182:8080/metrics

The curl responds fine with content but I've never got it to go below 1 second. However, it appears 1 second is hard coded: https://github.com/DataDog/integrations-core/blob/69e3a575ff5d9dc62703b9b9f7789d98e91a2ec5/datadog-checks-base/datadog_checks/checks/prometheus/mixins.py#L472

The payload is ~11214 bytes on that cluster. I tried increasing resources to the kube state metrics pod but wasn't able to get it to go any faster - the stats for the kube-state-metrics container show it's not even using close to its allocated cpu/memory.

I'm not sure how best to deal with this, as a start the timeout could be configurable but perhaps there are some overall plans to deal with this in some better way.

cknowles avatar Apr 05 '18 04:04 cknowles

On a slightly different point to solving this issue, I am still wondering why agent v5 works fine while agent v6 doesn't work. Did the timeout change or get overridden somewhere? Or perhaps agent v6 just uses newer versions of the integrations?

cknowles avatar Apr 05 '18 04:04 cknowles

Timings from other users in https://github.com/kubernetes/kube-state-metrics/issues/257 appear to indicate up to 10 seconds is not unusual.

cknowles avatar Apr 11 '18 05:04 cknowles

@c-knowles Thanks for opening this issue! We will review to increase the value of the timeout here. The details you sent are most helpful in that end. We will also get back to you on the support case we have in parallel, thanks for your patience again here!

jiquiame avatar Apr 12 '18 09:04 jiquiame

Ran into this problem as well today. Using v6.1.0 as well

simar7 avatar Apr 12 '18 22:04 simar7

Indeed, this is a regression from 6.0.x:

We used to query the payload with no timeout https://github.com/DataDog/datadog-agent/blob/6.0.x/cmd/agent/dist/checks/prometheus_check/prometheus_check.py#L425 And we introduced a 1 second timeout in 6.1.x: https://github.com/DataDog/integrations-core/blob/master/datadog_checks_base/datadog_checks/checks/prometheus/mixins.py#L476

I'll open a PR to move this timeout up to 10 seconds. Sorry for the inconvenience.

xvello avatar Apr 13 '18 16:04 xvello

We are seeing this issue on agent v6.1.1

clok avatar Apr 17 '18 11:04 clok

The PR was now merged, so the timeout should be set to 10 seconds in future release 6.1.4

jiquiame avatar Apr 17 '18 11:04 jiquiame

Also ran into this problem when I was using v6.1.3. I just upgraded to the just released v6.1.4 and it seems to still be using the 1 second timeout.

Read timed out. (read timeout=1)

smerchek avatar Apr 19 '18 18:04 smerchek

I think 6.1.4 was a security patch release so it was planned for 6.1.4 but didn't make it as the security issue got pushed quicker.

cknowles avatar Apr 20 '18 03:04 cknowles

The same applies for agent 5.23.0. Are you guys backporting the fix to it?

kessiler avatar Apr 22 '18 19:04 kessiler

We had some 5.23.0 issues too on different nodes, reverting to 5.22.3 (docker tag 12.6.5223) worked to resolve that.

cknowles avatar Apr 25 '18 09:04 cknowles

I was having the same issue running with 12.6.5230, downgrading worked for me, thanks @c-knowles. Is there a plan to rollout the fix on 5.x?

cainelli avatar Apr 25 '18 12:04 cainelli

Thanks for the inclusion of the 5.22.3 docker tag - I've got an open support issue and they weren't able to tell me which version introduced it so i could pin to work around it.

dbirtch-va avatar Apr 25 '18 14:04 dbirtch-va

Is there going to be a 6.1.5 with this fix? Right now the basic "getting started" instructions for kubernetes and datadog are broken due to this.

glasser avatar May 05 '18 02:05 glasser

Fixed with dd-agent 5.24.0 (docker tag 12.6.5240).

pdecat avatar May 17 '18 11:05 pdecat

"fixed" they now occasionally complete within the timeout - HPA monitoring graph between agent 5.22.3 and now "latest" 5.24.0

screen shot 2018-05-17 at 11 21 51 am

dbirtch-va avatar May 17 '18 20:05 dbirtch-va

Hmm, but what about the 6.x line?

glasser avatar May 17 '18 20:05 glasser

It’s the same with 6.2.0, kube state metrics are intermittent at best but they worked fine with the rest of the setup being the same on the older agents. I’ve reported it to DD support as well.

cknowles avatar May 18 '18 01:05 cknowles

Support did provide this as a workaround and it has been successful for me:

# Modifies line 477 increasing the timeout to 20
kubectl exec <dd-agent_podname> -- sed -i '477s/timeout=10/timeout=20/' /opt/datadog-agent/embedded/lib/python2.7/site-packages/datadog_checks/checks/prometheus/mixins.py

# Prints line to verify that the timeout has been changed
kubectl exec <dd-agent_podname> -- sed -n 477p /opt/datadog-agent/embedded/lib/python2.7/site-packages/datadog_checks/checks/prometheus/mixins.py

# For Agent v5: Kills the collector process without restart the container
kubectl exec <dd-agent_podname> -- pkill -TERM -F /opt/datadog-agent/run/dd-agent.pid

# For Agent v5: Trigger Supervisord to reread its configuration thereby restarting the collector process
kubectl exec <dd-agent_podname> -- pkill -HUP -F /opt/datadog-agent/run/datadog-supervisord.pid

# For Agent v6: Restarts the agent without restarting the container
kubectl exec <dd-agent_podname> -- s6-svc -t /var/run/s6/services/agent/

As i run my agents in a daemonset i've added the following to my pod specs to work around this issue.

    spec:
      containers:
      - image: datadog/docker-dd-agent
        name: dd-agent
        lifecycle:
          postStart:
            exec:
              command:
                - "/bin/sh"
                - "-c"
                - > 
                  sed -i '477s/timeout=10/timeout=20/' /opt/datadog-agent/embedded/lib/python2.7/site-packages/datadog_checks/checks/prometheus/mixins.py &&
                  pkill -TERM -F /opt/datadog-agent/run/dd-agent.pid;
                  sleep 3;
                  pkill -HUP -F /opt/datadog-agent/run/datadog-supervisord.pid;```

dbirtch-va avatar May 25 '18 20:05 dbirtch-va

All, I apologize for the delay!

It seems like the agent 6 does not handle the output of kube-state when it's too large (tied to the size of the cluster, the version of kube-state and the metrics available as well). We are actively investigating this and will keep you updated as soon as we make progress.

Thank you for your patience.

CharlyF avatar Jun 01 '18 18:06 CharlyF