ParseError signals errors while parsing the simple and flat text-based
exchange format.
LineintMsgstring
Error implements the error interface.
T : error
SampleDecoder wraps a Decoder to extract samples from the metric families
decoded by the wrapped Decoder.
DecDecoderOpts*DecodeOptionsfdto.MetricFamily
Decode calls the Decode method of the wrapped Decoder and then extracts the
samples from the decoded MetricFamily into the provided model.Vector.
TextParser is used to parse the simple and flat text-based exchange format. Its
zero value is ready to use.
// Where the parsed input is read through.
currentBucketfloat64
// The most recent byte read.
currentIsHistogramCountboolcurrentIsHistogramSumbool
These tell us if the currently processed line ends on '_count' or
'_sum' respectively and belong to a summary/histogram, representing the sample
count and sum of that summary/histogram.
These tell us if the currently processed line ends on '_count' or
'_sum' respectively and belong to a summary/histogram, representing the sample
count and sum of that summary/histogram.
currentLabelPair*dto.LabelPair
The remaining member variables are only used for summaries/histograms.
// All labels including '__name__' but excluding 'quantile'/'le'
currentMF*dto.MetricFamilycurrentMetric*dto.MetriccurrentQuantilefloat64
// Re-used each time a token has to be gathered from multiple bytes.
// Most recent error.
Histogram specific.
// Key is created with LabelsToSignature.
// Tracks the line count for error messages.
metricFamiliesByNamemap[string]*dto.MetricFamily
Summary specific.
// Key is created with LabelsToSignature.
TextToMetricFamilies reads 'in' as the simple and flat text-based exchange
format and creates MetricFamily proto messages. It returns the MetricFamily
proto messages in a map where the metric names are the keys, along with any
error encountered.
If the input contains duplicate metrics (i.e. lines with the same metric name
and exactly the same label set), the resulting MetricFamily will contain
duplicate Metric proto messages. Similar is true for duplicate label
names. Checks for duplicates have to be performed separately, if required.
Also note that neither the metrics within each MetricFamily are sorted nor
the label pairs within each Metric. Sorting is not required for the most
frequent use of this method, which is sample ingestion in the Prometheus
server. However, for presentation purposes, you might want to sort the
metrics, and in some cases, you must sort the labels, e.g. for consumption by
the metric family injection hook of the Prometheus registry.
Summaries and histograms are rather special beasts. You would probably not
use them in the simple text format anyway. This method can deal with
summaries and histograms if they are presented in exactly the way the
text.Create function creates them.
This method must not be called concurrently. If you want to parse different
input concurrently, instantiate a separate Parser for each goroutine.
parseError sets p.err to a ParseError at the current line with the given
message.
readTokenAsLabelName copies a label name from p.buf into p.currentToken.
The first byte considered is the byte already read (now in p.currentByte).
The first byte not part of a label name is still copied into p.currentByte,
but not into p.currentToken.
readTokenAsLabelValue copies a label value from p.buf into p.currentToken.
In contrast to the other 'readTokenAs...' functions, which start with the
last read byte in p.currentByte, this method ignores p.currentByte and starts
with reading a new byte from p.buf. The first byte not part of a label value
is still copied into p.currentByte, but not into p.currentToken.
readTokenAsMetricName copies a metric name from p.buf into p.currentToken.
The first byte considered is the byte already read (now in p.currentByte).
The first byte not part of a metric name is still copied into p.currentByte,
but not into p.currentToken.
readTokenUntilNewline copies bytes from p.buf into p.currentToken. The first
byte considered is the byte already read (now in p.currentByte). The first
newline byte encountered is still copied into p.currentByte, but not into
p.currentToken. If recognizeEscapeSequence is true, two escape sequences are
recognized: '\\' translates into '\', and '\n' into a line-feed character.
All other escape sequences are invalid and cause an error.
readTokenUntilWhitespace copies bytes from p.buf into p.currentToken. The
first byte considered is the byte already read (now in p.currentByte). The
first whitespace byte encountered is still copied into p.currentByte, but not
into p.currentToken.
readingHelp represents the state where the last byte read (now in
p.currentByte) is the first byte of the docstring after 'HELP'.
readingLabels represents the state where the last byte read (now in
p.currentByte) is either the first byte of the label set (i.e. a '{'), or the
first byte of the value (otherwise).
readingMetricName represents the state where the last byte read (now in
p.currentByte) is the first byte of a metric name.
readingType represents the state where the last byte read (now in
p.currentByte) is the first byte of the type hint after 'HELP'.
readingValue represents the state where the last byte read (now in
p.currentByte) is the first byte of the sample value (i.e. a float).
(*T) reset(in io.Reader)(*T) setOrCreateCurrentMF()
skipBlankTab reads (and discards) bytes from p.buf until it encounters a byte
that is neither ' ' nor '\t'. That byte is left in p.currentByte.
skipBlankTabIfCurrentBlankTab works exactly as skipBlankTab but doesn't do
anything if p.currentByte is neither ' ' nor '\t'.
startComment represents the state where the next byte read from p.buf is the
start of a comment (or whitespace leading up to it).
startLabelName represents the state where the next byte read from p.buf is
the start of a label name (or whitespace leading up to it).
startLabelValue represents the state where the next byte read from p.buf is
the start of a (quoted) label value (or whitespace leading up to it).
startOfLine represents the state where the next byte read from p.buf is the
start of a line (or whitespace leading up to it).
startTimestamp represents the state where the next byte read from p.buf is
the start of the timestamp (or whitespace leading up to it).
Package-Level Functions (total 28, in which 6 are exported)
ExtractSamples builds a slice of samples from the provided metric
families. If an error occurrs during sample extraction, it continues to
extract from the remaining metric families. The returned error is the last
error that has occurred.
MetricFamilyToText converts a MetricFamily proto message into text format and
writes the resulting lines to 'out'. It returns the number of bytes written
and any error encountered. The output will have the same order as the input,
no further sorting is performed. Furthermore, this function assumes the input
is already sanitized and does not perform any sanity checks. If the input
contains duplicate metrics or invalid metric or label names, the conversion
will result in invalid text format output.
This method fulfills the type 'prometheus.encoder'.
Negotiate returns the Content-Type based on the given Accept header.
If no appropriate accepted type is found, FmtText is returned.
NewDecoder returns a new decoder based on the given input format.
If the input format does not imply otherwise, a text format decoder is returned.
NewEncoder returns a new encoder based on content type negotiation.
ResponseFormat extracts the correct format from a HTTP response header.
If no matching format can be found FormatUnknown is returned.
writeFloat is equivalent to fmt.Fprint with a float64 argument but hardcodes
a few common cases for increased efficiency. For non-hardcoded cases, it uses
strconv.AppendFloat to avoid allocations, similar to writeInt.
writeInt is equivalent to fmt.Fprint with an int64 argument but uses
strconv.AppendInt with a byte slice taken from a sync.Pool to avoid
allocations.
writeLabelPairs converts a slice of LabelPair proto messages plus the
explicitly given additional label pair into text formatted as required by the
text format and writes it to 'w'. An empty slice in combination with an empty
string 'additionalLabelName' results in nothing being written. Otherwise, the
label pairs are written, escaped as required by the text format, and enclosed
in '{...}'. The function returns the number of bytes written and any error
encountered.
writeSample writes a single sample in text format to w, given the metric
name, the metric proto message itself, optionally an additional label name
with a float64 value (use empty string as label name if not required), and
the value. The function returns the number of bytes written and any error
encountered.
Package-Level Variables (total 4, none are exported)
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.