common

package
v0.0.0-...-0ada750 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2024 License: BSD-3-Clause Imports: 16 Imported by: 14

Documentation

Overview

Common tool initialization. import only from package main.

Index

Constants

View Source
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

View Source
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",
	}
)

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

func FSNewMultiStringFlag(fs *flag.FlagSet, name string, defaults []string, usage string) *[]string

FSNewMultiStringFlag returns a []string flag, loaded with the given defaults, usage string and name.

func Init

func Init()

Init runs commonly-used initialization metrics.

func InitWith

func InitWith(appName string, opts ...Opt) error

InitWith takes Opt's and initializes each service, where services are Prometheus, etc.

func InitWithMust

func InitWithMust(appName string, opts ...Opt)

InitWithMust calls InitWith and fails fatally if an error is encountered.

func MultiStringFlagVar

func MultiStringFlagVar(target *[]string, name string, defaults []string, usage string)

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.

func NewMultiStringFlag

func NewMultiStringFlag(name string, defaults []string, usage string) *[]string

NewMultiStringFlag returns a []string flag, loaded with the given defaults, usage string and name.

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

func CloudLogging(local *bool, projectID string) Opt

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

func FlagSetOpt(flagSet *flag.FlagSet) Opt

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

func PrometheusOpt(port *string) Opt

PrometheusOpt creates an Opt to initialize Prometheus metrics when passed to InitWith().

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL