Skip to content
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

fix(logadmin): use consistent filter in paging example #8221

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion logging/logadmin/example_paging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"html/template"
"log"
"net/http"
"time"

"cloud.google.com/go/logging"
"cloud.google.com/go/logging/logadmin"
Expand All @@ -31,6 +32,7 @@ import (
var (
client *logadmin.Client
projectID = flag.String("project-id", "", "ID of the project to use")
filter string
)

func ExampleClient_Entries_pagination() {
Expand All @@ -49,6 +51,15 @@ func ExampleClient_Entries_pagination() {
log.Fatalf("creating logging client: %v", err)
}

// Filter for logs of a specific name.
logName := fmt.Sprintf(`logName = "projects/%s/logs/testlog"`, *projectID)

// Filter for logs from the last twenty-four hours.
yesterday := time.Now().Add(-24 * time.Hour).UTC()
dayAgo := fmt.Sprintf("timestamp >= %q", yesterday.Format(time.RFC3339))

filter = fmt.Sprintf("%s AND %s", logName, dayAgo)

http.HandleFunc("/entries", handleEntries)
log.Print("listening on 8080")
log.Fatal(http.ListenAndServe(":8080", nil))
Expand All @@ -67,7 +78,6 @@ var pageTemplate = template.Must(template.New("").Parse(`

func handleEntries(w http.ResponseWriter, r *http.Request) {
ctx := context.Background()
filter := fmt.Sprintf(`logName = "projects/%s/logs/testlog"`, *projectID)
it := client.Entries(ctx, logadmin.Filter(filter))
var entries []*logging.Entry
nextTok, err := iterator.NewPager(it, 5, r.URL.Query().Get("pageToken")).NextPage(&entries)
Expand Down