From d80a3de235b5f1349591420c55925d82ca49204e Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Mon, 16 Jan 2017 20:34:49 +0100 Subject: [PATCH] pkg/textparse: add documentation --- pkg/textparse/lex.l.go | 2 +- pkg/textparse/parse.go | 12 ++++++++++++ web/api/v1/api.go | 3 +-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/textparse/lex.l.go b/pkg/textparse/lex.l.go index 8f308c6eb..6a4315682 100644 --- a/pkg/textparse/lex.l.go +++ b/pkg/textparse/lex.l.go @@ -295,7 +295,7 @@ yystate27: yyrule1: // \0 { - return 0 + return eof } yyrule2: // #[^\r\n]*\n { diff --git a/pkg/textparse/parse.go b/pkg/textparse/parse.go index 6a41e4c7c..51d08b932 100644 --- a/pkg/textparse/parse.go +++ b/pkg/textparse/parse.go @@ -1,4 +1,7 @@ +//go:generate go get github.com/cznic/golex //go:generate golex -o=lex.l.go lex.l + +// Package textparse contains an efficient parser for the Prometheus text format. package textparse import ( @@ -38,16 +41,21 @@ func (l *lexer) Error(es string) { l.err = errors.New(es) } +// Parser parses samples from a byte slice of samples in the official +// Prometheus text exposition format. type Parser struct { l *lexer err error val float64 } +// New returns a new parser of the byte slice. func New(b []byte) *Parser { return &Parser{l: &lexer{b: b}} } +// Next advances the parser to the next sample. It returns false if no +// more samples were read or an error occurred. func (p *Parser) Next() bool { switch p.l.Lex() { case 0, -1: @@ -58,10 +66,13 @@ func (p *Parser) Next() bool { panic("unexpected") } +// At returns the bytes of the metric, the timestamp if set, and the value +// of the current sample. func (p *Parser) At() ([]byte, *int64, float64) { return p.l.b[p.l.mstart:p.l.mend], nil, p.l.val } +// Err returns the current error. func (p *Parser) Err() error { if p.err != nil { return p.err @@ -72,6 +83,7 @@ func (p *Parser) Err() error { return p.l.err } +// Metric writes the labels of the current sample into the passed labels. func (p *Parser) Metric(l *labels.Labels) { // Allocate the full immutable string immediately, so we just // have to create references on it below. diff --git a/web/api/v1/api.go b/web/api/v1/api.go index de3eeb58d..6e2e66da0 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -290,8 +290,7 @@ func (api *API) series(r *http.Request) (interface{}, *apiError) { } else { end = maxTime } - fmt.Println("q range", timestamp.FromTime(start), timestamp.FromTime(end), r.FormValue("start"), r.FormValue("end")) - + var matcherSets [][]*labels.Matcher for _, s := range r.Form["match[]"] { matchers, err := promql.ParseMetricSelector(s)