metricsdbflag

package
v0.1.33 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: MIT Imports: 10 Imported by: 11

Documentation

Overview

Package metricsdbflag provides a standard flag set for configuring the metrics package and starting metrics collection. Typical usage would be something like:

	import(
		"bitbucket.org/pcas/metrics/metricsdb/metricsdbflag"
     "bitbucket.org/pcastools/flag"
		"context"
		...
	)

// parseArgs parses the command-line flags and environment variables.

func parseArgs() error {
	// Define the usage message and command-line flags
	flag.SetGlobalHeader(fmt.Sprintf("...header for the usage message...")
	flag.SetName("Options")
	flag.Add(
		flag.String("foo", ...),
     ...
	)
 // Add the flagset that controls metrics collection
	metricsSet := metricsdbflag.NewMetricsSet(nil)
	flag.AddSet(metricsSet)
	// Parse the flags
	flag.Parse()
 // Do any additional sanity checks
 ...
	// Should we start collecting metrics?
	if metricsSet.WithMetrics() {
		if err := metricsdbflag.SetMetrics(
			context.Background(),
			metricsSet.ClientConfig(),
			Name,
		); err != nil {
			return err
		}
	}
 return nil
 }

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetMetrics

func SetMetrics(ctx context.Context, c *metricsdb.ClientConfig, name string) error

SetMetrics sets the global metrics metrics.Metrics() as specified by the client config c and tagged with the given program name. This will also update the default metrics config to c.

Types

type MetricsSet

type MetricsSet struct {
	*Set
	// contains filtered or unexported fields
}

MetricsSet represents a set of command-line flags defined by a client config, and also provides a flag to turn metrics collection on or off.

func NewMetricsSet

func NewMetricsSet(c *metricsdb.ClientConfig) *MetricsSet

NewMetricsSet returns a set of command-line flags as described by NewSet. In addition, this set provides a flag to turn metrics collection on or off.

func (*MetricsSet) Flags

func (s *MetricsSet) Flags() []flag.Flag

Flags returns the members of the set.

func (*MetricsSet) WithMetrics

func (s *MetricsSet) WithMetrics() bool

WithMetrics returns true iff the user selected to enable metrics collection. This should only be called after the set has been successfully validated.

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set represents a set of command-line flags defined by a client config.

func NewSet

func NewSet(c *metricsdb.ClientConfig) *Set

NewSet returns a set of command-line flags with defaults given by c. If c is nil then the metricsdb.DefaultConfig() will be used. Note that this does not update the default client config, nor does this update c. To recover the updated client config after parse, call the ClientConfig() method on the returned set.

func (*Set) ClientConfig

func (s *Set) ClientConfig() *metricsdb.ClientConfig

ClientConfig returns the client config described by this set. This should only be called after the set has been successfully validated.

func (*Set) Flags

func (s *Set) Flags() []flag.Flag

Flags returns the members of the set.

func (*Set) Name

func (*Set) Name() string

Name returns the name of this collection of flags.

func (*Set) UsageFooter

func (*Set) UsageFooter() string

UsageFooter returns the footer for the usage message for this flag set.

func (*Set) UsageHeader

func (*Set) UsageHeader() string

UsageHeader returns the header for the usage message for this flag set.

func (*Set) Validate

func (s *Set) Validate() error

Validate validates the flag set.

Jump to

Keyboard shortcuts

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