mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-16 10:34:06 -08:00
7e42acd3b1
- Pick At... method via return value of Next/Seek. - Do not clobber returned buckets. - Add partial FloatHistogram suppert. Note that the promql package is now _only_ dealing with FloatHistograms, following the idea that PromQL only knows float values. As a byproduct, I have removed the histogramSeries metric. In my understanding, series can have both float and histogram samples, so that metric doesn't make sense anymore. As another byproduct, I have converged the sampleBuf and the histogramSampleBuf in memSeries into one. The sample type stored in the sampleBuf has been extended to also contain histograms even before this commit. Signed-off-by: beorn7 <beorn@grafana.com>
79 lines
1.9 KiB
Go
79 lines
1.9 KiB
Go
// Copyright 2019 The Prometheus Authors
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package tsdb
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"path/filepath"
|
|
|
|
"github.com/go-kit/log"
|
|
|
|
"github.com/prometheus/prometheus/storage"
|
|
"github.com/prometheus/prometheus/tsdb/chunkenc"
|
|
)
|
|
|
|
var ErrInvalidTimes = fmt.Errorf("max time is lesser than min time")
|
|
|
|
// CreateBlock creates a chunkrange block from the samples passed to it, and writes it to disk.
|
|
func CreateBlock(series []storage.Series, dir string, chunkRange int64, logger log.Logger) (string, error) {
|
|
if chunkRange == 0 {
|
|
chunkRange = DefaultBlockDuration
|
|
}
|
|
if chunkRange < 0 {
|
|
return "", ErrInvalidTimes
|
|
}
|
|
|
|
w, err := NewBlockWriter(logger, dir, chunkRange)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer func() {
|
|
if err := w.Close(); err != nil {
|
|
logger.Log("err closing blockwriter", err.Error())
|
|
}
|
|
}()
|
|
|
|
ctx := context.Background()
|
|
app := w.Appender(ctx)
|
|
|
|
for _, s := range series {
|
|
ref := storage.SeriesRef(0)
|
|
it := s.Iterator()
|
|
lset := s.Labels()
|
|
for it.Next() == chunkenc.ValFloat {
|
|
// TODO(beorn7): Add histogram support.
|
|
t, v := it.At()
|
|
ref, err = app.Append(ref, lset, t, v)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
}
|
|
if it.Err() != nil {
|
|
return "", it.Err()
|
|
}
|
|
}
|
|
|
|
if err = app.Commit(); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
ulid, err := w.Flush(ctx)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return filepath.Join(dir, ulid.String()), nil
|
|
}
|