MCPcopy Create free account
hub / github.com/cortexproject/cortex / ToWriteRequest

Function ToWriteRequest

pkg/cortexpb/compat.go:23–45  ·  view source on GitHub ↗

ToWriteRequest converts matched slices of Labels, Samples, Metadata and Histograms into a WriteRequest proto. It gets timeseries from the pool, so ReuseSlice() should be called when done.

(lbls []labels.Labels, samples []Sample, metadata []*MetricMetadata, histograms []WrappedHistogram, source SourceEnum)

Source from the content-addressed store, hash-verified

21// ToWriteRequest converts matched slices of Labels, Samples, Metadata and Histograms into a WriteRequest proto.
22// It gets timeseries from the pool, so ReuseSlice() should be called when done.
23func ToWriteRequest(lbls []labels.Labels, samples []Sample, metadata []*MetricMetadata, histograms []WrappedHistogram, source SourceEnum) *WriteRequest {
24 req := &WriteRequest{
25 Timeseries: PreallocTimeseriesSliceFromPool(),
26 Metadata: metadata,
27 Source: source,
28 }
29
30 i := 0
31 for i < len(samples) || i < len(histograms) {
32 ts := TimeseriesFromPool()
33 ts.Labels = append(ts.Labels, FromLabelsToLabelAdapters(lbls[i])...)
34 if i < len(samples) {
35 ts.Samples = append(ts.Samples, samples[i])
36 }
37 if i < len(histograms) {
38 ts.Histograms = append(ts.Histograms, histograms[i])
39 }
40 i++
41 req.Timeseries = append(req.Timeseries, PreallocTimeseries{TimeSeries: ts})
42 }
43
44 return req
45}
46
47func (w *WriteRequest) AddHistogramTimeSeries(lbls []labels.Labels, histograms []WrappedHistogram) {
48 for i := range lbls {

Calls 3

TimeseriesFromPoolFunction · 0.85