Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
KubeSphere
kubesphere
提交
e94ef57d
K
kubesphere
项目概览
KubeSphere
/
kubesphere
通知
144
Star
32
Fork
5
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
e94ef57d
编写于
5月 08, 2019
作者:
不
不羁
提交者:
GitHub
5月 08, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #394 from huanggze/logging-dev
fix: log query starttime must be greater than the namespace creation time
上级
60d0c81b
260ffe90
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
62 addition
and
15 deletion
+62
-15
pkg/apiserver/logging/logging.go
pkg/apiserver/logging/logging.go
+6
-0
pkg/models/log/logcollector.go
pkg/models/log/logcollector.go
+33
-0
pkg/simple/client/elasticsearch/esclient.go
pkg/simple/client/elasticsearch/esclient.go
+23
-15
未找到文件。
pkg/apiserver/logging/logging.go
浏览文件 @
e94ef57d
...
...
@@ -138,6 +138,7 @@ func logQuery(level log.LogQueryLevel, request *restful.Request) *es.QueryResult
{
param
.
NamespaceFilled
,
param
.
Namespaces
=
log
.
QueryWorkspace
(
request
.
QueryParameter
(
"workspaces"
),
request
.
QueryParameter
(
"workspace_query"
))
param
.
NamespaceFilled
,
param
.
Namespaces
=
log
.
MatchNamespace
(
request
.
QueryParameter
(
"namespaces"
),
param
.
NamespaceFilled
,
param
.
Namespaces
)
param
.
NamespaceFilled
,
param
.
NamespaceWithCreationTime
=
log
.
GetNamespaceCreationTimeMap
(
param
.
Namespaces
)
param
.
NamespaceQuery
=
request
.
QueryParameter
(
"namespace_query"
)
param
.
PodFilled
,
param
.
Pods
=
log
.
QueryWorkload
(
request
.
QueryParameter
(
"workloads"
),
request
.
QueryParameter
(
"workload_query"
),
param
.
Namespaces
)
param
.
PodFilled
,
param
.
Pods
=
log
.
MatchPod
(
request
.
QueryParameter
(
"pods"
),
param
.
PodFilled
,
param
.
Pods
)
...
...
@@ -149,6 +150,7 @@ func logQuery(level log.LogQueryLevel, request *restful.Request) *es.QueryResult
{
param
.
NamespaceFilled
,
param
.
Namespaces
=
log
.
QueryWorkspace
(
request
.
PathParameter
(
"workspace"
),
""
)
param
.
NamespaceFilled
,
param
.
Namespaces
=
log
.
MatchNamespace
(
request
.
QueryParameter
(
"namespaces"
),
param
.
NamespaceFilled
,
param
.
Namespaces
)
param
.
NamespaceFilled
,
param
.
NamespaceWithCreationTime
=
log
.
GetNamespaceCreationTimeMap
(
param
.
Namespaces
)
param
.
NamespaceQuery
=
request
.
QueryParameter
(
"namespace_query"
)
param
.
PodFilled
,
param
.
Pods
=
log
.
QueryWorkload
(
request
.
QueryParameter
(
"workloads"
),
request
.
QueryParameter
(
"workload_query"
),
param
.
Namespaces
)
param
.
PodFilled
,
param
.
Pods
=
log
.
MatchPod
(
request
.
QueryParameter
(
"pods"
),
param
.
PodFilled
,
param
.
Pods
)
...
...
@@ -159,6 +161,7 @@ func logQuery(level log.LogQueryLevel, request *restful.Request) *es.QueryResult
case
log
.
QueryLevelNamespace
:
{
param
.
NamespaceFilled
,
param
.
Namespaces
=
log
.
MatchNamespace
(
request
.
PathParameter
(
"namespace"
),
false
,
nil
)
param
.
NamespaceFilled
,
param
.
NamespaceWithCreationTime
=
log
.
GetNamespaceCreationTimeMap
(
param
.
Namespaces
)
param
.
PodFilled
,
param
.
Pods
=
log
.
QueryWorkload
(
request
.
QueryParameter
(
"workloads"
),
request
.
QueryParameter
(
"workload_query"
),
param
.
Namespaces
)
param
.
PodFilled
,
param
.
Pods
=
log
.
MatchPod
(
request
.
QueryParameter
(
"pods"
),
param
.
PodFilled
,
param
.
Pods
)
param
.
PodQuery
=
request
.
QueryParameter
(
"pod_query"
)
...
...
@@ -168,6 +171,7 @@ func logQuery(level log.LogQueryLevel, request *restful.Request) *es.QueryResult
case
log
.
QueryLevelWorkload
:
{
param
.
NamespaceFilled
,
param
.
Namespaces
=
log
.
MatchNamespace
(
request
.
PathParameter
(
"namespace"
),
false
,
nil
)
param
.
NamespaceFilled
,
param
.
NamespaceWithCreationTime
=
log
.
GetNamespaceCreationTimeMap
(
param
.
Namespaces
)
param
.
PodFilled
,
param
.
Pods
=
log
.
QueryWorkload
(
request
.
PathParameter
(
"workload"
),
""
,
param
.
Namespaces
)
param
.
PodFilled
,
param
.
Pods
=
log
.
MatchPod
(
request
.
QueryParameter
(
"pods"
),
param
.
PodFilled
,
param
.
Pods
)
param
.
PodQuery
=
request
.
QueryParameter
(
"pod_query"
)
...
...
@@ -177,6 +181,7 @@ func logQuery(level log.LogQueryLevel, request *restful.Request) *es.QueryResult
case
log
.
QueryLevelPod
:
{
param
.
NamespaceFilled
,
param
.
Namespaces
=
log
.
MatchNamespace
(
request
.
PathParameter
(
"namespace"
),
false
,
nil
)
param
.
NamespaceFilled
,
param
.
NamespaceWithCreationTime
=
log
.
GetNamespaceCreationTimeMap
(
param
.
Namespaces
)
param
.
PodFilled
,
param
.
Pods
=
log
.
MatchPod
(
request
.
PathParameter
(
"pod"
),
false
,
nil
)
param
.
ContainerFilled
,
param
.
Containers
=
log
.
MatchContainer
(
request
.
QueryParameter
(
"containers"
))
param
.
ContainerQuery
=
request
.
QueryParameter
(
"container_query"
)
...
...
@@ -184,6 +189,7 @@ func logQuery(level log.LogQueryLevel, request *restful.Request) *es.QueryResult
case
log
.
QueryLevelContainer
:
{
param
.
NamespaceFilled
,
param
.
Namespaces
=
log
.
MatchNamespace
(
request
.
PathParameter
(
"namespace"
),
false
,
nil
)
param
.
NamespaceFilled
,
param
.
NamespaceWithCreationTime
=
log
.
GetNamespaceCreationTimeMap
(
param
.
Namespaces
)
param
.
PodFilled
,
param
.
Pods
=
log
.
MatchPod
(
request
.
PathParameter
(
"pod"
),
false
,
nil
)
param
.
ContainerFilled
,
param
.
Containers
=
log
.
MatchContainer
(
request
.
PathParameter
(
"container"
))
}
...
...
pkg/models/log/logcollector.go
浏览文件 @
e94ef57d
...
...
@@ -24,7 +24,9 @@ import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers"
"reflect"
"strconv"
"strings"
"time"
)
func
intersection
(
s1
,
s2
[]
string
)
(
inter
[]
string
)
{
...
...
@@ -181,6 +183,37 @@ func MatchNamespace(namespaceMatch string, namespaceFilled bool, namespaces []st
return
true
,
namespacesMatch
}
func
GetNamespaceCreationTimeMap
(
namespaces
[]
string
)
(
bool
,
map
[
string
]
string
)
{
namespaceWithCreationTime
:=
make
(
map
[
string
]
string
)
nsLister
:=
informers
.
SharedInformerFactory
()
.
Core
()
.
V1
()
.
Namespaces
()
.
Lister
()
if
len
(
namespaces
)
==
0
{
nsList
,
err
:=
nsLister
.
List
(
labels
.
Everything
())
if
err
!=
nil
{
glog
.
Error
(
"failed to list namespace, error: "
,
err
)
return
true
,
namespaceWithCreationTime
}
for
_
,
ns
:=
range
nsList
{
namespaces
=
append
(
namespaces
,
ns
.
Name
)
}
}
for
_
,
item
:=
range
namespaces
{
ns
,
err
:=
nsLister
.
Get
(
item
)
if
err
!=
nil
{
glog
.
Error
(
"failed to get namespace, error: "
,
err
)
continue
}
namespaceWithCreationTime
[
ns
.
Name
]
=
strconv
.
FormatInt
(
ns
.
CreationTimestamp
.
UnixNano
()
/
int64
(
time
.
Millisecond
),
10
)
}
return
true
,
namespaceWithCreationTime
}
func
QueryWorkload
(
workloadMatch
string
,
workloadQuery
string
,
namespaces
[]
string
)
(
bool
,
[]
string
)
{
if
workloadMatch
==
""
&&
workloadQuery
==
""
{
return
false
,
nil
...
...
pkg/simple/client/elasticsearch/esclient.go
浏览文件 @
e94ef57d
...
...
@@ -58,7 +58,7 @@ type Request struct {
From
int64
`json:"from"`
Size
int64
`json:"size"`
Sorts
[]
Sort
`json:"sort,omitempty"`
MainQuery
Main
Query
`json:"query"`
MainQuery
Bool
Query
`json:"query"`
Aggs
interface
{}
`json:"aggs,omitempty"`
MainHighLight
MainHighLight
`json:"highlight,omitempty"`
}
...
...
@@ -71,11 +71,11 @@ type Order struct {
Order
string
`json:"order"`
}
type
Main
Query
struct
{
MainBoolQuery
MainBoolQuery
`json:"bool"`
type
Bool
Query
struct
{
BoolMusts
BoolMusts
`json:"bool"`
}
type
MainBoolQuery
struct
{
type
BoolMusts
struct
{
Musts
[]
interface
{}
`json:"must"`
}
...
...
@@ -173,17 +173,24 @@ type DateHistogram struct {
func
createQueryRequest
(
param
QueryParameters
)
(
int
,
[]
byte
,
error
)
{
var
request
Request
var
mainBoolQuery
MainBoolQuery
var
mainBoolQuery
BoolMusts
if
param
.
NamespaceFilled
{
var
shouldMatchPhrase
ShouldMatchPhrase
if
len
(
param
.
Namespace
s
)
==
0
{
if
len
(
param
.
Namespace
WithCreationTime
)
==
0
{
matchPhrase
:=
MatchPhrase
{
map
[
string
]
interface
{}{
"kubernetes.namespace_name.key_word"
:
QueryWord
{
""
}}}
shouldMatchPhrase
.
Shoulds
=
append
(
shouldMatchPhrase
.
Shoulds
,
matchPhrase
)
}
else
{
for
_
,
namespace
:=
range
param
.
Namespaces
{
for
namespace
,
creationTime
:=
range
param
.
NamespaceWithCreationTime
{
var
boolQuery
BoolQuery
matchPhrase
:=
MatchPhrase
{
map
[
string
]
interface
{}{
"kubernetes.namespace_name.keyword"
:
QueryWord
{
namespace
}}}
shouldMatchPhrase
.
Shoulds
=
append
(
shouldMatchPhrase
.
Shoulds
,
matchPhrase
)
rangeQuery
:=
RangeQuery
{
RangeSpec
{
TimeRange
{
creationTime
,
""
}}}
boolQuery
.
BoolMusts
.
Musts
=
append
(
boolQuery
.
BoolMusts
.
Musts
,
matchPhrase
)
boolQuery
.
BoolMusts
.
Musts
=
append
(
boolQuery
.
BoolMusts
.
Musts
,
rangeQuery
)
shouldMatchPhrase
.
Shoulds
=
append
(
shouldMatchPhrase
.
Shoulds
,
boolQuery
)
}
}
shouldMatchPhrase
.
MinimumShouldMatch
=
1
...
...
@@ -278,7 +285,7 @@ func createQueryRequest(param QueryParameters) (int, []byte, error) {
request
.
MainHighLight
=
mainHighLight
}
request
.
MainQuery
=
Main
Query
{
mainBoolQuery
}
request
.
MainQuery
=
Bool
Query
{
mainBoolQuery
}
queryRequest
,
err
:=
json
.
Marshal
(
request
)
...
...
@@ -544,12 +551,13 @@ func parseQueryResult(operation int, param QueryParameters, body []byte, query [
}
type
QueryParameters
struct
{
NamespaceFilled
bool
Namespaces
[]
string
PodFilled
bool
Pods
[]
string
ContainerFilled
bool
Containers
[]
string
NamespaceFilled
bool
Namespaces
[]
string
NamespaceWithCreationTime
map
[
string
]
string
PodFilled
bool
Pods
[]
string
ContainerFilled
bool
Containers
[]
string
NamespaceQuery
string
PodQuery
string
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录