[pkgsite] internal/dcensus: add metrics for codewiki link usage

5 views
Skip to first unread message

Ethan Lee (Gerrit)

unread,
Dec 17, 2025, 10:35:22 PM (4 days ago) Dec 17
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Ethan Lee has uploaded the change for review

Commit message

internal/dcensus: add metrics for codewiki link usage

- Count link usage, target url and referrer page.

Example: Run `go run ./cmd/frontend/main.go -dev -direct_proxy` and
access pkgsite via localhost:8080. After clicking on the link, observe
the relevant metric logged in localhost:8081/statz.
Change-Id: Ib312584162b81deac4c22b4ed923ff783133e11e

Change diff

diff --git a/cmd/frontend/main.go b/cmd/frontend/main.go
index c3541cd..934554d 100644
--- a/cmd/frontend/main.go
+++ b/cmd/frontend/main.go
@@ -192,6 +192,7 @@
middleware.CacheErrorCount,
middleware.CacheLatency,
middleware.QuotaResultCount,
+ dcensus.CodeWikiClickCountView,
)
if err := dcensus.Init(cfg, views...); err != nil {
log.Fatal(ctx, err)
diff --git a/internal/dcensus/dcensus.go b/internal/dcensus/dcensus.go
index 1447a0d..c525e4e 100644
--- a/internal/dcensus/dcensus.go
+++ b/internal/dcensus/dcensus.go
@@ -241,6 +241,22 @@
}
)

+var (
+ // KeyReferrer is a tag key for the referrer URL.
+ KeyReferrer = tag.MustNewKey("referrer")
+ // KeyTargetURL is a tag key for the target URL.
+ KeyTargetURL = tag.MustNewKey("target_url")
+
+ CodeWikiClickCount = stats.Int64("go-discovery/frontend_codewiki_clicks", "Codewiki link clicks", stats.UnitDimensionless)
+ CodeWikiClickCountView = &view.View{
+ Name: "go-discovery/frontend/codewiki_clicks",
+ Description: "Count of codewiki link clicks",
+ TagKeys: []tag.Key{KeyReferrer, KeyTargetURL},
+ Measure: CodeWikiClickCount,
+ Aggregation: view.Count(),
+ }
+)
+
// RecordWithTag is a convenience function for recording a single measurement with a single tag.
func RecordWithTag(ctx context.Context, key tag.Key, val string, m stats.Measurement) {
stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(key, val)}, m)
diff --git a/internal/frontend/server.go b/internal/frontend/server.go
index e15f929..44e52fc 100644
--- a/internal/frontend/server.go
+++ b/internal/frontend/server.go
@@ -20,8 +20,11 @@
"time"

"github.com/google/safehtml/template"
+ ocstats "go.opencensus.io/stats"
+ "go.opencensus.io/tag"
"golang.org/x/pkgsite/internal"
"golang.org/x/pkgsite/internal/config"
+ "golang.org/x/pkgsite/internal/dcensus"
"golang.org/x/pkgsite/internal/derrors"
"golang.org/x/pkgsite/internal/experiment"
pagepkg "golang.org/x/pkgsite/internal/frontend/page"
@@ -141,6 +144,21 @@
return s, nil
}

+func (s *Server) handleCodeWikiRedirect(w http.ResponseWriter, r *http.Request) {
+ url := r.FormValue("url")
+ if url == "" {
+ http.Error(w, "missing url", http.StatusBadRequest)
+ return
+ }
+ ctx := r.Context()
+ mutators := []tag.Mutator{
+ tag.Upsert(dcensus.KeyTargetURL, url),
+ tag.Upsert(dcensus.KeyReferrer, r.Header.Get("Referer")),
+ }
+ ocstats.RecordWithTags(ctx, mutators, dcensus.CodeWikiClickCount.M(1))
+ http.Redirect(w, r, url, http.StatusFound)
+}
+
// A Cacher is used to create request caches for http handlers.
type Cacher interface {
// Cache returns a new middleware that caches every request.
@@ -211,6 +229,7 @@
// (This is what golang.org/C does.)
http.Redirect(w, r, "/cmd/cgo", http.StatusMovedPermanently)
}))
+ handle("GET /codewiki", http.HandlerFunc(s.handleCodeWikiRedirect))
handle("GET /golang.org/x", s.staticPageHandler("subrepo", "Sub-repositories"))
handle("GET /files/", http.StripPrefix("/files", s.fileMux))
handle("GET /vuln/", vulnHandler)
diff --git a/static/frontend/unit/main/_meta.tmpl b/static/frontend/unit/main/_meta.tmpl
index 8e32eb2..5b3a8dd 100644
--- a/static/frontend/unit/main/_meta.tmpl
+++ b/static/frontend/unit/main/_meta.tmpl
@@ -42,7 +42,7 @@
{{end}}
{{with .CodeWikiURL}}
<li>
- <a href="{{.}}" title="View this repo on Code Wiki"
+ <a href="/codewiki?url={{.}}" title="View this repo on Code Wiki"
target="_blank" rel="noopener" data-test-id="meta-link-codewiki">
<img class="go-Icon" src="/static/shared/icon/codewiki-logo.svg"
alt="Code Wiki Logo" />

Change information

Files:
  • M cmd/frontend/main.go
  • M internal/dcensus/dcensus.go
  • M internal/frontend/server.go
  • M static/frontend/unit/main/_meta.tmpl
Change size: S
Delta: 4 files changed, 37 insertions(+), 1 deletion(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
  • requirement is not satisfiedkokoro-CI-Passes
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: Ib312584162b81deac4c22b4ed923ff783133e11e
Gerrit-Change-Number: 731020
Gerrit-PatchSet: 1
Gerrit-Owner: Ethan Lee <etha...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Jonathan Amsterdam (Gerrit)

unread,
Dec 18, 2025, 8:44:39 AM (4 days ago) Dec 18
to Ethan Lee, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Ethan Lee

Jonathan Amsterdam voted Code-Review+2

Code-Review+2
Open in Gerrit

Related details

Attention is currently required from:
  • Ethan Lee
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
  • requirement is not satisfiedkokoro-CI-Passes
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: Ib312584162b81deac4c22b4ed923ff783133e11e
Gerrit-Change-Number: 731020
Gerrit-PatchSet: 1
Gerrit-Owner: Ethan Lee <etha...@google.com>
Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
Gerrit-Attention: Ethan Lee <etha...@google.com>
Gerrit-Comment-Date: Thu, 18 Dec 2025 13:44:36 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Ethan Lee (Gerrit)

unread,
Dec 18, 2025, 3:08:57 PM (3 days ago) Dec 18
to goph...@pubsubhelper.golang.org, Jonathan Amsterdam, golang-co...@googlegroups.com

Ethan Lee voted and added 1 comment

Votes added by Ethan Lee

Auto-Submit+1
Commit-Queue+1

1 comment

Patchset-level comments
File-level comment, Patchset 2 (Latest):
Ethan Lee . resolved

kokoro rereun

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
  • requirement is not satisfiedkokoro-CI-Passes
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: Ib312584162b81deac4c22b4ed923ff783133e11e
Gerrit-Change-Number: 731020
Gerrit-PatchSet: 2
Gerrit-Owner: Ethan Lee <etha...@google.com>
Gerrit-Reviewer: Ethan Lee <etha...@google.com>
Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
Gerrit-Comment-Date: Thu, 18 Dec 2025 20:08:54 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Ethan Lee (Gerrit)

unread,
Dec 18, 2025, 3:20:30 PM (3 days ago) Dec 18
to goph...@pubsubhelper.golang.org, Go LUCI, Jonathan Amsterdam, golang-co...@googlegroups.com

Ethan Lee voted and added 1 comment

Votes added by Ethan Lee

Auto-Submit+1
Commit-Queue+1

1 comment

Patchset-level comments
File-level comment, Patchset 3 (Latest):
Ethan Lee . resolved

kokoro rerun

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
  • requirement is not satisfiedkokoro-CI-Passes
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: Ib312584162b81deac4c22b4ed923ff783133e11e
Gerrit-Change-Number: 731020
Gerrit-PatchSet: 3
Gerrit-Owner: Ethan Lee <etha...@google.com>
Gerrit-Reviewer: Ethan Lee <etha...@google.com>
Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
Gerrit-Comment-Date: Thu, 18 Dec 2025 20:20:27 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Ethan Lee (Gerrit)

unread,
Dec 19, 2025, 5:49:05 PM (2 days ago) Dec 19
to goph...@pubsubhelper.golang.org, Go LUCI, Jonathan Amsterdam, golang-co...@googlegroups.com

Ethan Lee voted and added 1 comment

Votes added by Ethan Lee

Auto-Submit+1
Commit-Queue+1

1 comment

Patchset-level comments
Ethan Lee . resolved

kokoro rerun

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
  • requirement is not satisfiedkokoro-CI-Passes
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: Ib312584162b81deac4c22b4ed923ff783133e11e
Gerrit-Change-Number: 731020
Gerrit-PatchSet: 4
Gerrit-Owner: Ethan Lee <etha...@google.com>
Gerrit-Reviewer: Ethan Lee <etha...@google.com>
Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
Gerrit-Comment-Date: Fri, 19 Dec 2025 22:49:01 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

kokoro (Gerrit)

unread,
Dec 19, 2025, 5:59:18 PM (2 days ago) Dec 19
to Ethan Lee, goph...@pubsubhelper.golang.org, Go LUCI, Jonathan Amsterdam, golang-co...@googlegroups.com
Attention needed from Ethan Lee

kokoro voted kokoro-CI-1

Kokoro presubmit build finished with status: FAILURE
Logs at: https://source.cloud.google.com/results/invocations/04250bec-7981-4909-a0bc-956488c4ab29

kokoro-CI-1
Open in Gerrit

Related details

Attention is currently required from:
  • Ethan Lee
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
  • requirement is not satisfiedkokoro-CI-Passes
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: Ib312584162b81deac4c22b4ed923ff783133e11e
Gerrit-Change-Number: 731020
Gerrit-PatchSet: 4
Gerrit-Owner: Ethan Lee <etha...@google.com>
Gerrit-Reviewer: Ethan Lee <etha...@google.com>
Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
Gerrit-Reviewer: kokoro <noreply...@google.com>
Gerrit-CC: kokoro <noreply...@google.com>
Gerrit-Attention: Ethan Lee <etha...@google.com>
Gerrit-Comment-Date: Fri, 19 Dec 2025 22:59:13 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Ethan Lee (Gerrit)

unread,
Dec 19, 2025, 6:12:00 PM (2 days ago) Dec 19
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Ethan Lee and Jonathan Amsterdam

Ethan Lee uploaded new patchset

Ethan Lee uploaded patch set #6 to this change.
Following approvals got outdated and were removed:
  • Code-Review: +2 by Jonathan Amsterdam
  • TryBots-Pass: LUCI-TryBot-Result-1 by Go LUCI
  • kokoro-CI-Passes: kokoro-CI-1 by kokoro
Open in Gerrit

Related details

Attention is currently required from:
  • Ethan Lee
  • Jonathan Amsterdam
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
  • requirement is not satisfiedkokoro-CI-Passes
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: Ib312584162b81deac4c22b4ed923ff783133e11e
Gerrit-Change-Number: 731020
Gerrit-PatchSet: 6
Gerrit-Owner: Ethan Lee <etha...@google.com>
Gerrit-Reviewer: Ethan Lee <etha...@google.com>
Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
Gerrit-Reviewer: kokoro <noreply...@google.com>
Gerrit-CC: kokoro <noreply...@google.com>
Gerrit-Attention: Jonathan Amsterdam <j...@google.com>
Gerrit-Attention: Ethan Lee <etha...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Ethan Lee (Gerrit)

unread,
10:59 PM (8 minutes ago) 10:59 PM
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Ethan Lee and Jonathan Amsterdam

Ethan Lee uploaded new patchset

Ethan Lee uploaded patch set #8 to this change.
Open in Gerrit

Related details

Attention is currently required from:
  • Ethan Lee
  • Jonathan Amsterdam
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
  • requirement is not satisfiedkokoro-CI-Passes
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: Ib312584162b81deac4c22b4ed923ff783133e11e
Gerrit-Change-Number: 731020
Gerrit-PatchSet: 8
unsatisfied_requirement
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages