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.
Macros ¶
Cloudprober configs support some macros to make configs construction easier:
*) env: get the value of an environment variable. A common use-case for this is using it inside a kubernetes cluster. Example:
# Use an environment variable in probe config probe { name: "dns_google_jp" type: DNS targets { host_names: "1.1.1.1" } dns_probe { resolved_domain: "{{env "TEST_DOM"}}" } interval_msec: 5000 # 5s timeout_msec: 1000 # 1s } # Then run cloudprober as: TEST_DOM=google.co.jp ./cloudprober --config_file=cloudprober.cfg
*) 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 - mkMap 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" mkMap "typ" "PING" "name" "ping_google"}}
{{template "probeTmpl" mkMap "typ" "HTTP" "name" "http_google"}}
*) mkSlice - mkSlice returns a slice consisting of the 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}}" } {{end}} {{end}}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse processes a config file as a Go text template and parses it into a ProberConfig proto.
func ParseTemplate ¶
ParseTemplate processes a config file as a Go text template.
func ReadFromGCEMetadata ¶
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 ¶
This section is empty.