mirror of
https://github.com/prometheus/prometheus.git
synced 2025-07-03 11:03:25 +00:00
Disable CT handling and enable exemplar handling
Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
This commit is contained in:
parent
e931587bf8
commit
7fccf1e6be
3 changed files with 92 additions and 89 deletions
|
@ -38,7 +38,6 @@ type NHCBParser struct {
|
|||
// For Series and Histogram.
|
||||
bytes []byte
|
||||
ts *int64
|
||||
ct *int64
|
||||
value float64
|
||||
h *histogram.Histogram
|
||||
fh *histogram.FloatHistogram
|
||||
|
@ -58,16 +57,16 @@ type NHCBParser struct {
|
|||
bytesNHCB []byte
|
||||
hNHCB *histogram.Histogram
|
||||
fhNHCB *histogram.FloatHistogram
|
||||
ctNHCB *int64
|
||||
lsetNHCB labels.Labels
|
||||
exemplars []exemplar.Exemplar
|
||||
metricStringNHCB string
|
||||
|
||||
// Collates values from the classic histogram series to build
|
||||
// the converted histogram later.
|
||||
tempLsetNHCB labels.Labels
|
||||
tempCtNHCB *int64
|
||||
tempCtNHCBbacking int64
|
||||
tempNHCB convertnhcb.TempHistogram
|
||||
tempExemplars []exemplar.Exemplar
|
||||
tempExemplarCount int
|
||||
isCollationInProgress bool
|
||||
|
||||
// Remembers the last base histogram metric name (assuming it's
|
||||
|
@ -81,6 +80,7 @@ func NewNHCBParser(p Parser, keepClassicHistograms bool) Parser {
|
|||
parser: p,
|
||||
keepClassicHistograms: keepClassicHistograms,
|
||||
tempNHCB: convertnhcb.NewTempHistogram(),
|
||||
tempExemplars: make([]exemplar.Exemplar, 0, 1),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,14 +121,19 @@ func (p *NHCBParser) Metric(l *labels.Labels) string {
|
|||
}
|
||||
|
||||
func (p *NHCBParser) Exemplar(ex *exemplar.Exemplar) bool {
|
||||
if p.justInsertedNHCB {
|
||||
if len(p.exemplars) == 0 {
|
||||
return false
|
||||
}
|
||||
*ex = p.exemplars[0]
|
||||
p.exemplars = p.exemplars[1:]
|
||||
return true
|
||||
}
|
||||
return p.parser.Exemplar(ex)
|
||||
}
|
||||
|
||||
func (p *NHCBParser) CreatedTimestamp() *int64 {
|
||||
if p.justInsertedNHCB {
|
||||
return p.ctNHCB
|
||||
}
|
||||
return p.ct
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *NHCBParser) Next() (Entry, error) {
|
||||
|
@ -154,7 +159,6 @@ func (p *NHCBParser) Next() (Entry, error) {
|
|||
case EntrySeries:
|
||||
p.bytes, p.ts, p.value = p.parser.Series()
|
||||
p.metricString = p.parser.Metric(&p.lset)
|
||||
p.ct = p.parser.CreatedTimestamp()
|
||||
// Check the label set to see if we can continue or need to emit the NHCB.
|
||||
if p.compareLabels() && p.processNHCB() {
|
||||
p.entry = et
|
||||
|
@ -167,7 +171,6 @@ func (p *NHCBParser) Next() (Entry, error) {
|
|||
case EntryHistogram:
|
||||
p.bytes, p.ts, p.h, p.fh = p.parser.Histogram()
|
||||
p.metricString = p.parser.Metric(&p.lset)
|
||||
p.ct = p.parser.CreatedTimestamp()
|
||||
case EntryType:
|
||||
p.bName, p.typ = p.parser.Type()
|
||||
}
|
||||
|
@ -255,10 +258,6 @@ func (p *NHCBParser) handleClassicHistogramSeries(lset labels.Labels) bool {
|
|||
if convertnhcb.GetHistogramMetricBaseName(mName) != string(p.bName) {
|
||||
return false
|
||||
}
|
||||
if p.ct != nil {
|
||||
p.tempCtNHCBbacking = *p.ct
|
||||
p.tempCtNHCB = &p.tempCtNHCBbacking
|
||||
}
|
||||
switch {
|
||||
case strings.HasSuffix(mName, "_bucket") && lset.Has(labels.BucketLabel):
|
||||
le, err := strconv.ParseFloat(lset.Get(labels.BucketLabel), 64)
|
||||
|
@ -285,9 +284,36 @@ func (p *NHCBParser) handleClassicHistogramSeries(lset labels.Labels) bool {
|
|||
func (p *NHCBParser) processClassicHistogramSeries(lset labels.Labels, suffix string, updateHist func(*convertnhcb.TempHistogram)) {
|
||||
p.isCollationInProgress = true
|
||||
p.tempLsetNHCB = convertnhcb.GetHistogramMetricBase(lset, suffix)
|
||||
p.storeExemplars()
|
||||
updateHist(&p.tempNHCB)
|
||||
}
|
||||
|
||||
func (p *NHCBParser) storeExemplars() {
|
||||
for ex := p.nextExemplarPtr(); p.parser.Exemplar(ex); ex = p.nextExemplarPtr() {
|
||||
p.tempExemplarCount++
|
||||
}
|
||||
}
|
||||
|
||||
func (p *NHCBParser) nextExemplarPtr() *exemplar.Exemplar {
|
||||
switch {
|
||||
case p.tempExemplarCount == len(p.tempExemplars)-1:
|
||||
// Reuse the previously allocated exemplar, it was not filled up.
|
||||
case len(p.tempExemplars) == cap(p.tempExemplars):
|
||||
// Let the runtime grow the slice.
|
||||
p.tempExemplars = append(p.tempExemplars, exemplar.Exemplar{})
|
||||
default:
|
||||
// Take the next element into use.
|
||||
p.tempExemplars = p.tempExemplars[:len(p.tempExemplars)+1]
|
||||
}
|
||||
return &p.tempExemplars[len(p.tempExemplars)-1]
|
||||
}
|
||||
|
||||
func (p *NHCBParser) swapExemplars() {
|
||||
p.exemplars = p.tempExemplars[:p.tempExemplarCount]
|
||||
p.tempExemplars = p.tempExemplars[:0]
|
||||
p.tempExemplarCount = 0
|
||||
}
|
||||
|
||||
// processNHCB converts the collated classic histogram series to NHCB and caches the info
|
||||
// to be returned to callers.
|
||||
func (p *NHCBParser) processNHCB() bool {
|
||||
|
@ -314,12 +340,11 @@ func (p *NHCBParser) processNHCB() bool {
|
|||
p.hNHCB = nil
|
||||
p.fhNHCB = fh
|
||||
}
|
||||
p.ctNHCB = p.tempCtNHCB
|
||||
p.metricStringNHCB = p.tempLsetNHCB.Get(labels.MetricName) + strings.ReplaceAll(p.tempLsetNHCB.DropMetricName().String(), ", ", ",")
|
||||
p.bytesNHCB = []byte(p.metricStringNHCB)
|
||||
p.lsetNHCB = p.tempLsetNHCB
|
||||
p.swapExemplars()
|
||||
p.tempNHCB = convertnhcb.NewTempHistogram()
|
||||
p.tempCtNHCB = nil
|
||||
p.isCollationInProgress = false
|
||||
p.justInsertedNHCB = true
|
||||
return true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue