Exemple #1
0
func main() {
	runtime.GOMAXPROCS(4)

	var interval = flag.String("interval", "1s", "Interval for reported results")
	var writeRate = flag.Int("writeRate", 15000, "Number of writes per second to send to metron")
	var stopAfter = flag.String("stopAfter", "5m", "How long to run the experiment for")
	flag.Parse()

	duration, err := time.ParseDuration(*interval)
	if err != nil {
		log.Fatalf("Invalid duration %s\n", *interval)
	}

	stopAfterDuration, err := time.ParseDuration(*stopAfter)
	if err != nil {
		log.Fatalf("Invalid duration %s\n", *stopAfter)
	}

	internalMetricsCounter := metricsreporter.NewCounter("internal metrics")
	reporter := metricsreporter.New(duration, os.Stdout, internalMetricsCounter)

	reader := messagereader.NewMessageReader(3457)
	legacyReader := legacyreader.NewLegacyReader(reporter.GetReceivedCounter(), internalMetricsCounter, reader)

	exp := experiment.NewExperiment(legacyReader)

	generator := messagegenerator.NewValueMetricGenerator()
	writer := messagewriter.NewMessageWriter("localhost", 51161, "", reporter.GetSentCounter())
	writeStrategy := writestrategies.NewConstantWriteStrategy(generator, writer, *writeRate)
	exp.AddWriteStrategy(writeStrategy)

	legacyGenerator := messagegenerator.NewLegacyLogGenerator()
	legacyWriter := messagewriter.NewMessageWriter("localhost", 51160, "", reporter.GetSentCounter())
	legacyWriteStrategy := writestrategies.NewConstantWriteStrategy(legacyGenerator, legacyWriter, *writeRate)
	exp.AddWriteStrategy(legacyWriteStrategy)

	announceToEtcd()

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

	timer := time.NewTimer(stopAfterDuration)
	<-timer.C
	exp.Stop()
	reporter.Stop()
}
			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)
			Expect(err).ToNot(HaveOccurred())
			Expect(envelope.GetLogMessage()).ToNot(BeNil())
			Expect(envelope.GetLogMessage().GetMessage()).To(BeEquivalentTo("test message"))
		})
	})
})