mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 21:22:44 +08:00
Chore: remove sql testdata (#38945)
This commit is contained in:
@ -370,7 +370,6 @@ func (hs *HTTPServer) registerRoutes() {
|
|||||||
|
|
||||||
// metrics
|
// metrics
|
||||||
apiRoute.Post("/tsdb/query", bind(dtos.MetricRequest{}), routing.Wrap(hs.QueryMetrics))
|
apiRoute.Post("/tsdb/query", bind(dtos.MetricRequest{}), routing.Wrap(hs.QueryMetrics))
|
||||||
apiRoute.Get("/tsdb/testdata/gensql", reqGrafanaAdmin, routing.Wrap(GenerateSQLTestData))
|
|
||||||
apiRoute.Get("/tsdb/testdata/random-walk", routing.Wrap(hs.GetTestDataRandomWalk))
|
apiRoute.Get("/tsdb/testdata/random-walk", routing.Wrap(hs.GetTestDataRandomWalk))
|
||||||
|
|
||||||
// DataSource w/ expressions
|
// DataSource w/ expressions
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||||
"github.com/grafana/grafana/pkg/api/dtos"
|
"github.com/grafana/grafana/pkg/api/dtos"
|
||||||
"github.com/grafana/grafana/pkg/api/response"
|
"github.com/grafana/grafana/pkg/api/response"
|
||||||
"github.com/grafana/grafana/pkg/bus"
|
|
||||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||||
"github.com/grafana/grafana/pkg/expr"
|
"github.com/grafana/grafana/pkg/expr"
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
@ -214,15 +213,6 @@ func (hs *HTTPServer) QueryMetrics(c *models.ReqContext, reqDto dtos.MetricReque
|
|||||||
return response.JSON(statusCode, &resp)
|
return response.JSON(statusCode, &resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET /api/tsdb/testdata/gensql
|
|
||||||
func GenerateSQLTestData(c *models.ReqContext) response.Response {
|
|
||||||
if err := bus.Dispatch(&models.InsertSQLTestDataCommand{}); err != nil {
|
|
||||||
return response.Error(500, "Failed to insert test data", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.JSON(200, &util.DynMap{"message": "OK"})
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET /api/tsdb/testdata/random-walk
|
// GET /api/tsdb/testdata/random-walk
|
||||||
func (hs *HTTPServer) GetTestDataRandomWalk(c *models.ReqContext) response.Response {
|
func (hs *HTTPServer) GetTestDataRandomWalk(c *models.ReqContext) response.Response {
|
||||||
from := c.Query("from")
|
from := c.Query("from")
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package models
|
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
type InsertSQLTestDataCommand struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type SQLTestData struct {
|
|
||||||
Id int64
|
|
||||||
Metric1 string
|
|
||||||
Metric2 string
|
|
||||||
ValueBigInt int64
|
|
||||||
ValueDouble float64
|
|
||||||
ValueFloat float32
|
|
||||||
ValueInt int
|
|
||||||
TimeEpoch int64
|
|
||||||
TimeDateTime time.Time
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
package sqlstore
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math/rand"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/bus"
|
|
||||||
"github.com/grafana/grafana/pkg/models"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
bus.AddHandler("sql", InsertSQLTestData)
|
|
||||||
}
|
|
||||||
|
|
||||||
func sqlRandomWalk(m1 string, m2 string, intWalker int64, floatWalker float64, sess *DBSession) error {
|
|
||||||
timeWalker := time.Now().UTC().Add(time.Hour * -200)
|
|
||||||
now := time.Now().UTC()
|
|
||||||
step := time.Minute
|
|
||||||
|
|
||||||
row := &models.SQLTestData{
|
|
||||||
Metric1: m1,
|
|
||||||
Metric2: m2,
|
|
||||||
TimeEpoch: timeWalker.Unix(),
|
|
||||||
TimeDateTime: timeWalker,
|
|
||||||
}
|
|
||||||
|
|
||||||
for timeWalker.Unix() < now.Unix() {
|
|
||||||
timeWalker = timeWalker.Add(step)
|
|
||||||
|
|
||||||
row.Id = 0
|
|
||||||
row.ValueBigInt += rand.Int63n(200) - 100
|
|
||||||
row.ValueDouble += rand.Float64() - 0.5
|
|
||||||
row.ValueFloat += rand.Float32() - 0.5
|
|
||||||
row.TimeEpoch = timeWalker.Unix()
|
|
||||||
row.TimeDateTime = timeWalker
|
|
||||||
|
|
||||||
sqlog.Info("Writing SQL test data row")
|
|
||||||
if _, err := sess.Table("test_data").Insert(row); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func InsertSQLTestData(cmd *models.InsertSQLTestDataCommand) error {
|
|
||||||
return inTransaction(func(sess *DBSession) error {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
sqlog.Info("SQL TestData: Clearing previous test data")
|
|
||||||
res, err := sess.Exec("TRUNCATE test_data")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
rows, _ := res.RowsAffected()
|
|
||||||
sqlog.Info("SQL TestData: Truncate done", "rows", rows)
|
|
||||||
|
|
||||||
if err := sqlRandomWalk("server1", "frontend", 100, 1.123, sess); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := sqlRandomWalk("server2", "frontend", 100, 1.123, sess); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return sqlRandomWalk("server3", "frontend", 100, 1.123, sess)
|
|
||||||
})
|
|
||||||
}
|
|
Reference in New Issue
Block a user