2017-03-29 15:54:07 -05:00
|
|
|
package mysql
|
|
|
|
|
|
|
|
import (
|
2017-08-28 06:29:24 -05:00
|
|
|
"container/list"
|
2017-03-29 15:54:07 -05:00
|
|
|
"context"
|
2017-03-30 06:46:46 -05:00
|
|
|
"database/sql"
|
2017-03-29 15:54:07 -05:00
|
|
|
"fmt"
|
2017-12-10 12:50:01 -06:00
|
|
|
"math"
|
2018-01-18 04:44:36 -06:00
|
|
|
"reflect"
|
2017-03-31 04:45:25 -05:00
|
|
|
"strconv"
|
2017-04-23 14:56:58 -05:00
|
|
|
|
2017-04-21 08:07:43 -05:00
|
|
|
"github.com/go-sql-driver/mysql"
|
2017-03-31 04:45:25 -05:00
|
|
|
"github.com/go-xorm/core"
|
|
|
|
"github.com/grafana/grafana/pkg/components/null"
|
2017-03-29 15:54:07 -05:00
|
|
|
"github.com/grafana/grafana/pkg/log"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
|
|
"github.com/grafana/grafana/pkg/tsdb"
|
|
|
|
)
|
|
|
|
|
2017-10-10 08:19:14 -05:00
|
|
|
type MysqlQueryEndpoint struct {
|
|
|
|
sqlEngine tsdb.SqlEngine
|
|
|
|
log log.Logger
|
2017-03-29 15:54:07 -05:00
|
|
|
}
|
|
|
|
|
2017-03-30 06:46:46 -05:00
|
|
|
func init() {
|
2017-10-10 08:19:14 -05:00
|
|
|
tsdb.RegisterTsdbQueryEndpoint("mysql", NewMysqlQueryEndpoint)
|
2017-03-30 06:46:46 -05:00
|
|
|
}
|
|
|
|
|
2017-10-10 08:19:14 -05:00
|
|
|
func NewMysqlQueryEndpoint(datasource *models.DataSource) (tsdb.TsdbQueryEndpoint, error) {
|
|
|
|
endpoint := &MysqlQueryEndpoint{
|
2017-09-21 08:03:47 -05:00
|
|
|
log: log.New("tsdb.mysql"),
|
2017-03-30 06:46:46 -05:00
|
|
|
}
|
|
|
|
|
2017-10-10 08:19:14 -05:00
|
|
|
endpoint.sqlEngine = &tsdb.DefaultSqlEngine{
|
|
|
|
MacroEngine: NewMysqlMacroEngine(),
|
2017-03-29 15:54:07 -05:00
|
|
|
}
|
|
|
|
|
2017-11-21 06:21:19 -06:00
|
|
|
cnnstr := fmt.Sprintf("%s:%s@%s(%s)/%s?collation=utf8mb4_unicode_ci&parseTime=true&loc=UTC&allowNativePasswords=true",
|
2017-10-10 08:19:14 -05:00
|
|
|
datasource.User,
|
|
|
|
datasource.Password,
|
2017-09-21 08:03:47 -05:00
|
|
|
"tcp",
|
2017-10-10 08:19:14 -05:00
|
|
|
datasource.Url,
|
|
|
|
datasource.Database,
|
|
|
|
)
|
|
|
|
endpoint.log.Debug("getEngine", "connection", cnnstr)
|
2017-03-30 06:46:46 -05:00
|
|
|
|
2017-10-10 08:19:14 -05:00
|
|
|
if err := endpoint.sqlEngine.InitEngine("mysql", datasource, cnnstr); err != nil {
|
|
|
|
return nil, err
|
2017-03-29 15:54:07 -05:00
|
|
|
}
|
|
|
|
|
2017-10-10 08:19:14 -05:00
|
|
|
return endpoint, nil
|
2017-03-29 15:54:07 -05:00
|
|
|
}
|
|
|
|
|
2017-10-10 08:19:14 -05:00
|
|
|
// Query is the main function for the MysqlExecutor
|
|
|
|
func (e *MysqlQueryEndpoint) Query(ctx context.Context, dsInfo *models.DataSource, tsdbQuery *tsdb.TsdbQuery) (*tsdb.Response, error) {
|
|
|
|
return e.sqlEngine.Query(ctx, dsInfo, tsdbQuery, e.transformToTimeSeries, e.transformToTable)
|
2017-03-31 04:45:25 -05:00
|
|
|
}
|
|
|
|
|
2017-12-09 13:35:00 -06:00
|
|
|
func (e MysqlQueryEndpoint) transformToTable(query *tsdb.Query, rows *core.Rows, result *tsdb.QueryResult, tsdbQuery *tsdb.TsdbQuery) error {
|
2017-04-21 08:07:43 -05:00
|
|
|
columnNames, err := rows.Columns()
|
|
|
|
columnCount := len(columnNames)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2017-04-19 10:26:29 -05:00
|
|
|
}
|
2017-04-21 08:07:43 -05:00
|
|
|
|
|
|
|
table := &tsdb.Table{
|
|
|
|
Columns: make([]tsdb.TableColumn, columnCount),
|
|
|
|
Rows: make([]tsdb.RowValues, 0),
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, name := range columnNames {
|
|
|
|
table.Columns[i].Text = name
|
|
|
|
}
|
|
|
|
|
|
|
|
rowLimit := 1000000
|
|
|
|
rowCount := 0
|
2018-01-18 04:44:36 -06:00
|
|
|
timeIndex := -1
|
|
|
|
|
|
|
|
// check if there is a column named time
|
|
|
|
for i, col := range columnNames {
|
|
|
|
switch col {
|
2018-03-22 09:40:46 -05:00
|
|
|
case "time", "time_sec":
|
2018-01-18 04:44:36 -06:00
|
|
|
timeIndex = i
|
|
|
|
}
|
|
|
|
}
|
2017-04-21 08:07:43 -05:00
|
|
|
|
2017-10-10 08:19:14 -05:00
|
|
|
for ; rows.Next(); rowCount++ {
|
2017-04-21 08:07:43 -05:00
|
|
|
if rowCount > rowLimit {
|
|
|
|
return fmt.Errorf("MySQL query row limit exceeded, limit %d", rowLimit)
|
|
|
|
}
|
|
|
|
|
2018-01-18 04:44:36 -06:00
|
|
|
values, err := e.getTypedRowData(rows)
|
2017-04-21 08:07:43 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-03-22 09:40:46 -05:00
|
|
|
// converts column named time to unix timestamp in milliseconds to make
|
|
|
|
// native mysql datetime types and epoch dates work in
|
|
|
|
// annotation and table queries.
|
|
|
|
tsdb.ConvertSqlTimeColumnToEpochMs(values, timeIndex)
|
2018-01-18 04:44:36 -06:00
|
|
|
|
2017-04-21 08:07:43 -05:00
|
|
|
table.Rows = append(table.Rows, values)
|
|
|
|
}
|
|
|
|
|
|
|
|
result.Tables = append(result.Tables, table)
|
|
|
|
result.Meta.Set("rowCount", rowCount)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-01-18 04:44:36 -06:00
|
|
|
func (e MysqlQueryEndpoint) getTypedRowData(rows *core.Rows) (tsdb.RowValues, error) {
|
|
|
|
types, err := rows.ColumnTypes()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-04-21 08:07:43 -05:00
|
|
|
values := make([]interface{}, len(types))
|
|
|
|
|
2018-01-18 04:44:36 -06:00
|
|
|
for i := range values {
|
|
|
|
scanType := types[i].ScanType()
|
|
|
|
values[i] = reflect.New(scanType).Interface()
|
|
|
|
|
|
|
|
if types[i].DatabaseTypeName() == "BIT" {
|
2017-08-08 05:00:39 -05:00
|
|
|
values[i] = new([]byte)
|
2017-04-21 08:07:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := rows.Scan(values...); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-01-18 04:44:36 -06:00
|
|
|
for i := 0; i < len(types); i++ {
|
|
|
|
typeName := reflect.ValueOf(values[i]).Type().String()
|
|
|
|
|
|
|
|
switch typeName {
|
|
|
|
case "*sql.RawBytes":
|
|
|
|
values[i] = string(*values[i].(*sql.RawBytes))
|
|
|
|
case "*mysql.NullTime":
|
|
|
|
sqlTime := (*values[i].(*mysql.NullTime))
|
|
|
|
if sqlTime.Valid {
|
|
|
|
values[i] = sqlTime.Time
|
|
|
|
} else {
|
|
|
|
values[i] = nil
|
|
|
|
}
|
|
|
|
case "*sql.NullInt64":
|
|
|
|
nullInt64 := (*values[i].(*sql.NullInt64))
|
|
|
|
if nullInt64.Valid {
|
|
|
|
values[i] = nullInt64.Int64
|
|
|
|
} else {
|
|
|
|
values[i] = nil
|
|
|
|
}
|
|
|
|
case "*sql.NullFloat64":
|
|
|
|
nullFloat64 := (*values[i].(*sql.NullFloat64))
|
|
|
|
if nullFloat64.Valid {
|
|
|
|
values[i] = nullFloat64.Float64
|
|
|
|
} else {
|
|
|
|
values[i] = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if types[i].DatabaseTypeName() == "DECIMAL" {
|
|
|
|
f, err := strconv.ParseFloat(values[i].(string), 64)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
values[i] = f
|
|
|
|
} else {
|
|
|
|
values[i] = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-21 08:07:43 -05:00
|
|
|
return values, nil
|
2017-04-19 10:26:29 -05:00
|
|
|
}
|
|
|
|
|
2017-12-09 13:35:00 -06:00
|
|
|
func (e MysqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.Rows, result *tsdb.QueryResult, tsdbQuery *tsdb.TsdbQuery) error {
|
2017-03-31 04:45:25 -05:00
|
|
|
pointsBySeries := make(map[string]*tsdb.TimeSeries)
|
2017-08-24 14:38:36 -05:00
|
|
|
seriesByQueryOrder := list.New()
|
2017-03-31 04:45:25 -05:00
|
|
|
|
2018-01-18 04:44:36 -06:00
|
|
|
columnNames, err := rows.Columns()
|
2017-03-31 04:45:25 -05:00
|
|
|
if err != nil {
|
2017-04-21 08:07:43 -05:00
|
|
|
return err
|
2017-03-31 04:45:25 -05:00
|
|
|
}
|
|
|
|
|
2018-03-22 09:40:46 -05:00
|
|
|
columnTypes, err := rows.ColumnTypes()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-04-19 03:09:52 -05:00
|
|
|
rowLimit := 1000000
|
|
|
|
rowCount := 0
|
2018-03-22 09:40:46 -05:00
|
|
|
timeIndex := -1
|
|
|
|
metricIndex := -1
|
|
|
|
|
|
|
|
// check columns of resultset: a column named time is mandatory
|
|
|
|
// the first text column is treated as metric name unless a column named metric is present
|
|
|
|
for i, col := range columnNames {
|
|
|
|
switch col {
|
|
|
|
case "time", "time_sec":
|
|
|
|
timeIndex = i
|
|
|
|
case "metric":
|
|
|
|
metricIndex = i
|
|
|
|
default:
|
|
|
|
if metricIndex == -1 {
|
|
|
|
switch columnTypes[i].DatabaseTypeName() {
|
|
|
|
case "CHAR", "VARCHAR", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT":
|
|
|
|
metricIndex = i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if timeIndex == -1 {
|
|
|
|
return fmt.Errorf("Found no column named time or time_sec")
|
|
|
|
}
|
2017-04-19 03:09:52 -05:00
|
|
|
|
2017-12-10 12:50:01 -06:00
|
|
|
fillMissing := query.Model.Get("fill").MustBool(false)
|
|
|
|
var fillInterval float64
|
|
|
|
fillValue := null.Float{}
|
|
|
|
if fillMissing {
|
|
|
|
fillInterval = query.Model.Get("fillInterval").MustFloat64() * 1000
|
Simplify comparison to bool constant (gosimple)
This fixes:
build.go:553:6: should omit comparison to bool constant, can be simplified to !strings.Contains(path, ".sha256") (S1002)
pkg/cmd/grafana-cli/commands/ls_command.go:27:5: should omit comparison to bool constant, can be simplified to !pluginDirInfo.IsDir() (S1002)
pkg/components/dynmap/dynmap_test.go:24:5: should omit comparison to bool constant, can be simplified to !value (S1002)
pkg/components/dynmap/dynmap_test.go:122:14: should omit comparison to bool constant, can be simplified to b (S1002)
pkg/components/dynmap/dynmap_test.go:125:14: should omit comparison to bool constant, can be simplified to !b (S1002)
pkg/components/dynmap/dynmap_test.go:128:14: should omit comparison to bool constant, can be simplified to !b (S1002)
pkg/models/org_user.go:51:5: should omit comparison to bool constant, can be simplified to !(*r).IsValid() (S1002)
pkg/plugins/datasource/wrapper/datasource_plugin_wrapper_test.go:77:12: should omit comparison to bool constant, can be simplified to !haveBool (S1002)
pkg/services/alerting/conditions/evaluator.go:23:9: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/conditions/evaluator.go:48:5: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/conditions/evaluator.go:91:5: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/conditions/query.go:56:6: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/extractor.go:107:20: should omit comparison to bool constant, can be simplified to !enabled.MustBool() (S1002)
pkg/services/alerting/notifiers/telegram.go:222:41: should omit comparison to bool constant, can be simplified to this.UploadImage (S1002)
pkg/services/sqlstore/apikey.go:58:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/apikey.go:72:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/dashboard.go:66:33: should omit comparison to bool constant, can be simplified to !cmd.Overwrite (S1002)
pkg/services/sqlstore/dashboard.go:175:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/dashboard.go:311:13: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/dashboard.go:444:12: should omit comparison to bool constant, can be simplified to !exists (S1002)
pkg/services/sqlstore/dashboard.go:472:12: should omit comparison to bool constant, can be simplified to !exists (S1002)
pkg/services/sqlstore/dashboard.go:554:32: should omit comparison to bool constant, can be simplified to !cmd.Overwrite (S1002)
pkg/services/sqlstore/dashboard_snapshot.go:83:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/plugin_setting.go:39:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:34:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:111:6: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:136:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:213:6: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/temp_user.go:129:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:157:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:182:5: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:191:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:212:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:307:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/social/generic_oauth.go:185:5: should omit comparison to bool constant, can be simplified to !s.extractToken(&data, token) (S1002)
pkg/tsdb/mssql/mssql.go:148:39: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/mssql/mssql.go:212:6: should omit comparison to bool constant, can be simplified to !query.Model.Get("fillNull").MustBool(false) (S1002)
pkg/tsdb/mssql/mssql.go:247:56: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/mssql/mssql.go:274:7: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/mssql/mssql.go:282:8: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/mysql/mysql.go:221:6: should omit comparison to bool constant, can be simplified to !query.Model.Get("fillNull").MustBool(false) (S1002)
pkg/tsdb/mysql/mysql.go:256:56: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/mysql/mysql.go:283:7: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/mysql/mysql.go:291:8: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/postgres/postgres.go:134:39: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/postgres/postgres.go:201:6: should omit comparison to bool constant, can be simplified to !query.Model.Get("fillNull").MustBool(false) (S1002)
pkg/tsdb/postgres/postgres.go:236:56: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/postgres/postgres.go:263:7: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/postgres/postgres.go:271:8: should omit comparison to bool constant, can be simplified to !exist (S1002)
2018-04-16 13:12:59 -05:00
|
|
|
if !query.Model.Get("fillNull").MustBool(false) {
|
2017-12-10 12:50:01 -06:00
|
|
|
fillValue.Float64 = query.Model.Get("fillValue").MustFloat64()
|
|
|
|
fillValue.Valid = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 09:40:46 -05:00
|
|
|
for rows.Next() {
|
|
|
|
var timestamp float64
|
|
|
|
var value null.Float
|
|
|
|
var metric string
|
|
|
|
|
2017-04-19 03:09:52 -05:00
|
|
|
if rowCount > rowLimit {
|
2018-03-22 09:40:46 -05:00
|
|
|
return fmt.Errorf("PostgreSQL query row limit exceeded, limit %d", rowLimit)
|
2017-04-19 03:09:52 -05:00
|
|
|
}
|
|
|
|
|
2018-03-22 09:40:46 -05:00
|
|
|
values, err := e.getTypedRowData(rows)
|
2017-03-30 06:46:46 -05:00
|
|
|
if err != nil {
|
2018-03-22 09:40:46 -05:00
|
|
|
return err
|
2017-03-30 06:46:46 -05:00
|
|
|
}
|
|
|
|
|
2018-04-10 04:01:43 -05:00
|
|
|
// converts column named time to unix timestamp in milliseconds to make
|
|
|
|
// native mysql datetime types and epoch dates work in
|
|
|
|
// annotation and table queries.
|
|
|
|
tsdb.ConvertSqlTimeColumnToEpochMs(values, timeIndex)
|
|
|
|
|
2018-03-22 09:40:46 -05:00
|
|
|
switch columnValue := values[timeIndex].(type) {
|
|
|
|
case int64:
|
2018-04-10 04:01:43 -05:00
|
|
|
timestamp = float64(columnValue)
|
2018-03-22 09:40:46 -05:00
|
|
|
case float64:
|
2018-04-10 04:01:43 -05:00
|
|
|
timestamp = columnValue
|
2018-03-22 09:40:46 -05:00
|
|
|
default:
|
2018-04-10 04:01:43 -05:00
|
|
|
return fmt.Errorf("Invalid type for column time/time_sec, must be of type timestamp or unix timestamp, got: %T %v", columnValue, columnValue)
|
2017-03-31 04:45:25 -05:00
|
|
|
}
|
|
|
|
|
2018-03-22 09:40:46 -05:00
|
|
|
if metricIndex >= 0 {
|
Simplify comparison to bool constant (gosimple)
This fixes:
build.go:553:6: should omit comparison to bool constant, can be simplified to !strings.Contains(path, ".sha256") (S1002)
pkg/cmd/grafana-cli/commands/ls_command.go:27:5: should omit comparison to bool constant, can be simplified to !pluginDirInfo.IsDir() (S1002)
pkg/components/dynmap/dynmap_test.go:24:5: should omit comparison to bool constant, can be simplified to !value (S1002)
pkg/components/dynmap/dynmap_test.go:122:14: should omit comparison to bool constant, can be simplified to b (S1002)
pkg/components/dynmap/dynmap_test.go:125:14: should omit comparison to bool constant, can be simplified to !b (S1002)
pkg/components/dynmap/dynmap_test.go:128:14: should omit comparison to bool constant, can be simplified to !b (S1002)
pkg/models/org_user.go:51:5: should omit comparison to bool constant, can be simplified to !(*r).IsValid() (S1002)
pkg/plugins/datasource/wrapper/datasource_plugin_wrapper_test.go:77:12: should omit comparison to bool constant, can be simplified to !haveBool (S1002)
pkg/services/alerting/conditions/evaluator.go:23:9: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/conditions/evaluator.go:48:5: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/conditions/evaluator.go:91:5: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/conditions/query.go:56:6: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/extractor.go:107:20: should omit comparison to bool constant, can be simplified to !enabled.MustBool() (S1002)
pkg/services/alerting/notifiers/telegram.go:222:41: should omit comparison to bool constant, can be simplified to this.UploadImage (S1002)
pkg/services/sqlstore/apikey.go:58:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/apikey.go:72:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/dashboard.go:66:33: should omit comparison to bool constant, can be simplified to !cmd.Overwrite (S1002)
pkg/services/sqlstore/dashboard.go:175:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/dashboard.go:311:13: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/dashboard.go:444:12: should omit comparison to bool constant, can be simplified to !exists (S1002)
pkg/services/sqlstore/dashboard.go:472:12: should omit comparison to bool constant, can be simplified to !exists (S1002)
pkg/services/sqlstore/dashboard.go:554:32: should omit comparison to bool constant, can be simplified to !cmd.Overwrite (S1002)
pkg/services/sqlstore/dashboard_snapshot.go:83:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/plugin_setting.go:39:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:34:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:111:6: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:136:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:213:6: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/temp_user.go:129:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:157:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:182:5: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:191:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:212:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:307:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/social/generic_oauth.go:185:5: should omit comparison to bool constant, can be simplified to !s.extractToken(&data, token) (S1002)
pkg/tsdb/mssql/mssql.go:148:39: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/mssql/mssql.go:212:6: should omit comparison to bool constant, can be simplified to !query.Model.Get("fillNull").MustBool(false) (S1002)
pkg/tsdb/mssql/mssql.go:247:56: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/mssql/mssql.go:274:7: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/mssql/mssql.go:282:8: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/mysql/mysql.go:221:6: should omit comparison to bool constant, can be simplified to !query.Model.Get("fillNull").MustBool(false) (S1002)
pkg/tsdb/mysql/mysql.go:256:56: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/mysql/mysql.go:283:7: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/mysql/mysql.go:291:8: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/postgres/postgres.go:134:39: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/postgres/postgres.go:201:6: should omit comparison to bool constant, can be simplified to !query.Model.Get("fillNull").MustBool(false) (S1002)
pkg/tsdb/postgres/postgres.go:236:56: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/postgres/postgres.go:263:7: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/postgres/postgres.go:271:8: should omit comparison to bool constant, can be simplified to !exist (S1002)
2018-04-16 13:12:59 -05:00
|
|
|
if columnValue, ok := values[metricIndex].(string); ok {
|
2018-03-22 09:40:46 -05:00
|
|
|
metric = columnValue
|
|
|
|
} else {
|
|
|
|
return fmt.Errorf("Column metric must be of type char,varchar or text, got: %T %v", values[metricIndex], values[metricIndex])
|
|
|
|
}
|
2017-03-31 04:45:25 -05:00
|
|
|
}
|
2017-03-30 06:46:46 -05:00
|
|
|
|
2018-03-22 09:40:46 -05:00
|
|
|
for i, col := range columnNames {
|
|
|
|
if i == timeIndex || i == metricIndex {
|
|
|
|
continue
|
|
|
|
}
|
2017-12-10 12:50:01 -06:00
|
|
|
|
2018-04-24 12:53:06 -05:00
|
|
|
if value, err = tsdb.ConvertSqlValueColumnToFloat(col, values[i]); err != nil {
|
|
|
|
return err
|
2018-03-22 09:40:46 -05:00
|
|
|
}
|
2018-04-24 12:53:06 -05:00
|
|
|
|
2018-03-22 09:40:46 -05:00
|
|
|
if metricIndex == -1 {
|
|
|
|
metric = col
|
|
|
|
}
|
|
|
|
|
|
|
|
series, exist := pointsBySeries[metric]
|
Simplify comparison to bool constant (gosimple)
This fixes:
build.go:553:6: should omit comparison to bool constant, can be simplified to !strings.Contains(path, ".sha256") (S1002)
pkg/cmd/grafana-cli/commands/ls_command.go:27:5: should omit comparison to bool constant, can be simplified to !pluginDirInfo.IsDir() (S1002)
pkg/components/dynmap/dynmap_test.go:24:5: should omit comparison to bool constant, can be simplified to !value (S1002)
pkg/components/dynmap/dynmap_test.go:122:14: should omit comparison to bool constant, can be simplified to b (S1002)
pkg/components/dynmap/dynmap_test.go:125:14: should omit comparison to bool constant, can be simplified to !b (S1002)
pkg/components/dynmap/dynmap_test.go:128:14: should omit comparison to bool constant, can be simplified to !b (S1002)
pkg/models/org_user.go:51:5: should omit comparison to bool constant, can be simplified to !(*r).IsValid() (S1002)
pkg/plugins/datasource/wrapper/datasource_plugin_wrapper_test.go:77:12: should omit comparison to bool constant, can be simplified to !haveBool (S1002)
pkg/services/alerting/conditions/evaluator.go:23:9: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/conditions/evaluator.go:48:5: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/conditions/evaluator.go:91:5: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/conditions/query.go:56:6: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/extractor.go:107:20: should omit comparison to bool constant, can be simplified to !enabled.MustBool() (S1002)
pkg/services/alerting/notifiers/telegram.go:222:41: should omit comparison to bool constant, can be simplified to this.UploadImage (S1002)
pkg/services/sqlstore/apikey.go:58:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/apikey.go:72:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/dashboard.go:66:33: should omit comparison to bool constant, can be simplified to !cmd.Overwrite (S1002)
pkg/services/sqlstore/dashboard.go:175:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/dashboard.go:311:13: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/dashboard.go:444:12: should omit comparison to bool constant, can be simplified to !exists (S1002)
pkg/services/sqlstore/dashboard.go:472:12: should omit comparison to bool constant, can be simplified to !exists (S1002)
pkg/services/sqlstore/dashboard.go:554:32: should omit comparison to bool constant, can be simplified to !cmd.Overwrite (S1002)
pkg/services/sqlstore/dashboard_snapshot.go:83:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/plugin_setting.go:39:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:34:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:111:6: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:136:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:213:6: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/temp_user.go:129:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:157:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:182:5: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:191:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:212:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:307:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/social/generic_oauth.go:185:5: should omit comparison to bool constant, can be simplified to !s.extractToken(&data, token) (S1002)
pkg/tsdb/mssql/mssql.go:148:39: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/mssql/mssql.go:212:6: should omit comparison to bool constant, can be simplified to !query.Model.Get("fillNull").MustBool(false) (S1002)
pkg/tsdb/mssql/mssql.go:247:56: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/mssql/mssql.go:274:7: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/mssql/mssql.go:282:8: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/mysql/mysql.go:221:6: should omit comparison to bool constant, can be simplified to !query.Model.Get("fillNull").MustBool(false) (S1002)
pkg/tsdb/mysql/mysql.go:256:56: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/mysql/mysql.go:283:7: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/mysql/mysql.go:291:8: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/postgres/postgres.go:134:39: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/postgres/postgres.go:201:6: should omit comparison to bool constant, can be simplified to !query.Model.Get("fillNull").MustBool(false) (S1002)
pkg/tsdb/postgres/postgres.go:236:56: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/postgres/postgres.go:263:7: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/postgres/postgres.go:271:8: should omit comparison to bool constant, can be simplified to !exist (S1002)
2018-04-16 13:12:59 -05:00
|
|
|
if !exist {
|
2018-03-22 09:40:46 -05:00
|
|
|
series = &tsdb.TimeSeries{Name: metric}
|
|
|
|
pointsBySeries[metric] = series
|
|
|
|
seriesByQueryOrder.PushBack(metric)
|
2017-12-10 12:50:01 -06:00
|
|
|
}
|
|
|
|
|
2018-03-22 09:40:46 -05:00
|
|
|
if fillMissing {
|
|
|
|
var intervalStart float64
|
Simplify comparison to bool constant (gosimple)
This fixes:
build.go:553:6: should omit comparison to bool constant, can be simplified to !strings.Contains(path, ".sha256") (S1002)
pkg/cmd/grafana-cli/commands/ls_command.go:27:5: should omit comparison to bool constant, can be simplified to !pluginDirInfo.IsDir() (S1002)
pkg/components/dynmap/dynmap_test.go:24:5: should omit comparison to bool constant, can be simplified to !value (S1002)
pkg/components/dynmap/dynmap_test.go:122:14: should omit comparison to bool constant, can be simplified to b (S1002)
pkg/components/dynmap/dynmap_test.go:125:14: should omit comparison to bool constant, can be simplified to !b (S1002)
pkg/components/dynmap/dynmap_test.go:128:14: should omit comparison to bool constant, can be simplified to !b (S1002)
pkg/models/org_user.go:51:5: should omit comparison to bool constant, can be simplified to !(*r).IsValid() (S1002)
pkg/plugins/datasource/wrapper/datasource_plugin_wrapper_test.go:77:12: should omit comparison to bool constant, can be simplified to !haveBool (S1002)
pkg/services/alerting/conditions/evaluator.go:23:9: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/conditions/evaluator.go:48:5: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/conditions/evaluator.go:91:5: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/conditions/query.go:56:6: should omit comparison to bool constant, can be simplified to !reducedValue.Valid (S1002)
pkg/services/alerting/extractor.go:107:20: should omit comparison to bool constant, can be simplified to !enabled.MustBool() (S1002)
pkg/services/alerting/notifiers/telegram.go:222:41: should omit comparison to bool constant, can be simplified to this.UploadImage (S1002)
pkg/services/sqlstore/apikey.go:58:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/apikey.go:72:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/dashboard.go:66:33: should omit comparison to bool constant, can be simplified to !cmd.Overwrite (S1002)
pkg/services/sqlstore/dashboard.go:175:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/dashboard.go:311:13: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/dashboard.go:444:12: should omit comparison to bool constant, can be simplified to !exists (S1002)
pkg/services/sqlstore/dashboard.go:472:12: should omit comparison to bool constant, can be simplified to !exists (S1002)
pkg/services/sqlstore/dashboard.go:554:32: should omit comparison to bool constant, can be simplified to !cmd.Overwrite (S1002)
pkg/services/sqlstore/dashboard_snapshot.go:83:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/plugin_setting.go:39:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:34:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:111:6: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:136:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/quota.go:213:6: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/temp_user.go:129:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:157:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:182:5: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:191:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:212:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/services/sqlstore/user.go:307:12: should omit comparison to bool constant, can be simplified to !has (S1002)
pkg/social/generic_oauth.go:185:5: should omit comparison to bool constant, can be simplified to !s.extractToken(&data, token) (S1002)
pkg/tsdb/mssql/mssql.go:148:39: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/mssql/mssql.go:212:6: should omit comparison to bool constant, can be simplified to !query.Model.Get("fillNull").MustBool(false) (S1002)
pkg/tsdb/mssql/mssql.go:247:56: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/mssql/mssql.go:274:7: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/mssql/mssql.go:282:8: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/mysql/mysql.go:221:6: should omit comparison to bool constant, can be simplified to !query.Model.Get("fillNull").MustBool(false) (S1002)
pkg/tsdb/mysql/mysql.go:256:56: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/mysql/mysql.go:283:7: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/mysql/mysql.go:291:8: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/postgres/postgres.go:134:39: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/postgres/postgres.go:201:6: should omit comparison to bool constant, can be simplified to !query.Model.Get("fillNull").MustBool(false) (S1002)
pkg/tsdb/postgres/postgres.go:236:56: should omit comparison to bool constant, can be simplified to ok (S1002)
pkg/tsdb/postgres/postgres.go:263:7: should omit comparison to bool constant, can be simplified to !exist (S1002)
pkg/tsdb/postgres/postgres.go:271:8: should omit comparison to bool constant, can be simplified to !exist (S1002)
2018-04-16 13:12:59 -05:00
|
|
|
if !exist {
|
2018-03-22 09:40:46 -05:00
|
|
|
intervalStart = float64(tsdbQuery.TimeRange.MustGetFrom().UnixNano() / 1e6)
|
|
|
|
} else {
|
|
|
|
intervalStart = series.Points[len(series.Points)-1][1].Float64 + fillInterval
|
|
|
|
}
|
2017-12-10 12:50:01 -06:00
|
|
|
|
2018-03-22 09:40:46 -05:00
|
|
|
// align interval start
|
|
|
|
intervalStart = math.Floor(intervalStart/fillInterval) * fillInterval
|
|
|
|
|
|
|
|
for i := intervalStart; i < timestamp; i += fillInterval {
|
|
|
|
series.Points = append(series.Points, tsdb.TimePoint{fillValue, null.FloatFrom(i)})
|
|
|
|
rowCount++
|
|
|
|
}
|
2017-12-10 12:50:01 -06:00
|
|
|
}
|
|
|
|
|
2018-03-22 09:40:46 -05:00
|
|
|
series.Points = append(series.Points, tsdb.TimePoint{value, null.FloatFrom(timestamp)})
|
|
|
|
|
|
|
|
e.log.Debug("Rows", "metric", metric, "time", timestamp, "value", value)
|
|
|
|
rowCount++
|
|
|
|
|
|
|
|
}
|
2017-03-31 04:45:25 -05:00
|
|
|
}
|
2017-03-30 06:46:46 -05:00
|
|
|
|
2017-08-24 14:38:36 -05:00
|
|
|
for elem := seriesByQueryOrder.Front(); elem != nil; elem = elem.Next() {
|
|
|
|
key := elem.Value.(string)
|
|
|
|
result.Series = append(result.Series, pointsBySeries[key])
|
2017-12-10 12:50:01 -06:00
|
|
|
|
2018-05-02 07:06:46 -05:00
|
|
|
if fillMissing {
|
|
|
|
series := pointsBySeries[key]
|
|
|
|
// fill in values from last fetched value till interval end
|
|
|
|
intervalStart := series.Points[len(series.Points)-1][1].Float64
|
|
|
|
intervalEnd := float64(tsdbQuery.TimeRange.MustGetTo().UnixNano() / 1e6)
|
|
|
|
|
|
|
|
// align interval start
|
|
|
|
intervalStart = math.Floor(intervalStart/fillInterval) * fillInterval
|
|
|
|
for i := intervalStart + fillInterval; i < intervalEnd; i += fillInterval {
|
|
|
|
series.Points = append(series.Points, tsdb.TimePoint{fillValue, null.FloatFrom(i)})
|
|
|
|
rowCount++
|
|
|
|
}
|
2017-12-10 12:50:01 -06:00
|
|
|
}
|
2017-03-29 15:54:07 -05:00
|
|
|
}
|
2017-03-30 06:46:46 -05:00
|
|
|
|
2017-04-21 08:07:43 -05:00
|
|
|
result.Meta.Set("rowCount", rowCount)
|
|
|
|
return nil
|
2017-03-30 06:46:46 -05:00
|
|
|
}
|