mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-27 06:29:42 -08:00
Merge "Retain DTO on each cycle."
This commit is contained in:
commit
d91a40c3cf
|
@ -345,8 +345,14 @@ func (l *LevelDBMetricPersistence) AppendSamples(samples clientmodel.Samples) (e
|
||||||
samplesBatch := leveldb.NewBatch()
|
samplesBatch := leveldb.NewBatch()
|
||||||
defer samplesBatch.Close()
|
defer samplesBatch.Close()
|
||||||
|
|
||||||
|
key := new(SampleKey)
|
||||||
|
keyDto := new(dto.SampleKey)
|
||||||
|
value := new(dto.SampleValueSeries)
|
||||||
|
|
||||||
for fingerprint, group := range fingerprintToSamples {
|
for fingerprint, group := range fingerprintToSamples {
|
||||||
for {
|
for {
|
||||||
|
value.Reset()
|
||||||
|
|
||||||
lengthOfGroup := len(group)
|
lengthOfGroup := len(group)
|
||||||
|
|
||||||
if lengthOfGroup == 0 {
|
if lengthOfGroup == 0 {
|
||||||
|
@ -361,24 +367,21 @@ func (l *LevelDBMetricPersistence) AppendSamples(samples clientmodel.Samples) (e
|
||||||
chunk := group[0:take]
|
chunk := group[0:take]
|
||||||
group = group[take:lengthOfGroup]
|
group = group[take:lengthOfGroup]
|
||||||
|
|
||||||
key := SampleKey{
|
key.Fingerprint = &fingerprint
|
||||||
Fingerprint: &fingerprint,
|
key.FirstTimestamp = chunk[0].Timestamp
|
||||||
FirstTimestamp: chunk[0].Timestamp,
|
key.LastTimestamp = chunk[take-1].Timestamp
|
||||||
LastTimestamp: chunk[take-1].Timestamp,
|
key.SampleCount = uint32(take)
|
||||||
SampleCount: uint32(take),
|
|
||||||
}
|
|
||||||
|
|
||||||
value := &dto.SampleValueSeries{}
|
|
||||||
for _, sample := range chunk {
|
for _, sample := range chunk {
|
||||||
|
// XXX: Candidate for allocation reduction.
|
||||||
value.Value = append(value.Value, &dto.SampleValueSeries_Value{
|
value.Value = append(value.Value, &dto.SampleValueSeries_Value{
|
||||||
Timestamp: proto.Int64(sample.Timestamp.Unix()),
|
Timestamp: proto.Int64(sample.Timestamp.Unix()),
|
||||||
Value: proto.Float64(float64(sample.Value)),
|
Value: proto.Float64(float64(sample.Value)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
k := &dto.SampleKey{}
|
key.Dump(keyDto)
|
||||||
key.Dump(k)
|
samplesBatch.Put(keyDto, value)
|
||||||
samplesBatch.Put(k, value)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue