Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
ee95aeff
K
kubesphere
项目概览
水淹萌龙
/
kubesphere
与 Fork 源项目一致
Fork自
KubeSphere / kubesphere
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
ee95aeff
编写于
12月 14, 2020
作者:
W
wanjunlei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resolve conversation
Signed-off-by:
N
wanjunlei
<
wanjunlei@yunify.com
>
上级
b543ae1a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
50 addition
and
50 deletion
+50
-50
pkg/apiserver/auditing/backend.go
pkg/apiserver/auditing/backend.go
+34
-34
pkg/apiserver/auditing/types.go
pkg/apiserver/auditing/types.go
+1
-1
pkg/simple/client/auditing/elasticsearch/options.go
pkg/simple/client/auditing/elasticsearch/options.go
+15
-15
未找到文件。
pkg/apiserver/auditing/backend.go
浏览文件 @
ee95aeff
...
...
@@ -29,55 +29,55 @@ import (
)
const
(
WaitTimeout
=
time
.
Second
GetSenderTimeout
=
time
.
Second
SendTimeout
=
time
.
Second
*
3
Default
GoroutinesNum
=
100
Default
SendersNum
=
100
DefaultBatchSize
=
100
DefaultBatch
Wait
=
time
.
Second
*
3
DefaultBatch
Interval
=
time
.
Second
*
3
WebhookURL
=
"https://kube-auditing-webhook-svc.kubesphere-logging-system.svc:443/audit/webhook/event"
)
type
Backend
struct
{
url
string
se
mCh
chan
interface
{}
cache
chan
*
v1alpha1
.
Event
client
http
.
Client
sendTimeout
time
.
Duration
waitTimeout
time
.
Duration
maxBatchSize
int
maxBatchWait
time
.
Duration
stopCh
<-
chan
struct
{}
url
string
se
nderCh
chan
interface
{}
cache
chan
*
v1alpha1
.
Event
client
http
.
Client
sendTimeout
time
.
Duration
getSenderTimeout
time
.
Duration
eventBatchSize
int
eventBatchInterval
time
.
Duration
stopCh
<-
chan
struct
{}
}
func
NewBackend
(
opts
*
options
.
Options
,
cache
chan
*
v1alpha1
.
Event
,
stopCh
<-
chan
struct
{})
*
Backend
{
b
:=
Backend
{
url
:
opts
.
WebhookUrl
,
waitTimeout
:
Wait
Timeout
,
cache
:
cache
,
sendTimeout
:
SendTimeout
,
maxBatchSize
:
opts
.
Max
BatchSize
,
maxBatchWait
:
opts
.
MaxBatchWait
,
stopCh
:
stopCh
,
url
:
opts
.
WebhookUrl
,
getSenderTimeout
:
GetSender
Timeout
,
cache
:
cache
,
sendTimeout
:
SendTimeout
,
eventBatchSize
:
opts
.
Event
BatchSize
,
eventBatchInterval
:
opts
.
EventBatchInterval
,
stopCh
:
stopCh
,
}
if
len
(
b
.
url
)
==
0
{
b
.
url
=
WebhookURL
}
if
b
.
maxBatchWait
==
0
{
b
.
maxBatchWait
=
DefaultBatchWait
if
b
.
eventBatchInterval
==
0
{
b
.
eventBatchInterval
=
DefaultBatchInterval
}
if
b
.
max
BatchSize
==
0
{
b
.
max
BatchSize
=
DefaultBatchSize
if
b
.
event
BatchSize
==
0
{
b
.
event
BatchSize
=
DefaultBatchSize
}
goroutinesNum
:=
opts
.
Goroutine
sNum
if
goroutine
sNum
==
0
{
goroutinesNum
=
DefaultGoroutine
sNum
sendersNum
:=
opts
.
EventSender
sNum
if
sender
sNum
==
0
{
sendersNum
=
DefaultSender
sNum
}
b
.
se
mCh
=
make
(
chan
interface
{},
goroutine
sNum
)
b
.
se
nderCh
=
make
(
chan
interface
{},
sender
sNum
)
b
.
client
=
http
.
Client
{
Transport
:
&
http
.
Transport
{
...
...
@@ -111,7 +111,7 @@ func (b *Backend) worker() {
func
(
b
*
Backend
)
getEvents
()
*
v1alpha1
.
EventList
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
b
.
maxBatchWait
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
b
.
eventBatchInterval
)
defer
cancel
()
events
:=
&
v1alpha1
.
EventList
{}
...
...
@@ -122,7 +122,7 @@ func (b *Backend) getEvents() *v1alpha1.EventList {
break
}
events
.
Items
=
append
(
events
.
Items
,
*
event
)
if
len
(
events
.
Items
)
>=
b
.
max
BatchSize
{
if
len
(
events
.
Items
)
>=
b
.
event
BatchSize
{
return
events
}
case
<-
ctx
.
Done
()
:
...
...
@@ -141,14 +141,14 @@ func (b *Backend) sendEvents(events *v1alpha1.EventList) {
stopCh
:=
make
(
chan
struct
{})
send
:=
func
()
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
b
.
wait
Timeout
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
b
.
getSender
Timeout
)
defer
cancel
()
select
{
case
<-
ctx
.
Done
()
:
klog
.
Error
(
"
get goroutine
timeout"
)
klog
.
Error
(
"
Get auditing event sender
timeout"
)
return
case
b
.
se
m
Ch
<-
struct
{}{}
:
case
b
.
se
nder
Ch
<-
struct
{}{}
:
}
start
:=
time
.
Now
()
...
...
@@ -159,7 +159,7 @@ func (b *Backend) sendEvents(events *v1alpha1.EventList) {
bs
,
err
:=
b
.
eventToBytes
(
events
)
if
err
!=
nil
{
klog
.
V
(
6
)
.
Info
f
(
"json marshal error, %s"
,
err
)
klog
.
Error
f
(
"json marshal error, %s"
,
err
)
return
}
...
...
@@ -180,7 +180,7 @@ func (b *Backend) sendEvents(events *v1alpha1.EventList) {
go
send
()
defer
func
()
{
<-
b
.
se
m
Ch
<-
b
.
se
nder
Ch
}()
select
{
...
...
pkg/apiserver/auditing/types.go
浏览文件 @
ee95aeff
...
...
@@ -229,7 +229,7 @@ func (a *auditing) cacheEvent(e auditv1alpha1.Event) {
case
a
.
cache
<-
&
e
:
return
case
<-
time
.
After
(
CacheTimeout
)
:
klog
.
Error
f
(
"cache audit event %s timeout"
,
e
.
AuditID
)
klog
.
V
(
8
)
.
Info
f
(
"cache audit event %s timeout"
,
e
.
AuditID
)
break
}
}
...
...
pkg/simple/client/auditing/elasticsearch/options.go
浏览文件 @
ee95aeff
...
...
@@ -25,15 +25,15 @@ import (
type
Options
struct
{
Enable
bool
`json:"enable" yaml:"enable"`
WebhookUrl
string
`json:"webhookUrl" yaml:"webhookUrl"`
// The
number of goroutines which send auditing events to
webhook.
GoroutinesNum
int
`json:"goroutinesNum" yaml:"goroutine
sNum"`
// The
max size of the auditing event in a batch
.
MaxBatchSize
int
`json:"batchSize" yaml:"b
atchSize"`
//
MaxBatchWait indicates the maximum interval between two batche
s.
MaxBatchWait
time
.
Duration
`json:"batchTimeout" yaml:"batchTimeout
"`
Host
string
`json:"host" yaml:"host"`
IndexPrefix
string
`json:"indexPrefix,omitempty" yaml:"indexPrefix"`
Version
string
`json:"version" yaml:"version"`
// The
maximum concurrent senders which send auditing events to the auditing
webhook.
EventSendersNum
int
`json:"eventSendersNum" yaml:"eventSender
sNum"`
// The
batch size of auditing events
.
EventBatchSize
int
`json:"eventBatchSize" yaml:"eventB
atchSize"`
//
The batch interval of auditing event
s.
EventBatchInterval
time
.
Duration
`json:"eventBatchInterval" yaml:"eventBatchInterval
"`
Host
string
`json:"host" yaml:"host"`
IndexPrefix
string
`json:"indexPrefix,omitempty" yaml:"indexPrefix"`
Version
string
`json:"version" yaml:"version"`
}
func
NewElasticSearchOptions
()
*
Options
{
...
...
@@ -59,12 +59,12 @@ func (s *Options) AddFlags(fs *pflag.FlagSet, c *Options) {
fs
.
BoolVar
(
&
s
.
Enable
,
"auditing-enabled"
,
c
.
Enable
,
"Enable auditing component or not. "
)
fs
.
StringVar
(
&
s
.
WebhookUrl
,
"auditing-webhook-url"
,
c
.
WebhookUrl
,
"Auditing wehook url"
)
fs
.
IntVar
(
&
s
.
GoroutinesNum
,
"auditing-goroutines-num"
,
c
.
Goroutine
sNum
,
"The
number of goroutines which send auditing events to
webhook."
)
fs
.
IntVar
(
&
s
.
MaxBatchSize
,
"auditing-batch-max-size"
,
c
.
Max
BatchSize
,
"The
max size of the auditing event in a batch
."
)
fs
.
DurationVar
(
&
s
.
MaxBatchWait
,
"auditing-batch-max-wait"
,
c
.
MaxBatchWait
,
"
MaxBatchWait indicates the maximum interval between two batche
s."
)
fs
.
IntVar
(
&
s
.
EventSendersNum
,
"auditing-event-senders-num"
,
c
.
EventSender
sNum
,
"The
maximum concurrent senders which send auditing events to the auditing
webhook."
)
fs
.
IntVar
(
&
s
.
EventBatchSize
,
"auditing-event-batch-size"
,
c
.
Event
BatchSize
,
"The
batch size of auditing events
."
)
fs
.
DurationVar
(
&
s
.
EventBatchInterval
,
"auditing-event-batch-interval"
,
c
.
EventBatchInterval
,
"
The batch interval of auditing event
s."
)
fs
.
StringVar
(
&
s
.
Host
,
"auditing-elasticsearch-host"
,
c
.
Host
,
""
+
"Elasticsearch service host. KubeSphere is using elastic as auditing store, "
+
"if this filed left blank, KubeSphere will use kubernetes builtin event API instead, and"
+
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录