Ejemplo n.º 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 doppler")
	var stopAfter = flag.String("stopAfter", "5m", "How long to run the experiment for")
	var sharedSecret string
	flag.StringVar(&sharedSecret, "sharedSecret", "", "Shared secret used by Doppler to verify message validity")
	var dopplerOutgoingPort = flag.Int("dopplerOutgoingPort", 8080, "Outgoing port from doppler")
	var dopplerIncomingDropsondePort = flag.Int("dopplerIncomingDropsondePort", 3457, "Incoming dropsonde port to doppler")
	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)
	ip, err := localip.LocalIP()
	if err != nil {
		panic(err)
	}

	generator := messagegenerator.NewValueMetricGenerator()
	writer := messagewriter.NewMessageWriter(ip, *dopplerIncomingDropsondePort, sharedSecret, reporter.SentCounter())
	reader := websocketmessagereader.New(fmt.Sprintf("%s:%d", ip, *dopplerOutgoingPort), reporter.ReceivedCounter())
	defer reader.Close()

	writeStrategy := writestrategies.NewConstantWriteStrategy(generator, writer, *writeRate)
	exp := experiment.NewExperiment(reader)
	exp.AddWriteStrategy(writeStrategy)

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

	timer := time.NewTimer(stopAfterDuration)
	<-timer.C
	exp.Stop()
	reporter.Stop()
}
Ejemplo n.º 2
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()
}
Ejemplo n.º 3
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"
	"github.com/onsi/gomega/gbytes"
)

var _ = Describe("MetricsReporter", func() {
	var (
		buffer   *gbytes.Buffer
		reporter *metricsreporter.MetricsReporter
		start    time.Time
		counters []*metricsreporter.Counter
	)

	JustBeforeEach(func() {
		buffer = gbytes.NewBuffer()
		reporter = metricsreporter.New(time.Millisecond*10, buffer, counters...)
		start = time.Now()
		go reporter.Start()
	})

	AfterEach(func() {
		buffer.Close()
	})

	Describe("SentCounter", func() {
		It("returns a non-nil counter", func() {
			Expect(reporter.SentCounter()).NotTo(BeNil())
		})
	})

	Describe("ReceiveCounter", func() {
Ejemplo n.º 5
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
}