internal/worker: remove experiment update form if from config
If the experiments come from a config file, they can't be dynamically
updated. So remove the update form on the worker home page.
Change-Id: I1a6dda10570aa7e08b0392af593dfcc6b44cfa91
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/256517
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
diff --git a/content/static/html/worker/index.tmpl b/content/static/html/worker/index.tmpl
index 95db06f..e5dffbb 100644
--- a/content/static/html/worker/index.tmpl
+++ b/content/static/html/worker/index.tmpl
@@ -80,29 +80,52 @@
<div class="Experiments">
<h3>Experiments</h3>
{{if .Experiments}}
- <table>
- <thead>
- <tr>
- <th>Name</th>
- <th>Description</th>
- <th>Rollout</th>
- <th></th>
- <th></th>
- </tr>
- </thead>
- <tbody>
- {{range .Experiments}}
- <form action="/update-experiment" method="post" target="experimentUpdateResult">
+ {{if .ExperimentsFromConfig}}
+ <table>
+ <thead>
<tr>
- <td>{{.Name}}<input name="name" value="{{.Name}}" readonly hidden></td>
- <td>{{.Description}}<input name="description" value="{{.Description}}" readonly hidden></td>
- <td><input name="rollout" size="1rem" type="number" min="0" max="100" step="1" pattern="[0-9]{0,3}" value="{{.Rollout}}" required></td>
- <td><button>Update</button></td>
+ <th>Name</th>
+ <th>Description</th>
+ <th>Rollout</th>
</tr>
- </form>
- {{end}}
- </tbody>
- </table>
+ </thead>
+ <tbody>
+ {{range .Experiments}}
+ <tr>
+ <td>{{.Name}}</td>
+ <td>{{.Description}}</td>
+ <td>{{.Rollout}}</td>
+ </tr>
+ {{end}}
+ </tbody>
+ </table>
+ <p>To update experiments, modify the {{.Env}}-config.yaml file and deploy with
+ the <code>-config-only</code> flag.</p>
+ {{else}}
+ <table>
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Description</th>
+ <th>Rollout</th>
+ <th></th>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+ {{range .Experiments}}
+ <form action="/update-experiment" method="post" target="experimentUpdateResult">
+ <tr>
+ <td>{{.Name}}<input name="name" value="{{.Name}}" readonly hidden></td>
+ <td>{{.Description}}<input name="description" value="{{.Description}}" readonly hidden></td>
+ <td><input name="rollout" size="1rem" type="number" min="0" max="100" step="1" pattern="[0-9]{0,3}" value="{{.Rollout}}" required></td>
+ <td><button>Update</button></td>
+ </tr>
+ </form>
+ {{end}}
+ </tbody>
+ </table>
+ {{end}}
{{else}}
<p>No experiments.</p>
{{end}}
diff --git a/internal/worker/pages.go b/internal/worker/pages.go
index 3077fd1..0f0fc2b 100644
--- a/internal/worker/pages.go
+++ b/internal/worker/pages.go
@@ -74,28 +74,30 @@
}
page := struct {
- Config *config.Config
- Env string
- ResourcePrefix string
- LatestTimestamp *time.Time
- LocationID string
- Experiments []*internal.Experiment
- Excluded []string
- LoadShedStats fetch.LoadShedStats
- GoMemStats runtime.MemStats
- ProcessStats processMemStats
- SystemStats systemMemStats
+ Config *config.Config
+ Env string
+ ResourcePrefix string
+ LatestTimestamp *time.Time
+ LocationID string
+ Experiments []*internal.Experiment
+ ExperimentsFromConfig bool
+ Excluded []string
+ LoadShedStats fetch.LoadShedStats
+ GoMemStats runtime.MemStats
+ ProcessStats processMemStats
+ SystemStats systemMemStats
}{
- Config: s.cfg,
- Env: env(s.cfg),
- ResourcePrefix: strings.ToLower(env(s.cfg)) + "-",
- LocationID: s.cfg.LocationID,
- Experiments: experiments,
- Excluded: excluded,
- LoadShedStats: fetch.ZipLoadShedStats(),
- GoMemStats: gms,
- ProcessStats: pms,
- SystemStats: sms,
+ Config: s.cfg,
+ Env: env(s.cfg),
+ ResourcePrefix: strings.ToLower(env(s.cfg)) + "-",
+ LocationID: s.cfg.LocationID,
+ Experiments: experiments,
+ ExperimentsFromConfig: os.Getenv("GO_DISCOVERY_EXPERIMENTS_FROM_CONFIG") == "true",
+ Excluded: excluded,
+ LoadShedStats: fetch.ZipLoadShedStats(),
+ GoMemStats: gms,
+ ProcessStats: pms,
+ SystemStats: sms,
}
return renderPage(ctx, w, page, s.templates[indexTemplate])
}