Skip to content

Commit ce7b4bd

Browse files
committed
Update oci_logging.py
1 parent 34661b6 commit ce7b4bd

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

ads/common/oci_logging.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def _search_and_format(
533533
time_end: datetime.datetime = None,
534534
limit: int = LOG_RECORDS_LIMIT,
535535
sort_by: str = "datetime",
536-
sort_order: str = SortOrder.DESC,
536+
sort_order: str = SortOrder.ASC,
537537
log_filter: str = None,
538538
):
539539
"""Returns the formatted log records.
@@ -550,7 +550,7 @@ def _search_and_format(
550550
Maximum number of records to be returned.
551551
sort_by: (str, optional). Defaults to "datetime"
552552
The field for sorting the logs.
553-
sort_order: (str, optional). Defaults to "DESC".
553+
sort_order: (str, optional). Defaults to "ASC".
554554
The sort order for the log records. Can be "ASC" or "DESC".
555555
log_filter : (str, optional). Defaults to None.
556556
Expression for filtering the logs.
@@ -574,8 +574,8 @@ def _search_and_format(
574574
sort_order=sort_order,
575575
log_filter=log_filter,
576576
)
577-
logs = sorted((log.data for log in logs), key=lambda x: x.get("datetime"))
578-
logs = [log.get("logContent", {}) for log in logs]
577+
578+
logs = [log.data.get("logContent", {}) for log in logs]
579579
return [
580580
{
581581
"id": log.get("id"),
@@ -617,7 +617,7 @@ def tail(
617617
return self._search_and_format(
618618
source=source,
619619
limit=limit,
620-
sort_order=SortOrder.DESC,
620+
sort_order=SortOrder.ASC,
621621
time_start=time_start,
622622
log_filter=log_filter,
623623
)
@@ -808,7 +808,7 @@ def stream(
808808
logs = self._search_and_format(
809809
source=source,
810810
limit=None,
811-
sort_order=SortOrder.DESC,
811+
sort_order=SortOrder.ASC,
812812
time_start=time_start,
813813
log_filter=log_filter,
814814
)
@@ -858,7 +858,7 @@ def tail(
858858
self._search_and_format(
859859
source=source,
860860
limit=limit,
861-
sort_order=SortOrder.DESC,
861+
sort_order=SortOrder.ASC,
862862
time_start=time_start,
863863
log_filter=log_filter,
864864
)
@@ -927,7 +927,7 @@ def search(
927927
time_end: datetime.datetime = None,
928928
limit: int = None,
929929
sort_by: str = "datetime",
930-
sort_order: str = SortOrder.DESC,
930+
sort_order: str = SortOrder.ASC,
931931
log_filter: str = None,
932932
) -> List[oci.loggingsearch.models.SearchResult]:
933933
"""Searches raw logs.
@@ -951,7 +951,7 @@ def search(
951951
Defaults to "datetime"
952952
sort_order : str, optional.
953953
The sort order for the log records. Can be "ASC" or "DESC".
954-
Defaults to "DESC".
954+
Defaults to "ASC".
955955
log_filter : str, optional
956956
Expression for filtering the logs. This will be the WHERE clause of the query.
957957
Defaults to None.
@@ -979,7 +979,7 @@ def _search_and_format(
979979
time_end: datetime.datetime = None,
980980
limit: int = LOG_RECORDS_LIMIT,
981981
sort_by: str = "datetime",
982-
sort_order: str = SortOrder.DESC,
982+
sort_order: str = SortOrder.ASC,
983983
log_filter: str = None,
984984
need_format: bool = True,
985985
) -> List[Union[oci.loggingsearch.models.SearchResult, dict]]:
@@ -1005,7 +1005,7 @@ def _search_and_format(
10051005
Defaults to "datetime"
10061006
sort_order : str, optional.
10071007
The sort order for the log records. Can be "ASC" or "DESC".
1008-
Defaults to "DESC".
1008+
Defaults to "ASC".
10091009
log_filter : str, optional
10101010
Expression for filtering the logs. This will be the WHERE clause of the query.
10111011
Defaults to None.
@@ -1039,12 +1039,6 @@ def _search_and_format(
10391039
)
10401040
)
10411041

1042-
# _collect_logs returns a list of either dict or oci.loggingsearch.models.SearchResult
1043-
# objects based on `need_format` parameter, so below there are two cases for log sorting.
1044-
if need_format:
1045-
batch_logs.sort(key=lambda x: x.get("datetime"))
1046-
else:
1047-
batch_logs.sort(key=lambda x: x.data.get("datetime"))
10481042
if limit and len(batch_logs) > limit:
10491043
batch_logs = batch_logs[:limit]
10501044
return batch_logs
@@ -1057,7 +1051,7 @@ def _collect_logs(
10571051
time_end: datetime.datetime = None,
10581052
limit: int = LOG_RECORDS_LIMIT,
10591053
sort_by: str = "datetime",
1060-
sort_order: str = SortOrder.DESC,
1054+
sort_order: str = SortOrder.ASC,
10611055
log_filter: str = None,
10621056
need_format: bool = True,
10631057
) -> List[Union[oci.loggingsearch.models.SearchResult, dict]]:
@@ -1085,7 +1079,7 @@ def _collect_logs(
10851079
Defaults to "datetime"
10861080
sort_order : str, optional.
10871081
The sort order for the log records. Can be "ASC" or "DESC".
1088-
Defaults to "DESC".
1082+
Defaults to "ASC".
10891083
log_filter : str, optional
10901084
Expression for filtering the logs. This will be the WHERE clause of the query.
10911085
Defaults to None.

0 commit comments

Comments
 (0)