提交 393386a3 编写于 作者: J junotx

fix events search bug when no events

Signed-off-by: Njunotx <junotx@126.com>
上级 26ac41d0
......@@ -98,7 +98,7 @@ func (c *ClientV6) parse(resp *es6api.Response, err error) (*Response, error) {
return nil, fmt.Errorf(resp.String())
}
var r struct {
Hits *struct {
Hits struct {
Total int64 `json:"total"`
Hits jsoniter.RawMessage `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())
}
var r struct {
Hits *struct {
Hits struct {
Total struct {
Value int64 `json:"value"`
} `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),
Body: bytes.NewBuffer(body),
})
if err != nil || resp == nil {
if err != nil {
return nil, err
}
if resp == nil || len(resp.Hits.Hits) == 0 {
return &events.Events{}, nil
}
var innerHits []struct {
*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),
Body: bytes.NewBuffer(body),
})
if err != nil || resp == nil {
if err != nil {
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 {
Buckets []struct {
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),
Body: bytes.NewBuffer(body),
})
if err != nil || resp == nil {
if err != nil {
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 {
Value int64 `json:"value"`
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册