config

package
v0.0.0-...-eff70b3 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package config provides parser for cloudprober configs.

Example Usage:

c, err := config.Parse(*configFile, sysvars.SysVars())

Parse processes a config file as a Go text template and parses it into a ProberConfig proto. Config file is processed using the provided variable map (usually GCP metadata variables) and some predefined macros.

Cloudprober configs support following macros:

*) mkSlice - mkSlice returns a slice consisting of arguments. Example use in config:

# Sharded VM-to-VM connectivity checks over internal IP
# Instance name format: ig-<zone>-<shard>-<random-characters>, e.g. ig-asia-east1-a-00-ftx1

{{with $shards := mkSlice "00" "01" "02" "03"}}
{{range $_, $shard := $shards}}
{{$targets := printf "^ig-([^-]+-[^-]+-[^-]+)-%s-[^-]+$" $shard}}
{{$run_on := printf "^ig-([^-]+-[^-]+-[^-]+)-%s-[^-.]+(|[.].*)$" $shard}}

probe {
	name: "vm-to-vm-{{$shard}}"
	type: PING
	targets {
		gce_targets {
			instances {}
		}
		regex: "{{$targets}}"
	}
	run_on: "{{$run_on}}"
}

*) extractSubstring - extract substring from a string using regex. Example use in config:

# Sharded VM-to-VM connectivity checks over internal IP
# Instance name format: ig-<zone>-<shard>-<random-characters>, e.g. ig-asia-east1-a-00-ftx1
{{$shard := .instance | extractSubstring "[^-]+-[^-]+-[^-]+-[^-]+-([^-]+)-.*" 1}}
probe {
	name: "vm-to-vm-{{$shard}}"
	type: PING
	targets {
		gce_targets {
			instances {}
		}
		regex: "{{$targets}}"
	}
	run_on: "{{$run_on}}"
}

Package config is a generated protocol buffer package.

It is generated from these files:

github.com/google/cloudprober/config/config.proto

It has these top-level messages:

ProberConfig

Index

Constants

View Source
const Default_ProberConfig_SysvarsEnvVar string = "SYSVARS"
View Source
const Default_ProberConfig_SysvarsIntervalMsec int32 = 10000

Variables

This section is empty.

Functions

func DefaultConfig

func DefaultConfig() string

DefaultConfig returns the default config string.

func ParseTemplate

func ParseTemplate(config string, sysVars map[string]string) (string, error)

ParseTemplate processes a config file as a Go text template.

func ReadFromGCEMetadata

func ReadFromGCEMetadata(metadataKeyName string) (string, error)

ReadFromGCEMetadata reads the config from the GCE metadata. To allow for instance level as well as project-wide config, we look for the config in metadata in the following manner:

	a. If cloudprober_config is set in the instance's custom metadata, its
        value is returned.
	b. If (and only if), the key is not found in the step above, we look for
	   the same key in the project's custom metadata.

Types

type ProberConfig

type ProberConfig struct {
	// Probes to run.
	Probe []*cloudprober_probes.ProbeDef `protobuf:"bytes,1,rep,name=probe" json:"probe,omitempty"`
	// Surfacers are used to export probe results for further processing.
	// If no surfacer is configured, a prometheus and a file surfacer are
	// initialized:
	//  - Prometheus makes probe results available at http://<host>:9313/metrics.
	//  - File surfacer writes results to stdout.
	//
	// You can disable default surfacers (in case you want no surfacer at all), by
	// adding the following to your config:
	//   surfacer {}
	Surfacer []*cloudprober_surfacer.SurfacerDef `protobuf:"bytes,2,rep,name=surfacer" json:"surfacer,omitempty"`
	// Servers to run inside cloudprober. These servers can serve as targets for
	// other probes.
	Server []*cloudprober_servers.ServerDef `protobuf:"bytes,3,rep,name=server" json:"server,omitempty"`
	// Port for the default HTTP server. This port is also used for prometheus
	// exporter (URL /metrics). Default port is 9313. If not specified in the
	// config, default port can be overridden by the environment variable
	// CLOUDPROBER_PORT.
	Port *int32 `protobuf:"varint,96,opt,name=port" json:"port,omitempty"`
	// How often to export system variables. To learn more about system variables:
	// http://godoc.org/github.com/google/cloudprober/sysvars.
	SysvarsIntervalMsec *int32 `protobuf:"varint,97,opt,name=sysvars_interval_msec,json=sysvarsIntervalMsec,def=10000" json:"sysvars_interval_msec,omitempty"`
	// Variables specified in this environment variable are exported as it is.
	// This is specifically useful to export information about system environment,
	// for example, docker image tag/digest-id, OS version etc. See
	// tools/cloudprober_startup.sh in the cloudprober directory for an example on
	// how to use these variables.
	SysvarsEnvVar *string `protobuf:"bytes,98,opt,name=sysvars_env_var,json=sysvarsEnvVar,def=SYSVARS" json:"sysvars_env_var,omitempty"`
	// Options for RTC reporter. RTC reporter reports information about the
	// current instance to a Runtime Config (RTC). This is useful if you want your
	// instance to be dynamically discoverable through RTC targets. This is
	// disabled by default.
	RtcReportOptions *cloudprober_targets_rtcreporter.RtcReportOptions `protobuf:"bytes,99,opt,name=rtc_report_options,json=rtcReportOptions" json:"rtc_report_options,omitempty"`
	// Global targets options. Per-probe options are specified within the probe
	// stanza.
	GlobalTargetsOptions *cloudprober_targets.GlobalTargetsOptions `protobuf:"bytes,100,opt,name=global_targets_options,json=globalTargetsOptions" json:"global_targets_options,omitempty"`
	XXX_unrecognized     []byte                                    `json:"-"`
}

func Parse

func Parse(config string, sysVars map[string]string) (*ProberConfig, error)

Parse processes a config file as a Go text template and parses it into a ProberConfig proto.

func (*ProberConfig) Descriptor

func (*ProberConfig) Descriptor() ([]byte, []int)

func (*ProberConfig) GetGlobalTargetsOptions

func (m *ProberConfig) GetGlobalTargetsOptions() *cloudprober_targets.GlobalTargetsOptions

func (*ProberConfig) GetPort

func (m *ProberConfig) GetPort() int32

func (*ProberConfig) GetProbe

func (m *ProberConfig) GetProbe() []*cloudprober_probes.ProbeDef

func (*ProberConfig) GetRtcReportOptions

func (*ProberConfig) GetServer

func (m *ProberConfig) GetServer() []*cloudprober_servers.ServerDef

func (*ProberConfig) GetSurfacer

func (m *ProberConfig) GetSurfacer() []*cloudprober_surfacer.SurfacerDef

func (*ProberConfig) GetSysvarsEnvVar

func (m *ProberConfig) GetSysvarsEnvVar() string

func (*ProberConfig) GetSysvarsIntervalMsec

func (m *ProberConfig) GetSysvarsIntervalMsec() int32

func (*ProberConfig) ProtoMessage

func (*ProberConfig) ProtoMessage()

func (*ProberConfig) Reset

func (m *ProberConfig) Reset()

func (*ProberConfig) String

func (m *ProberConfig) String() string

Jump to

Keyboard shortcuts

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