utils

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: May 30, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TmplFuncMap = template.FuncMap{
	"replace": replace,
	"split":   split,
	"escape":  escape,
	"isSet":   isSet,
}

TmplFuncMap expose custom go template functions

Functions

func CheckOverflow

func CheckOverflow(m map[string]interface{}, ctx string) error

CheckOverflow enforce m to be empty. Usefull to detect unknown fields.

func Escape

func Escape(tv string) string

Escape escapes a model.LabelValue into runes allowed in Graphite. The runes allowed in Graphite are all single-byte. This function encodes the arbitrary byte sequence found in this TagValue in way very similar to the traditional percent-encoding (https://en.wikipedia.org/wiki/Percent-encoding):

- The string that underlies TagValue is scanned byte by byte.

  • If a byte represents a legal Graphite rune with the exception of '%', '/', '=' and '.', that byte is directly copied to the resulting byte slice. % is used for percent-encoding of other bytes. / is not usable in filenames. = is used when generating the path to associate values to labels. . already means something for Graphite and thus can't be used in a value.
  • If the byte is any of (){},=.'"\, then a '\' will be prepended to it. We do not percent-encode them since they are explicitly usable in this way in Graphite.
  • All other bytes are replaced by '%' followed by two bytes containing the uppercase ASCII representation of their hexadecimal value.

This encoding allows to save arbitrary Go strings in Graphite. That's required because Prometheus label values can contain anything. Using percent encoding makes it easy to unescape, even in javascript.

Examples:

"foo-bar-42" -> "foo-bar-42"

"foo_bar%42" -> "foo_bar%2542"

"http://example.org:8080" -> "http:%2F%2Fexample%2Eorg:8080"

"Björn's email: bjoern@soundcloud.com" -> "Bj%C3%B6rn's%20email:%20bjoern%40soundcloud.com"

"日" -> "%E6%97%A5"

func FetchURL

func FetchURL(ctx context.Context, logger log.Logger, u *url.URL) ([]byte, error)

FetchURL return body of a fetched url.URL

func PrepareURL

func PrepareURL(schemeHost string, path string, params map[string]string) (*url.URL, error)

PrepareURL return an url.URL from it's parameters

func Unescape added in v0.0.16

func Unescape(tv string) string

Unescape takes string that have been escape to comply graphite's storage format and return their original value

Types

This section is empty.

Jump to

Keyboard shortcuts

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