utils

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2017 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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"

Types

This section is empty.

Jump to

Keyboard shortcuts

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