Exemplo n.º 1
0
func main() {
	flag.Parse()

	level, err := gosteno.GetLogLevel(*logLevel)
	if err != nil {
		level = gosteno.LOG_INFO
	}
	loggingConfig := &gosteno.Config{
		Sinks: []gosteno.Sink{
			gosteno.NewIOSink(os.Stdout),
		},
		Level:     level,
		Codec:     gosteno.NewJsonCodec(),
		EnableLOC: true,
	}

	gosteno.Init(loggingConfig)
	logger := gosteno.NewLogger("statsdinjector")

	statsdMessageListener := statsdlistener.New(*statsdPort, logger)
	statsdEmitter := statsdemitter.New(*metronPort, logger)

	inputChan := make(chan *events.Envelope)

	go statsdMessageListener.Run(inputChan)
	statsdEmitter.Run(inputChan)
}
	)

	var _ = BeforeEach(func() {
		udpAddr, _ := net.ResolveUDPAddr("udp", "localhost:8088")
		udpListener, _ = net.ListenUDP("udp", udpAddr)
		loggertesthelper.TestLoggerSink.Clear()
	})

	var _ = AfterEach(func() {
		udpListener.Close()
	})

	It("emits the serialized envelope on the given UDP port", func(done Done) {
		defer close(done)
		inputChan := make(chan *events.Envelope)
		emitter := statsdemitter.New(8088, loggertesthelper.Logger())
		go emitter.Run(inputChan)
		message := &events.Envelope{
			Origin:    proto.String("origin"),
			Timestamp: proto.Int64(3000000000),
			EventType: events.Envelope_CounterEvent.Enum(),
			CounterEvent: &events.CounterEvent{
				Name:  proto.String("counterName"),
				Delta: proto.Uint64(3),
				Total: proto.Uint64(15),
			},
		}

		inputChan <- message

		buffer := make([]byte, 4096)