Skip to content

Commit

Permalink
Add Value Label to TS.RANGE command similar to TS.MRANGE (#110)
Browse files Browse the repository at this point in the history
* Add Value Label to TS.RANGE to align with TS.MRANGE

* Update redis-time-series.go
  • Loading branch information
mikhail-vl authored Dec 20, 2020
1 parent 189b7b9 commit cc86308
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pkg/redis-time-series.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func (ds *redisDatasource) queryTsRange(from int64, to int64, qm queryModel, cli
}

// Create data frame response
frame := data.NewFrame(qm.Key,
frame := data.NewFrame(legend,
data.NewField("time", nil, []time.Time{}),
data.NewField(legend, nil, []float64{}))
data.NewField(qm.Value, nil, []float64{}))

// Previous time to fill missing intervals
var prevTime time.Time
Expand Down Expand Up @@ -140,7 +140,7 @@ func (ds *redisDatasource) queryTsMRange(from int64, to int64, qm queryModel, cl
}

// Use value's label if specified
value := "value"
value := ""
if qm.Value != "" {
value = labels[qm.Value]
}
Expand Down
12 changes: 11 additions & 1 deletion src/components/query-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,24 @@ export class QueryEditor extends PureComponent<Props> {
/>
)}

{CommandParameters.value.includes(command) && (
<FormField
labelWidth={8}
inputWidth={10}
value={value}
onChange={this.onValueChange}
label="Value"
tooltip="Value override"
/>
)}

{CommandParameters.legendLabel.includes(command) && (
<FormField
labelWidth={8}
inputWidth={10}
value={legend}
onChange={this.onLegendChange}
label="Legend Label"
tooltip="Legend Label"
/>
)}

Expand Down
2 changes: 2 additions & 0 deletions src/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export class DataSource extends DataSourceWithBackend<RedisQuery, RedisDataSourc
query: query.query ? templateSrv.replace(query.query, scopedVars) : '',
field: query.field ? templateSrv.replace(query.field, scopedVars) : '',
filter: query.filter ? templateSrv.replace(query.filter, scopedVars) : '',
legend: query.legend ? templateSrv.replace(query.legend, scopedVars) : '',
value: query.value ? templateSrv.replace(query.value, scopedVars) : '',
};
}

Expand Down
1 change: 1 addition & 0 deletions src/redis/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const CommandParameters = {
legend: ['ts.range'],
legendLabel: ['ts.mrange'],
section: ['info'],
value: ['ts.range'],
valueLabel: ['ts.mrange'],
fill: ['ts.range', 'ts.mrange'],
size: ['slowlogGet']
Expand Down
2 changes: 1 addition & 1 deletion src/redis/time-series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ export const Aggregations: Array<SelectableValue<AggregationValue>> = [
{ label: 'Max', description: 'Maximum', value: AggregationValue.MAX },
{ label: 'Min', description: 'Minimum', value: AggregationValue.MIN },
{ label: 'Range', description: 'Diff between maximum and minimum in the bucket', value: AggregationValue.RANGE },
{ label: 'Sum', description: 'Sum', value: AggregationValue.SUM },
{ label: 'Sum', description: 'Summation', value: AggregationValue.SUM },
];

0 comments on commit cc86308

Please sign in to comment.