File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -118,6 +118,9 @@ func main() {
118118}
119119
120120func (p * analysisServer ) Analyze (event * plugins.Event , _ grpc.ServerStreamingServer [plugins.Alert ]) error {
121+ m := utils .NewMeter ("Enqueue log for OpenSearch" )
122+ defer m .Elapsed ("finished" )
123+
121124 jLog , err := utils .ToString (event )
122125 if err != nil {
123126 return catcher .Error ("cannot convert event to json" , err , nil )
Original file line number Diff line number Diff line change 55 "fmt"
66 "github.com/threatwinds/go-sdk/catcher"
77 "github.com/threatwinds/go-sdk/plugins"
8+ "github.com/threatwinds/go-sdk/utils"
89 "runtime"
910 "sync"
1011 "time"
@@ -59,6 +60,9 @@ func startQueue() {
5960 numCPU := runtime .NumCPU () * 2
6061 for i := 0 ; i < numCPU ; i ++ {
6162 go func () {
63+ ndM := utils .NewMeter ("Generate NDJson" )
64+ bulkM := utils .NewMeter ("Send Bulk" )
65+
6266 var ndMutex = & sync.Mutex {}
6367 var nd = make ([]opensearch.BulkItem , 0 , 10 )
6468
@@ -69,6 +73,8 @@ func startQueue() {
6973 continue
7074 }
7175
76+ bulkM .Reset ()
77+
7278 ndMutex .Lock ()
7379 err := opensearch .Bulk (context .Background (), nd )
7480 if err != nil {
@@ -77,12 +83,16 @@ func startQueue() {
7783
7884 nd = make ([]opensearch.BulkItem , 0 , 10 )
7985 ndMutex .Unlock ()
86+
87+ bulkM .Elapsed ("bulk sent" )
8088 }
8189 }()
8290
8391 for {
8492 l := <- logs
8593
94+ ndM .Reset ()
95+
8696 dataType := gjson .Get (l , "dataType" ).String ()
8797
8898 id := gjson .Get (l , "id" ).String ()
@@ -97,6 +107,8 @@ func startQueue() {
97107 Action : "index" ,
98108 })
99109 ndMutex .Unlock ()
110+
111+ ndM .Elapsed ("nd json generated" )
100112 }
101113 }()
102114 }
You can’t perform that action at this time.
0 commit comments