Commit bd4f0734 by Torkel Ödegaard

mysql: minor update

parent 998f04e1
......@@ -252,6 +252,7 @@ func (hs *HttpServer) registerRoutes() {
// metrics
r.Post("/tsdb/query", bind(dtos.MetricRequest{}), wrap(QueryMetrics))
r.Get("/tsdb/testdata/scenarios", wrap(GetTestDataScenarios))
r.Get("/tsdb/testdata/gensql", reqGrafanaAdmin, wrap(GenerateSqlTestData))
// metrics
r.Get("/metrics", wrap(GetInternalMetrics))
......
......@@ -126,3 +126,12 @@ func GenerateError(c *middleware.Context) Response {
var array []string
return Json(200, array[20])
}
// GET /api/tsdb/testdata/gensql
func GenerateSqlTestData(c *middleware.Context) Response {
if err := bus.Dispatch(&models.InsertSqlTestDataCommand{}); err != nil {
return ApiError(500, "Failed to insert test data", err)
}
return Json(200, &util.DynMap{"message": "OK"})
}
......@@ -11,6 +11,7 @@ type SqlTestData struct {
Metric2 string
ValueBigInt int64
ValueDouble float64
ValueFloat float32
ValueInt int
TimeEpoch int64
TimeDateTime time.Time
......
......@@ -41,7 +41,7 @@ func addTestDataMigrations(mg *Migrator) {
{Name: "id", Type: DB_Int, IsPrimaryKey: true, IsAutoIncrement: true},
{Name: "metric1", Type: DB_Varchar, Length: 20, Nullable: true},
{Name: "metric2", Type: DB_NVarchar, Length: 150, Nullable: true},
{Name: "value_big_ing", Type: DB_BigInt, Nullable: true},
{Name: "value_big_int", Type: DB_BigInt, Nullable: true},
{Name: "value_double", Type: DB_Double, Nullable: true},
{Name: "value_float", Type: DB_Float, Nullable: true},
{Name: "value_int", Type: DB_Int, Nullable: true},
......
package sqlstore
import (
"time"
"github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models"
)
......@@ -12,10 +14,17 @@ func init() {
func InsertSqlTestData(cmd *m.InsertSqlTestDataCommand) error {
return inTransaction2(func(sess *session) error {
// create user
user := &m.SqlTestData{}
row := &m.SqlTestData{
Metric1: "server1",
Metric2: "frontend",
ValueBigInt: 123123,
ValueDouble: 3.14159265359,
ValueFloat: 3.14159265359,
TimeEpoch: time.Now().Unix(),
TimeDateTime: time.Now(),
}
if _, err := sess.Insert(user); err != nil {
if _, err := sess.Table("test_data").Insert(row); err != nil {
return err
}
......
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