mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* tsdb: add support for setting debug flag of tsdb query * alerting: adds debug flag in eval context Debug flag is set when testing an alert rule and this debug flag is used to return more debug information in test aler rule response. This debug flag is also provided to tsdb queries so datasources can optionally add support for returning additional debug data * alerting: improve test alert rule ui Adds buttons for expand/collapse json and copy json to clipboard, very similar to how the query inspector works. * elasticsearch: implement support for tsdb query debug flag * elasticsearch: embedding client response in struct * alerting: return proper query model when testing rule
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package elasticsearch
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/tsdb"
|
|
"github.com/grafana/grafana/pkg/tsdb/elasticsearch/client"
|
|
)
|
|
|
|
// ElasticsearchExecutor represents a handler for handling elasticsearch datasource request
|
|
type ElasticsearchExecutor struct{}
|
|
|
|
var (
|
|
glog log.Logger
|
|
intervalCalculator tsdb.IntervalCalculator
|
|
)
|
|
|
|
// NewElasticsearchExecutor creates a new elasticsearch executor
|
|
func NewElasticsearchExecutor(dsInfo *models.DataSource) (tsdb.TsdbQueryEndpoint, error) {
|
|
return &ElasticsearchExecutor{}, nil
|
|
}
|
|
|
|
func init() {
|
|
glog = log.New("tsdb.elasticsearch")
|
|
intervalCalculator = tsdb.NewIntervalCalculator(nil)
|
|
tsdb.RegisterTsdbQueryEndpoint("elasticsearch", NewElasticsearchExecutor)
|
|
}
|
|
|
|
// Query handles an elasticsearch datasource request
|
|
func (e *ElasticsearchExecutor) Query(ctx context.Context, dsInfo *models.DataSource, tsdbQuery *tsdb.TsdbQuery) (*tsdb.Response, error) {
|
|
if len(tsdbQuery.Queries) == 0 {
|
|
return nil, fmt.Errorf("query contains no queries")
|
|
}
|
|
|
|
client, err := es.NewClient(ctx, dsInfo, tsdbQuery.TimeRange)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if tsdbQuery.Debug {
|
|
client.EnableDebug()
|
|
}
|
|
|
|
query := newTimeSeriesQuery(client, tsdbQuery, intervalCalculator)
|
|
return query.execute()
|
|
}
|