mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 08:35:43 -06:00
* Chore: Upgrade to Go 1.13 Fixes: #18878 Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Chore: Upgrade lint tools in order to work with Go 1.13 Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Chore: Fix Go linting issues Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package elasticsearch
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/tsdb"
|
|
es "github.com/grafana/grafana/pkg/tsdb/elasticsearch/client"
|
|
)
|
|
|
|
// ElasticsearchExecutor represents a handler for handling elasticsearch datasource request
|
|
type ElasticsearchExecutor struct{}
|
|
|
|
var (
|
|
intervalCalculator tsdb.IntervalCalculator
|
|
)
|
|
|
|
// NewElasticsearchExecutor creates a new elasticsearch executor
|
|
func NewElasticsearchExecutor(dsInfo *models.DataSource) (tsdb.TsdbQueryEndpoint, error) {
|
|
return &ElasticsearchExecutor{}, nil
|
|
}
|
|
|
|
func init() {
|
|
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()
|
|
}
|