mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
chore: comments and readability updates
Signed-off-by: Manik Rana <manikrana54@gmail.com>
This commit is contained in:
parent
49bf90c897
commit
debe023afa
|
@ -95,21 +95,26 @@ type OpenMetricsParser struct {
|
|||
exemplarTs int64
|
||||
hasExemplarTs bool
|
||||
|
||||
// lines ending with _created are skipped by default as they are
|
||||
// parsed by the CreatedTimestamp method. The skipCT flag is set to
|
||||
// false when the CreatedTimestamp method is called.
|
||||
skipCTSeries bool
|
||||
}
|
||||
|
||||
type openMetricsParserOptions struct {
|
||||
// SkipCT skips the parsing of _created lines.
|
||||
SkipCTSeries bool
|
||||
}
|
||||
|
||||
// SkipCTSeries skips the parsing of _created lines.
|
||||
type OpenMetricsOption func(*openMetricsParserOptions)
|
||||
|
||||
func WithOMParserCTSeriesSkipped(skipCTSeries bool) OpenMetricsOption {
|
||||
// WithOMParserCTSeriesSkipped turns off exposing _created lines
|
||||
// as series, which makes those only used for parsing created timestamp
|
||||
// for `CreatedTimestamp` method purposes.
|
||||
//
|
||||
// It's recommended to use this option to avoid using _created lines for other
|
||||
// purposes than created timestamp, but leave false by default for the
|
||||
// best-effort compatibility.
|
||||
func WithOMParserCTSeriesSkipped() OpenMetricsOption {
|
||||
return func(o *openMetricsParserOptions) {
|
||||
o.SkipCTSeries = skipCTSeries
|
||||
o.SkipCTSeries = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,17 +129,17 @@ func NewOpenMetricsParser(b []byte, st *labels.SymbolTable) Parser {
|
|||
|
||||
// NewOpenMetricsParserWithOpts returns a new parser of the byte slice with options.
|
||||
func NewOpenMetricsParserWithOpts(b []byte, st *labels.SymbolTable, opts ...OpenMetricsOption) Parser {
|
||||
options := &openMetricsParserOptions{}
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
}
|
||||
|
||||
parser := &OpenMetricsParser{
|
||||
l: &openMetricsLexer{b: b},
|
||||
builder: labels.NewScratchBuilderWithSymbolTable(st, 16),
|
||||
skipCTSeries: options.SkipCTSeries,
|
||||
}
|
||||
DefaultOpenMetricsParserOptions := openMetricsParserOptions{
|
||||
SkipCTSeries: true,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(&DefaultOpenMetricsParserOptions)
|
||||
}
|
||||
parser.skipCTSeries = DefaultOpenMetricsParserOptions.SkipCTSeries
|
||||
|
||||
return parser
|
||||
}
|
||||
|
|
|
@ -330,7 +330,7 @@ fizz_created 17.0`
|
|||
},
|
||||
}
|
||||
|
||||
p := NewOpenMetricsParserWithOpts([]byte(input), labels.NewSymbolTable(), WithOMParserCTSeriesSkipped(true))
|
||||
p := NewOpenMetricsParserWithOpts([]byte(input), labels.NewSymbolTable(), WithOMParserCTSeriesSkipped())
|
||||
checkParseResults(t, p, exp)
|
||||
}
|
||||
|
||||
|
@ -918,7 +918,7 @@ foobar{quantile="0.99"} 150.0`
|
|||
},
|
||||
}
|
||||
|
||||
p := NewOpenMetricsParserWithOpts([]byte(input), labels.NewSymbolTable(), WithOMParserCTSeriesSkipped(true))
|
||||
p := NewOpenMetricsParserWithOpts([]byte(input), labels.NewSymbolTable(), WithOMParserCTSeriesSkipped())
|
||||
i := 0
|
||||
|
||||
var res labels.Labels
|
||||
|
@ -955,7 +955,7 @@ go_gc_duration_seconds
|
|||
go_gc_duration_seconds_created`)
|
||||
|
||||
st := labels.NewSymbolTable()
|
||||
parser := NewOpenMetricsParserWithOpts(input, st, WithOMParserCTSeriesSkipped(true)).(*OpenMetricsParser)
|
||||
parser := NewOpenMetricsParserWithOpts(input, st, WithOMParserCTSeriesSkipped()).(*OpenMetricsParser)
|
||||
|
||||
// Modify the original parser state
|
||||
_, err := parser.Next()
|
||||
|
|
Loading…
Reference in a new issue