2020-06-01 10:46:37 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"time"
|
2020-06-29 19:21:03 +00:00
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
2020-06-01 10:46:37 +00:00
|
|
|
)
|
|
|
|
|
2021-06-09 09:20:38 +00:00
|
|
|
func newTimeSeries(values []float64, timestamps []int64, labels map[string]string) prompbmarshal.TimeSeries {
|
|
|
|
ts := prompbmarshal.TimeSeries{
|
|
|
|
Samples: make([]prompbmarshal.Sample, len(values)),
|
|
|
|
}
|
|
|
|
for i := range values {
|
|
|
|
ts.Samples[i] = prompbmarshal.Sample{
|
|
|
|
Value: values[i],
|
|
|
|
Timestamp: time.Unix(timestamps[i], 0).UnixNano() / 1e6,
|
|
|
|
}
|
|
|
|
}
|
2020-06-01 10:46:37 +00:00
|
|
|
keys := make([]string, 0, len(labels))
|
|
|
|
for k := range labels {
|
|
|
|
keys = append(keys, k)
|
|
|
|
}
|
2021-06-09 09:20:38 +00:00
|
|
|
sort.Strings(keys) // make order deterministic
|
2020-06-01 10:46:37 +00:00
|
|
|
for _, key := range keys {
|
|
|
|
ts.Labels = append(ts.Labels, prompbmarshal.Label{
|
|
|
|
Name: key,
|
|
|
|
Value: labels[key],
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return ts
|
|
|
|
}
|
2022-03-29 13:09:07 +00:00
|
|
|
|
|
|
|
// newTimeSeriesPB creates prompbmarshal.TimeSeries with given
|
|
|
|
// values, timestamps and labels.
|
|
|
|
// It expects that labels are already sorted.
|
|
|
|
func newTimeSeriesPB(values []float64, timestamps []int64, labels []prompbmarshal.Label) prompbmarshal.TimeSeries {
|
|
|
|
ts := prompbmarshal.TimeSeries{
|
|
|
|
Samples: make([]prompbmarshal.Sample, len(values)),
|
|
|
|
}
|
|
|
|
for i := range values {
|
|
|
|
ts.Samples[i] = prompbmarshal.Sample{
|
|
|
|
Value: values[i],
|
|
|
|
Timestamp: time.Unix(timestamps[i], 0).UnixNano() / 1e6,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ts.Labels = labels
|
|
|
|
return ts
|
|
|
|
}
|