[pkgsite] internal, static: add telemetry click beacon for search A/B testing

1 view
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Aug 10, 2026, 5:58:30 PM (12 hours ago) Aug 10
to Ethan Lee, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, kokoro, golang...@luci-project-accounts.iam.gserviceaccount.com, Jonathan Amsterdam, golang-co...@googlegroups.com

Gopher Robot submitted the change with unreviewed changes

Unreviewed changes

7 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:

```
The name of the file: internal/frontend/search.go
Insertions: 8, Deletions: 8.

@@ -22,7 +22,6 @@
"golang.org/x/mod/semver"
"golang.org/x/pkgsite/internal"
"golang.org/x/pkgsite/internal/derrors"
- "golang.org/x/pkgsite/internal/embeddings"
"golang.org/x/pkgsite/internal/experiment"
pagepkg "golang.org/x/pkgsite/internal/frontend/page"
"golang.org/x/pkgsite/internal/frontend/serrors"
@@ -62,7 +61,7 @@
page interface{ SetBasePage(pagepkg.BasePage) }
}

-func determineSearchAction(r *http.Request, ds internal.DataSource, vulnClient *vuln.Client, embeddingsClient *embeddings.Client) (*searchAction, error) {
+func determineSearchAction(r *http.Request, ds internal.DataSource, vulnClient *vuln.Client, embeddingsClient VectorEmbedder) (*searchAction, error) {
if r.Method != http.MethodGet && r.Method != http.MethodHead {
return nil, &serrors.ServerError{Status: http.StatusMethodNotAllowed}
}
@@ -246,20 +245,20 @@
// fetchSearchPage fetches data matching the search query from the database and
// returns a SearchPage.
func fetchSearchPage(ctx context.Context, ds internal.DataSource, cq, symbol string,
- pageParams paginationParams, searchSymbols bool, vulnClient *vuln.Client, embeddingsClient *embeddings.Client) (*SearchPage, error) {
+ pageParams paginationParams, searchSymbols bool, vulnClient *vuln.Client, embeddingsClient VectorEmbedder) (*SearchPage, error) {
maxResultCount := maxSearchOffset + pageParams.limit

var (
- vec []float32
- embeddingLatencyMs int64
- searchLatencyMs int64
+ vec []float32
+ embeddingLatency time.Duration
+ searchLatency time.Duration
)
if embeddingsClient != nil && !searchSymbols && strings.TrimSpace(cq) != "" && experiment.IsActive(ctx, internal.ExperimentVectorSearch) {
embedCtx, cancel := context.WithTimeout(ctx, searchEmbeddingTimeout)
defer cancel()
startEmbed := time.Now()
- vecs, err := embeddingsClient.GenerateEmbeddings(embedCtx, []string{cq}, embeddings.TaskTypeQuery)
- embeddingLatencyMs = time.Since(startEmbed).Milliseconds()
+ vecs, err := embeddingsClient.GenerateEmbeddings(embedCtx, []string{cq}, "RETRIEVAL_QUERY")
+ embeddingLatency = time.Since(startEmbed)
if err != nil {
log.Errorf(ctx, "failed to generate query vector for %q: %v", cq, err)
} else if len(vecs) > 0 {
@@ -279,7 +278,7 @@
GroupResults: true,
Vector: vec,
})
- searchLatencyMs = time.Since(startSearch).Milliseconds()
+ searchLatency = time.Since(startSearch)
if err != nil {
return nil, err
}
@@ -317,8 +316,8 @@
"log_type": "search_query_execution",
"query": cq,
"cohort": cohort,
- "embedding_latency_ms": embeddingLatencyMs,
- "search_latency_ms": searchLatencyMs,
+ "embedding_latency_ms": embeddingLatency.Milliseconds(),
+ "search_latency_ms": searchLatency.Milliseconds(),
"num_results": numResults,
})

```

Change information

Commit message:
internal, static: add telemetry click beacon for search A/B testing

Add /search-click handler to log search result click metadata
(query, clicked_package, rank, cohort, timestamp) to Cloud Logging.
Pass IsVectorSearch to SearchPage template and fire non-blocking
sendBeacon telemetry when users select search results.
Change-Id: I4d4aec11d28bdb65c4977b04288d63cef57c96c6
Reviewed-by: Jonathan Amsterdam <j...@google.com>
Auto-Submit: Ethan Lee <etha...@google.com>
kokoro-CI: kokoro <noreply...@google.com>
Files:
  • M internal/frontend/search.go
  • M internal/frontend/search_test.go
  • M internal/frontend/server.go
  • M static/frontend/search/search.js
  • M static/frontend/search/search.tmpl
  • M static/frontend/search/search.ts
Change size: M
Delta: 6 files changed, 154 insertions(+), 3 deletions(-)
Branch: refs/heads/master
Submit Requirements:
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: I4d4aec11d28bdb65c4977b04288d63cef57c96c6
Gerrit-Change-Number: 806500
Gerrit-PatchSet: 20
Gerrit-Owner: Ethan Lee <etha...@google.com>
Gerrit-Reviewer: Ethan Lee <etha...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
Gerrit-Reviewer: kokoro <noreply...@google.com>
Gerrit-CC: kokoro <noreply...@google.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages