File diff suppressed because it is too large
Load Diff
Vendored
+64
-20
@@ -95,27 +95,20 @@ func init() {
|
|||||||
Id: "random_walk",
|
Id: "random_walk",
|
||||||
Name: "Random Walk",
|
Name: "Random Walk",
|
||||||
|
|
||||||
Handler: func(query *tsdb.Query, tsdbQuery *tsdb.TsdbQuery) *tsdb.QueryResult {
|
Handler: func(query *tsdb.Query, context *tsdb.TsdbQuery) *tsdb.QueryResult {
|
||||||
timeWalkerMs := tsdbQuery.TimeRange.GetFromAsMsEpoch()
|
return getRandomWalk(query, context)
|
||||||
to := tsdbQuery.TimeRange.GetToAsMsEpoch()
|
},
|
||||||
|
})
|
||||||
|
|
||||||
series := newSeriesForQuery(query)
|
registerScenario(&Scenario{
|
||||||
|
Id: "slow_query",
|
||||||
points := make(tsdb.TimeSeriesPoints, 0)
|
Name: "Slow Query",
|
||||||
walker := rand.Float64() * 100
|
StringInput: "5s",
|
||||||
|
Handler: func(query *tsdb.Query, context *tsdb.TsdbQuery) *tsdb.QueryResult {
|
||||||
for i := int64(0); i < 10000 && timeWalkerMs < to; i++ {
|
stringInput := query.Model.Get("stringInput").MustString()
|
||||||
points = append(points, tsdb.NewTimePoint(null.FloatFrom(walker), float64(timeWalkerMs)))
|
parsedInterval, _ := time.ParseDuration(stringInput)
|
||||||
|
time.Sleep(parsedInterval)
|
||||||
walker += rand.Float64() - 0.5
|
return getRandomWalk(query, context)
|
||||||
timeWalkerMs += query.IntervalMs
|
|
||||||
}
|
|
||||||
|
|
||||||
series.Points = points
|
|
||||||
|
|
||||||
queryRes := tsdb.NewQueryResult()
|
|
||||||
queryRes.Series = append(queryRes.Series, series)
|
|
||||||
return queryRes
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -221,6 +214,57 @@ func init() {
|
|||||||
return queryRes
|
return queryRes
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
registerScenario(&Scenario{
|
||||||
|
Id: "table_static",
|
||||||
|
Name: "Table Static",
|
||||||
|
|
||||||
|
Handler: func(query *tsdb.Query, context *tsdb.TsdbQuery) *tsdb.QueryResult {
|
||||||
|
timeWalkerMs := context.TimeRange.GetFromAsMsEpoch()
|
||||||
|
to := context.TimeRange.GetToAsMsEpoch()
|
||||||
|
|
||||||
|
table := tsdb.Table{
|
||||||
|
Columns: []tsdb.TableColumn{
|
||||||
|
{Text: "Time"},
|
||||||
|
{Text: "Message"},
|
||||||
|
{Text: "Description"},
|
||||||
|
{Text: "Value"},
|
||||||
|
},
|
||||||
|
Rows: []tsdb.RowValues{},
|
||||||
|
}
|
||||||
|
for i := int64(0); i < 10 && timeWalkerMs < to; i++ {
|
||||||
|
table.Rows = append(table.Rows, tsdb.RowValues{float64(timeWalkerMs), "This is a message", "Description", 23.1})
|
||||||
|
timeWalkerMs += query.IntervalMs
|
||||||
|
}
|
||||||
|
|
||||||
|
queryRes := tsdb.NewQueryResult()
|
||||||
|
queryRes.Tables = append(queryRes.Tables, &table)
|
||||||
|
return queryRes
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRandomWalk(query *tsdb.Query, tsdbQuery *tsdb.TsdbQuery) *tsdb.QueryResult {
|
||||||
|
timeWalkerMs := tsdbQuery.TimeRange.GetFromAsMsEpoch()
|
||||||
|
to := tsdbQuery.TimeRange.GetToAsMsEpoch()
|
||||||
|
|
||||||
|
series := newSeriesForQuery(query)
|
||||||
|
|
||||||
|
points := make(tsdb.TimeSeriesPoints, 0)
|
||||||
|
walker := rand.Float64() * 100
|
||||||
|
|
||||||
|
for i := int64(0); i < 10000 && timeWalkerMs < to; i++ {
|
||||||
|
points = append(points, tsdb.NewTimePoint(null.FloatFrom(walker), float64(timeWalkerMs)))
|
||||||
|
|
||||||
|
walker += rand.Float64() - 0.5
|
||||||
|
timeWalkerMs += query.IntervalMs
|
||||||
|
}
|
||||||
|
|
||||||
|
series.Points = points
|
||||||
|
|
||||||
|
queryRes := tsdb.NewQueryResult()
|
||||||
|
queryRes.Series = append(queryRes.Series, series)
|
||||||
|
return queryRes
|
||||||
}
|
}
|
||||||
|
|
||||||
func registerScenario(scenario *Scenario) {
|
func registerScenario(scenario *Scenario) {
|
||||||
|
|||||||
+37
-12
@@ -1,4 +1,5 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import TableModel from 'app/core/table_model';
|
||||||
|
|
||||||
class TestDataDatasource {
|
class TestDataDatasource {
|
||||||
id: any;
|
id: any;
|
||||||
@@ -29,16 +30,29 @@ class TestDataDatasource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return this.backendSrv
|
return this.backendSrv
|
||||||
.post('/api/tsdb/query', {
|
.datasourceRequest({
|
||||||
from: options.range.from.valueOf().toString(),
|
method: 'POST',
|
||||||
to: options.range.to.valueOf().toString(),
|
url: '/api/tsdb/query',
|
||||||
queries: queries,
|
data: {
|
||||||
|
from: options.range.from.valueOf().toString(),
|
||||||
|
to: options.range.to.valueOf().toString(),
|
||||||
|
queries: queries,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
const data = [];
|
const data = [];
|
||||||
|
|
||||||
if (res.results) {
|
if (res.data.results) {
|
||||||
_.forEach(res.results, queryRes => {
|
_.forEach(res.data.results, queryRes => {
|
||||||
|
if (queryRes.tables) {
|
||||||
|
for (const table of queryRes.tables) {
|
||||||
|
const model = new TableModel();
|
||||||
|
model.rows = table.rows;
|
||||||
|
model.columns = table.columns;
|
||||||
|
|
||||||
|
data.push(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
for (const series of queryRes.series) {
|
for (const series of queryRes.series) {
|
||||||
data.push({
|
data.push({
|
||||||
target: series.name,
|
target: series.name,
|
||||||
@@ -48,17 +62,28 @@ class TestDataDatasource {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(res);
|
||||||
return { data: data };
|
return { data: data };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
annotationQuery(options) {
|
annotationQuery(options) {
|
||||||
return this.backendSrv.get('/api/annotations', {
|
let timeWalker = options.range.from.valueOf();
|
||||||
from: options.range.from.valueOf(),
|
const to = options.range.to.valueOf();
|
||||||
to: options.range.to.valueOf(),
|
const events = [];
|
||||||
limit: options.limit,
|
const eventCount = 10;
|
||||||
type: options.type,
|
const step = (to - timeWalker) / eventCount;
|
||||||
});
|
|
||||||
|
for (let i = 0; i < eventCount; i++) {
|
||||||
|
events.push({
|
||||||
|
annotation: options.annotation,
|
||||||
|
time: timeWalker,
|
||||||
|
text: 'This is the text, <a href="https://grafana.com">Grafana.com</a>',
|
||||||
|
tags: ['text', 'server'],
|
||||||
|
});
|
||||||
|
timeWalker += step;
|
||||||
|
}
|
||||||
|
return this.$q.when(events);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ class TestDataAnnotationsQueryCtrl {
|
|||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
static template = '<h2>test data</h2>';
|
static template = '<h2>Annotation scenario</h2>';
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|||||||
Reference in New Issue
Block a user