예제 #1
0
func Initialize() {
	http.DefaultTransport = &http.Transport{Proxy: http.ProxyFromEnvironment}
	autowiredEmitter = nil

	origin := os.Getenv("DROPSONDE_ORIGIN")
	if len(origin) == 0 {
		log.Println("Failed to auto-initialize dropsonde: DROPSONDE_ORIGIN environment variable not set")
		return
	}

	destination = os.Getenv("DROPSONDE_DESTINATION")
	if len(destination) == 0 {
		log.Println("DROPSONDE_DESTINATION not set. Using " + defaultDestination)
		destination = defaultDestination
	}

	udpEmitter, err := emitter.NewUdpEmitter(destination)
	if err != nil {
		log.Printf("Failed to auto-initialize dropsonde: %v\n", err)
		return
	}

	hbEmitter, err := emitter.NewHeartbeatEmitter(udpEmitter, origin)
	if err != nil {
		log.Printf("Failed to auto-initialize dropsonde: %v\n", err)
		return
	}

	autowiredEmitter = emitter.NewEventEmitter(hbEmitter, origin)

	http.DefaultTransport = InstrumentedRoundTripper(http.DefaultTransport)
}
예제 #2
0
	"code.google.com/p/gogoprotobuf/proto"
	"github.com/cloudfoundry-incubator/dropsonde/emitter"
	"github.com/cloudfoundry-incubator/dropsonde/emitter/fake"
	"github.com/cloudfoundry-incubator/dropsonde/events"

	"github.com/cloudfoundry-incubator/dropsonde/factories"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("EventEmitter", func() {
	Describe("Emit", func() {
		Context("without an origin", func() {
			It("returns an error", func() {
				innerEmitter := fake.NewFakeByteEmitter()
				eventEmitter := emitter.NewEventEmitter(innerEmitter, "")

				testEvent := factories.NewHeartbeat(1, 2, 3)
				err := eventEmitter.Emit(testEvent)

				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("Wrap: "))
			})
		})

		It("marshals events and delegates to the inner emitter", func() {
			innerEmitter := fake.NewFakeByteEmitter()
			origin := "fake-origin"
			eventEmitter := emitter.NewEventEmitter(innerEmitter, origin)

			testEvent := factories.NewHeartbeat(1, 2, 3)