mirror of https://github.com/prometheus/prometheus
use caps for NHCB
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>pull/14978/head
parent
90c266845b
commit
97ba2fc39d
|
@ -28,7 +28,7 @@ import (
|
||||||
"github.com/prometheus/prometheus/util/convertnhcb"
|
"github.com/prometheus/prometheus/util/convertnhcb"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NhcbParser struct {
|
type NHCBParser struct {
|
||||||
// The parser we're wrapping.
|
// The parser we're wrapping.
|
||||||
parser Parser
|
parser Parser
|
||||||
// Option to keep classic histograms along with converted histograms.
|
// Option to keep classic histograms along with converted histograms.
|
||||||
|
@ -52,18 +52,18 @@ type NhcbParser struct {
|
||||||
// halfway through.
|
// halfway through.
|
||||||
entry Entry
|
entry Entry
|
||||||
err error
|
err error
|
||||||
justInsertedNhcb bool
|
justInsertedNHCB bool
|
||||||
// Caches the values and metric for the inserted converted NHCB.
|
// Caches the values and metric for the inserted converted NHCB.
|
||||||
bytesNhcb []byte
|
bytesNHCB []byte
|
||||||
hNhcb *histogram.Histogram
|
hNHCB *histogram.Histogram
|
||||||
fhNhcb *histogram.FloatHistogram
|
fhNHCB *histogram.FloatHistogram
|
||||||
lsetNhcb labels.Labels
|
lsetNHCB labels.Labels
|
||||||
metricStringNhcb string
|
metricStringNHCB string
|
||||||
|
|
||||||
// Collates values from the classic histogram series to build
|
// Collates values from the classic histogram series to build
|
||||||
// the converted histogram later.
|
// the converted histogram later.
|
||||||
tempLsetNhcb labels.Labels
|
tempLsetNHCB labels.Labels
|
||||||
tempNhcb convertnhcb.TempHistogram
|
tempNHCB convertnhcb.TempHistogram
|
||||||
isCollationInProgress bool
|
isCollationInProgress bool
|
||||||
|
|
||||||
// Remembers the last native histogram name so we can ignore
|
// Remembers the last native histogram name so we can ignore
|
||||||
|
@ -75,63 +75,63 @@ type NhcbParser struct {
|
||||||
lastBaseHistName string
|
lastBaseHistName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNhcbParser(p Parser, keepClassicHistograms bool) Parser {
|
func NewNHCBParser(p Parser, keepClassicHistograms bool) Parser {
|
||||||
return &NhcbParser{
|
return &NHCBParser{
|
||||||
parser: p,
|
parser: p,
|
||||||
keepClassicHistograms: keepClassicHistograms,
|
keepClassicHistograms: keepClassicHistograms,
|
||||||
tempNhcb: convertnhcb.NewTempHistogram(),
|
tempNHCB: convertnhcb.NewTempHistogram(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *NhcbParser) Series() ([]byte, *int64, float64) {
|
func (p *NHCBParser) Series() ([]byte, *int64, float64) {
|
||||||
return p.bytes, p.ts, p.value
|
return p.bytes, p.ts, p.value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *NhcbParser) Histogram() ([]byte, *int64, *histogram.Histogram, *histogram.FloatHistogram) {
|
func (p *NHCBParser) Histogram() ([]byte, *int64, *histogram.Histogram, *histogram.FloatHistogram) {
|
||||||
if p.justInsertedNhcb {
|
if p.justInsertedNHCB {
|
||||||
return p.bytesNhcb, p.ts, p.hNhcb, p.fhNhcb
|
return p.bytesNHCB, p.ts, p.hNHCB, p.fhNHCB
|
||||||
}
|
}
|
||||||
return p.bytes, p.ts, p.h, p.fh
|
return p.bytes, p.ts, p.h, p.fh
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *NhcbParser) Help() ([]byte, []byte) {
|
func (p *NHCBParser) Help() ([]byte, []byte) {
|
||||||
return p.parser.Help()
|
return p.parser.Help()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *NhcbParser) Type() ([]byte, model.MetricType) {
|
func (p *NHCBParser) Type() ([]byte, model.MetricType) {
|
||||||
return p.bType, p.typ
|
return p.bType, p.typ
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *NhcbParser) Unit() ([]byte, []byte) {
|
func (p *NHCBParser) Unit() ([]byte, []byte) {
|
||||||
return p.parser.Unit()
|
return p.parser.Unit()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *NhcbParser) Comment() []byte {
|
func (p *NHCBParser) Comment() []byte {
|
||||||
return p.parser.Comment()
|
return p.parser.Comment()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *NhcbParser) Metric(l *labels.Labels) string {
|
func (p *NHCBParser) Metric(l *labels.Labels) string {
|
||||||
if p.justInsertedNhcb {
|
if p.justInsertedNHCB {
|
||||||
*l = p.lsetNhcb
|
*l = p.lsetNHCB
|
||||||
return p.metricStringNhcb
|
return p.metricStringNHCB
|
||||||
}
|
}
|
||||||
*l = p.lset
|
*l = p.lset
|
||||||
return p.metricString
|
return p.metricString
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *NhcbParser) Exemplar(ex *exemplar.Exemplar) bool {
|
func (p *NHCBParser) Exemplar(ex *exemplar.Exemplar) bool {
|
||||||
return p.parser.Exemplar(ex)
|
return p.parser.Exemplar(ex)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *NhcbParser) CreatedTimestamp() *int64 {
|
func (p *NHCBParser) CreatedTimestamp() *int64 {
|
||||||
return p.parser.CreatedTimestamp()
|
return p.parser.CreatedTimestamp()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *NhcbParser) Next() (Entry, error) {
|
func (p *NHCBParser) Next() (Entry, error) {
|
||||||
if p.justInsertedNhcb {
|
if p.justInsertedNHCB {
|
||||||
p.justInsertedNhcb = false
|
p.justInsertedNHCB = false
|
||||||
if p.entry == EntrySeries {
|
if p.entry == EntrySeries {
|
||||||
if isNhcb := p.handleClassicHistogramSeries(p.lset); isNhcb && !p.keepClassicHistograms {
|
if isNHCB := p.handleClassicHistogramSeries(p.lset); isNHCB && !p.keepClassicHistograms {
|
||||||
return p.Next()
|
return p.Next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ func (p *NhcbParser) Next() (Entry, error) {
|
||||||
}
|
}
|
||||||
et, err := p.parser.Next()
|
et, err := p.parser.Next()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, io.EOF) && p.processNhcb() {
|
if errors.Is(err, io.EOF) && p.processNHCB() {
|
||||||
p.entry = et
|
p.entry = et
|
||||||
p.err = err
|
p.err = err
|
||||||
return EntryHistogram, nil
|
return EntryHistogram, nil
|
||||||
|
@ -154,13 +154,13 @@ func (p *NhcbParser) Next() (Entry, error) {
|
||||||
if histBaseName == p.lastNativeHistName {
|
if histBaseName == p.lastNativeHistName {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
shouldInsertNhcb := p.lastBaseHistName != "" && p.lastBaseHistName != histBaseName
|
shouldInsertNHCB := p.lastBaseHistName != "" && p.lastBaseHistName != histBaseName
|
||||||
p.lastBaseHistName = histBaseName
|
p.lastBaseHistName = histBaseName
|
||||||
if shouldInsertNhcb && p.processNhcb() {
|
if shouldInsertNHCB && p.processNHCB() {
|
||||||
p.entry = et
|
p.entry = et
|
||||||
return EntryHistogram, nil
|
return EntryHistogram, nil
|
||||||
}
|
}
|
||||||
if isNhcb := p.handleClassicHistogramSeries(p.lset); isNhcb && !p.keepClassicHistograms {
|
if isNHCB := p.handleClassicHistogramSeries(p.lset); isNHCB && !p.keepClassicHistograms {
|
||||||
return p.Next()
|
return p.Next()
|
||||||
}
|
}
|
||||||
return et, err
|
return et, err
|
||||||
|
@ -171,7 +171,7 @@ func (p *NhcbParser) Next() (Entry, error) {
|
||||||
case EntryType:
|
case EntryType:
|
||||||
p.bType, p.typ = p.parser.Type()
|
p.bType, p.typ = p.parser.Type()
|
||||||
}
|
}
|
||||||
if p.processNhcb() {
|
if p.processNHCB() {
|
||||||
p.entry = et
|
p.entry = et
|
||||||
return EntryHistogram, nil
|
return EntryHistogram, nil
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ func (p *NhcbParser) Next() (Entry, error) {
|
||||||
// if it is actually a classic histogram series (and not a normal float series) and if there
|
// if it is actually a classic histogram series (and not a normal float series) and if there
|
||||||
// isn't already a native histogram with the same name (assuming it is always processed
|
// isn't already a native histogram with the same name (assuming it is always processed
|
||||||
// right before the classic histograms) and returns true if the collation was done.
|
// right before the classic histograms) and returns true if the collation was done.
|
||||||
func (p *NhcbParser) handleClassicHistogramSeries(lset labels.Labels) bool {
|
func (p *NHCBParser) handleClassicHistogramSeries(lset labels.Labels) bool {
|
||||||
if p.typ != model.MetricTypeHistogram {
|
if p.typ != model.MetricTypeHistogram {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -213,43 +213,43 @@ func (p *NhcbParser) handleClassicHistogramSeries(lset labels.Labels) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *NhcbParser) processClassicHistogramSeries(lset labels.Labels, suffix string, updateHist func(*convertnhcb.TempHistogram)) {
|
func (p *NHCBParser) processClassicHistogramSeries(lset labels.Labels, suffix string, updateHist func(*convertnhcb.TempHistogram)) {
|
||||||
p.isCollationInProgress = true
|
p.isCollationInProgress = true
|
||||||
p.tempLsetNhcb = convertnhcb.GetHistogramMetricBase(lset, suffix)
|
p.tempLsetNHCB = convertnhcb.GetHistogramMetricBase(lset, suffix)
|
||||||
updateHist(&p.tempNhcb)
|
updateHist(&p.tempNHCB)
|
||||||
}
|
}
|
||||||
|
|
||||||
// processNhcb converts the collated classic histogram series to NHCB and caches the info
|
// processNHCB converts the collated classic histogram series to NHCB and caches the info
|
||||||
// to be returned to callers.
|
// to be returned to callers.
|
||||||
func (p *NhcbParser) processNhcb() bool {
|
func (p *NHCBParser) processNHCB() bool {
|
||||||
if !p.isCollationInProgress {
|
if !p.isCollationInProgress {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
ub := make([]float64, 0, len(p.tempNhcb.BucketCounts))
|
ub := make([]float64, 0, len(p.tempNHCB.BucketCounts))
|
||||||
for b := range p.tempNhcb.BucketCounts {
|
for b := range p.tempNHCB.BucketCounts {
|
||||||
ub = append(ub, b)
|
ub = append(ub, b)
|
||||||
}
|
}
|
||||||
upperBounds, hBase := convertnhcb.ProcessUpperBoundsAndCreateBaseHistogram(ub, false)
|
upperBounds, hBase := convertnhcb.ProcessUpperBoundsAndCreateBaseHistogram(ub, false)
|
||||||
fhBase := hBase.ToFloat(nil)
|
fhBase := hBase.ToFloat(nil)
|
||||||
h, fh := convertnhcb.ConvertHistogramWrapper(p.tempNhcb, upperBounds, hBase, fhBase)
|
h, fh := convertnhcb.ConvertHistogramWrapper(p.tempNHCB, upperBounds, hBase, fhBase)
|
||||||
if h != nil {
|
if h != nil {
|
||||||
if err := h.Validate(); err != nil {
|
if err := h.Validate(); err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
p.hNhcb = h
|
p.hNHCB = h
|
||||||
p.fhNhcb = nil
|
p.fhNHCB = nil
|
||||||
} else if fh != nil {
|
} else if fh != nil {
|
||||||
if err := fh.Validate(); err != nil {
|
if err := fh.Validate(); err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
p.hNhcb = nil
|
p.hNHCB = nil
|
||||||
p.fhNhcb = fh
|
p.fhNHCB = fh
|
||||||
}
|
}
|
||||||
p.metricStringNhcb = p.tempLsetNhcb.Get(labels.MetricName) + strings.ReplaceAll(p.tempLsetNhcb.DropMetricName().String(), ", ", ",")
|
p.metricStringNHCB = p.tempLsetNHCB.Get(labels.MetricName) + strings.ReplaceAll(p.tempLsetNHCB.DropMetricName().String(), ", ", ",")
|
||||||
p.bytesNhcb = []byte(p.metricStringNhcb)
|
p.bytesNHCB = []byte(p.metricStringNHCB)
|
||||||
p.lsetNhcb = p.tempLsetNhcb
|
p.lsetNHCB = p.tempLsetNHCB
|
||||||
p.tempNhcb = convertnhcb.NewTempHistogram()
|
p.tempNHCB = convertnhcb.NewTempHistogram()
|
||||||
p.isCollationInProgress = false
|
p.isCollationInProgress = false
|
||||||
p.justInsertedNhcb = true
|
p.justInsertedNHCB = true
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -1473,7 +1473,7 @@ type appendErrors struct {
|
||||||
func (sl *scrapeLoop) append(app storage.Appender, b []byte, contentType string, ts time.Time) (total, added, seriesAdded int, err error) {
|
func (sl *scrapeLoop) append(app storage.Appender, b []byte, contentType string, ts time.Time) (total, added, seriesAdded int, err error) {
|
||||||
p, err := textparse.New(b, contentType, sl.scrapeClassicHistograms, sl.symbolTable)
|
p, err := textparse.New(b, contentType, sl.scrapeClassicHistograms, sl.symbolTable)
|
||||||
if sl.convertClassicHistograms {
|
if sl.convertClassicHistograms {
|
||||||
p = textparse.NewNhcbParser(p, sl.scrapeClassicHistograms)
|
p = textparse.NewNHCBParser(p, sl.scrapeClassicHistograms)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
level.Debug(sl.l).Log(
|
level.Debug(sl.l).Log(
|
||||||
|
|
Loading…
Reference in New Issue