コード例 #1
0
ファイル: autowire.go プロジェクト: ninglipeng/gorouter
func CreateDefaultEmitter() (emitter.EventEmitter, string) {
	origin := os.Getenv("DROPSONDE_ORIGIN")
	if len(origin) == 0 {
		log.Println("Failed to auto-initialize dropsonde: DROPSONDE_ORIGIN environment variable not set")
		return nil, ""
	}

	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 nil, destination
	}

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

	return emitter.NewEventEmitter(hbEmitter, origin), destination
}
コード例 #2
0
ファイル: autowire.go プロジェクト: johannespetzold/gorouter
// Initialize creates default emitters and instruments the default HTTP
// transport.
//
// The DROPSONDE_ORIGIN environment variable is required and specifies the
// source name for all metrics emitted by this process. If it is not set, the
// program will run normally but will not emit metrics.
//
// The DROPSONDE_DESTINATION environment variable sets the host and port to
// which metrics are sent. It is optional, and defaults to DefaultDestination.
func Initialize() {
	http.DefaultTransport = &http.Transport{Proxy: http.ProxyFromEnvironment}
	autowiredEmitter = &nullEventEmitter{}

	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)

	go runtime_stats.NewRuntimeStats(autowiredEmitter, runtimeStatsInterval).Run(nil)

	http.DefaultTransport = InstrumentedRoundTripper(http.DefaultTransport)
}
コード例 #3
0
func createDefaultEmitter(origin, destination string) (EventEmitter, error) {
	if len(origin) == 0 {
		return nil, errors.New("Failed to initialize dropsonde: origin variable not set")
	}

	if len(destination) == 0 {
		return nil, errors.New("Failed to initialize dropsonde: destination variable not set")
	}

	udpEmitter, err := emitter.NewUdpEmitter(destination)
	if err != nil {
		return nil, fmt.Errorf("Failed to initialize dropsonde: %v", err.Error())
	}

	return emitter.NewEventEmitter(udpEmitter, origin), nil
}
コード例 #4
0
ファイル: main.go プロジェクト: kei-yamazaki/loggregator
func setupDefaultEmitter(origin, destination string) error {
	if origin == "" {
		return errors.New("Cannot initialize metrics with an empty origin")
	}

	if destination == "" {
		return errors.New("Cannot initialize metrics with an empty destination")
	}

	udpEmitter, err := emitter.NewUdpEmitter(destination)
	if err != nil {
		return fmt.Errorf("Failed to initialize dropsonde: %v", err.Error())
	}

	dropsonde.DefaultEmitter = emitter.NewEventEmitter(udpEmitter, origin)
	return nil
}
コード例 #5
0
ファイル: dropsonde.go プロジェクト: trainchou/gorouter
func createDefaultEmitter(origin, destination string) (emitter.EventEmitter, error) {
	if len(origin) == 0 {
		return nil, errors.New("Failed to initialize dropsonde: origin variable not set")
	}

	if len(destination) == 0 {
		return nil, errors.New("Failed to initialize dropsonde: destination variable not set")
	}

	udpEmitter, err := emitter.NewUdpEmitter(destination)
	if err != nil {
		return nil, fmt.Errorf("Failed to initialize dropsonde: %v", err.Error())
	}

	heartbeatResponder, err := emitter.NewHeartbeatResponder(udpEmitter, origin)
	if err != nil {
		return nil, fmt.Errorf("Failed to initialize dropsonde: %v", err.Error())
	}

	go udpEmitter.ListenForHeartbeatRequest(heartbeatResponder.Respond)

	return emitter.NewEventEmitter(heartbeatResponder, origin), nil
}
コード例 #6
0
ファイル: autowire_test.go プロジェクト: ninglipeng/gorouter
	var oldOrigin string

	BeforeEach(func() {
		oldDestination = os.Getenv("DROPSONDE_DESTINATION")
		oldOrigin = os.Getenv("DROPSONDE_ORIGIN")
	})

	AfterEach(func() {
		os.Setenv("DROPSONDE_DESTINATION", oldDestination)
		os.Setenv("DROPSONDE_ORIGIN", oldOrigin)
	})

	Describe("Initialize", func() {
		Context("with a non-nil emitter", func() {
			It("instruments the HTTP default transport", func() {
				autowire.Initialize(emitter.NewEventEmitter(nil, ""))
				Expect(reflect.TypeOf(http.DefaultTransport).Elem().Name()).ToNot(Equal("Transport"))
			})
		})

		Context("with a nil-emitter", func() {
			It("resets the HTTP default transport to not be instrumented", func() {
				autowire.Initialize(nil)
				Expect(reflect.TypeOf(http.DefaultTransport).Elem().Name()).To(Equal("Transport"))
			})
		})
	})

	Describe("CreateDefaultEmitter", func() {
		Context("with DROPSONDE_ORIGIN set", func() {
			BeforeEach(func() {
コード例 #7
0
	"github.com/cloudfoundry/dropsonde/emitter"
	"github.com/cloudfoundry/dropsonde/emitter/fake"
	"github.com/cloudfoundry/dropsonde/events"
	"github.com/cloudfoundry/dropsonde/factories"
	"github.com/gogo/protobuf/proto"

	. "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)
コード例 #8
0
	"github.com/cloudfoundry/dropsonde/envelope_extensions"
	"github.com/cloudfoundry/dropsonde/instrumented_handler"
	"github.com/cloudfoundry/sonde-go/events"
	uuid "github.com/nu7hatch/gouuid"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Sending Http events through loggregator", func() {
	Context("When the instrumented handler receives a request", func() {
		It("should emit an HttpStartStop through the firehose", func() {
			msgChan, errorChan := helpers.ConnectToFirehose()

			udpEmitter, err := emitter.NewUdpEmitter(fmt.Sprintf("localhost:%d", config.DropsondePort))
			Expect(err).ToNot(HaveOccurred())
			emitter := emitter.NewEventEmitter(udpEmitter, helpers.ORIGIN_NAME)
			done := make(chan struct{})
			handler := instrumented_handler.InstrumentedHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				w.WriteHeader(http.StatusTeapot)
				close(done)
			}), emitter)

			r, err := http.NewRequest("HEAD", "/", nil)
			Expect(err).ToNot(HaveOccurred())
			r.Header.Add("User-Agent", "Spider-Man")
			w := httptest.NewRecorder()
			handler.ServeHTTP(w, r)
			Eventually(done).Should(BeClosed())

			receivedEnvelope := helpers.FindMatchingEnvelope(msgChan)
			Expect(receivedEnvelope).NotTo(BeNil())