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() }
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, } }
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() }
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" "tools/benchmark/metricsreporter" ) var _ = Describe("MessageWriter", func() { var ( sentCounter *metricsreporter.Counter ) BeforeEach(func() { sentCounter = metricsreporter.NewCounter("sent") }) It("should keep track of the total sent messages", func() { msgWriter := messagewriter.NewMessageWriter("localhost", 51161, "", sentCounter) message := []byte{} msgWriter.Write(message) msgWriter.Write(message) msgWriter.Write(message) msgWriter.Write(message) msgWriter.Write(message) msgWriter.Write(message) msgWriter.Write(message) msgWriter.Write(message) Expect(sentCounter.GetValue()).To(BeEquivalentTo(8)) }) It("should not increment total sent messages", func() { messagewriter.NewMessageWriter("localhost", 51161, "", sentCounter)
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 }