config

package
v0.0.0-...-e1c190b Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2018 License: Apache-2.0 Imports: 7 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}}"
}

Index

Constants

This section is empty.

Variables

This section is empty.

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 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

This section is empty.

Directories

Path Synopsis
Package proto is a generated protocol buffer package.
Package proto is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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