func main() { setupHTTP() uaaURL, err := url.Parse(uaa) if nil != err { panic("Failed to parse uaa url!") } creds, err := uaaclientcredentials.New(uaaURL, true, clientID, clientSecret) if nil != err { panic("Failed to obtain creds!") } consumer := noaa.NewConsumer(dopplerAddress, &tls.Config{InsecureSkipVerify: true}, nil) httpStartStopProcessor := processors.NewHttpStartStopProcessor() sender := statsd.NewStatsdClient(statsdAddress, statsdPrefix) sender.CreateSocket() var processedMetrics []metrics.Metric msgChan := make(chan *events.Envelope) go func() { defer close(msgChan) errorChan := make(chan error) token, err := creds.GetBearerToken() if nil != err { panic(err) } go consumer.Firehose(firehoseSubscriptionID, token, msgChan, errorChan, nil) for err := range errorChan { fmt.Fprintf(os.Stderr, "%v\n", err.Error()) } }() for msg := range msgChan { eventType := msg.GetEventType() switch eventType { case events.Envelope_HttpStartStop: processedMetrics = httpStartStopProcessor.Process(msg) default: atomic.AddUint64(&count, 1) // do nothing } if len(processedMetrics) > 0 { for _, metric := range processedMetrics { metric.Send(sender) } } processedMetrics = nil } }
func getToken(appEnv *cfenv.App) string { uaa, err := GetUserProvidedServiceByName("uaa", appEnv) dieIfError("Could not find uaa service, did you bind it?", err) uaaURL, err := url.Parse(uaa.Credentials["uri"].(string)) dieIfError("Could not parse uaa URI", err) uaaConnection, err := uaaclientcredentials.New(uaaURL, skipSSLVerify, uaa.Credentials["client_id"].(string), uaa.Credentials["client_secret"].(string)) dieIfError("Failed to setup uaa connection", err) token, err := uaaConnection.GetBearerToken() dieIfError("Failed to get token from UAA", err) return token }