Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_log_all() support select query #168

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions aliyun/log/logclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ def get_logs(self, request):
query, reverse, offset, size)

def get_log_all(self, project, logstore, from_time, to_time, topic=None,
query=None, reverse=False, offset=0):
query=None, reverse=False, offset=0, page_size=5000):
""" Get logs from log service. will retry when incomplete.
Unsuccessful opertaion will cause an LogException. different with `get_log` with size=-1,
It will try to iteratively fetch all data every 100 items and yield them, in CLI, it could apply jmes filter to
Expand Down Expand Up @@ -635,16 +635,23 @@ def get_log_all(self, project, logstore, from_time, to_time, topic=None,

:raise: LogException
"""
stats_query = is_stats_query(query)
while True:
response = self.get_log(project, logstore, from_time, to_time, topic=topic,
query=query, reverse=reverse, offset=offset, size=100)
response = None
if stats_query:
limit_query = "%s limit %d,%d" % (query, offset, page_size)
response = self.get_log(project, logstore, from_time, to_time, topic=topic,
query=limit_query, reverse=reverse, size=page_size)
else:
response = self.get_log(project, logstore, from_time, to_time, topic=topic,
query=query, reverse=reverse, offset=offset, size=page_size)

yield response

count = response.get_count()
offset += count

if count == 0 or is_stats_query(query):
if count == 0:
break

def get_context_logs(self, project, logstore, pack_id, pack_meta, back_lines, forward_lines):
Expand Down