cmd/telemetrygodev: provide links to reports and charts
Adds sections to the index page linking to chart pages
and report download links.
Change-Id: I8177c33764e72c5951ebde0b06566dbaa7c2e78c
Reviewed-on: https://go-review.googlesource.com/c/telemetry/+/523975
Run-TryBot: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/godev/cmd/telemetrygodev/main.go b/godev/cmd/telemetrygodev/main.go
index 387ebe7..8c5d643 100644
--- a/godev/cmd/telemetrygodev/main.go
+++ b/godev/cmd/telemetrygodev/main.go
@@ -44,10 +44,9 @@
log.Fatal(err)
}
fsys := fsys(cfg.DevMode)
- cserv := content.Server(fsys)
mux := http.NewServeMux()
- mux.Handle("/", cserv)
+ mux.Handle("/", handleRoot(fsys, ucfg, buckets))
mux.Handle("/upload/", handleUpload(ucfg, buckets))
mux.Handle("/charts/", handleChart(fsys, ucfg, buckets))
@@ -62,6 +61,55 @@
log.Fatal(http.ListenAndServe(":"+cfg.Port, mw(mux)))
}
+type link struct {
+ Text, URL string
+}
+
+type indexPage struct {
+ Charts []*link
+ Reports []*link
+}
+
+func handleRoot(fsys fs.FS, ucfg *tconfig.Config, buckets *stores) content.HandlerFunc {
+ cserv := content.Server(fsys)
+ return func(w http.ResponseWriter, r *http.Request) error {
+ if r.URL.Path != "/" {
+ cserv.ServeHTTP(w, r)
+ return nil
+ }
+ page := indexPage{}
+
+ ctx := r.Context()
+ it, err := buckets.chart.List(ctx, "")
+ if err != nil {
+ return err
+ }
+ for {
+ obj, err := it.Next()
+ if errors.Is(err, storage.ErrObjectIteratorDone) {
+ break
+ }
+ date := strings.TrimSuffix(obj, ".json")
+ page.Charts = append(page.Charts, &link{Text: date, URL: "/charts/" + date})
+ }
+ it, err = buckets.merge.List(ctx, "")
+ if err != nil {
+ return err
+ }
+ for {
+ obj, err := it.Next()
+ if errors.Is(err, storage.ErrObjectIteratorDone) {
+ break
+ }
+ page.Reports = append(page.Reports, &link{
+ Text: strings.TrimSuffix(obj, ".json"),
+ URL: buckets.merge.Location() + "/" + obj,
+ })
+ }
+ return content.Template(w, fsys, "index.html", page, http.StatusOK)
+ }
+}
+
type chartPage struct {
Charts map[string]any
}
diff --git a/godev/content/telemetrygodev/index.html b/godev/content/telemetrygodev/index.html
new file mode 100644
index 0000000..ea83f8c
--- /dev/null
+++ b/godev/content/telemetrygodev/index.html
@@ -0,0 +1,40 @@
+<!--
+ Copyright 2023 The Go Authors. All rights reserved.
+ Use of this source code is governed by a BSD-style
+ license that can be found in the LICENSE file.
+-->
+
+{{template "base" .}}
+
+{{define "title"}}Go Telemetry{{end}}
+
+{{define "content"}}
+<main id="main">
+ <h1>Go Telemetry</h1>
+ <section>
+ <h2>Overview</h2>
+ <p>This page will provide information about telemetry collection in the Go
+ toolchain.</p>
+
+ </p>For privacy information about this service, see <a href="/privacy">telemetry.go.dev/privacy</a>.</p>
+ </section>
+ <section>
+ <h2>Charts</h2>
+ <p>View charts for telemetry data.</p>
+ <ul style="column-count: auto; column-width: 10rem">
+ {{range .Charts}}
+ <li><a href="{{.URL}}">{{.Text}}</a></li>
+ {{end}}
+ </ul>
+ </section>
+ <section>
+ <h2>Reports</h2>
+ <p>Download telemetry reports.</p>
+ <ul style="column-count: auto; column-width: 10rem">
+ {{range .Reports}}
+ <li><a href="{{.URL}}">{{.Text}}</a></li>
+ {{end}}
+ </ul>
+ </section>
+</main>
+{{end}}
\ No newline at end of file
diff --git a/godev/content/telemetrygodev/index.md b/godev/content/telemetrygodev/index.md
deleted file mode 100644
index 14855e8..0000000
--- a/godev/content/telemetrygodev/index.md
+++ /dev/null
@@ -1,13 +0,0 @@
----
-Title: Go Telemetry
-Layout: base.html
----
-
-# Go Telemetry
-
-## Overview
-
-This page will provide information about telemetry collection in the Go
-toolchain.
-
-For privacy information about this service, see [telemetry.go.dev/privacy](https://telemetry.go.dev/privacy).
\ No newline at end of file