Elasticsearch: Fix processing of logs with not-recognized time format (#67767)

* Elasticsearch: Fix parsing of invalid time

* Fix lint

* Add more test data to data.js

* Add tests

* Fix lint

* Update pkg/tsdb/elasticsearch/client/search_request.go
This commit is contained in:
Ivana Huckova
2023-05-04 19:33:00 +02:00
committed by GitHub
parent 49ff85ef54
commit 95cf598423
8 changed files with 142 additions and 37 deletions
+24 -3
View File
@@ -122,6 +122,15 @@ func processLogsResponse(res *es.SearchResponse, target *Query, configuredFields
}
}
if hit["fields"] != nil {
source, ok := hit["fields"].(map[string]interface{})
if ok {
for k, v := range source {
doc[k] = v
}
}
}
for key := range doc {
propNames[key] = true
}
@@ -258,15 +267,27 @@ func processDocsToDataFrameFields(docs []map[string]interface{}, propNames []str
size := len(docs)
isFilterable := true
allFields := make([]*data.Field, len(propNames))
timeString := ""
timeStringOk := false
for propNameIdx, propName := range propNames {
// Special handling for time field
if propName == configuredFields.TimeField {
timeVector := make([]*time.Time, size)
for i, doc := range docs {
timeString, ok := doc[configuredFields.TimeField].(string)
if !ok {
continue
// Check if time field is a string
timeString, timeStringOk = doc[configuredFields.TimeField].(string)
// If not, it might be an array with one time string
if !timeStringOk {
timeList, ok := doc[configuredFields.TimeField].([]interface{})
if !ok || len(timeList) != 1 {
continue
}
// Check if the first element is a string
timeString, timeStringOk = timeList[0].(string)
if !timeStringOk {
continue
}
}
timeValue, err := time.Parse(time.RFC3339Nano, timeString)
if err != nil {