Skip to content

Commit

Permalink
Merge pull request #27 from Revolution1/misc/iter-chunck-size-and-ext…
Browse files Browse the repository at this point in the history
…ra-api-codec

decode out put of metrics_raw, change iter-content chunck size to imp…
  • Loading branch information
Revolution1 committed Mar 30, 2018
2 parents 84c7a11 + a14d83f commit 62bb4f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion etcd3/apis/extra.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from collections import namedtuple

import six

from .base import BaseAPI

EtcdVersion = namedtuple('EtcdVersion', ['etcdserver', 'etcdcluster'])
Expand Down Expand Up @@ -34,7 +36,10 @@ def metrics_raw(self): # pragma: no cover
"""
resp = self._get(self._url('/metrics'))
self._raise_for_status(resp)
return resp.content
metrics = resp.content
if not isinstance(metrics, six.text_type):
metrics = six.text_type(metrics, encoding='utf-8')
return metrics

def metrics(self): # pragma: no cover
"""
Expand Down
4 changes: 3 additions & 1 deletion etcd3/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def iter_response(resp):
:return: dict
"""
left_chunk = b''
for chunk in resp.iter_content(chunk_size=2048):
# https://github.com/coreos/etcd/blob/master/etcdserver/api/v3rpc/maintenance.go#L98
# 2**15 < ceil(32*1024/3*4) < 2**16 = 65536
for chunk in resp.iter_content(chunk_size=65536):
chunk = left_chunk + chunk
for ok, s, _ in iter_json_string(chunk, resp=resp, err_cls=Etcd3StreamError):
if ok:
Expand Down

0 comments on commit 62bb4f6

Please sign in to comment.