Skip to content

[Logging] page_size appears to not work; no iterator(s) #203

@DazWilkin

Description

@DazWilkin

See #136

Code

requirements.txt:

google-auth==1.27.0
google-cloud-logging==2.2.0

And main.py (derived from the Google published sample)

Using client.list_entries:

import os

from google.cloud import logging
from google.cloud.logging import DESCENDING

client = logging.Client()

PROJECT = os.getenv("PROJECT")
resource = "projects/{project}".format(project=PROJECT)
log_name = "{resource}/logs/cloudaudit.googleapis.com%2Factivity".format(
    resource=resource)
filter = "logName=\"{log_name}\"".format(log_name=log_name)

entries = client.list_entries(filter_=filter,
                              order_by=DESCENDING,
                              page_size=3,
                              resource_names=[resource])

print("Listing entries for logger {}:".format(log_name))
for entry in entries:
    timestamp = entry.timestamp.isoformat()
    print("{}".format(timestamp))

Using logger.list_entries:

import os

from google.cloud import logging
from google.cloud.logging import DESCENDING

client = logging.Client()

log_name = "cloudaudit.googleapis.com%2Factivity"
logger = client.logger(log_name)

entries = logger.list_entries(
    order_by=DESCENDING,
    page_size=3,
)

print("Listing entries for logger {}:".format(log_name))
for entry in entries:
    timestamp = entry.timestamp.isoformat()
    print("{}".format(timestamp))

Steps to reproduce

Running the Python:

python3 cloud/main.py 
Listing entries for logger projects/dazwilkin-210302-66371557/logs/cloudaudit.googleapis.com%2Factivity:
2021-03-02T17:39:09.421835+00:00
2021-03-02T17:39:12.121825+00:00
2021-03-02T17:39:12.933201+00:00
2021-03-02T17:39:16.011850+00:00
2021-03-02T17:39:17.114823+00:00
2021-03-02T17:39:18.699000+00:00
2021-03-02T17:41:29.759709+00:00
2021-03-02T17:41:30.937346+00:00
2021-03-02T17:41:32.653000+00:00

NOTE Neither DESCENDING nor limited

Running the equivalent (!) gcloud yields the expected result:

gcloud logging read "logName=\"projects/${PROJECT}/logs/cloudaudit.googleapis.com%2Factivity\"" \
--project=${PROJECT} \
--order=desc \
--limit=3 \
--format="value(timestamp)" \
--log-http

...
== body start ==
{
  "filter": "timestamp>=\"2021-03-01T19:14:21.929877Z\" AND logName=\"projects/${PROJECT{/logs/cloudaudit.googleapis.com%2Factivity\"",
  "orderBy": "timestamp desc",
  "pageSize": 3,
  "resourceNames": ["projects/${PROJECT}"]
}
== body end ==
...
2021-03-02T17:41:32.653Z
2021-03-02T17:41:30.937346481Z
2021-03-02T17:41:29.759709770Z

Additionally:

  • The list_entries result should be an interator that can be paged; it is not
  • The library 'encourages' repetition of resource|project (logging_client.logger, filter and resource_names) and it's unclear how I can only specify this once

Metadata

Metadata

Assignees

Labels

api: loggingIssues related to the googleapis/python-logging API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions