mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 08:35:43 -06:00
* Introduce TSDB service Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> Co-authored-by: Erik Sundell <erik.sundell87@gmail.com> Co-authored-by: Will Browne <will.browne@grafana.com> Co-authored-by: Torkel Ödegaard <torkel@grafana.org> Co-authored-by: Will Browne <wbrowne@users.noreply.github.com> Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package elasticsearch
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/plugins"
|
|
es "github.com/grafana/grafana/pkg/tsdb/elasticsearch/client"
|
|
"github.com/grafana/grafana/pkg/tsdb/interval"
|
|
)
|
|
|
|
// ElasticsearchExecutor represents a handler for handling elasticsearch datasource request
|
|
type Executor struct {
|
|
intervalCalculator interval.Calculator
|
|
}
|
|
|
|
// NewExecutor creates a new Executor.
|
|
func NewExecutor(*models.DataSource) (plugins.DataPlugin, error) {
|
|
return &Executor{
|
|
intervalCalculator: interval.NewCalculator(),
|
|
}, nil
|
|
}
|
|
|
|
// Query handles an elasticsearch datasource request
|
|
func (e *Executor) DataQuery(ctx context.Context, dsInfo *models.DataSource,
|
|
tsdbQuery plugins.DataQuery) (plugins.DataResponse, error) {
|
|
if len(tsdbQuery.Queries) == 0 {
|
|
return plugins.DataResponse{}, fmt.Errorf("query contains no queries")
|
|
}
|
|
|
|
client, err := es.NewClient(ctx, dsInfo, *tsdbQuery.TimeRange)
|
|
if err != nil {
|
|
return plugins.DataResponse{}, err
|
|
}
|
|
|
|
if tsdbQuery.Debug {
|
|
client.EnableDebug()
|
|
}
|
|
|
|
query := newTimeSeriesQuery(client, tsdbQuery, e.intervalCalculator)
|
|
return query.execute()
|
|
}
|