Example #1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	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")
	var concurrentWriters = flag.Int("concurrentWriters", 1, "Number of concurrent writers")

	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)
	}

	reporter := metricsreporter.New(duration, os.Stdout)
	generator := messagegenerator.NewValueMetricGenerator()
	reader := messagereader.NewMessageReader(3457)
	valueMetricReader := valuemetricreader.NewValueMetricReader(reporter.GetReceivedCounter(), reader)
	exp := experiment.NewExperiment(valueMetricReader)

	for i := 0; i < *concurrentWriters; i++ {
		writer := messagewriter.NewMessageWriter("localhost", 51161, "", reporter.GetSentCounter())
		writeStrategy := writestrategies.NewConstantWriteStrategy(generator, writer, *writeRate)
		exp.AddWriteStrategy(writeStrategy)
	}

	announceToEtcd()

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

	timer := time.NewTimer(stopAfterDuration)
	<-timer.C
	exp.Stop()
	reporter.Stop()
}
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("ValueMetricReader", func() {
	Context("Read", func() {
		var (
			receivedCounter   *metricsreporter.Counter
			reader            fakeReader
			valueMetricReader *valuemetricreader.ValueMetricReader
		)

		BeforeEach(func() {
			receivedCounter = metricsreporter.NewCounter("counter")
			reader = fakeReader{}
			valueMetricReader = valuemetricreader.NewValueMetricReader(receivedCounter, &reader)
		})

		It("should report value metrics", func() {
			reader.event = messagegenerator.BasicValueMetricEnvelope(valuemetricreader.TestOrigin)

			valueMetricReader.Read()

			Expect(receivedCounter.GetValue()).To(BeEquivalentTo(1))
		})

		It("should not report log messages", func() {
			reader.event = messagegenerator.BasicLogMessageEnvelope(valuemetricreader.TestOrigin, "appID")

			valueMetricReader.Read()