4
4
"log/slog"
5
5
"os"
6
6
"strings"
7
+ "time"
7
8
8
9
"github.com/spf13/pflag"
9
10
"github.com/wzshiming/kube-apiserver-audit-exporter/exporter"
@@ -14,32 +15,39 @@ var (
14
15
address = ":8080"
15
16
cluster = ""
16
17
replay = false
18
+ delay time.Duration
17
19
)
18
20
19
21
func init () {
20
22
pflag .StringArrayVar (& auditLogPath , "audit-log-path" , auditLogPath , "Path to audit log files, path[:clusterName]" )
21
23
pflag .StringVar (& address , "address" , address , "Address to listen on" )
22
24
pflag .StringVar (& cluster , "cluster-label" , cluster , "Default cluster label of metrics" )
23
25
pflag .BoolVar (& replay , "replay" , replay , "replay the audit log" )
26
+ pflag .DurationVar (& delay , "delay" , 0 , "delay to start" )
24
27
pflag .Parse ()
25
28
}
26
29
27
30
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 )
34
34
}
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
+ }
35
42
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
+ }()
43
51
44
52
if err := exporter .ListenAndServe (address ); err != nil {
45
53
slog .Error ("Failed" , "err" , err )
0 commit comments