mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
rename hist to histogram according to code review
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
This commit is contained in:
parent
4c2aa872d4
commit
b8cb12b989
|
@ -502,15 +502,15 @@ func getHistogramMetricBase(m labels.Labels, suffix string) (labels.Labels, uint
|
||||||
}
|
}
|
||||||
|
|
||||||
type tempHistogramWrapper struct {
|
type tempHistogramWrapper struct {
|
||||||
metric labels.Labels
|
metric labels.Labels
|
||||||
upperBounds []float64
|
upperBounds []float64
|
||||||
histByTs map[int64]tempHistogram
|
histogramByTs map[int64]tempHistogram
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTempHistogramWrapper() tempHistogramWrapper {
|
func newTempHistogramWrapper() tempHistogramWrapper {
|
||||||
return tempHistogramWrapper{
|
return tempHistogramWrapper{
|
||||||
upperBounds: []float64{},
|
upperBounds: []float64{},
|
||||||
histByTs: map[int64]tempHistogram{},
|
histogramByTs: map[int64]tempHistogram{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -526,28 +526,28 @@ func newTempHistogram() tempHistogram {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func processClassicHistogramSeries(m labels.Labels, suffix string, histMap map[uint64]tempHistogramWrapper, smpls []promql.Sample, updateHistWrapper func(*tempHistogramWrapper), updateHist func(*tempHistogram, float64)) {
|
func processClassicHistogramSeries(m labels.Labels, suffix string, histogramMap map[uint64]tempHistogramWrapper, smpls []promql.Sample, updateHistogramWrapper func(*tempHistogramWrapper), updateHistogram func(*tempHistogram, float64)) {
|
||||||
m2, m2hash := getHistogramMetricBase(m, suffix)
|
m2, m2hash := getHistogramMetricBase(m, suffix)
|
||||||
histWrapper, exists := histMap[m2hash]
|
histogramWrapper, exists := histogramMap[m2hash]
|
||||||
if !exists {
|
if !exists {
|
||||||
histWrapper = newTempHistogramWrapper()
|
histogramWrapper = newTempHistogramWrapper()
|
||||||
}
|
}
|
||||||
histWrapper.metric = m2
|
histogramWrapper.metric = m2
|
||||||
if updateHistWrapper != nil {
|
if updateHistogramWrapper != nil {
|
||||||
updateHistWrapper(&histWrapper)
|
updateHistogramWrapper(&histogramWrapper)
|
||||||
}
|
}
|
||||||
for _, s := range smpls {
|
for _, s := range smpls {
|
||||||
if s.H != nil {
|
if s.H != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
hist, exists := histWrapper.histByTs[s.T]
|
histogram, exists := histogramWrapper.histogramByTs[s.T]
|
||||||
if !exists {
|
if !exists {
|
||||||
hist = newTempHistogram()
|
histogram = newTempHistogram()
|
||||||
}
|
}
|
||||||
updateHist(&hist, s.F)
|
updateHistogram(&histogram, s.F)
|
||||||
histWrapper.histByTs[s.T] = hist
|
histogramWrapper.histogramByTs[s.T] = histogram
|
||||||
}
|
}
|
||||||
histMap[m2hash] = histWrapper
|
histogramMap[m2hash] = histogramWrapper
|
||||||
}
|
}
|
||||||
|
|
||||||
func processUpperBoundsAndCreateBaseHistogram(upperBounds0 []float64) ([]float64, *histogram.FloatHistogram) {
|
func processUpperBoundsAndCreateBaseHistogram(upperBounds0 []float64) ([]float64, *histogram.FloatHistogram) {
|
||||||
|
@ -581,7 +581,7 @@ func processUpperBoundsAndCreateBaseHistogram(upperBounds0 []float64) ([]float64
|
||||||
// If classic histograms are defined, convert them into native histograms with custom
|
// If classic histograms are defined, convert them into native histograms with custom
|
||||||
// bounds and append the defined time series to the storage.
|
// bounds and append the defined time series to the storage.
|
||||||
func (cmd *loadCmd) appendCustomHistogram(a storage.Appender) error {
|
func (cmd *loadCmd) appendCustomHistogram(a storage.Appender) error {
|
||||||
histMap := map[uint64]tempHistogramWrapper{}
|
histogramMap := map[uint64]tempHistogramWrapper{}
|
||||||
|
|
||||||
// Go through all the time series to collate classic histogram data
|
// Go through all the time series to collate classic histogram data
|
||||||
// and organise them by timestamp.
|
// and organise them by timestamp.
|
||||||
|
@ -594,32 +594,32 @@ func (cmd *loadCmd) appendCustomHistogram(a storage.Appender) error {
|
||||||
if err != nil || math.IsNaN(le) {
|
if err != nil || math.IsNaN(le) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
processClassicHistogramSeries(m, "_bucket", histMap, smpls, func(histWrapper *tempHistogramWrapper) {
|
processClassicHistogramSeries(m, "_bucket", histogramMap, smpls, func(histogramWrapper *tempHistogramWrapper) {
|
||||||
histWrapper.upperBounds = append(histWrapper.upperBounds, le)
|
histogramWrapper.upperBounds = append(histogramWrapper.upperBounds, le)
|
||||||
}, func(hist *tempHistogram, f float64) {
|
}, func(histogram *tempHistogram, f float64) {
|
||||||
hist.bucketCounts[le] = f
|
histogram.bucketCounts[le] = f
|
||||||
})
|
})
|
||||||
case strings.HasSuffix(mName, "_count"):
|
case strings.HasSuffix(mName, "_count"):
|
||||||
processClassicHistogramSeries(m, "_count", histMap, smpls, nil, func(hist *tempHistogram, f float64) {
|
processClassicHistogramSeries(m, "_count", histogramMap, smpls, nil, func(histogram *tempHistogram, f float64) {
|
||||||
hist.count = f
|
histogram.count = f
|
||||||
})
|
})
|
||||||
case strings.HasSuffix(mName, "_sum"):
|
case strings.HasSuffix(mName, "_sum"):
|
||||||
processClassicHistogramSeries(m, "_sum", histMap, smpls, nil, func(hist *tempHistogram, f float64) {
|
processClassicHistogramSeries(m, "_sum", histogramMap, smpls, nil, func(histogram *tempHistogram, f float64) {
|
||||||
hist.sum = f
|
histogram.sum = f
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the collated classic histogram data into native histograms
|
// Convert the collated classic histogram data into native histograms
|
||||||
// with custom bounds and append them to the storage.
|
// with custom bounds and append them to the storage.
|
||||||
for _, histWrapper := range histMap {
|
for _, histogramWrapper := range histogramMap {
|
||||||
upperBounds, fhBase := processUpperBoundsAndCreateBaseHistogram(histWrapper.upperBounds)
|
upperBounds, fhBase := processUpperBoundsAndCreateBaseHistogram(histogramWrapper.upperBounds)
|
||||||
samples := make([]promql.Sample, 0, len(histWrapper.histByTs))
|
samples := make([]promql.Sample, 0, len(histogramWrapper.histogramByTs))
|
||||||
for t, hist := range histWrapper.histByTs {
|
for t, histogram := range histogramWrapper.histogramByTs {
|
||||||
fh := fhBase.Copy()
|
fh := fhBase.Copy()
|
||||||
var prevCount, total float64
|
var prevCount, total float64
|
||||||
for i, le := range upperBounds {
|
for i, le := range upperBounds {
|
||||||
currCount, exists := hist.bucketCounts[le]
|
currCount, exists := histogram.bucketCounts[le]
|
||||||
if !exists {
|
if !exists {
|
||||||
currCount = 0
|
currCount = 0
|
||||||
}
|
}
|
||||||
|
@ -628,9 +628,9 @@ func (cmd *loadCmd) appendCustomHistogram(a storage.Appender) error {
|
||||||
total += count
|
total += count
|
||||||
prevCount = currCount
|
prevCount = currCount
|
||||||
}
|
}
|
||||||
fh.Sum = hist.sum
|
fh.Sum = histogram.sum
|
||||||
if hist.count != 0 {
|
if histogram.count != 0 {
|
||||||
total = hist.count
|
total = histogram.count
|
||||||
}
|
}
|
||||||
fh.Count = total
|
fh.Count = total
|
||||||
s := promql.Sample{T: t, H: fh.Compact(0)}
|
s := promql.Sample{T: t, H: fh.Compact(0)}
|
||||||
|
@ -641,7 +641,7 @@ func (cmd *loadCmd) appendCustomHistogram(a storage.Appender) error {
|
||||||
}
|
}
|
||||||
sort.Slice(samples, func(i, j int) bool { return samples[i].T < samples[j].T })
|
sort.Slice(samples, func(i, j int) bool { return samples[i].T < samples[j].T })
|
||||||
for _, s := range samples {
|
for _, s := range samples {
|
||||||
if err := appendSample(a, s, histWrapper.metric); err != nil {
|
if err := appendSample(a, s, histogramWrapper.metric); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue