@@ -2,24 +2,25 @@ package main
22
33import (
44 "fmt"
5- "log "
5+ "io/ioutil "
66 "os"
7- "time"
8-
97 "runtime"
8+ "time"
109
1110 "bitbucket.org/mcplusa-ondemand/firehose-to-sumologic/caching"
1211 "bitbucket.org/mcplusa-ondemand/firehose-to-sumologic/eventQueue"
1312 "bitbucket.org/mcplusa-ondemand/firehose-to-sumologic/eventRouting"
13+ "bitbucket.org/mcplusa-ondemand/firehose-to-sumologic/events"
1414 "bitbucket.org/mcplusa-ondemand/firehose-to-sumologic/firehoseclient"
15+ "bitbucket.org/mcplusa-ondemand/firehose-to-sumologic/logging"
1516 "bitbucket.org/mcplusa-ondemand/firehose-to-sumologic/sumoCFFirehose"
1617 "github.com/cloudfoundry-community/go-cfclient"
1718 "gopkg.in/alecthomas/kingpin.v2"
1819)
1920
2021var (
21- debug = true //debug", "Enable debug mode, print in console
22- apiEndpoint = "https://api.bosh-lite.com"
22+ debug = true //debug", "Enable debug mode, print in console
23+ apiEndpoint = kingpin . Flag ( "api-endpoint" , "Sumo Endpoint" ). String () // "https://api.bosh-lite.com"
2324 sumoEndpoint = kingpin .Flag ("sumo-endpoint" , "Sumo Endpoint" ).String ()
2425 dopplerEndpoint = kingpin .Flag ("doppler-endpoint" , "Overwrite default doppler endpoint return by /v2/info" ).OverrideDefaultFromEnvar ("DOPPLER_ENDPOINT" ).String ()
2526 subscriptionId = kingpin .Flag ("subscription-id" , "Id for the subscription." ).Default ("firehose" ).OverrideDefaultFromEnvar ("FIREHOSE_SUBSCRIPTION_ID" ).String ()
@@ -38,14 +39,27 @@ var (
3839)
3940
4041func main () {
42+ //logging init
43+ logging .Init (ioutil .Discard , os .Stdout , os .Stdout , os .Stderr )
44+
4145 kingpin .Version (version )
4246 kingpin .Parse ()
47+
4348 runtime .GOMAXPROCS (1 )
4449
45- fmt .Printf ("Starting firehose-to-sumo %s \n " , version )
50+ logging .Info .Println ("Configurations set:" )
51+ logging .Info .Println ("Api Endpoint: " + * apiEndpoint )
52+ logging .Info .Println ("Sumo Endpoint: " + * sumoEndpoint )
53+ logging .Info .Println ("Cloudfoundry Doppler Endpoint: " + * dopplerEndpoint )
54+ logging .Info .Println ("Cloudfoundry Nozzle Subscription ID: " + * subscriptionId )
55+ logging .Info .Println ("Cloudfoundry User: " + user )
56+
57+ logging .Info .Printf ("Events Batch Size: [%d]\n " , eventsBatchSize )
58+
59+ logging .Info .Println ("Starting firehose-to-sumo " + version )
4660
4761 c := cfclient.Config {
48- ApiAddress : apiEndpoint ,
62+ ApiAddress : * apiEndpoint ,
4963 Username : user ,
5064 Password : password ,
5165 SkipSslValidation : * skipSSLValidation ,
@@ -64,26 +78,26 @@ func main() {
6478 cachingClient = caching .NewCachingEmpty ()
6579 }
6680
67- // Creating queue
68- queue := eventQueue .NewQueue (make ([]* eventQueue. Node , 100 ))
81+ logging . Info . Println ( " Creating queue" )
82+ queue := eventQueue .NewQueue (make ([]* events. Event , 100 ))
6983 loggingClientSumo := sumoCFFirehose .NewSumoLogicAppender (* sumoEndpoint , 1000 , & queue , * eventsBatchSize )
7084 go loggingClientSumo .Start () //multi
7185
72- // Creating Events
86+ logging . Info . Println ( " Creating Events" )
7387 events := eventRouting .NewEventRouting (cachingClient , * loggingClientSumo , & queue )
7488 err := events .SetupEventRouting (* wantedEvents )
7589 if err != nil {
76- log .Fatal ("Error setting up event routing: " , err )
90+ logging . Error .Fatal ("Error setting up event routing: " , err )
7791 os .Exit (1 )
7892
7993 }
8094
8195 // Parse extra fields from cmd call
8296 cachingClient .CreateBucket ()
8397 //Let's Update the database the first time
84- fmt .Printf ("Start filling app/space/org cache.\n " )
98+ logging . Info .Printf ("Start filling app/space/org cache.\n " )
8599 apps := cachingClient .GetAllApp ()
86- fmt .Printf ("Done filling cache! Found [%d] Apps \n " , len (apps ))
100+ logging . Info .Printf ("Done filling cache! Found [%d] Apps \n " , len (apps ))
87101
88102 //Let's start the goRoutine
89103 cachingClient .PerformPoollingCaching (tickerTime )
@@ -95,15 +109,12 @@ func main() {
95109 FirehoseSubscriptionID : * subscriptionId ,
96110 }
97111
98- if /*loggingClientSumo.Connect() ||*/ debug {
112+ logging . Info . Printf ( "Connecting to Firehose... \n " )
99113
100- fmt .Printf ("Connected to Server! Connecting to Firehose... \n " )
114+ firehoseClient := firehoseclient .NewFirehoseNozzle (cfClient , events , firehoseConfig )
115+ go firehoseClient .Start ()
101116
102- firehoseClient := firehoseclient .NewFirehoseNozzle (cfClient , events , firehoseConfig )
103- go firehoseClient .Start ()
104-
105- defer firehoseClient .Start ()
106- }
117+ defer firehoseClient .Start ()
107118
108119 defer cachingClient .Close ()
109120
0 commit comments