mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 11:44:26 -06:00
4840adff00
Removes moment dependency. Adds response parser tests (based on frontend tests). Adds time series query tests (based on frontend tests). Fixes various issues related to response parsing and building search request queries. Added support for extended stats metrics and geo hash grid aggregations.
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package elasticsearch
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/grafana/grafana/pkg/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
|
|
}
|
|
|
|
query := newTimeSeriesQuery(client, tsdbQuery, intervalCalculator)
|
|
return query.execute()
|
|
}
|