Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MRANGE: add fill zero option #53

Merged
merged 1 commit into from
Aug 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion pkg/redis-time-series.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ func (ds *redisDatasource) queryTsMRange(from int64, to int64, qm queryModel, cl
)
}

// Previous time and bucket to fill missing intervals
var prevTime time.Time
var bucket, _ = strconv.ParseInt(qm.Bucket, 10, 64)

// Values
for _, valueRaw := range tsArrReply[2].([]interface{}) {
kvPair := valueRaw.([]interface{})
Expand All @@ -175,6 +179,20 @@ func (ds *redisDatasource) queryTsMRange(from int64, to int64, qm queryModel, cl
k = kvPair[0].(int64)
}

ts := time.Unix(k/1000, 0)

// Fill missing intervals
if qm.Fill && bucket != 0 {
if !prevTime.IsZero() {
for ts.Sub(prevTime) > time.Duration(bucket)*time.Millisecond {
prevTime = prevTime.Add(time.Duration(bucket) * time.Millisecond)
frame.AppendRow(prevTime, float64(0))
}
}

prevTime = ts
}

// Value
switch kvPair[1].(type) {
case []byte:
Expand All @@ -184,7 +202,7 @@ func (ds *redisDatasource) queryTsMRange(from int64, to int64, qm queryModel, cl
}

// Append Row to Frame
frame.AppendRow(time.Unix(k/1000, 0), v)
frame.AppendRow(ts, v)
}

// add the frames to the response
Expand Down
2 changes: 1 addition & 1 deletion src/redis/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,5 @@ export const CommandParameters = {
legendLabel: ['ts.mrange'],
section: ['info'],
valueLabel: ['ts.mrange'],
fill: ['ts.range'],
fill: ['ts.range', 'ts.mrange'],
};