@@ -12,10 +12,10 @@ import (
1212
1313 "github.com/grafana/grafana-plugin-sdk-go/backend"
1414 "github.com/grafana/grafana-plugin-sdk-go/data"
15- "golang.org/x/exp/slices"
1615
1716 es "github.com/quickwit-oss/quickwit-datasource/pkg/quickwit/client"
1817 "github.com/quickwit-oss/quickwit-datasource/pkg/quickwit/simplejson"
18+ utils "github.com/quickwit-oss/quickwit-datasource/pkg/utils"
1919)
2020
2121const (
@@ -247,7 +247,7 @@ func processDocsToDataFrameFields(docs []map[string]interface{}, propNames []str
247247 if propName == configuredFields .TimeField {
248248 timeVector := make ([]* time.Time , size )
249249 for i , doc := range docs {
250- timeValue , err := ParseToTime (doc [configuredFields .TimeField ], configuredFields .TimeOutputFormat )
250+ timeValue , err := utils . ParseTime (doc [configuredFields .TimeField ], configuredFields .TimeOutputFormat )
251251 if err != nil {
252252 continue
253253 }
@@ -291,44 +291,6 @@ func processDocsToDataFrameFields(docs []map[string]interface{}, propNames []str
291291 return allFields
292292}
293293
294- // Parses a value into Time given a timeOutputFormat. The conversion
295- // only works with float64 as this is what we get when parsing a response.
296- // TODO: understand why we get a float64?
297- func ParseToTime (value interface {}, timeOutputFormat string ) (time.Time , error ) {
298-
299- if timeOutputFormat == Iso8601 || timeOutputFormat == Rfc3339 {
300- value_string := value .(string )
301- timeValue , err := time .Parse (time .RFC3339 , value_string )
302- if err != nil {
303- return time.Time {}, err
304- }
305- return timeValue , nil
306- } else if timeOutputFormat == Rfc2822 {
307- value_string := value .(string )
308- timeValue , err := time .Parse (time .RFC822Z , value_string )
309- if err != nil {
310- return time.Time {}, err
311- }
312- return timeValue , nil
313- } else if slices .Contains ([]string {TimestampSecs , TimestampMillis , TimestampMicros , TimestampNanos }, timeOutputFormat ) {
314- typed_value , ok := value .(float64 )
315- if ! ok {
316- return time.Time {}, errors .New ("parse time only accepts float64 with timestamp based format" )
317- }
318- int64_value := int64 (typed_value )
319- if timeOutputFormat == TimestampSecs {
320- return time .Unix (int64_value , 0 ), nil
321- } else if timeOutputFormat == TimestampMillis {
322- return time .Unix (0 , int64_value * 1_000_000 ), nil
323- } else if timeOutputFormat == TimestampMicros {
324- return time .Unix (0 , int64_value * 1_000 ), nil
325- } else if timeOutputFormat == TimestampNanos {
326- return time .Unix (0 , int64_value ), nil
327- }
328- }
329- return time.Time {}, fmt .Errorf ("timeOutputFormat not supported yet %s" , timeOutputFormat )
330- }
331-
332294func processBuckets (aggs map [string ]interface {}, target * Query ,
333295 queryResult * backend.DataResponse , props map [string ]string , depth int ) error {
334296 var err error
0 commit comments