Commit 5e0b0392 by Torkel Ödegaard

Merge branch 'v4.3.x'

parents ab44c7d6 0d39852e
...@@ -253,6 +253,7 @@ func (hs *HttpServer) registerRoutes() { ...@@ -253,6 +253,7 @@ func (hs *HttpServer) registerRoutes() {
r.Post("/tsdb/query", bind(dtos.MetricRequest{}), wrap(QueryMetrics)) r.Post("/tsdb/query", bind(dtos.MetricRequest{}), wrap(QueryMetrics))
r.Get("/tsdb/testdata/scenarios", wrap(GetTestDataScenarios)) r.Get("/tsdb/testdata/scenarios", wrap(GetTestDataScenarios))
r.Get("/tsdb/testdata/gensql", reqGrafanaAdmin, wrap(GenerateSqlTestData)) r.Get("/tsdb/testdata/gensql", reqGrafanaAdmin, wrap(GenerateSqlTestData))
r.Get("/tsdb/testdata/random-walk", wrap(GetTestDataRandomWalk))
// metrics // metrics
r.Get("/metrics", wrap(GetInternalMetrics)) r.Get("/metrics", wrap(GetInternalMetrics))
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/metrics" "github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/middleware" "github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
...@@ -144,3 +145,29 @@ func GenerateSqlTestData(c *middleware.Context) Response { ...@@ -144,3 +145,29 @@ func GenerateSqlTestData(c *middleware.Context) Response {
return Json(200, &util.DynMap{"message": "OK"}) return Json(200, &util.DynMap{"message": "OK"})
} }
// GET /api/tsdb/testdata/random-walk
func GetTestDataRandomWalk(c *middleware.Context) Response {
from := c.Query("from")
to := c.Query("to")
intervalMs := c.QueryInt64("intervalMs")
timeRange := tsdb.NewTimeRange(from, to)
request := &tsdb.Request{TimeRange: timeRange}
request.Queries = append(request.Queries, &tsdb.Query{
RefId: "A",
IntervalMs: intervalMs,
Model: simplejson.NewFromAny(&util.DynMap{
"scenario": "random_walk",
}),
DataSource: &models.DataSource{Type: "grafana-testdata-datasource"},
})
resp, err := tsdb.HandleRequest(context.Background(), request)
if err != nil {
return ApiError(500, "Metric request error", err)
}
return Json(200, &resp)
}
...@@ -8,11 +8,31 @@ class GrafanaDatasource { ...@@ -8,11 +8,31 @@ class GrafanaDatasource {
constructor(private backendSrv, private $q) {} constructor(private backendSrv, private $q) {}
query(options) { query(options) {
return this.$q.when({data: []}); return this.backendSrv.get('/api/tsdb/testdata/random-walk', {
from: options.range.from.valueOf(),
to: options.range.to.valueOf(),
intervalMs: options.intervalMs,
maxDataPoints: options.maxDataPoints,
}).then(res => {
var data = [];
if (res.results) {
_.forEach(res.results, queryRes => {
for (let series of queryRes.series) {
data.push({
target: series.name,
datapoints: series.points
});
}
});
} }
metricFindQuery() { return {data: data};
return this.$q.when([]); });
}
metricFindQuery(options) {
return this.$q.when({data: []});
} }
annotationQuery(options) { annotationQuery(options) {
......
<query-editor-row query-ctrl="ctrl" can-collapse="false"> <query-editor-row query-ctrl="ctrl" can-collapse="false">
<div class="gf-form-inline"> <div class="gf-form-inline">
<div class="gf-form"> <div class="gf-form">
<label class="gf-form-label">Test metric (fake data source)</label> <label class="gf-form-label">Test data: random walk</label>
</div>
<div class="gf-form gf-form--grow">
<div class="gf-form-label gf-form-label--grow"></div>
</div> </div>
</div> </div>
</query-editor-row> </query-editor-row>
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