You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 13, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 13, 2026. It is now read-only.
[Logging] page_size appears to not work; no iterator(s) #203
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.653Z2021-03-02T17:41:30.937346481Z2021-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
I believe this issue is related to #154: We currently have two different implementations (grpc and http), which are implemented in inconsistent ways. This results in the gRPC layer ignoring some of the arguments. Unfortuantely a fix will likely have to wait until our next major relase, because it'll have to be a breaking change.
In the mean time, you can try to use HTTP mode instead of gRPC mode, which seems to work as you expect. You can turn it on with client = logging.Client(_use_grpc=0) or setting the DISABLE_GRPC environment variable to any value.
Note though that if your code iterates through all pages. If you just want a single page, you have to iterate differently:
for entry in next(entries.pages):
timestamp = entry.timestamp.isoformat()
print("{}".format(timestamp))
NOTE I'm using a new project today so the entries are different but the issue remains (all results instead of 3)
Yields:
All results (expect 3)
method returns generator (suggesting DISABLE_GRPC is ineffective!?)
And (unset DISABLE_GRPC):
NOTEElsewhere this variable is referenced as GOOGLE_CLOUD_DISBABLE_GRPC: True. I tried that and this then returns an google.api_core.page_iterator.HTTPIterator but all results
client=logging.Client(_use_grpc=0)
Yields:
All results (expect 3)
method returns an google.api_core.page_iterator.HTTPIterator
I used a slightly different mechanism on the iterator:
NOTE Elsewhere this variable is referenced as GOOGLE_CLOUD_DISBABLE_GRPC: True. I tried that and this then returns an google.api_core.page_iterator.HTTPIterator but all results
Sorry, you're right. The variable is called DISABLE_GRPCin the code, but it looks like the real name to use is GOOGLE_CLOUD_DISBABLE_GRPC
I used a slightly different mechanism on the iterator:
The problem with your code is the double loop. You are through iterating all pages, along with all entries in each page. This will give you all entries, just loaded in batches of 3. If you just want all 3 entries from a single page, you'll have to do something like the code I posted above:
for entry in next(entries.pages):
timestamp = entry.timestamp.isoformat()
print("{}".format(timestamp))
This should give you all 3 results on the first page of results, which seems to be what you're looking for. But let me know if you're still having issues.
Activity
daniel-sanche commentedon Mar 3, 2021
I believe this issue is related to #154: We currently have two different implementations (grpc and http), which are implemented in inconsistent ways. This results in the gRPC layer ignoring some of the arguments. Unfortuantely a fix will likely have to wait until our next major relase, because it'll have to be a breaking change.
In the mean time, you can try to use HTTP mode instead of gRPC mode, which seems to work as you expect. You can turn it on with
client = logging.Client(_use_grpc=0)or setting theDISABLE_GRPCenvironment variable to any value.Note though that if your code iterates through all pages. If you just want a single page, you have to iterate differently:
https://googleapis.dev/python/google-api-core/latest/page_iterator.html
DazWilkin commentedon Mar 3, 2021
It does not work (nor as documented by #154).
Yields:
generator(suggestingDISABLE_GRPCis ineffective!?)And (
unset DISABLE_GRPC):Yields:
google.api_core.page_iterator.HTTPIteratorI used a slightly different mechanism on the iterator:
daniel-sanche commentedon Mar 3, 2021
Sorry, you're right. The variable is called
DISABLE_GRPCin the code, but it looks like the real name to use isGOOGLE_CLOUD_DISBABLE_GRPCThe problem with your code is the double loop. You are through iterating all pages, along with all entries in each page. This will give you all entries, just loaded in batches of 3. If you just want all 3 entries from a single page, you'll have to do something like the code I posted above:
This should give you all 3 results on the first page of results, which seems to be what you're looking for. But let me know if you're still having issues.
DazWilkin commentedon Mar 3, 2021
Doh! Thanks. Yes, of course.
I was thinking I would get one page of three results but I'm actually getting n pages of 3 results.
Thank you!
keenan-devrel commentedon Sep 16, 2021
This should be addressed in the upcoming 3.0 release planned for Q4 2021.