mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
wip: began work on support for testdata tables & annotations support
This commit is contained in:
parent
1935497813
commit
9e72588cec
27
pkg/tsdb/testdata/scenarios.go
vendored
27
pkg/tsdb/testdata/scenarios.go
vendored
@ -221,6 +221,33 @@ func init() {
|
||||
return queryRes
|
||||
},
|
||||
})
|
||||
|
||||
registerScenario(&Scenario{
|
||||
Id: "annotations",
|
||||
Name: "Annotations",
|
||||
|
||||
Handler: func(query *tsdb.Query, tsdbQuery *tsdb.TsdbQuery) *tsdb.QueryResult {
|
||||
timeWalkerMs := tsdbQuery.TimeRange.GetFromAsMsEpoch()
|
||||
to := tsdbQuery.TimeRange.GetToAsMsEpoch()
|
||||
|
||||
table := tsdb.Table{
|
||||
Columns: []tsdb.TableColumn{
|
||||
{Text: "time"},
|
||||
{Text: "message"},
|
||||
},
|
||||
Rows: []tsdb.RowValues{},
|
||||
}
|
||||
|
||||
for i := int64(0); i < 10 && timeWalkerMs < to; i++ {
|
||||
table.Rows = append(table.Rows, tsdb.RowValues{float64(timeWalkerMs), "hello"})
|
||||
timeWalkerMs += query.IntervalMs
|
||||
}
|
||||
|
||||
queryRes := tsdb.NewQueryResult()
|
||||
queryRes.Tables = append(queryRes.Tables, &table)
|
||||
return queryRes
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func registerScenario(scenario *Scenario) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import _ from 'lodash';
|
||||
import TableModel from 'app/core/table_model';
|
||||
|
||||
class TestDataDatasource {
|
||||
id: any;
|
||||
@ -29,16 +30,29 @@ class TestDataDatasource {
|
||||
}
|
||||
|
||||
return this.backendSrv
|
||||
.post('/api/tsdb/query', {
|
||||
.datasourceRequest({
|
||||
method: 'POST',
|
||||
url: '/api/tsdb/query',
|
||||
data: {
|
||||
from: options.range.from.valueOf().toString(),
|
||||
to: options.range.to.valueOf().toString(),
|
||||
queries: queries,
|
||||
},
|
||||
})
|
||||
.then(res => {
|
||||
const data = [];
|
||||
|
||||
if (res.results) {
|
||||
_.forEach(res.results, queryRes => {
|
||||
if (res.data.results) {
|
||||
_.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) {
|
||||
data.push({
|
||||
target: series.name,
|
||||
@ -48,16 +62,34 @@ class TestDataDatasource {
|
||||
});
|
||||
}
|
||||
|
||||
console.log(res);
|
||||
return { data: data };
|
||||
});
|
||||
}
|
||||
|
||||
annotationQuery(options) {
|
||||
return this.backendSrv.get('/api/annotations', {
|
||||
from: options.range.from.valueOf(),
|
||||
to: options.range.to.valueOf(),
|
||||
limit: options.limit,
|
||||
type: options.type,
|
||||
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 [];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ class TestDataAnnotationsQueryCtrl {
|
||||
|
||||
constructor() {}
|
||||
|
||||
static template = '<h2>test data</h2>';
|
||||
static template = '<h2>Annotation scenario</h2>';
|
||||
}
|
||||
|
||||
export {
|
||||
|
Loading…
Reference in New Issue
Block a user