2016-06-06 03:31:21 -05:00
|
|
|
package tsdb
|
|
|
|
|
2016-09-28 02:15:48 -05:00
|
|
|
import (
|
2017-01-13 05:32:30 -06:00
|
|
|
"github.com/grafana/grafana/pkg/components/null"
|
2016-09-28 02:15:48 -05:00
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
2016-12-07 04:10:42 -06:00
|
|
|
"github.com/grafana/grafana/pkg/models"
|
2016-09-28 02:15:48 -05:00
|
|
|
)
|
2016-09-21 04:17:29 -05:00
|
|
|
|
2020-03-06 07:37:36 -06:00
|
|
|
// TsdbQuery contains all information about a query request.
|
2017-09-20 11:31:34 -05:00
|
|
|
type TsdbQuery struct {
|
|
|
|
TimeRange *TimeRange
|
2017-09-20 11:56:33 -05:00
|
|
|
Queries []*Query
|
2019-06-25 01:52:17 -05:00
|
|
|
Debug bool
|
2020-03-06 07:37:36 -06:00
|
|
|
User *models.SignedInUser
|
2017-09-20 11:31:34 -05:00
|
|
|
}
|
|
|
|
|
2016-09-21 00:01:53 -05:00
|
|
|
type Query struct {
|
2016-09-27 07:39:51 -05:00
|
|
|
RefId string
|
|
|
|
Model *simplejson.Json
|
2016-12-07 04:10:42 -06:00
|
|
|
DataSource *models.DataSource
|
2016-09-27 07:39:51 -05:00
|
|
|
MaxDataPoints int64
|
|
|
|
IntervalMs int64
|
2016-06-06 03:31:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type Response struct {
|
2017-09-21 11:04:06 -05:00
|
|
|
Results map[string]*QueryResult `json:"results"`
|
|
|
|
Message string `json:"message,omitempty"`
|
2016-10-06 07:16:26 -05:00
|
|
|
}
|
|
|
|
|
2016-06-06 03:31:21 -05:00
|
|
|
type QueryResult struct {
|
2017-04-19 10:26:29 -05:00
|
|
|
Error error `json:"-"`
|
|
|
|
ErrorString string `json:"error,omitempty"`
|
|
|
|
RefId string `json:"refId"`
|
|
|
|
Meta *simplejson.Json `json:"meta,omitempty"`
|
|
|
|
Series TimeSeriesSlice `json:"series"`
|
2017-04-21 08:07:43 -05:00
|
|
|
Tables []*Table `json:"tables"`
|
2019-10-24 10:15:27 -05:00
|
|
|
Dataframes [][]byte `json:"dataframes"`
|
2016-06-06 03:31:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type TimeSeries struct {
|
2017-02-06 07:59:29 -06:00
|
|
|
Name string `json:"name"`
|
|
|
|
Points TimeSeriesPoints `json:"points"`
|
2017-04-21 08:07:43 -05:00
|
|
|
Tags map[string]string `json:"tags,omitempty"`
|
2016-06-06 03:31:21 -05:00
|
|
|
}
|
|
|
|
|
2017-04-21 08:07:43 -05:00
|
|
|
type Table struct {
|
|
|
|
Columns []TableColumn `json:"columns"`
|
|
|
|
Rows []RowValues `json:"rows"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type TableColumn struct {
|
|
|
|
Text string `json:"text"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type RowValues []interface{}
|
2016-09-28 02:15:48 -05:00
|
|
|
type TimePoint [2]null.Float
|
|
|
|
type TimeSeriesPoints []TimePoint
|
2016-06-06 03:31:21 -05:00
|
|
|
type TimeSeriesSlice []*TimeSeries
|
|
|
|
|
2016-09-28 03:37:30 -05:00
|
|
|
func NewQueryResult() *QueryResult {
|
|
|
|
return &QueryResult{
|
|
|
|
Series: make(TimeSeriesSlice, 0),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-06 05:51:45 -05:00
|
|
|
func NewTimePoint(value null.Float, timestamp float64) TimePoint {
|
|
|
|
return TimePoint{value, null.FloatFrom(timestamp)}
|
2016-09-28 02:15:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewTimeSeriesPointsFromArgs(values ...float64) TimeSeriesPoints {
|
|
|
|
points := make(TimeSeriesPoints, 0)
|
|
|
|
|
|
|
|
for i := 0; i < len(values); i += 2 {
|
2016-10-06 05:51:45 -05:00
|
|
|
points = append(points, NewTimePoint(null.FloatFrom(values[i]), values[i+1]))
|
2016-09-28 02:15:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return points
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTimeSeries(name string, points TimeSeriesPoints) *TimeSeries {
|
2016-06-06 03:31:21 -05:00
|
|
|
return &TimeSeries{
|
|
|
|
Name: name,
|
|
|
|
Points: points,
|
|
|
|
}
|
|
|
|
}
|