Merge pull request #2137 from huanggze/logging-fix

logging: start_time and end_time are not required params
This commit is contained in:
KubeSphere CI Bot
2020-06-01 20:20:36 +08:00
committed by GitHub
3 changed files with 30 additions and 8 deletions

View File

@@ -119,14 +119,15 @@ func (bb *bodyBuilder) mainBool(sf logging.SearchFilter) *bodyBuilder {
ms = append(ms, Match{Bool: &b})
}
if !sf.Starttime.IsZero() || !sf.Endtime.IsZero() {
fromTo := Match{
Range: &Range{&Time{
Gte: &sf.Starttime,
Lte: &sf.Endtime,
}},
}
ms = append(ms, fromTo)
r := &Range{Time: &Time{}}
if !sf.Starttime.IsZero() {
r.Gte = &sf.Starttime
}
if !sf.Endtime.IsZero() {
r.Lte = &sf.Endtime
}
if r.Lte != nil || r.Gte != nil {
ms = append(ms, Match{Range: r})
}
bb.Body.Query = &Query{Bool{Filter: ms}}

View File

@@ -45,6 +45,12 @@ func TestMainBool(t *testing.T) {
},
expected: "api_body_4.json",
},
{
filter: logging.SearchFilter{
Starttime: time.Unix(1590744676, 0),
},
expected: "api_body_7.json",
},
}
for i, test := range tests {

View File

@@ -0,0 +1,15 @@
{
"query":{
"bool":{
"filter":[
{
"range":{
"time":{
"gte":"2020-05-29T17:31:16+08:00"
}
}
}
]
}
}
}