Skip to content

Commit cd12599

Browse files
author
Miguel Acero
committed
internal/frontend: add metrics for playground share requests
A metric is added for everytime a request is sent to play.golang.org. The request status code will be used and is useful to have better visibility on how many users click the new playground "play" button. For golang/go#36865 Change-Id: I243efe5b3d8724fa6bdd60d332e2932925ffe094 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245898 Reviewed-by: Jonathan Amsterdam <[email protected]>
1 parent 94d940a commit cd12599

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

cmd/frontend/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ func main() {
131131
postgres.SearchResponseCount,
132132
frontend.FetchLatencyDistribution,
133133
frontend.FetchResponseCount,
134+
frontend.PlaygroundShareRequestCount,
134135
middleware.CacheResultCount,
135136
middleware.CacheErrorCount,
136137
middleware.QuotaResultCount,

internal/frontend/playground.go

+25
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,34 @@ package frontend
77
import (
88
"io"
99
"net/http"
10+
"strconv"
1011

12+
"go.opencensus.io/stats"
13+
"go.opencensus.io/stats/view"
14+
"go.opencensus.io/tag"
1115
"golang.org/x/pkgsite/internal/log"
1216
)
1317

1418
// playgroundURL is the playground endpoint used for share links.
1519
const playgroundURL = "https://play.golang.org"
1620

21+
var (
22+
keyPlaygroundShareStatus = tag.MustNewKey("playground.share.status")
23+
playgroundShareStatus = stats.Int64(
24+
"go-discovery/playground_share_count",
25+
"The status of a request to play.golang.org/share",
26+
stats.UnitDimensionless,
27+
)
28+
29+
PlaygroundShareRequestCount = &view.View{
30+
Name: "go-discovery/playground/share_count",
31+
Measure: playgroundShareStatus,
32+
Aggregation: view.Count(),
33+
Description: "Playground share request count",
34+
TagKeys: []tag.Key{keyPlaygroundShareStatus},
35+
}
36+
)
37+
1738
// handlePlay handles requests that mirror play.golang.org/share.
1839
func (s *Server) handlePlay(w http.ResponseWriter, r *http.Request) {
1940
makeFetchPlayRequest(w, r, playgroundURL)
@@ -43,6 +64,10 @@ func makeFetchPlayRequest(w http.ResponseWriter, r *http.Request, pgURL string)
4364
httpErrorStatus(w, http.StatusInternalServerError)
4465
return
4566
}
67+
stats.RecordWithTags(r.Context(),
68+
[]tag.Mutator{tag.Upsert(keyPlaygroundShareStatus, strconv.Itoa(resp.StatusCode))},
69+
playgroundShareStatus.M(int64(resp.StatusCode)),
70+
)
4671
copyHeader := func(k string) {
4772
if v := resp.Header.Get(k); v != "" {
4873
w.Header().Set(k, v)

0 commit comments

Comments
 (0)