aliyun / aliyun-log-cli

Command Line Interface for Aliyun Log Service
http://aliyun-log-cli.readthedocs.io
MIT License
60 stars 20 forks source link

Timezone issue in python2 in GetLogs API #53

Open liketic opened 5 years ago

liketic commented 5 years ago

The following command aliyunlog log get_log --project=xxx --logstore=xxx --access-id=xxx --access-key=xxxx --region-endpoint=cn-zhangjiakou.log.aliyuncs.com --query='*| select DISTINCT("listener_info.listener_id") limit 2000' --from_time='5 min ago' --to_time='now'

returns different result for python2 and python3.
version:

aliyun-log-cli                     0.1.14
aliyun-log-python-sdk              0.6.38

More details: Python 3.6.6:

$ python -c 'import time; from aliyun.log import util; print(util.parse_timestamp("now") - time.time());'
-0.61266...
$ python --version
Python 3.6.6

Python 2.7.8:

$ python -c 'import time; from aliyun.log import util; print(util.parse_timestamp("now") - time.time());'
28799.619...
$ python --version
Python 2.7.8
wjo1212 commented 5 years ago

@liketic seems something wrong with default time-zone in Py2

Solution1: Append time-zone info instead

aliyunlog log get_log --project=xxx --logstore=xxx --access-id=xxx --access-key=xxxx --region-endpoint=cn-zhangjiakou.log.aliyuncs.com --query='*| select DISTINCT("listener_info.listener_id") limit 2000' --from_time='5 min ago' --to_time='now' ==>

aliyunlog log get_log --project=xxx --logstore=xxx --access-id=xxx --access-key=xxxx --region-endpoint=cn-zhangjiakou.log.aliyuncs.com --query='*| select DISTINCT("listener_info.listener_id") limit 2000' --from_time='5 min ago UTC+8' --to_time='now UTC+8'

Solution2: change to Python 3

I will update doc accordingly.