@ -9,6 +9,7 @@ import (
"time"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"golang.org/x/exp/slices"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/log"
@ -53,6 +54,7 @@ func (e *elasticsearchDataQuery) execute() (*backend.QueryDataResponse, error) {
from := e . dataQueries [ 0 ] . TimeRange . From . UnixNano ( ) / int64 ( time . Millisecond )
to := e . dataQueries [ 0 ] . TimeRange . To . UnixNano ( ) / int64 ( time . Millisecond )
for _ , q := range queries {
fmt . Printf ( "Query = %v" , q )
if err := e . processQuery ( q , ms , from , to ) ; err != nil {
mq , _ := json . Marshal ( q )
e . logger . Error ( "Failed to process query to multisearch request builder" , "error" , err , "query" , string ( mq ) , "queriesLength" , len ( queries ) , "duration" , time . Since ( start ) , "stage" , es . StagePrepareRequest )
@ -160,22 +162,27 @@ func addDateHistogramAgg(aggBuilder es.AggBuilder, bucketAgg *BucketAgg, timeFro
field = timeField
}
aggBuilder . DateHistogram ( bucketAgg . ID , field , func ( a * es . DateHistogramAgg , b es . AggBuilder ) {
a . FixedInterval = bucketAgg . Settings . Get ( "interval" ) . MustString ( "auto" )
var interval = bucketAgg . Settings . Get ( "interval" ) . MustString ( "auto" )
if slices . Contains ( es . GetCalendarIntervals ( ) , interval ) {
a . CalendarInterval = interval
} else {
if interval == "auto" {
// note this is not really a valid grafana-variable-handling,
// because normally this would not match `$__interval_ms`,
// but because how we apply these in the go-code, this will work
// correctly, and becomes something like `500ms`.
// a nicer way would be to use `${__interval_ms}ms`, but
// that format is not recognized where we apply these variables
// in the elasticsearch datasource
a . FixedInterval = "$__interval_msms"
} else {
a . FixedInterval = interval
}
}
a . MinDocCount = bucketAgg . Settings . Get ( "min_doc_count" ) . MustInt ( 0 )
a . ExtendedBounds = & es . ExtendedBounds { Min : timeFrom , Max : timeTo }
a . Format = bucketAgg . Settings . Get ( "format" ) . MustString ( es . DateFormatEpochMS )
if a . FixedInterval == "auto" {
// note this is not really a valid grafana-variable-handling,
// because normally this would not match `$__interval_ms`,
// but because how we apply these in the go-code, this will work
// correctly, and becomes something like `500ms`.
// a nicer way would be to use `${__interval_ms}ms`, but
// that format is not recognized where we apply these variables
// in the elasticsearch datasource
a . FixedInterval = "$__interval_msms"
}
if offset , err := bucketAgg . Settings . Get ( "offset" ) . String ( ) ; err == nil {
a . Offset = offset
}