示例#1
0
func NewFakeApp(appID string, logRate int) *FakeApp {

	generator := messagegenerator.NewLogMessageGenerator(appID)
	counter := metricsreporter.NewCounter("sentLogs")
	// 49625 is the DropsondeIncomingMessagesPort for the metron that will be spun up.
	writer := messagewriter.NewMessageWriter("localhost", 49625, "", counter)

	writeStrategy := writestrategies.NewConstantWriteStrategy(generator, writer, logRate)

	return &FakeApp{
		appID:         appID,
		logRate:       logRate,
		writeStrategy: writeStrategy,
		logCounter:    counter,
	}
}
示例#2
0
var _ = Describe("End to end tests", func() {
	Context("with metron sending on tcp", func() {
		BeforeEach(func() {
			metronConfig = "metrontcp"
		})

		Context("with doppler reading on tcp", func() {
			BeforeEach(func() {
				dopplerConfig = "dopplertcp"
			})

			It("can send a message", func() {
				const writeRatePerSecond = 1000
				metronStreamWriter := endtoend.NewMetronStreamWriter()
				firehoseReader := endtoend.NewFirehoseReader()
				generator := messagegenerator.NewLogMessageGenerator("custom-app-id")

				writeStrategy := writestrategies.NewConstantWriteStrategy(generator, metronStreamWriter, writeRatePerSecond)
				ex := experiment.NewExperiment(firehoseReader)
				ex.AddWriteStrategy(writeStrategy)

				ex.Warmup()

				go stopExperimentAfterTimeout(ex)
				ex.Start()

				Eventually(firehoseReader.LastLogMessage()).Should(ContainSubstring("custom-app-id"))
			}, 10)
		})
	})
})
var _ = Describe("Messagegenerator", func() {
	Context("The ValueMetricGenerator", func() {
		It("generates a value metric message", func() {
			generator := messagegenerator.NewValueMetricGenerator()
			bytes := generator.Generate()
			var envelope events.Envelope
			err := proto.Unmarshal(bytes, &envelope)
			Expect(err).ToNot(HaveOccurred())
			Expect(envelope.GetEventType()).To(Equal(events.Envelope_ValueMetric))
		})
	})

	Context("The LogGenerator", func() {
		It("generates a log message envelope", func() {
			generator := messagegenerator.NewLogMessageGenerator()
			bytes := generator.Generate()
			var envelope events.Envelope
			err := proto.Unmarshal(bytes, &envelope)
			Expect(err).ToNot(HaveOccurred())
			Expect(envelope.GetLogMessage()).ToNot(BeNil())
			Expect(envelope.GetLogMessage().GetMessage()).To(BeEquivalentTo("test message"))
		})
	})

	Context("The LegacyLogGenerator", func() {
		It("generates a legacy log message envelope", func() {
			generator := messagegenerator.NewLegacyLogGenerator()
			bytes := generator.Generate()
			var envelope logmessage.LogEnvelope
			err := proto.Unmarshal(bytes, &envelope)
示例#4
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	var (
		interval          time.Duration
		writeRate         int
		stopAfter         time.Duration
		concurrentWriters int
		eventType         events.Envelope_EventType
		protocol          string
		serverCert        string
		serverKey         string
		caCert            string
		burstDelay        time.Duration
	)

	flag.Var(newDurationValue(&interval, time.Second), "interval", "Interval for reported results")
	flag.IntVar(&writeRate, "writeRate", 15000, "Number of writes per second to send to metron")
	flag.Var(newDurationValue(&stopAfter, 5*time.Minute), "stopAfter", "How long to run the experiment for")
	flag.IntVar(&concurrentWriters, "concurrentWriters", 1, "Number of concurrent writers")
	flag.Var(newEventTypeValue(&eventType, events.Envelope_ValueMetric), "eventType", "The event type to test")
	flag.StringVar(&protocol, "protocol", "udp", "The protocol to configure metron to send messages over")
	flag.StringVar(&serverCert, "serverCert", "../../integration_tests/fixtures/server.crt", "The server cert file (for TLS connections)")
	flag.StringVar(&serverKey, "serverKey", "../../integration_tests/fixtures/server.key", "The server key file (for TLS connections)")
	flag.StringVar(&caCert, "caCert", "../../integration_tests/fixtures/loggregator-ca.crt", "The certificate authority cert file (for TLS connections)")
	flag.Var(newDurationValue(&burstDelay, 0), "burstDelay", "The delay between burst sequences.  If this is non-zero then writeRate is used as the number of messages to send each burst.")

	flag.Parse()

	reporter := metricsreporter.New(interval, os.Stdout)
	var generator writestrategies.MessageGenerator
	switch eventType {
	case events.Envelope_ValueMetric:
		generator = messagegenerator.NewValueMetricGenerator()
	case events.Envelope_LogMessage:
		generator = messagegenerator.NewLogMessageGenerator("fake-app-id")
	default:
		log.Fatalf("Unsupported envelope type: %v", eventType)
	}
	var dopplerURLs []string
	var reader eventtypereader.MessageReader
	switch protocol {
	case "udp":
		reader = messagereader.NewUDP(3457)
		dopplerURLs = []string{"udp://127.0.0.1:3457"}
	case "tls":
		tlsConfig, err := listeners.NewTLSConfig(
			serverCert,
			serverKey,
			caCert,
		)
		if err != nil {
			log.Printf("Error: failed to load TLS config: %s", err)
			os.Exit(1)
		}
		tlsConfig.InsecureSkipVerify = true
		reader = messagereader.NewTLS(3458, tlsConfig)
		dopplerURLs = []string{"tls://127.0.0.1:3458"}
	default:
		panic(fmt.Errorf("Unknown protocol %s", protocol))
	}
	valueMetricReader := eventtypereader.New(reporter.ReceivedCounter(), reader, eventType, "test-origin")
	exp := experiment.NewExperiment(valueMetricReader)

	for i := 0; i < concurrentWriters; i++ {
		writer := messagewriter.NewMessageWriter("localhost", 51161, "", reporter.SentCounter())
		writeStrategy := chooseStrategy(generator, writer, writeRate, burstDelay)
		exp.AddWriteStrategy(writeStrategy)
	}

	adapter := announceToEtcd(dopplerURLs...)
	defer func() {
		exp.Stop()
		reporter.Stop()
		err := adapter.Delete(nodeKey)
		if err != nil {
			log.Printf("Warning: Failed to delete etcd key %s: %s", nodeKey, err)
		}
		adapter.Disconnect()
	}()

	exp.Warmup()
	go reporter.Start()
	go exp.Start()

	timer := time.NewTimer(stopAfter)
	<-timer.C
}
var _ = Describe("Messagegenerator", func() {
	Context("The ValueMetricGenerator", func() {
		It("generates a value metric message", func() {
			generator := messagegenerator.NewValueMetricGenerator()
			bytes := generator.Generate()
			var envelope events.Envelope
			err := proto.Unmarshal(bytes, &envelope)
			Expect(err).ToNot(HaveOccurred())
			Expect(envelope.GetEventType()).To(Equal(events.Envelope_ValueMetric))
		})
	})

	Context("The LogGenerator", func() {
		It("generates a log message envelope", func() {
			generator := messagegenerator.NewLogMessageGenerator("appID")
			bytes := generator.Generate()
			var envelope events.Envelope
			err := proto.Unmarshal(bytes, &envelope)
			Expect(err).ToNot(HaveOccurred())
			Expect(envelope.GetLogMessage()).ToNot(BeNil())
			Expect(envelope.GetLogMessage().GetMessage()).To(BeEquivalentTo("test message"))
		})
	})

	Context("The LegacyLogGenerator", func() {
		It("generates a legacy log message envelope", func() {
			generator := messagegenerator.NewLegacyLogGenerator()
			bytes := generator.Generate()
			var envelope logmessage.LogEnvelope
			err := proto.Unmarshal(bytes, &envelope)