kosx

Google create_experiment_config / main.go

Dec 30th, 2020
1,142
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Copyright 2020 The Go Authors. All rights reserved.
  3. // Use of this source code is governed by a BSD-style
  4. // license that can be found in the LICENSE file.
  5. // Command create_experiment_config creates an experiment.yaml file, which will
  6. // set a rollout of 100 for all experiments.
  7. package main
  8. import (
  9.     "fmt"
  10.     "log"
  11.     "os"
  12.     "sort"
  13.     "strings"
  14.     "github.com/ghodss/yaml"
  15.     "golang.org/x/pkgsite/internal"
  16. )
  17. type Experiment struct {
  18.     Name    string `yaml:"name"`
  19.     Rollout int    `yaml:"rollout"`
  20. }
  21. func main() {
  22.     data, err := experimentsYAML()
  23.     if err != nil {
  24.         log.Fatal(err)
  25.     }
  26.     if err := writeConfigFile(data); err != nil {
  27.         log.Fatal(err)
  28.     }
  29. }
  30. func experimentsYAML() ([]byte, error) {
  31.     var exps []*Experiment
  32.     for e := range internal.Experiments {
  33.         exps = append(exps, &Experiment{
  34.             Name:    e,
  35.             Rollout: 100,
  36.         })
  37.     }
  38.     sort.Slice(exps, func(i, j int) bool { return exps[i].Name < exps[j].Name })
  39.     data := map[string][]*Experiment{"experiments": exps}
  40.     return yaml.Marshal(&data)
  41. }
  42. func writeConfigFile(data []byte) error {
  43.     path, err := os.Getwd()
  44.     if err != nil {
  45.         return err
  46.     }
  47.     p := strings.TrimSuffix(path, "/devtools/cmd/run_beta") + "/experiment.yaml"
  48.     f, err := os.Create(p)
  49.     if err != nil {
  50.         return err
  51.     }
  52.     if _, err = f.Write(data); err != nil {
  53.         // Ignore f.Close() error, since f.Write returned an error.
  54.         _ = f.Close()
  55.         return err
  56.     }
  57.     if err := f.Close(); err != nil {
  58.         return err
  59.     }
  60.     fmt.Printf("Set `export GO_DISCOVERY_CONFIG_DYNAMIC=%q` to enable experiments.\n", p)
  61.     return nil
  62. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×