Documentation
¶
Overview ¶
Package config provides parser for cloudprober configs.
Example Usage:
c, err := config.ParseTemplate(config, sysvars.SysVars())
ParseTemplate processes a config file as a Go text template using the provided variable map (usually GCP metadata variables) and some predefined macros.
Macros ¶
Cloudprober configs support Go text templates with sprig functions (https://masterminds.github.io/sprig/) and the following macros to make configs construction easier:
gceCustomMetadata
Get value of a GCE custom metadata key. It first looks for the given key in
the instance's custom metadata and if it is not found there, it looks for it
in the project's custom metaata.
# Get load balancer IP from metadata.
probe {
name: "http_lb"
type: HTTP
targets {
host_names: "{{gceCustomMetadata "lb_ip"}}"
}
}
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}}"
}
mkMap or dict
Same as dict: https://masterminds.github.io/sprig/dicts.html. Returns a
map built from the arguments. It's useful as Go templates take only one
argument. With this function, we can create a map of multiple values and
pass it to a template. Example use in config:
{{define "probeTmpl"}}
probe {
type: {{.typ}}
name: "{{.name}}"
targets {
host_names: "www.google.com"
}
}
{{end}}
{{template "probeTmpl" dict "typ" "PING" "name" "ping_google"}}
{{template "probeTmpl" dict "typ" "HTTP" "name" "http_google"}}
mkSlice or list
Same as list: https://masterminds.github.io/sprig/lists.html. It can be
used with the built-in'range' function to replicate text.
{{with $regions := list "us=central1" "us-east1"}}
{{range $_, $region := $regions}}
probe {
name: "service-a-{{$region}}"
type: HTTP
targets {
host_names: "service-a.{{$region}}.corp.xx.com"
}
}
{{end}}
{{end}}
configDir
configDir expands to the config file's directory. This is useful to
specify files relative to the config file.
probe {
name: "test_x"
type: EXTERNAL
probe_external {
# test_x.sh is in the same directory as the config file.
command: "{{configDir}}/test_x.sh"
}
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var EnvRegex = regexp.MustCompile(`\*\*\$([^*\s]+)\*\*`)
EnvRegex is the regex used to find environment variable placeholders in the config file. The placeholders are of the form **$<env_var_name>**, and are added during Go template processing for envSecret functions.
Functions ¶
func ConfigTest ¶ added in v0.12.9
func ConfigTest(cs ConfigSource) error
func DumpConfig ¶ added in v0.12.9
func DumpConfig(outFormat string, cs ConfigSource) ([]byte, error)
Types ¶
type ConfigSource ¶ added in v0.13.1
type ConfigSource interface {
GetConfig() (*configpb.ProberConfig, error)
RawConfig() string
ParsedConfig() string
}
func ConfigSourceWithFile ¶ added in v0.13.1
func ConfigSourceWithFile(fileName string, opts ...Option) ConfigSource
func DefaultConfigSource ¶ added in v0.13.1
func DefaultConfigSource(opts ...Option) ConfigSource
type Option ¶ added in v0.13.7
type Option func(ConfigSource) ConfigSource
func WithBaseVars ¶ added in v0.13.7
func WithSurfacerConfig ¶ added in v0.13.7
Click to show internal directories.
Click to hide internal directories.