diff --git a/pkg/redis-time-series.go b/pkg/redis-time-series.go index 7339d9d..1559643 100644 --- a/pkg/redis-time-series.go +++ b/pkg/redis-time-series.go @@ -98,14 +98,17 @@ func queryTsMRange(from int64, to int64, qm queryModel, client redisClient) back return response } - var args []interface{} - //args := []interface{}{strconv.FormatInt(from, 10), to} + var args = []interface{}{to} + + if qm.Latest { + args = append(args, "LATEST") + } // Execute command if qm.Aggregation != "" { - args = []interface{}{to, "AGGREGATION", qm.Aggregation, qm.Bucket, "WITHLABELS", "FILTER", filter} + args = append(args, "AGGREGATION", qm.Aggregation, qm.Bucket, "WITHLABELS", "FILTER", filter) } else { - args = []interface{}{to, qm.Bucket, "WITHLABELS", "FILTER", filter} + args = append(args, qm.Bucket, "WITHLABELS", "FILTER", filter) } if qm.TsGroupByLabel != "" { diff --git a/pkg/types.go b/pkg/types.go index 3897352..82bff36 100644 --- a/pkg/types.go +++ b/pkg/types.go @@ -48,6 +48,7 @@ type queryModel struct { Command string `json:"command"` Aggregation string `json:"aggregation"` Bucket int `json:"bucket"` + Latest bool `json:"tsLatest"` Legend string `json:"legend"` Value string `json:"value"` Section string `json:"section"` diff --git a/src/components/QueryEditor/QueryEditor.tsx b/src/components/QueryEditor/QueryEditor.tsx index 408aabe..98e7b19 100644 --- a/src/components/QueryEditor/QueryEditor.tsx +++ b/src/components/QueryEditor/QueryEditor.tsx @@ -206,6 +206,12 @@ export class QueryEditor extends PureComponent { */ onAggregationChange = this.createSelectFieldHandler('aggregation'); + /** + * LATEST change + */ + + onLatestChange = this.createSwitchFieldHandler('tsLatest'); + /** * ZRANGE Query change */ @@ -346,6 +352,7 @@ export class QueryEditor extends PureComponent { streamingDataType, tsGroupByLabel, tsReducer, + tsLatest, } = this.props.query; const { onRunQuery, datasource } = this.props; @@ -755,11 +762,25 @@ export class QueryEditor extends PureComponent { )} + {type === QueryTypeValue.TIMESERIES && + command && + CommandParameters.tsLatest.includes(command as RedisTimeSeries) && ( +
+ +
+ )} +
diff --git a/src/redis/command.ts b/src/redis/command.ts index e970d02..74e00ed 100644 --- a/src/redis/command.ts +++ b/src/redis/command.ts @@ -78,6 +78,7 @@ export const CommandParameters = { pyFunction: [RedisGears.PYEXECUTE], tsGroupBy: [RedisTimeSeries.MRANGE], tsReducer: [RedisTimeSeries.MRANGE], + tsLatest: [RedisTimeSeries.MRANGE], searchQuery: [RediSearch.SEARCH], offset: [RediSearch.SEARCH], returnFields: [RediSearch.SEARCH], diff --git a/src/redis/types.ts b/src/redis/types.ts index bce7e79..84143c1 100644 --- a/src/redis/types.ts +++ b/src/redis/types.ts @@ -109,6 +109,8 @@ export interface RedisQuery extends DataQuery { */ tsGroupByLabel?: string; + tsLatest?: boolean; + /** * ZRANGE Query *