mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
refac: readability updates
Signed-off-by: Manik Rana <manikrana54@gmail.com>
This commit is contained in:
parent
84bc9d6c3f
commit
c4b2a14590
|
@ -95,7 +95,11 @@ type OpenMetricsParser struct {
|
||||||
exemplarVal float64
|
exemplarVal float64
|
||||||
exemplarTs int64
|
exemplarTs int64
|
||||||
hasExemplarTs bool
|
hasExemplarTs bool
|
||||||
skipCT 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.
|
||||||
|
skipCT bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOpenMetricsParser returns a new parser of the byte slice.
|
// NewOpenMetricsParser returns a new parser of the byte slice.
|
||||||
|
@ -229,7 +233,7 @@ func (p *OpenMetricsParser) CreatedTimestamp() *int64 {
|
||||||
p.Metric(&lbs)
|
p.Metric(&lbs)
|
||||||
lbs = lbs.DropMetricName()
|
lbs = lbs.DropMetricName()
|
||||||
|
|
||||||
newParser := deepCopyParser(p)
|
newParser := createdTimestampParser(p)
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
switch t, _ := newParser.Next(); t {
|
switch t, _ := newParser.Next(); t {
|
||||||
|
@ -280,11 +284,11 @@ loop:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// deepCopyParser creates a copy of a parser without re-using the slices' original memory addresses.
|
// createdTimestampParser creates a copy of a parser without re-using the slices' original memory addresses.
|
||||||
// The function `CreatedTimestamp()` uses a copy of the parser to "peek" at _created lines that might be several lines ahead, without changing the state of the original parser.
|
// The function `CreatedTimestamp()` uses a copy of the parser to "peek" at _created lines that might be several lines ahead, without changing the state of the original parser.
|
||||||
//
|
//
|
||||||
// Additionally, deepCopyParser switches `skipCT` from false to true, because this new parser needs to return _created lines.
|
// Additionally, createdTimestampParser switches `skipCT` from true to false, because this new parser needs to return _created lines.
|
||||||
func deepCopyParser(p *OpenMetricsParser) OpenMetricsParser {
|
func createdTimestampParser(p *OpenMetricsParser) OpenMetricsParser {
|
||||||
newB := make([]byte, len(p.l.b))
|
newB := make([]byte, len(p.l.b))
|
||||||
copy(newB, p.l.b)
|
copy(newB, p.l.b)
|
||||||
|
|
||||||
|
@ -296,34 +300,12 @@ func deepCopyParser(p *OpenMetricsParser) OpenMetricsParser {
|
||||||
state: p.l.state,
|
state: p.l.state,
|
||||||
}
|
}
|
||||||
|
|
||||||
newSeries := make([]byte, len(p.series))
|
|
||||||
copy(newSeries, p.series)
|
|
||||||
newText := make([]byte, len(p.text))
|
|
||||||
copy(newText, p.text)
|
|
||||||
newOffsets := make([]int, len(p.offsets))
|
|
||||||
copy(newOffsets, p.offsets)
|
|
||||||
newEOffsets := p.eOffsets
|
|
||||||
newExemplar := p.exemplar
|
|
||||||
newParser := OpenMetricsParser{
|
newParser := OpenMetricsParser{
|
||||||
l: newLexer,
|
l: newLexer,
|
||||||
builder: p.builder,
|
mtype: p.mtype,
|
||||||
series: newSeries,
|
mName: p.mName,
|
||||||
text: newText,
|
val: p.val,
|
||||||
mtype: p.mtype,
|
skipCT: false,
|
||||||
mName: p.mName,
|
|
||||||
val: p.val,
|
|
||||||
ts: p.ts,
|
|
||||||
hasTS: p.hasTS,
|
|
||||||
start: p.start,
|
|
||||||
|
|
||||||
offsets: newOffsets,
|
|
||||||
|
|
||||||
eOffsets: newEOffsets,
|
|
||||||
exemplar: newExemplar,
|
|
||||||
exemplarVal: p.exemplarVal,
|
|
||||||
exemplarTs: p.exemplarTs,
|
|
||||||
hasExemplarTs: p.hasExemplarTs,
|
|
||||||
skipCT: false,
|
|
||||||
}
|
}
|
||||||
return newParser
|
return newParser
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue