Skip to content

Commit 5b11f87

Browse files
committed
the appender calls for the next Event in queue and parse it to string
1 parent a50dd4c commit 5b11f87

3 files changed

Lines changed: 20 additions & 21 deletions

File tree

eventRouting/eventrouting.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,8 @@ 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.GetCount() == 10 { //if the queue has 10 elements, send to the appender (10 elements to wait to send to the appender?)
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.Fields["timestamp"])
83-
fmt.Println("sendig event TO queue")*/
84-
e.queue.Push(eventQueue.NewNode(*event))
85-
}
86-
78+
//Push the event to the queue
79+
e.queue.Push(eventQueue.NewNode(*event))
8780
e.selectedEventsCount[eventType.String()]++
8881

8982
}
@@ -151,8 +144,10 @@ func (e *EventRouting) LogEventTotals(logTotalsTime time.Duration) {
151144
startTime = time.Now()
152145
event, lastCount := e.getEventTotals(totalElapsedTime, elapsedTime, count)
153146
count = lastCount
154-
//*e.log.ShipEvents(event.Fields, event.Msg)
155-
e.sLAppender.AppendLogs(*event)
147+
148+
//Push the event to the queue
149+
e.queue.Push(eventQueue.NewNode(*event))
150+
//e.sLAppender.AppendLogs(*event)
156151
}
157152
}()
158153
}

main.go

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

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

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

@@ -64,11 +66,8 @@ func main() {
6466
cachingClient = caching.NewCachingEmpty()
6567
}
6668

67-
//Creating queue
68-
queue := eventQueue.NewQueue(make([]*eventQueue.Node, 100))
69-
7069
//Creating Events
71-
events := eventRouting.NewEventRouting(cachingClient, *loggingClientSumo, *queue)
70+
events := eventRouting.NewEventRouting(cachingClient, *loggingClientSumo, *nozzleQueue)
7271
err := events.SetupEventRouting(*wantedEvents)
7372
if err != nil {
7473
log.Fatal("Error setting up event routing: ", err)

sumoCFFirehose/sumoLogicAppender.go

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

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

1414
type SumoLogicAppender struct {
1515
url string
1616
connectionTimeout int //10000
1717
httpClient http.Client
18+
nozzleQueue eventQueue.Queue
1819
}
1920

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

@@ -42,7 +44,9 @@ func (s *SumoLogicAppender) Connect() bool {
4244
return success
4345
}
4446

45-
func (s *SumoLogicAppender) AppendLogs(event Event) {
47+
func (s *SumoLogicAppender) AppendLogs() {
48+
// the appender calls for the next message in the queue and parse it to a string
49+
event := s.nozzleQueue.Pop().GetNodeEvent()
4650
/*
4751
if event == nil {
4852
return
@@ -56,7 +60,8 @@ func (s *SumoLogicAppender) AppendLogs(event Event) {
5660
return
5761
}
5862

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

0 commit comments

Comments
 (0)