-->

unable to extra/list all event log on watson assis

2019-08-18 03:59发布

问题:

Please help I was trying to call watson assistant endpoint https://gateway.watsonplatform.net/assistant/api/v1/workspaces/myworkspace/logs?version=2018-09-20 to get all the list of events

and filter by date range using this params

var param =
{ workspace_id: '{myworkspace}',
page_limit: 100000,
filter: 'response_timestamp%3C2018-17-12,response_timestamp%3E2019-01-01'}

apparently I got any empty response below.

{
"logs": [],
"pagination": {}
} 

回答1:

Couple of things to check.

1. You have 2018-17-12 which is a metric date. This translates to "12th day of the 17th month of 2018".

2. Assuming the date should be a valid one, your search says "Documents that are Before 17th Dec 2018 and after 1st Jan 2019". Which would return no documents.

3. Logs are only generated when you call the message() method through the API. So check your logging page in the tooling to see if you even have logs.

4. If you have a lite account logs are only stored for 7 days and then deleted. To keep logs longer you need to upgrade to a standard account.

Although not directly related to your issue, be aware that page_limit has an upper hard coded limit (IIRC 200-300?). So you may ask for 100,000 records, but it won't give it to you.


This is sample python code (unsupported) that is using pagination to read the logs:

from watson_developer_cloud import AssistantV1

username = '...'
password = '...'
workspace_id = '....'
url = '...'
version = '2018-09-20'

c = AssistantV1(url=url, version=version, username=username, password=password)

totalpages = 999
pagelimit = 200
logs = []
page_count = 1
cursor = None
count = 0

x = { 'pagination': 'DUMMY' }
while x['pagination']:
    if page_count > totalpages: 
        break

    print('Reading page {}. '.format(page_count), end='')
    x = c.list_logs(workspace_id=workspace_id,cursor=cursor,page_limit=pagelimit)
    if x is None: break

    print('Status: {}'.format(x.get_status_code()))
    x = x.get_result()

    logs.append(x['logs'])
    count = count + len(x['logs'])

    page_count = page_count + 1

    if 'pagination' in x and 'next_url' in x['pagination']:
        p = x['pagination']['next_url']
        u = urlparse(p)
        query = parse_qs(u.query)
        cursor = query['cursor'][0]

Your logs object should contain the logs.



回答2:

I believe the limit is 500, and then we return a pagination URL so you can get the next 500. I dont think this is the issue but once you start getting logs back its good to know