config

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: Apache-2.0 Imports: 9 Imported by: 12

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.

	Example:

	probe {
	  name: "dns_google_jp"
	  type: DNS
	  targets {
	    host_names: "1.1.1.1"
	  }
	  dns_probe {
	    resolved_domain: "{{env "TEST_DOM"}}"
	  }
	}

	# Then run cloudprober as:
	TEST_DOM=google.co.jp ./cloudprober --config_file=cloudprober.cfg

 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
	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
	Returns a slice consisting of the arguments. It can be used with the built-in
	'range' function to replicate text.

	{{with $regions := mkSlice "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}}

Index

Constants

This section is empty.

Variables

View Source
var ReadFromGCEMetadata = func(metadataKeyName string) (string, error) {
	val, err := metadata.InstanceAttributeValue(metadataKeyName)

	if _, notFound := err.(metadata.NotDefinedError); !notFound {
		return val, err
	}

	return metadata.ProjectAttributeValue(metadataKeyName)
}

ReadFromGCEMetadata returns the value of GCE custom metadata variables. To allow for instance level as project level variables, it looks for metadata variable in the following order: a. If the given key 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.

Functions

func DefaultConfig

func DefaultConfig() string

DefaultConfig returns the default config string.

func Parse

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

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

func ParseForTest added in v0.10.8

func ParseForTest(config string, sysVars map[string]string) (*configpb.ProberConfig, error)

ParseForTest processes a config file as a Go text template in test mode and parses it into a ProberConfig proto. This function is useful for testing configs.

func ParseTemplate

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

ParseTemplate processes a config file as a Go text template.

Types

This section is empty.

Directories

Path Synopsis
Package runconfig stores cloudprober config that is specific to a single invocation.
Package runconfig stores cloudprober config that is specific to a single invocation.

Jump to

Keyboard shortcuts

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