Documentation ¶
Index ¶
- Variables
- func ConvertSqlTimeColumnToEpochMs(values RowValues, timeIndex int)
- func ConvertSqlValueColumnToFloat(columnName string, columnValue interface{}) (null.Float, error)
- func EpochPrecisionToMs(value float64) float64
- func FormatDuration(inter time.Duration) string
- func GetIntervalFrom(dsInfo *models.DataSource, queryModel *simplejson.Json, ...) (time.Duration, error)
- func NewIntervalCalculator(opt *IntervalOptions) *intervalCalculator
- func RegisterTsdbQueryEndpoint(pluginId string, fn GetTsdbQueryEndpointFn)
- func SetupFillmode(query *Query, interval time.Duration, fillmode string) error
- type GetTsdbQueryEndpointFn
- type HandleRequestFunc
- type Interval
- type IntervalCalculator
- type IntervalOptions
- type Query
- type QueryResult
- type Response
- type RowValues
- type SqlMacroEngine
- type SqlMacroEngineBase
- type SqlQueryEndpointConfiguration
- type SqlTableRowTransformer
- type Table
- type TableColumn
- type TimePoint
- type TimeRange
- func (tr *TimeRange) GetFromAsMsEpoch() int64
- func (tr *TimeRange) GetFromAsSecondsEpoch() int64
- func (tr *TimeRange) GetFromAsTimeUTC() time.Time
- func (tr *TimeRange) GetToAsMsEpoch() int64
- func (tr *TimeRange) GetToAsSecondsEpoch() int64
- func (tr *TimeRange) GetToAsTimeUTC() time.Time
- func (tr *TimeRange) MustGetFrom() time.Time
- func (tr *TimeRange) MustGetTo() time.Time
- func (tr *TimeRange) ParseFrom() (time.Time, error)
- func (tr *TimeRange) ParseTo() (time.Time, error)
- type TimeSeries
- type TimeSeriesPoints
- type TimeSeriesSlice
- type TsdbQuery
- type TsdbQueryEndpoint
Constants ¶
This section is empty.
Variables ¶
var Interpolate = func(query *Query, timeRange *TimeRange, sql string) (string, error) { minInterval, err := GetIntervalFrom(query.DataSource, query.Model, time.Second*60) if err != nil { return sql, nil } interval := sqlIntervalCalculator.Calculate(timeRange, minInterval) sql = strings.Replace(sql, "$__interval_ms", strconv.FormatInt(interval.Milliseconds(), 10), -1) sql = strings.Replace(sql, "$__interval", interval.Text, -1) sql = strings.Replace(sql, "$__unixEpochFrom()", fmt.Sprintf("%d", timeRange.GetFromAsSecondsEpoch()), -1) sql = strings.Replace(sql, "$__unixEpochTo()", fmt.Sprintf("%d", timeRange.GetToAsSecondsEpoch()), -1) return sql, nil }
global macros/substitutions for all sql datasources
var NewSqlQueryEndpoint = func(config *SqlQueryEndpointConfiguration, rowTransformer SqlTableRowTransformer, macroEngine SqlMacroEngine, log log.Logger) (TsdbQueryEndpoint, error) { queryEndpoint := sqlQueryEndpoint{ rowTransformer: rowTransformer, macroEngine: macroEngine, timeColumnNames: []string{"time"}, log: log, } if len(config.TimeColumnNames) > 0 { queryEndpoint.timeColumnNames = config.TimeColumnNames } if len(config.MetricColumnTypes) > 0 { queryEndpoint.metricColumnTypes = config.MetricColumnTypes } engineCache.Lock() defer engineCache.Unlock() if engine, present := engineCache.cache[config.Datasource.Id]; present { if version := engineCache.versions[config.Datasource.Id]; version == config.Datasource.Version { queryEndpoint.engine = engine return &queryEndpoint, nil } } engine, err := NewXormEngine(config.DriverName, config.ConnectionString) if err != nil { return nil, err } maxOpenConns := config.Datasource.JsonData.Get("maxOpenConns").MustInt(0) engine.SetMaxOpenConns(maxOpenConns) maxIdleConns := config.Datasource.JsonData.Get("maxIdleConns").MustInt(2) engine.SetMaxIdleConns(maxIdleConns) connMaxLifetime := config.Datasource.JsonData.Get("connMaxLifetime").MustInt(14400) engine.SetConnMaxLifetime(time.Duration(connMaxLifetime) * time.Second) engineCache.versions[config.Datasource.Id] = config.Datasource.Version engineCache.cache[config.Datasource.Id] = engine queryEndpoint.engine = engine return &queryEndpoint, nil }
Functions ¶
func ConvertSqlTimeColumnToEpochMs ¶
ConvertSqlTimeColumnToEpochMs converts column named time to unix timestamp in milliseconds to make native datetime types and epoch dates work in annotation and table queries.
func ConvertSqlValueColumnToFloat ¶
ConvertSqlValueColumnToFloat converts timeseries value column to float.
func EpochPrecisionToMs ¶
EpochPrecisionToMs converts epoch precision to millisecond, if needed. Only seconds to milliseconds supported right now
func FormatDuration ¶
FormatDuration converts a duration into the kbn format e.g. 1m 2h or 3d
func GetIntervalFrom ¶
func GetIntervalFrom(dsInfo *models.DataSource, queryModel *simplejson.Json, defaultInterval time.Duration) (time.Duration, error)
func NewIntervalCalculator ¶
func NewIntervalCalculator(opt *IntervalOptions) *intervalCalculator
func RegisterTsdbQueryEndpoint ¶
func RegisterTsdbQueryEndpoint(pluginId string, fn GetTsdbQueryEndpointFn)
Types ¶
type GetTsdbQueryEndpointFn ¶
type GetTsdbQueryEndpointFn func(dsInfo *models.DataSource) (TsdbQueryEndpoint, error)
type HandleRequestFunc ¶
type Interval ¶
func (*Interval) Milliseconds ¶
type IntervalCalculator ¶
type IntervalOptions ¶
type Query ¶
type Query struct { RefId string Model *simplejson.Json DataSource *models.DataSource MaxDataPoints int64 IntervalMs int64 }
type QueryResult ¶
type QueryResult struct { Error error `json:"-"` ErrorString string `json:"error,omitempty"` RefId string `json:"refId"` Meta *simplejson.Json `json:"meta,omitempty"` Series TimeSeriesSlice `json:"series"` Tables []*Table `json:"tables"` }
func NewQueryResult ¶
func NewQueryResult() *QueryResult
type Response ¶
type Response struct { Results map[string]*QueryResult `json:"results"` Message string `json:"message,omitempty"` }
func HandleRequest ¶
type SqlMacroEngine ¶
type SqlMacroEngine interface {
Interpolate(query *Query, timeRange *TimeRange, sql string) (string, error)
}
SqlMacroEngine interpolates macros into sql. It takes in the Query to have access to query context and timeRange to be able to generate queries that use from and to.
type SqlMacroEngineBase ¶
type SqlMacroEngineBase struct{}
func NewSqlMacroEngineBase ¶
func NewSqlMacroEngineBase() *SqlMacroEngineBase
func (*SqlMacroEngineBase) ReplaceAllStringSubmatchFunc ¶
type SqlTableRowTransformer ¶
type SqlTableRowTransformer interface {
Transform(columnTypes []*sql.ColumnType, rows *core.Rows) (RowValues, error)
}
SqlTableRowTransformer transforms a query result row to RowValues with proper types.
type Table ¶
type Table struct { Columns []TableColumn `json:"columns"` Rows []RowValues `json:"rows"` }
type TableColumn ¶
type TableColumn struct {
Text string `json:"text"`
}
type TimeRange ¶
func NewTimeRange ¶
func (*TimeRange) GetFromAsMsEpoch ¶
func (*TimeRange) GetFromAsSecondsEpoch ¶
func (*TimeRange) GetFromAsTimeUTC ¶
func (*TimeRange) GetToAsMsEpoch ¶
func (*TimeRange) GetToAsSecondsEpoch ¶
func (*TimeRange) GetToAsTimeUTC ¶
func (*TimeRange) MustGetFrom ¶
type TimeSeries ¶
type TimeSeries struct { Name string `json:"name"` Points TimeSeriesPoints `json:"points"` Tags map[string]string `json:"tags,omitempty"` }
func NewTimeSeries ¶
func NewTimeSeries(name string, points TimeSeriesPoints) *TimeSeries
type TimeSeriesPoints ¶
type TimeSeriesPoints []TimePoint
func NewTimeSeriesPointsFromArgs ¶
func NewTimeSeriesPointsFromArgs(values ...float64) TimeSeriesPoints
type TimeSeriesSlice ¶
type TimeSeriesSlice []*TimeSeries