Small fixes to make loading of logs faster

Removes filtering of log types where not necessary, removes filtering based on namespace when filtering based on repository (superfluous check that was causing issues in MySQL preventing the use of the correct index) and fix some other small issues around the API

Fixes https://jira.coreos.com/browse/QUAY-931
This commit is contained in:
Joseph Schorr 2018-05-14 11:41:49 -04:00
parent 29058201e5
commit e3248bde47
3 changed files with 15 additions and 17 deletions

View file

@ -26,7 +26,7 @@ def _logs_query(selections, start_time, end_time, performer=None, repository=Non
if performer: if performer:
joined = joined.where(LogEntry.performer == performer) joined = joined.where(LogEntry.performer == performer)
if namespace: if namespace and not repository:
namespace_user = user.get_user_or_org(namespace) namespace_user = user.get_user_or_org(namespace)
if namespace_user is None: if namespace_user is None:
raise DataModelException('Invalid namespace requested') raise DataModelException('Invalid namespace requested')

View file

@ -50,10 +50,10 @@ def get_logs(start_time, end_time, performer_name=None, repository_name=None, na
include_namespace = namespace_name is None and repository_name is None include_namespace = namespace_name is None and repository_name is None
return { return {
'start_time': format_date(start_time), 'start_time': format_date(start_time),
'end_time': format_date(end_time), 'end_time': format_date(end_time),
'logs': [log.to_dict(kinds, include_namespace) for log in log_entry_page.logs], 'logs': [log.to_dict(kinds, include_namespace) for log in log_entry_page.logs],
}, log_entry_page.next_page_token }, log_entry_page.next_page_token
def get_aggregate_logs(start_time, end_time, performer_name=None, repository=None, namespace=None, def get_aggregate_logs(start_time, end_time, performer_name=None, repository=None, namespace=None,
@ -80,7 +80,6 @@ class RepositoryLogs(RepositoryParamResource):
@parse_args() @parse_args()
@query_param('starttime', 'Earliest time from which to get logs (%m/%d/%Y %Z)', type=str) @query_param('starttime', 'Earliest time from which to get logs (%m/%d/%Y %Z)', type=str)
@query_param('endtime', 'Latest time to which to get logs (%m/%d/%Y %Z)', type=str) @query_param('endtime', 'Latest time to which to get logs (%m/%d/%Y %Z)', type=str)
@query_param('page', 'The page number for the logs', type=int, default=1)
@page_support() @page_support()
def get(self, namespace, repository, page_token, parsed_args): def get(self, namespace, repository, page_token, parsed_args):
""" List the logs for the specified repository. """ """ List the logs for the specified repository. """
@ -89,8 +88,8 @@ class RepositoryLogs(RepositoryParamResource):
start_time = parsed_args['starttime'] start_time = parsed_args['starttime']
end_time = parsed_args['endtime'] end_time = parsed_args['endtime']
return get_logs(start_time, end_time, repository_name=repository, page_token=page_token, namespace_name=namespace, return get_logs(start_time, end_time, repository_name=repository, page_token=page_token,
ignore=SERVICE_LEVEL_LOG_KINDS) namespace_name=namespace)
@resource('/v1/user/logs') @resource('/v1/user/logs')
@ -111,8 +110,9 @@ class UserLogs(ApiResource):
end_time = parsed_args['endtime'] end_time = parsed_args['endtime']
user = get_authenticated_user() user = get_authenticated_user()
return get_logs(start_time, end_time, performer_name=performer_name, namespace_name=user.username, return get_logs(start_time, end_time, performer_name=performer_name,
page_token=page_token, ignore=SERVICE_LEVEL_LOG_KINDS) namespace_name=user.username, page_token=page_token,
ignore=SERVICE_LEVEL_LOG_KINDS)
@resource('/v1/organization/<orgname>/logs') @resource('/v1/organization/<orgname>/logs')
@ -126,7 +126,6 @@ class OrgLogs(ApiResource):
@query_param('starttime', 'Earliest time from which to get logs. (%m/%d/%Y %Z)', type=str) @query_param('starttime', 'Earliest time from which to get logs. (%m/%d/%Y %Z)', type=str)
@query_param('endtime', 'Latest time to which to get logs. (%m/%d/%Y %Z)', type=str) @query_param('endtime', 'Latest time to which to get logs. (%m/%d/%Y %Z)', type=str)
@query_param('performer', 'Username for which to filter logs.', type=str) @query_param('performer', 'Username for which to filter logs.', type=str)
@query_param('page', 'The page number for the logs', type=int, default=1)
@page_support() @page_support()
@require_scope(scopes.ORG_ADMIN) @require_scope(scopes.ORG_ADMIN)
def get(self, orgname, page_token, parsed_args): def get(self, orgname, page_token, parsed_args):
@ -160,8 +159,7 @@ class RepositoryAggregateLogs(RepositoryParamResource):
start_time = parsed_args['starttime'] start_time = parsed_args['starttime']
end_time = parsed_args['endtime'] end_time = parsed_args['endtime']
return get_aggregate_logs(start_time, end_time, repository=repository, namespace=namespace, return get_aggregate_logs(start_time, end_time, repository=repository, namespace=namespace)
ignore=SERVICE_LEVEL_LOG_KINDS)
@resource('/v1/user/aggregatelogs') @resource('/v1/user/aggregatelogs')

View file

@ -37,8 +37,8 @@ class PreOCIModel(LogEntryDataInterface):
before it was changed to support the OCI specification. before it was changed to support the OCI specification.
""" """
def get_logs_query(self, start_time, end_time, performer_name=None, repository_name=None, namespace_name=None, def get_logs_query(self, start_time, end_time, performer_name=None, repository_name=None,
ignore=None, page_token=None): namespace_name=None, ignore=None, page_token=None):
repo = None repo = None
if repository_name and namespace_name: if repository_name and namespace_name:
repo = model.repository.get_repository(namespace_name, repository_name) repo = model.repository.get_repository(namespace_name, repository_name)
@ -65,8 +65,8 @@ class PreOCIModel(LogEntryDataInterface):
return False return False
return True return True
def get_aggregated_logs(self, start_time, end_time, performer_name=None, repository_name=None, namespace_name=None, def get_aggregated_logs(self, start_time, end_time, performer_name=None, repository_name=None,
ignore=None): namespace_name=None, ignore=None):
repo = None repo = None
if repository_name and namespace_name: if repository_name and namespace_name:
repo = model.repository.get_repository(namespace_name, repository_name) repo = model.repository.get_repository(namespace_name, repository_name)