Documentation ¶
Overview ¶
Common tool initialization. import only from package main.
Index ¶
- Constants
- Variables
- func Defer()
- func FSMultiStringFlagVar(fs *flag.FlagSet, target *[]string, name string, defaults []string, ...)
- func FSNewMultiStringFlag(fs *flag.FlagSet, name string, defaults []string, usage string) *[]string
- func Init()
- func InitWith(appName string, opts ...Opt) error
- func InitWithMust(appName string, opts ...Opt)
- func MultiStringFlagVar(target *[]string, name string, defaults []string, usage string)
- func NewMultiStringFlag(name string, defaults []string, usage string) *[]string
- type Opt
Constants ¶
const ( // Compute Engine project ID. // TODO(dogben): This probably should be passed as a command-line flag wherever it's used. PROJECT_ID = "google.com:skia-buildbots" REPO_ANGLE = "https://chromium.googlesource.com/angle/angle.git" REPO_CHROMIUM = "https://chromium.googlesource.com/chromium/src.git" REPO_DEPOT_TOOLS = "https://chromium.googlesource.com/chromium/tools/depot_tools.git" REPO_ESKIA = "https://skia.googlesource.com/eskia.git" REPO_K8S_CONFIG = "https://skia.googlesource.com/k8s-config.git" REPO_LOTTIE_CI = "https://skia.googlesource.com/lottie-ci.git" REPO_PDFIUM = "https://pdfium.googlesource.com/pdfium.git" REPO_SKCMS = "https://skia.googlesource.com/skcms.git" REPO_SKIA = "https://skia.googlesource.com/skia.git" REPO_SKIABOT_TEST = "https://skia.googlesource.com/skiabot-test.git" REPO_SKIA_AUTOROLL_INTERNAL_CONFIG = "https://skia.googlesource.com/skia-autoroll-internal-config.git" REPO_SKIA_INFRA = "https://skia.googlesource.com/buildbot.git" REPO_SKIA_INTERNAL = "https://skia.googlesource.com/skia_internal.git" REPO_SKIA_INTERNAL_TEST = "https://skia.googlesource.com/internal_test.git" REPO_WEBRTC = "https://webrtc.googlesource.com/src.git" SAMPLE_PERIOD = time.Minute )
Variables ¶
var ( // PROJECT_REPO_MAPPING is a mapping of project names to repo URLs. It // is filled in during init(). PROJECT_REPO_MAPPING = map[string]string{} // REPO_PROJECT_MAPPING is a mapping of repo URLs to project names. REPO_PROJECT_MAPPING = map[string]string{ REPO_ESKIA: "eskia", REPO_K8S_CONFIG: "k8s-config", REPO_LOTTIE_CI: "lottie-ci", REPO_SKCMS: "skcms", REPO_SKIA: "skia", REPO_SKIABOT_TEST: "skiabot-test", REPO_SKIA_AUTOROLL_INTERNAL_CONFIG: "skia-autoroll-internal-config", REPO_SKIA_INFRA: "skiabuildbot", REPO_SKIA_INTERNAL: "skia-internal", REPO_SKIA_INTERNAL_TEST: "skia-internal-test", } )
var FlagSet *flag.FlagSet = flag.CommandLine
FlagSet is the flag.FlagSet we use to parse command line flags. It defaults to flag.CommandLine, but can be over-ridden with FlagSetOpt.
Functions ¶
func Defer ¶
func Defer()
Any programs which use a variant of common.Init should do `defer common.Defer()` in main.
func FSMultiStringFlagVar ¶
func FSMultiStringFlagVar(fs *flag.FlagSet, target *[]string, name string, defaults []string, usage string)
FSMultiStringFlagVar defines a MultiString flag with the specified name, defaults, and usage string. The argument target points to a []string variable in which to store the values of the flag.
func FSNewMultiStringFlag ¶
FSNewMultiStringFlag returns a []string flag, loaded with the given defaults, usage string and name.
func InitWith ¶
InitWith takes Opt's and initializes each service, where services are Prometheus, etc.
func InitWithMust ¶
InitWithMust calls InitWith and fails fatally if an error is encountered.
func MultiStringFlagVar ¶
MultiStringFlagVar defines a MultiString flag with the specified name, defaults, and usage string. The argument target points to a []string variable in which to store the values of the flag.
Types ¶
type Opt ¶
type Opt interface {
// contains filtered or unexported methods
}
Opt represents the initialization parameters for a single init service, where services are Prometheus, etc.
Initializing flags, metrics, and logging, with two options for metrics, and another option for logging is complicated by the fact that some initializations are order dependent, and each app may want a different subset of options. The solution is to encapsulate each optional piece, prom, etc, into its own Opt, and then initialize each Opt in the right order.
Not only are the Opts order dependent but initialization needs to be broken into two phases, preinit() and init().
The desired order for all Opts is:
0 - base 1 - cloudlogging 3 - prometheus 4 - slog
Construct the Opts that are desired and pass them to common.InitWith(), i.e.:
common.InitWith( "skiaperf", common.PrometheusOpt(promPort), common.CloudLoggingOpt(), )
func CloudLogging ¶
CloudLogging creates an Opt to initialize cloud logging when passed to InitWith().
Uses the instance service account for auth. No cloud logging is done if local is true.
func FlagSetOpt ¶
FlagSetOpt allows changing the flag.FlagSet used to parse command line arguments.
If this Opt is not used then flag.CommandLine is used as the default.
func PrometheusOpt ¶
PrometheusOpt creates an Opt to initialize Prometheus metrics when passed to InitWith().