Skip to content

Commit 636fe17

Browse files
committed
Merged in feature/SCFF-29 (pull request #7)
Feature/SCFF-29
2 parents 76a9d81 + 12d0f57 commit 636fe17

4 files changed

Lines changed: 25 additions & 18 deletions

File tree

eventQueue/eventQueue.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ func (q *Queue) GetNode() []*Node {
3333
return q.nodes
3434
}
3535

36+
func (n *Queue) GetCount() int {
37+
return n.count
38+
}
39+
3640
func (n *Node) GetNodeEvent() Event {
3741
return n.event
3842
}

eventRouting/eventrouting.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,9 @@ func (e *EventRouting) RouteEvent(msg *events.Envelope) {
7575
if ignored, hasIgnoredField := event.Fields["cf_ignored_app"]; ignored == true && hasIgnoredField {
7676
e.selectedEventsCount["ignored_app_message"]++
7777
} else {
78-
if e.queue.Pop() != nil { //if the queue is not empty
79-
fmt.Println("sendig event from queue to appender")
80-
e.sLAppender.AppendLogs(e.queue.Pop().GetNodeEvent()) // send to appender event from queue
81-
} else { //if the queue is empty, send the event to queue
82-
fmt.Println(event.Msg)
83-
fmt.Println("sendig event TO queue")
84-
e.queue.Push(eventQueue.NewNode(*event))
85-
}
78+
//Push the event to the queue
79+
fmt.Println("pushing event to queue")
80+
e.queue.Push(eventQueue.NewNode(*event))
8681
e.selectedEventsCount[eventType.String()]++
8782

8883
}
@@ -150,8 +145,10 @@ func (e *EventRouting) LogEventTotals(logTotalsTime time.Duration) {
150145
startTime = time.Now()
151146
event, lastCount := e.getEventTotals(totalElapsedTime, elapsedTime, count)
152147
count = lastCount
153-
//*e.log.ShipEvents(event.Fields, event.Msg)
154-
e.sLAppender.AppendLogs(*event)
148+
149+
//Push the event to the queue
150+
e.queue.Push(eventQueue.NewNode(*event))
151+
//e.sLAppender.AppendLogs(*event)
155152
}
156153
}()
157154
}

main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ func main() {
4040

4141
fmt.Println("this is the sumo endpoint")
4242
fmt.Println(sumoEndpoint)
43-
loggingClientSumo := sumoCFFirehose.NewSumoLogicAppender(*sumoEndpoint, 1000)
43+
44+
//Creating queue
45+
queue := eventQueue.NewQueue(make([]*eventQueue.Node, 100))
46+
loggingClientSumo := sumoCFFirehose.NewSumoLogicAppender(*sumoEndpoint, 1000, *queue)
4447

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

@@ -64,9 +67,6 @@ func main() {
6467
cachingClient = caching.NewCachingEmpty()
6568
}
6669

67-
//Creating queue
68-
queue := eventQueue.NewQueue(make([]*eventQueue.Node, 100))
69-
7070
//Creating Events
7171
events := eventRouting.NewEventRouting(cachingClient, *loggingClientSumo, *queue)
7272
err := events.SetupEventRouting(*wantedEvents)

sumoCFFirehose/sumoLogicAppender.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@ import (
77
"net/http"
88
"time"
99

10-
. "bitbucket.org/mcplusa-ondemand/firehose-to-sumologic/events"
10+
"bitbucket.org/mcplusa-ondemand/firehose-to-sumologic/eventQueue"
1111
)
1212

1313
type SumoLogicAppender struct {
1414
url string
1515
connectionTimeout int //10000
1616
httpClient http.Client
17+
nozzleQueue eventQueue.Queue
1718
}
1819

19-
func NewSumoLogicAppender(urlValue string, connectionTimeoutValue int) *SumoLogicAppender {
20+
func NewSumoLogicAppender(urlValue string, connectionTimeoutValue int, nozzleQueue eventQueue.Queue) *SumoLogicAppender {
2021
return &SumoLogicAppender{
2122
url: urlValue,
2223
connectionTimeout: connectionTimeoutValue,
2324
httpClient: http.Client{Timeout: time.Duration(connectionTimeoutValue * int(time.Millisecond))},
25+
nozzleQueue: nozzleQueue,
2426
}
2527
}
2628

@@ -41,7 +43,10 @@ func (s *SumoLogicAppender) Connect() bool {
4143
return success
4244
}
4345

44-
func (s *SumoLogicAppender) AppendLogs(event Event) {
46+
func (s *SumoLogicAppender) AppendLogs() {
47+
// the appender calls for the next message in the queue and parse it to a string
48+
fmt.Println("i'm in appendLogs")
49+
event := s.nozzleQueue.Pop().GetNodeEvent()
4550
/*
4651
if event == nil {
4752
return
@@ -55,7 +60,8 @@ func (s *SumoLogicAppender) AppendLogs(event Event) {
5560
return
5661
}
5762

58-
Message := /*strconv.Itoa(fields["timestamp"]) + */ "\t" + event.Fields["message_type"].(string) + "\t" + event.Msg
63+
Message := time.Unix(0, event.Fields["timestamp"].(int64)*int64(time.Nanosecond)).String() + "\t" + event.Fields["message_type"].(string) + "\t" + event.Msg + "\n"
64+
fmt.Println(Message)
5965
s.SendToSumo(Message)
6066
}
6167

0 commit comments

Comments
 (0)