Example #1
0
		var err error
		serverConfig, err = listeners.NewTLSConfig(
			"fixtures/server.crt",
			"fixtures/server.key",
			"fixtures/loggregator-ca.crt",
		)
		Expect(err).ToNot(HaveOccurred())
		serverConfig.InsecureSkipVerify = true
		clientConfig, err = listeners.NewTLSConfig(
			"fixtures/client.crt",
			"fixtures/client.key",
			"fixtures/loggregator-ca.crt",
		)
		Expect(err).ToNot(HaveOccurred())
		clientConfig.InsecureSkipVerify = true
		reader = messagereader.NewTLS(port, serverConfig)
	})

	AfterEach(func() {
		port += 1
		reader.Close()
	})

	It("receives a message on the specified port", func() {
		tlsWriteMessage(port, clientConfig)
		tlsWriteMessage(port, clientConfig)
		Eventually(reader.Read()).ShouldNot(BeNil())
		Eventually(reader.Read()).ShouldNot(BeNil())
	})

	It("doesn't panic when message size is smaller than it's prefixed length", func() {
Example #2
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
}