mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
added slow queries scenario to test data source, added new panel test dashboard with slow queries
This commit is contained in:
1166
devenv/dev-dashboards/panel_tests_slow_queries_and_annotations.json
Normal file
1166
devenv/dev-dashboards/panel_tests_slow_queries_and_annotations.json
Normal file
File diff suppressed because it is too large
Load Diff
75
pkg/tsdb/testdata/scenarios.go
vendored
75
pkg/tsdb/testdata/scenarios.go
vendored
@@ -95,27 +95,20 @@ func init() {
|
||||
Id: "random_walk",
|
||||
Name: "Random Walk",
|
||||
|
||||
Handler: func(query *tsdb.Query, tsdbQuery *tsdb.TsdbQuery) *tsdb.QueryResult {
|
||||
timeWalkerMs := tsdbQuery.TimeRange.GetFromAsMsEpoch()
|
||||
to := tsdbQuery.TimeRange.GetToAsMsEpoch()
|
||||
Handler: func(query *tsdb.Query, context *tsdb.TsdbQuery) *tsdb.QueryResult {
|
||||
return getRandomWalk(query, context)
|
||||
},
|
||||
})
|
||||
|
||||
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
|
||||
registerScenario(&Scenario{
|
||||
Id: "slow_query",
|
||||
Name: "Slow Query",
|
||||
StringInput: "5s",
|
||||
Handler: func(query *tsdb.Query, context *tsdb.TsdbQuery) *tsdb.QueryResult {
|
||||
stringInput := query.Model.Get("stringInput").MustString()
|
||||
parsedInterval, _ := time.ParseDuration(stringInput)
|
||||
time.Sleep(parsedInterval)
|
||||
return getRandomWalk(query, context)
|
||||
},
|
||||
})
|
||||
|
||||
@@ -223,23 +216,24 @@ func init() {
|
||||
})
|
||||
|
||||
registerScenario(&Scenario{
|
||||
Id: "annotations",
|
||||
Name: "Annotations",
|
||||
Id: "table_static",
|
||||
Name: "Table Static",
|
||||
|
||||
Handler: func(query *tsdb.Query, tsdbQuery *tsdb.TsdbQuery) *tsdb.QueryResult {
|
||||
timeWalkerMs := tsdbQuery.TimeRange.GetFromAsMsEpoch()
|
||||
to := tsdbQuery.TimeRange.GetToAsMsEpoch()
|
||||
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: "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), "hello"})
|
||||
table.Rows = append(table.Rows, tsdb.RowValues{float64(timeWalkerMs), "This is a message", "Description", 23.1})
|
||||
timeWalkerMs += query.IntervalMs
|
||||
}
|
||||
|
||||
@@ -250,6 +244,29 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
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) {
|
||||
ScenarioRegistry[scenario.Id] = scenario
|
||||
}
|
||||
|
@@ -68,29 +68,22 @@ class TestDataDatasource {
|
||||
}
|
||||
|
||||
annotationQuery(options) {
|
||||
return this.backendSrv
|
||||
.datasourceRequest({
|
||||
method: 'POST',
|
||||
url: '/api/tsdb/query',
|
||||
data: {
|
||||
from: options.range.from.valueOf().toString(),
|
||||
to: options.range.to.valueOf().toString(),
|
||||
queries: [
|
||||
{
|
||||
refId: 'A',
|
||||
scenarioId: 'annotations',
|
||||
intervalMs: 100,
|
||||
maxDataPoints: 100,
|
||||
stringInput: '',
|
||||
datasourceId: this.id,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
.then(resp => {
|
||||
console.log(resp);
|
||||
return [];
|
||||
let timeWalker = options.range.from.valueOf();
|
||||
const to = options.range.to.valueOf();
|
||||
const events = [];
|
||||
const eventCount = 10;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user