-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logadmin: Unable to paginate entries throught different processes/requests #8186
Comments
@beni0888 Thank you for reporting this issue with the pagination sample for logadmin (*Client) Entries. I reproduced the error myself by downloading the sample from cloud.google.com and running it without modification apart from the log name:
|
@quartzmo Thank you for taking a look! Can we expect this issue to be fixed in the short term? |
After some debugging and trial & error I found that reusing the same // ...
var (
// ...
it *EntryIterator
)
// ...
func handleEntries(w http.ResponseWriter, r *http.Request) {
// ...
if it == nil {
it = client.Entries(ctx, logadmin.Filter(filter))
}
// ... The reason this worked is because of the following interesting default behavior: To test this hunch I added So nothing is broken except for this sample. We should either add |
I decided to just add a timestamp and create the filter once, on server start up. |
Without supplying a `timestamp` in the `ListLogEntries.Filter`, the client by default sets one for the last twenty-four hours when the `EntryIterator` is created. Since this example creates a new `EntryIterator` on each request, a new `timestamp` of a slightly different twenty-four hour window is added. When the `Next Page` button is pressed, it reuses the `NextPageToken` from the previous call, but that was created for a different twenty-four hour window `Filter`. This creates a mismatch between the requested `Filter` and the `Filter` used to create the `NextPageToken`, resulting in an error. To address this, we create the filter in the main function before server start up. In this filter, we set a timestamp **explicitly**. Note: I made this a `fix` commit because this is part of the GoDoc examples and we need this to appear as the latest release, otherwise no one will see it until another release comes along. Fixes #8186.
Client
logadmin.Client
Environment
macOS Ventura 13.4 - Apple M1 Pro
Go Environment
$ go version
go version go1.20.3 darwin/arm64
$ go env
GOARCH="arm64"
GOCACHE="/Users/myuser/Library/Caches/go-build"
GOENV="/Users/myuser/Library/Application Support/go/env"
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOMODCACHE="/Users/myuser/.asdf/installs/golang/1.20.3/packages/pkg/mod"
GOOS="darwin"
GOPATH="/Users/myuser/.asdf/installs/golang/1.20.3/packages"
GOROOT="/Users/myuser/.asdf/installs/golang/1.20.3/go"
GOTOOLDIR="/Users/myuser/.asdf/installs/golang/1.20.3/go/pkg/tool/darwin_arm64"
GOVERSION="go1.20.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-O2 -g"
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/k2/c4by0t896cl33tv1bt6dty0r0000gq/T/go-build2139043596=/tmp/go-build -gno-record-gcc-switches -fno-common"
Code
The code can be found here.
Expected behavior
When a request is made providing a valid pagination token in the
pageToken
query parameter (e.g.http://localhost:8080/entries?pageToken=EAA4n_GIvMjgk6THAUq0BSIe...
) the corresponding page of the list of logs is returned.Actual behavior
When you provide the
pageToken
query param with a valid pagination token, you get an error sayingproblem getting the next page: rpc error: code = InvalidArgument desc = page_token doesn't match arguments from the request
Additional context
go 1.20
require (
cloud.google.com/go/logging v1.7.0
google.golang.org/api v0.129.0
)
The text was updated successfully, but these errors were encountered: