From 2e30f1231b6686e69afe1abb199c57dfe98fba07 Mon Sep 17 00:00:00 2001 From: Ondrej Kokes Date: Thu, 29 Feb 2024 16:40:53 +0100 Subject: [PATCH] docs: textparse.Parser return type mismatch The docs suggest the Next method returns a bool, but that's not the case (`Entry` is an int). ``` // Next advances the parser to the next sample. It returns false if no // more samples were read or an error occurred. Next() (Entry, error) ``` The docs were first added in d80a3de235b5f1349591420c55925d82ca49204e in 2017. Back then the signature was indeed `func (p *Parser) Next() bool`. But then it got refactored in 76a4a46cb0b78ab5b25f099693e9ddd23860a38d and the signature changed with it, yet docs stayed the same - and eventually made their way into the `Parser` interface. However, the Protobuf parser does have the right wording: 5de2df752f39de05c6ab53a9ec93f797027da0b9 ``` // Next advances the parser to the next "sample" (emulating the behavior of a // text format parser). It returns (EntryInvalid, io.EOF) if no samples were // read. ``` Changing all other implementations (and the interface itself) to match this doc. Signed-off-by: Ondrej Kokes --- model/textparse/interface.go | 4 ++-- model/textparse/openmetricsparse.go | 4 ++-- model/textparse/promparse.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/model/textparse/interface.go b/model/textparse/interface.go index 2e8c40e72..df01dbc34 100644 --- a/model/textparse/interface.go +++ b/model/textparse/interface.go @@ -71,8 +71,8 @@ type Parser interface { // if the scrape protocol or metric type does not support created timestamps. CreatedTimestamp() *int64 - // Next advances the parser to the next sample. It returns false if no - // more samples were read or an error occurred. + // Next advances the parser to the next sample. + // It returns (EntryInvalid, io.EOF) if no samples were read. Next() (Entry, error) } diff --git a/model/textparse/openmetricsparse.go b/model/textparse/openmetricsparse.go index ea92bc55f..b7ad1dd85 100644 --- a/model/textparse/openmetricsparse.go +++ b/model/textparse/openmetricsparse.go @@ -239,8 +239,8 @@ func (p *OpenMetricsParser) parseError(exp string, got token) error { return fmt.Errorf("%s, got %q (%q) while parsing: %q", exp, p.l.b[p.l.start:e], got, p.l.b[p.start:e]) } -// Next advances the parser to the next sample. It returns false if no -// more samples were read or an error occurred. +// Next advances the parser to the next sample. +// It returns (EntryInvalid, io.EOF) if no samples were read. func (p *OpenMetricsParser) Next() (Entry, error) { var err error diff --git a/model/textparse/promparse.go b/model/textparse/promparse.go index 54b5306e6..a611f3aea 100644 --- a/model/textparse/promparse.go +++ b/model/textparse/promparse.go @@ -280,8 +280,8 @@ func (p *PromParser) parseError(exp string, got token) error { return fmt.Errorf("%s, got %q (%q) while parsing: %q", exp, p.l.b[p.l.start:e], got, p.l.b[p.start:e]) } -// Next advances the parser to the next sample. It returns false if no -// more samples were read or an error occurred. +// Next advances the parser to the next sample. +// It returns (EntryInvalid, io.EOF) if no samples were read. func (p *PromParser) Next() (Entry, error) { var err error