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

Add support for TS.MRANGE LATEST #322

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 7 additions & 4 deletions pkg/redis-time-series.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
1 change: 1 addition & 0 deletions pkg/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
23 changes: 22 additions & 1 deletion src/components/QueryEditor/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ export class QueryEditor extends PureComponent<Props> {
*/
onAggregationChange = this.createSelectFieldHandler<AggregationValue>('aggregation');

/**
* LATEST change
*/

onLatestChange = this.createSwitchFieldHandler('tsLatest');

/**
* ZRANGE Query change
*/
Expand Down Expand Up @@ -346,6 +352,7 @@ export class QueryEditor extends PureComponent<Props> {
streamingDataType,
tsGroupByLabel,
tsReducer,
tsLatest,
} = this.props.query;
const { onRunQuery, datasource } = this.props;

Expand Down Expand Up @@ -755,11 +762,25 @@ export class QueryEditor extends PureComponent<Props> {
</div>
)}

{type === QueryTypeValue.TIMESERIES &&
command &&
CommandParameters.tsLatest.includes(command as RedisTimeSeries) && (
<div className="gf-form">
<Switch
label="Latest"
labelClass="width-8"
tooltip="If checked, will return the latest (incomplete bucket)."
checked={tsLatest || false}
onChange={this.onLatestChange}
/>
</div>
)}

<div className="gf-form">
<Switch
label="Streaming"
labelClass="width-8"
tooltip="If checked, the datasource will stream data."
tooltip="If checked, the datasource will stream datas."
checked={streaming || false}
onChange={this.onStreamingChange}
/>
Expand Down
1 change: 1 addition & 0 deletions src/redis/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 2 additions & 0 deletions src/redis/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ export interface RedisQuery extends DataQuery {
*/
tsGroupByLabel?: string;

tsLatest?: boolean;

/**
* ZRANGE Query
*
Expand Down