mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 14:09:41 -08:00
pkg/textparse: add documentation
This commit is contained in:
parent
db48726a6b
commit
d80a3de235
|
@ -295,7 +295,7 @@ yystate27:
|
||||||
|
|
||||||
yyrule1: // \0
|
yyrule1: // \0
|
||||||
{
|
{
|
||||||
return 0
|
return eof
|
||||||
}
|
}
|
||||||
yyrule2: // #[^\r\n]*\n
|
yyrule2: // #[^\r\n]*\n
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
|
//go:generate go get github.com/cznic/golex
|
||||||
//go:generate golex -o=lex.l.go lex.l
|
//go:generate golex -o=lex.l.go lex.l
|
||||||
|
|
||||||
|
// Package textparse contains an efficient parser for the Prometheus text format.
|
||||||
package textparse
|
package textparse
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -38,16 +41,21 @@ func (l *lexer) Error(es string) {
|
||||||
l.err = errors.New(es)
|
l.err = errors.New(es)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parser parses samples from a byte slice of samples in the official
|
||||||
|
// Prometheus text exposition format.
|
||||||
type Parser struct {
|
type Parser struct {
|
||||||
l *lexer
|
l *lexer
|
||||||
err error
|
err error
|
||||||
val float64
|
val float64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New returns a new parser of the byte slice.
|
||||||
func New(b []byte) *Parser {
|
func New(b []byte) *Parser {
|
||||||
return &Parser{l: &lexer{b: b}}
|
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 {
|
func (p *Parser) Next() bool {
|
||||||
switch p.l.Lex() {
|
switch p.l.Lex() {
|
||||||
case 0, -1:
|
case 0, -1:
|
||||||
|
@ -58,10 +66,13 @@ func (p *Parser) Next() bool {
|
||||||
panic("unexpected")
|
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) {
|
func (p *Parser) At() ([]byte, *int64, float64) {
|
||||||
return p.l.b[p.l.mstart:p.l.mend], nil, p.l.val
|
return p.l.b[p.l.mstart:p.l.mend], nil, p.l.val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Err returns the current error.
|
||||||
func (p *Parser) Err() error {
|
func (p *Parser) Err() error {
|
||||||
if p.err != nil {
|
if p.err != nil {
|
||||||
return p.err
|
return p.err
|
||||||
|
@ -72,6 +83,7 @@ func (p *Parser) Err() error {
|
||||||
return p.l.err
|
return p.l.err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Metric writes the labels of the current sample into the passed labels.
|
||||||
func (p *Parser) Metric(l *labels.Labels) {
|
func (p *Parser) Metric(l *labels.Labels) {
|
||||||
// Allocate the full immutable string immediately, so we just
|
// Allocate the full immutable string immediately, so we just
|
||||||
// have to create references on it below.
|
// have to create references on it below.
|
||||||
|
|
|
@ -290,7 +290,6 @@ func (api *API) series(r *http.Request) (interface{}, *apiError) {
|
||||||
} else {
|
} else {
|
||||||
end = maxTime
|
end = maxTime
|
||||||
}
|
}
|
||||||
fmt.Println("q range", timestamp.FromTime(start), timestamp.FromTime(end), r.FormValue("start"), r.FormValue("end"))
|
|
||||||
|
|
||||||
var matcherSets [][]*labels.Matcher
|
var matcherSets [][]*labels.Matcher
|
||||||
for _, s := range r.Form["match[]"] {
|
for _, s := range r.Form["match[]"] {
|
||||||
|
|
Loading…
Reference in a new issue