Commit 449a3075 by Marcus Efraimsson

mssql: remove dynamic construction of metric column and other columns

This seems like a niche feature which can be solved by defining multiple queries. In the future
we'll probably add support for defining series name by alias field similar to how other datasources
have solved that, e.g. prometheus.
parent b8e2414e
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
"gnetId": null, "gnetId": null,
"graphTooltip": 0, "graphTooltip": 0,
"id": null, "id": null,
"iteration": 1521458057789, "iteration": 1521475806814,
"links": [], "links": [],
"panels": [ "panels": [
{ {
...@@ -655,8 +655,14 @@ ...@@ -655,8 +655,14 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT \n $__timeGroup(time, '$summarize') as time, \n measurement as metric, \n avg(valueOne) as valueOne, \n avg(valueTwo) as valueTwo \nFROM\n metric_values \nGROUP BY \n $__timeGroup(time, '$summarize'), \n measurement \nORDER BY 1", "rawSql": "SELECT \n $__timeGroup(time, '$summarize') as time, \n measurement + ' - value one' as metric, \n avg(valueOne) as valueOne\nFROM\n metric_values \nGROUP BY \n $__timeGroup(time, '$summarize'), \n measurement \nORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT \n $__timeGroup(time, '$summarize') as time, \n measurement + ' - value two' as metric, \n avg(valueTwo) as valueTwo \nFROM\n metric_values \nGROUP BY \n $__timeGroup(time, '$summarize'), \n measurement \nORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -819,8 +825,14 @@ ...@@ -819,8 +825,14 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement as metric, valueOne, valueTwo FROM metric_values ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement + ' - value one' as metric, valueOne FROM metric_values ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value two' as metric, valueTwo FROM metric_values ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -983,8 +995,14 @@ ...@@ -983,8 +995,14 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement as metric, valueOne, valueTwo FROM metric_values ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement + ' - value one' as metric, valueOne FROM metric_values ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value two' as metric, valueTwo FROM metric_values ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1147,8 +1165,14 @@ ...@@ -1147,8 +1165,14 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement as metric, valueOne, valueTwo FROM metric_values ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement + ' - value one' as metric, valueOne FROM metric_values ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value two' as metric, valueTwo FROM metric_values ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1309,8 +1333,14 @@ ...@@ -1309,8 +1333,14 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement as metric, valueOne, valueTwo FROM metric_values ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement + ' - value one' as metric, valueOne FROM metric_values ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value two' as metric, valueTwo FROM metric_values ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1476,8 +1506,14 @@ ...@@ -1476,8 +1506,14 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement as metric, valueOne, valueTwo FROM metric_values ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement + ' - value one' as metric, valueOne FROM metric_values ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value two' as metric, valueTwo FROM metric_values ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1643,8 +1679,14 @@ ...@@ -1643,8 +1679,14 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement as metric, valueOne, valueTwo FROM metric_values ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement + ' - value one' as metric, valueOne FROM metric_values ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value two' as metric, valueTwo FROM metric_values ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -1810,8 +1852,14 @@ ...@@ -1810,8 +1852,14 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement as metric, valueOne, valueTwo FROM metric_values ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement + ' - value one' as metric, valueOne FROM metric_values ORDER BY 1",
"refId": "A" "refId": "A"
},
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeEpoch(time), measurement + ' - value two' as metric, valueTwo FROM metric_values ORDER BY 1",
"refId": "B"
} }
], ],
"thresholds": [], "thresholds": [],
...@@ -2024,5 +2072,5 @@ ...@@ -2024,5 +2072,5 @@
"timezone": "", "timezone": "",
"title": "Microsoft SQL Server Data Source Test", "title": "Microsoft SQL Server Data Source Test",
"uid": "GlAqcPgmz", "uid": "GlAqcPgmz",
"version": 33 "version": 35
} }
\ No newline at end of file
...@@ -214,7 +214,6 @@ func (e MssqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core. ...@@ -214,7 +214,6 @@ func (e MssqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.
for rows.Next() { for rows.Next() {
var timestamp float64 var timestamp float64
var value null.Float var value null.Float
var metricColVal string
var metric string var metric string
if rowCount > rowLimit { if rowCount > rowLimit {
...@@ -239,7 +238,7 @@ func (e MssqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core. ...@@ -239,7 +238,7 @@ func (e MssqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.
if metricIndex >= 0 { if metricIndex >= 0 {
if columnValue, ok := values[metricIndex].(string); ok == true { if columnValue, ok := values[metricIndex].(string); ok == true {
metricColVal = columnValue metric = columnValue
} else { } else {
return fmt.Errorf("Column metric must be of type CHAR, VARCHAR, NCHAR or NVARCHAR. metric column name: %s type: %s but datatype is %T", columnNames[metricIndex], columnTypes[metricIndex].DatabaseTypeName(), values[metricIndex]) return fmt.Errorf("Column metric must be of type CHAR, VARCHAR, NCHAR or NVARCHAR. metric column name: %s type: %s but datatype is %T", columnNames[metricIndex], columnTypes[metricIndex].DatabaseTypeName(), values[metricIndex])
} }
...@@ -260,16 +259,8 @@ func (e MssqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core. ...@@ -260,16 +259,8 @@ func (e MssqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.
default: default:
return fmt.Errorf("Value column must have numeric datatype, column: %s type: %T value: %v", col, columnValue, columnValue) return fmt.Errorf("Value column must have numeric datatype, column: %s type: %T value: %v", col, columnValue, columnValue)
} }
// construct the metric name
// if there is more than 3 columns (more than one value) and there is
// a metric column, join them to make the metric name
if metricIndex == -1 { if metricIndex == -1 {
metric = col metric = col
} else if len(columnNames) > 3 {
metric = metricColVal + " - " + col
} else {
metric = metricColVal
} }
series, exist := pointsBySeries[metric] series, exist := pointsBySeries[metric]
......
...@@ -364,7 +364,7 @@ func TestMSSQL(t *testing.T) { ...@@ -364,7 +364,7 @@ func TestMSSQL(t *testing.T) {
Queries: []*tsdb.Query{ Queries: []*tsdb.Query{
{ {
Model: simplejson.NewFromAny(map[string]interface{}{ Model: simplejson.NewFromAny(map[string]interface{}{
"rawSql": "SELECT $__timeEpoch(time), measurement as metric, valueOne, valueTwo FROM metric_values ORDER BY 1", "rawSql": "SELECT $__timeEpoch(time), measurement + ' - value one' as metric, valueOne FROM metric_values ORDER BY 1",
"format": "time_series", "format": "time_series",
}), }),
RefId: "A", RefId: "A",
...@@ -377,11 +377,9 @@ func TestMSSQL(t *testing.T) { ...@@ -377,11 +377,9 @@ func TestMSSQL(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(queryResult.Error, ShouldBeNil) So(queryResult.Error, ShouldBeNil)
So(len(queryResult.Series), ShouldEqual, 4) So(len(queryResult.Series), ShouldEqual, 2)
So(queryResult.Series[0].Name, ShouldEqual, "Metric A - valueOne") So(queryResult.Series[0].Name, ShouldEqual, "Metric A - value one")
So(queryResult.Series[1].Name, ShouldEqual, "Metric A - valueTwo") So(queryResult.Series[1].Name, ShouldEqual, "Metric B - value one")
So(queryResult.Series[2].Name, ShouldEqual, "Metric B - valueOne")
So(queryResult.Series[3].Name, ShouldEqual, "Metric B - valueTwo")
}) })
Convey("When doing a metric query grouping by time should return correct series", func() { Convey("When doing a metric query grouping by time should return correct series", func() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment