@@ -27,30 +27,56 @@ func init() {
27
27
pflag .Parse ()
28
28
}
29
29
30
- func main () {
31
- go func () {
32
- if delay > 0 {
33
- time .Sleep (delay )
30
+ func monitorAndStartExporters () {
31
+ for ! validAuditLogs () {
32
+ time .Sleep (time .Second )
33
+ }
34
+
35
+ if delay > 0 {
36
+ time .Sleep (delay )
37
+ }
38
+
39
+ for _ , path := range auditLogPath {
40
+ startExporterForPath (path )
41
+ }
42
+ }
43
+
44
+ func validAuditLogs () bool {
45
+ for _ , p := range auditLogPath {
46
+ info , err := os .Stat (p )
47
+ if err != nil {
48
+ slog .Warn ("Failed to stat audit log" , "path" , p , "err" , err )
49
+ return false
34
50
}
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
- }
42
-
43
- e := exporter .NewExporter (
44
- exporter .WithReplay (replay ),
45
- exporter .WithFile (path ),
46
- exporter .WithClusterLabel (clusterLabel ),
47
- )
48
- e .Start ()
51
+ if info .Size () == 0 {
52
+ slog .Info ("Audit log is empty, waiting for content" , "path" , p )
53
+ return false
49
54
}
50
- }()
55
+ }
56
+ return true
57
+ }
58
+
59
+ func startExporterForPath (pathWithLabel string ) {
60
+ parts := strings .SplitN (pathWithLabel , ":" , 2 )
61
+ path := parts [0 ]
62
+ clusterLabel := cluster
63
+ if len (parts ) > 1 {
64
+ clusterLabel = parts [1 ]
65
+ }
66
+
67
+ e := exporter .NewExporter (
68
+ exporter .WithReplay (replay ),
69
+ exporter .WithFile (path ),
70
+ exporter .WithClusterLabel (clusterLabel ),
71
+ )
72
+ e .Start ()
73
+ }
74
+
75
+ func main () {
76
+ go monitorAndStartExporters ()
51
77
52
78
if err := exporter .ListenAndServe (address ); err != nil {
53
- slog .Error ("Failed" , "err" , err )
79
+ slog .Error ("Failed to start metrics server " , "err" , err )
54
80
os .Exit (1 )
55
81
}
56
82
}
0 commit comments