Add unit to buffers

This commit is contained in:
Thomas Roehl 2023-08-21 15:47:16 +02:00
parent e71e1b123b
commit 5e5586f319
3 changed files with 7 additions and 4 deletions

4
api.go
View File

@ -183,7 +183,7 @@ type ApiQueryRequest struct {
From int64 `json:"from"` From int64 `json:"from"`
To int64 `json:"to"` To int64 `json:"to"`
WithStats bool `json:"with-stats"` WithStats bool `json:"with-stats"`
WithUnit bool `json:"with-unit"` WithUnit bool `json:"with-unit,omitempty"`
WithData bool `json:"with-data"` WithData bool `json:"with-data"`
WithPadding bool `json:"with-padding"` WithPadding bool `json:"with-padding"`
Queries []ApiQuery `json:"queries"` Queries []ApiQuery `json:"queries"`
@ -303,7 +303,7 @@ func handleQuery(rw http.ResponseWriter, r *http.Request) {
if req.WithPadding { if req.WithPadding {
data.PadDataWithNull(req.From, req.To, query.Metric) data.PadDataWithNull(req.From, req.To, query.Metric)
} }
if req.WithUnit { if req.WithUnit && len(unit) > 0 {
data.Unit = unit data.Unit = unit
} }
if !req.WithData { if !req.WithData {

View File

@ -24,7 +24,7 @@ import (
type CheckpointMetrics struct { type CheckpointMetrics struct {
Frequency int64 `json:"frequency"` Frequency int64 `json:"frequency"`
Start int64 `json:"start"` Start int64 `json:"start"`
Unit string `json:"unit"` Unit string `json:"unit,omitempty"`
Data []Float `json:"data"` Data []Float `json:"data"`
} }
@ -312,7 +312,7 @@ func (l *level) loadFile(cf *CheckpointFile, m *MemoryStore) error {
frequency: metric.Frequency, frequency: metric.Frequency,
start: metric.Start, start: metric.Start,
data: metric.Data[0:n:n], // Space is wasted here :( data: metric.Data[0:n:n], // Space is wasted here :(
unit: "", unit: metric.Unit,
prev: nil, prev: nil,
next: nil, next: nil,
archived: true, archived: true,

View File

@ -21,6 +21,9 @@ func (b *buffer) debugDump(buf []byte) []byte {
if b.archived { if b.archived {
buf = append(buf, `,"saved":true`...) buf = append(buf, `,"saved":true`...)
} }
if b.unit != "" {
buf = append(buf, fmt.Sprintf(`,"unit":"%s"`, b.unit)...)
}
if b.next != nil { if b.next != nil {
buf = append(buf, `},`...) buf = append(buf, `},`...)
} else { } else {