fix events search bug when no events
Signed-off-by: junotx <junotx@126.com>
This commit is contained in:
@@ -98,7 +98,7 @@ func (c *ClientV6) parse(resp *es6api.Response, err error) (*Response, error) {
|
|||||||
return nil, fmt.Errorf(resp.String())
|
return nil, fmt.Errorf(resp.String())
|
||||||
}
|
}
|
||||||
var r struct {
|
var r struct {
|
||||||
Hits *struct {
|
Hits struct {
|
||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
Hits jsoniter.RawMessage `json:"hits"`
|
Hits jsoniter.RawMessage `json:"hits"`
|
||||||
} `json:"hits"`
|
} `json:"hits"`
|
||||||
@@ -128,7 +128,7 @@ func (c *ClientV7) parse(resp *es7api.Response, err error) (*Response, error) {
|
|||||||
return nil, fmt.Errorf(resp.String())
|
return nil, fmt.Errorf(resp.String())
|
||||||
}
|
}
|
||||||
var r struct {
|
var r struct {
|
||||||
Hits *struct {
|
Hits struct {
|
||||||
Total struct {
|
Total struct {
|
||||||
Value int64 `json:"value"`
|
Value int64 `json:"value"`
|
||||||
} `json:"total"`
|
} `json:"total"`
|
||||||
|
|||||||
@@ -49,9 +49,12 @@ func (es *elasticsearch) SearchEvents(filter *events.Filter, from, size int64,
|
|||||||
Index: resolveIndexNames(es.opts.indexPrefix, filter.StartTime, filter.EndTime),
|
Index: resolveIndexNames(es.opts.indexPrefix, filter.StartTime, filter.EndTime),
|
||||||
Body: bytes.NewBuffer(body),
|
Body: bytes.NewBuffer(body),
|
||||||
})
|
})
|
||||||
if err != nil || resp == nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if resp == nil || len(resp.Hits.Hits) == 0 {
|
||||||
|
return &events.Events{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
var innerHits []struct {
|
var innerHits []struct {
|
||||||
*corev1.Event `json:"_source"`
|
*corev1.Event `json:"_source"`
|
||||||
@@ -95,11 +98,17 @@ func (es *elasticsearch) CountOverTime(filter *events.Filter, interval string) (
|
|||||||
Index: resolveIndexNames(es.opts.indexPrefix, filter.StartTime, filter.EndTime),
|
Index: resolveIndexNames(es.opts.indexPrefix, filter.StartTime, filter.EndTime),
|
||||||
Body: bytes.NewBuffer(body),
|
Body: bytes.NewBuffer(body),
|
||||||
})
|
})
|
||||||
if err != nil || resp == nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if resp == nil || resp.Aggregations == nil {
|
||||||
|
return &events.Histogram{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
raw := resp.Aggregations[aggName]
|
raw, ok := resp.Aggregations[aggName]
|
||||||
|
if !ok || len(raw) == 0 {
|
||||||
|
return &events.Histogram{}, nil
|
||||||
|
}
|
||||||
var agg struct {
|
var agg struct {
|
||||||
Buckets []struct {
|
Buckets []struct {
|
||||||
KeyAsString string `json:"key_as_string"`
|
KeyAsString string `json:"key_as_string"`
|
||||||
@@ -142,11 +151,17 @@ func (es *elasticsearch) StatisticsOnResources(filter *events.Filter) (*events.S
|
|||||||
Index: resolveIndexNames(es.opts.indexPrefix, filter.StartTime, filter.EndTime),
|
Index: resolveIndexNames(es.opts.indexPrefix, filter.StartTime, filter.EndTime),
|
||||||
Body: bytes.NewBuffer(body),
|
Body: bytes.NewBuffer(body),
|
||||||
})
|
})
|
||||||
if err != nil || resp == nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if resp == nil || resp.Aggregations == nil {
|
||||||
|
return &events.Statistics{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
raw := resp.Aggregations[aggName]
|
raw, ok := resp.Aggregations[aggName]
|
||||||
|
if !ok || len(raw) == 0 {
|
||||||
|
return &events.Statistics{}, nil
|
||||||
|
}
|
||||||
var agg struct {
|
var agg struct {
|
||||||
Value int64 `json:"value"`
|
Value int64 `json:"value"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user