Skip to content

Commit 9a22f1f

Browse files
committed
Add --delay
1 parent 43f8a33 commit 9a22f1f

File tree

1 file changed

+21
-13
lines changed
  • cmd/kube-apiserver-audit-exporter

1 file changed

+21
-13
lines changed

cmd/kube-apiserver-audit-exporter/main.go

+21-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"log/slog"
55
"os"
66
"strings"
7+
"time"
78

89
"github.com/spf13/pflag"
910
"github.com/wzshiming/kube-apiserver-audit-exporter/exporter"
@@ -14,32 +15,39 @@ var (
1415
address = ":8080"
1516
cluster = ""
1617
replay = false
18+
delay time.Duration
1719
)
1820

1921
func init() {
2022
pflag.StringArrayVar(&auditLogPath, "audit-log-path", auditLogPath, "Path to audit log files, path[:clusterName]")
2123
pflag.StringVar(&address, "address", address, "Address to listen on")
2224
pflag.StringVar(&cluster, "cluster-label", cluster, "Default cluster label of metrics")
2325
pflag.BoolVar(&replay, "replay", replay, "replay the audit log")
26+
pflag.DurationVar(&delay, "delay", 0, "delay to start")
2427
pflag.Parse()
2528
}
2629

2730
func main() {
28-
for _, p := range auditLogPath {
29-
ns := strings.SplitN(p, ":", 2)
30-
path := ns[0]
31-
clusterLabel := cluster
32-
if len(ns) > 1 {
33-
clusterLabel = ns[1]
31+
go func() {
32+
if delay > 0 {
33+
time.Sleep(delay)
3434
}
35+
for _, p := range auditLogPath {
36+
ns := strings.SplitN(p, ":", 2)
37+
path := ns[0]
38+
clusterLabel := cluster
39+
if len(ns) > 1 {
40+
clusterLabel = ns[1]
41+
}
3542

36-
e := exporter.NewExporter(
37-
exporter.WithReplay(replay),
38-
exporter.WithFile(path),
39-
exporter.WithClusterLabel(clusterLabel),
40-
)
41-
e.Start()
42-
}
43+
e := exporter.NewExporter(
44+
exporter.WithReplay(replay),
45+
exporter.WithFile(path),
46+
exporter.WithClusterLabel(clusterLabel),
47+
)
48+
e.Start()
49+
}
50+
}()
4351

4452
if err := exporter.ListenAndServe(address); err != nil {
4553
slog.Error("Failed", "err", err)

0 commit comments

Comments
 (0)