Skip to content

Commit 302f54e

Browse files
committed
SCFF-31 filling the queue, buffering, and sending to sumo
1 parent 891580c commit 302f54e

4 files changed

Lines changed: 21 additions & 34 deletions

File tree

eventQueue/eventQueue.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package eventQueue
22

3-
import (
4-
. "bitbucket.org/mcplusa-ondemand/firehose-to-sumologic/events"
5-
)
3+
import . "bitbucket.org/mcplusa-ondemand/firehose-to-sumologic/events"
64

75
//Node to put in queue
86
type Node struct {
@@ -23,8 +21,8 @@ func NewNode(event Event) *Node {
2321
}
2422
}
2523

26-
func NewQueue(n []*Node) *Queue {
27-
return &Queue{
24+
func NewQueue(n []*Node) Queue {
25+
return Queue{
2826
Nodes: n,
2927
}
3028
}

eventRouting/eventrouting.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ type EventRouting struct {
2121
selectedEventsCount map[string]uint64
2222
mutex *sync.Mutex
2323
sLAppender sumoCFFirehose.SumoLogicAppender //**
24-
queue eventQueue.Queue
24+
queue *eventQueue.Queue
2525
}
2626

27-
func NewEventRouting(caching caching.Caching, sLAppender sumoCFFirehose.SumoLogicAppender, queue eventQueue.Queue) *EventRouting {
27+
func NewEventRouting(caching caching.Caching, sLAppender sumoCFFirehose.SumoLogicAppender, queue *eventQueue.Queue) *EventRouting {
2828
return &EventRouting{
2929
CachingClient: caching,
3030
selectedEvents: make(map[string]bool),

main.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var (
4040
func main() {
4141
kingpin.Version(version)
4242
kingpin.Parse()
43-
runtime.GOMAXPROCS(2)
43+
runtime.GOMAXPROCS(1)
4444

4545
fmt.Printf("Starting firehose-to-sumo %s \n", version)
4646

@@ -66,11 +66,11 @@ func main() {
6666

6767
//Creating queue
6868
queue := eventQueue.NewQueue(make([]*eventQueue.Node, 100))
69-
loggingClientSumo := sumoCFFirehose.NewSumoLogicAppender(*sumoEndpoint, 1000, *queue, *eventsBatchSize)
69+
loggingClientSumo := sumoCFFirehose.NewSumoLogicAppender(*sumoEndpoint, 1000, &queue, *eventsBatchSize)
7070
go loggingClientSumo.Start() //multi
7171

7272
//Creating Events
73-
events := eventRouting.NewEventRouting(cachingClient, *loggingClientSumo, *queue)
73+
events := eventRouting.NewEventRouting(cachingClient, *loggingClientSumo, &queue)
7474
err := events.SetupEventRouting(*wantedEvents)
7575
if err != nil {
7676
log.Fatal("Error setting up event routing: ", err)
@@ -100,20 +100,11 @@ func main() {
100100
fmt.Printf("Connected to Server! Connecting to Firehose... \n")
101101

102102
firehoseClient := firehoseclient.NewFirehoseNozzle(cfClient, events, firehoseConfig)
103+
go firehoseClient.Start()
103104

104-
//go firehoseClient.Start()
105-
err = firehoseClient.Start()
106-
if err != nil {
107-
fmt.Printf("Failed connecting to Firehose...Please check settings and try again! \n") //Log error
108-
109-
} else {
110-
fmt.Printf("Firehose Subscription Succesfull! Routing events... \n")
111-
}
112-
113-
} else {
114-
fmt.Printf("Failed connecting to the Fluentd Server...Please check settings and try again! \n") //Log error
115-
105+
defer firehoseClient.Start()
116106
}
117107

118108
defer cachingClient.Close()
109+
119110
}

sumoCFFirehose/sumoLogicAppender.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ type SumoLogicAppender struct {
1414
url string
1515
connectionTimeout int //10000
1616
httpClient http.Client
17-
nozzleQueue eventQueue.Queue
17+
nozzleQueue *eventQueue.Queue
1818
eventsBatchSize int
1919
logEventsInCurrentBuffer int
2020
logStringToSend string
2121
}
2222

23-
func NewSumoLogicAppender(urlValue string, connectionTimeoutValue int, nozzleQueue eventQueue.Queue, eventsBatchSize int) *SumoLogicAppender {
23+
func NewSumoLogicAppender(urlValue string, connectionTimeoutValue int, nozzleQueue *eventQueue.Queue, eventsBatchSize int) *SumoLogicAppender {
2424
return &SumoLogicAppender{
2525
url: urlValue,
2626
connectionTimeout: connectionTimeoutValue,
@@ -50,30 +50,29 @@ func (s *SumoLogicAppender) Connect() bool {
5050
}
5151

5252
func (s *SumoLogicAppender) Start() {
53-
timer := time.NewTimer(60 * time.Second)
53+
timer := time.Now()
5454
fmt.Println("Starting Appender Worker")
55-
5655
s.logStringToSend = ""
5756
for {
58-
fmt.Println("nozzle queue")
59-
fmt.Println(s.nozzleQueue.GetCount())
6057
time.Sleep(300 * time.Millisecond)
6158
if s.nozzleQueue.GetCount() != 0 {
62-
fmt.Println("i'm on the if")
6359
s.AppendLogs()
60+
fmt.Println(s.logStringToSend)
6461
}
65-
fmt.Println("passed first if")
6662
if s.logEventsInCurrentBuffer >= s.eventsBatchSize {
63+
fmt.Println("Buffer full")
64+
fmt.Println(s.logStringToSend)
6765
s.SendToSumo(s.logStringToSend)
6866
s.logEventsInCurrentBuffer = 0 // reset counter
6967
s.logStringToSend = "" //reset String
70-
} else if (<-timer.C).Second() == 0 {
68+
} else if time.Since(timer).Seconds() >= 10 {
69+
fmt.Println("timer finished, sending logs...")
70+
fmt.Println(s.logStringToSend)
7171
s.SendToSumo(s.logStringToSend)
7272
s.logEventsInCurrentBuffer = 0 // reset counter
7373
s.logStringToSend = "" //reset String
74+
timer = time.Now() //reset timer
7475
}
75-
fmt.Println("passed second if")
76-
fmt.Println("end of bucle")
7776

7877
}
7978
}
@@ -97,7 +96,6 @@ func (s *SumoLogicAppender) AppendLogs() {
9796
//timer := time.NewTimer(60 * time.Second)
9897
s.logStringToSend = s.logStringToSend + StringBuilder(s.nozzleQueue.Pop())
9998
s.logEventsInCurrentBuffer++
100-
10199
}
102100

103101
func (s *SumoLogicAppender) SendToSumo(log string) {

0 commit comments

Comments
 (0)