From d665abdf46e4d6af59fab33e71c0dc4eb84dc0d7 Mon Sep 17 00:00:00 2001 From: Gabriel Diaz Date: Wed, 6 Mar 2019 12:24:14 +0100 Subject: [PATCH] wip: agents clean up --- tests/qedmanager | 92 ++++++++++++++++++++++++++++++++++++++++++++++ tests/riot.go | 61 ++++-------------------------- tests/riot/main.go | 51 ------------------------- 3 files changed, 99 insertions(+), 105 deletions(-) create mode 100644 tests/qedmanager diff --git a/tests/qedmanager b/tests/qedmanager new file mode 100644 index 000000000..08fb15659 --- /dev/null +++ b/tests/qedmanager @@ -0,0 +1,92 @@ +#!/usr/bin/env bash + +# Copyright 2018 Banco Bilbao Vizcaya Argentaria, S.A. + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +certs="$HOME/.ssh" +qed="go run $GOPATH/src/github.com/bbva/qed/main.go" +service="go run $GOPATH/src/github.com/bbva/qed/tests/gossip/test_service.go" + + +apikey() { echo "--apikey test_key"; } +nodeId() { echo "--node-id ${FUNCNAME[1]}_$1";} +path() { echo "--path $1";} +log() { echo "--log $1";} +keyPath() { echo "--keypath $certs/id_ed25519"; } +httpAddr() { echo "--http-addr 127.0.0.1:88`printf '%02d' $1`"; } +mgmtAddr() { echo "--mgmt-addr 127.0.0.1:87`printf '%02d' $1`"; } +metricsAddr() { echo "--metris-addr 127.0.0.1:86`printf '%02d' $1`";} +raftAddr() { echo "--raft-addr 127.0.0.1:85`printf '%02d' $1`"; } +gossipAddr() { echo "--gossip-addr 127.0.0.1:84`printf '%02d' $1`"; } +joinAddr() { echo "--join-addr 127.0.0.1:8700"; } +gossipJoinAddr() { echo "--gossip-join-addr 127.0.0.1:8400"; } +profiling() { echo "--profiling"; } +cert() { echo "--certificate $certs/server.crt"; } +certKey() { echo "--certificate-key $certs/server.key"; } +tempDir() { mktemp -d -p "/var/tmp"; } + +bindAddr() { echo "--bind 127.0.0.1:8`printf '%d%02d' $1 $2`"; } +alertsUrls() { echo "--alertsUrls http://127.0.0.1:8888"; } +qedUrls() { echo "--qedUrls http://127.0.0.1:8800"; } +pubUrls() { echo "--pubUrl http://127.0.0.1:8888"; } + +qedLeader() { + dir=`tempDir` + echo $qed `apikey` `path $dir` `nodeId 0` `keyPath` `gossipAddr 0` `log error` `cert` `certKey` `profiling` +} + +qedFollower() { + dir=`tempDir` + echo $qed `apikey` `path $dir` `nodeId $1` `keyPath` `gossipAddr $1` `log error` `cert` `certKey` `httpAddr $1` `mgmtAddr $1` `metricsAddr $1` `raftAddr $1` `gossipAddr $1` `joinAddr` `gossipJoinAddr` `cert` `certKey``profiling` +} + + +agent() { + type=$1; shift; + portIndex=$1; shift + id=$1; shift; + echo $qed agent `alertsUrls` $type `apiKey` `log error` `bindAddr $portIndex $id``gossipJoinAddr` `quedUrls` `pubUrls` `nodeId $id` +} + +auditor() { + agent auditor 1 $1 +} + +monitor() { + agent monitor 2 $1 +} + +publisher() { + agent publisher 3 $1 +} + +service() { + echo $service +} + +run() { + name=$1; shift; + cmd=$1; shift; + dir=$1; shift; + $cmd 2>&1 > $dir/$name.log & + echo $! +} + +x=$1; shift +qedCluster=$1; shift; +monitors=$1; shift; +auditors=$1; shift; +publisers=$1; shift; + + diff --git a/tests/riot.go b/tests/riot.go index 6caad362d..11be22dd8 100644 --- a/tests/riot.go +++ b/tests/riot.go @@ -34,19 +34,17 @@ import ( "sync" "time" - chart "github.com/wcharczuk/go-chart" - "github.com/bbva/qed/protocol" ) var ( - endpoint string - apiKey string - wantAdd bool - wantIncremental bool - wantMembership bool - offload bool - charts bool + endpoint string + apiKey string + wantAdd bool + wantIncremental bool + wantMembership bool + offload bool + profiling bool incrementalDelta int offset int @@ -71,7 +69,6 @@ func init() { flag.BoolVar(&wantIncremental, "incremental", false, "Execute Incremental benchmark") flag.BoolVar(&offload, "offload", false, "Perform reads only on %50 of the cluster size (With cluster size 2 reads will be performed only on follower1)") - flag.BoolVar(&charts, "charts", false, "Create charts while executing the benchmarks. Output: graph-$testname.png") flag.BoolVar(&profiling, "profiling", false, "Enable Go profiling with pprof tool. $ go tool pprof -http : http://localhost:6061 ") usageDelta := "Specify delta for the IncrementalProof" @@ -248,46 +245,6 @@ type axis struct { x, y []float64 } -func drawChart(m string, a *axis) { - graph := chart.Chart{ - XAxis: chart.XAxis{ - Name: "Time", - NameStyle: chart.StyleShow(), - Style: chart.StyleShow(), - }, - YAxis: chart.YAxis{ - Name: "Reqests", - NameStyle: chart.StyleShow(), - Style: chart.StyleShow(), - }, - Series: []chart.Series{ - chart.ContinuousSeries{ - Style: chart.Style{ - Show: true, - StrokeColor: chart.GetDefaultColor(0).WithAlpha(64), - FillColor: chart.GetDefaultColor(0).WithAlpha(64), - }, - - XValues: a.x, - YValues: a.y, - }, - }, - } - - req := fmt.Sprint(numRequests) - file, _ := os.Create("results/graph-" + m + "-" + req + ".png") - defer file.Close() - _ = graph.Render(chart.PNG, file) - -} - -func chartsData(a *axis, elapsed, reqs float64) *axis { - a.x = append(a.x, elapsed) - a.y = append(a.y, reqs) - - return a -} - func summary(message string, numRequestsf, elapsed float64, c *Config) { fmt.Printf( @@ -332,10 +289,6 @@ func stats(c *Config, t Task, message string) { case t := <-ticker.C: _ = t elapsed := time.Now().Sub(start).Seconds() - if charts { - os.Mkdir("results", 0755) - go drawChart(message, chartsData(graph, elapsed, c.counter/elapsed)) - } summaryPerDuration(message, numRequestsf, elapsed, c) } } diff --git a/tests/riot/main.go b/tests/riot/main.go index f3b595c25..70e635f78 100644 --- a/tests/riot/main.go +++ b/tests/riot/main.go @@ -26,7 +26,6 @@ import ( "github.com/imdario/mergo" "github.com/spf13/cobra" "github.com/spf13/viper" - chart "github.com/wcharczuk/go-chart" "github.com/bbva/qed/client" "github.com/bbva/qed/log" @@ -45,7 +44,6 @@ type Config struct { // stress conf Offload bool - Charts bool Profiling bool IncrementalDelta uint Offset uint @@ -112,7 +110,6 @@ func newRiotCommand() *cobra.Command { f.BoolVarP(&config.Membership, "membership", "m", false, "Benchmark MembershipProof") f.BoolVar(&config.Incremental, "incremental", false, "Execute Incremental benchmark") f.BoolVar(&config.Offload, "offload", false, "Perform reads only on %50 of the cluster size (With cluster size 2 reads will be performed only on follower1)") - f.BoolVar(&config.Charts, "charts", false, "Create charts while executing the benchmarks. Output: graph-$testname.png") f.BoolVar(&config.Profiling, "profiling", false, "Enable Go profiling with pprof tool. $ go tool pprof -http : http://localhost:6061 ") f.UintVarP(&config.IncrementalDelta, "delta", "d", 1000, "Specify delta for the IncrementalProof") f.UintVar(&config.NumRequests, "n", 10e4, "Number of requests for the attack") @@ -323,32 +320,16 @@ func (a *Attack) CreateFanOut() { } } -func chartsData(a *axis, elapsed, reqs float64) *axis { - a.x = append(a.x, elapsed) - a.y = append(a.y, reqs) - - return a -} - func setupMetrics(conf Config) { graph := &axis{} ticker := time.NewTicker(1 * time.Second) start := time.Now() defer ticker.Stop() - if conf.Charts { - if err := os.Mkdir("results", 0755); err != nil { - log.Error("Unable to create `results` folder") - } - } - go func() { for { <-ticker.C elapsed := time.Since(start).Seconds() - if conf.Charts { - go drawChart(conf, chartsData(graph, elapsed, conf.counter/elapsed)) - } summaryPerDuration(conf, elapsed) } }() @@ -368,35 +349,3 @@ func summaryPerDuration(conf Config, elapsed float64) { type axis struct { x, y []float64 } - -func drawChart(conf Config, a *axis) { - graph := chart.Chart{ - XAxis: chart.XAxis{ - Name: "Time", - NameStyle: chart.StyleShow(), - Style: chart.StyleShow(), - }, - YAxis: chart.YAxis{ - Name: "Reqests", - NameStyle: chart.StyleShow(), - Style: chart.StyleShow(), - }, - Series: []chart.Series{ - chart.ContinuousSeries{ - Style: chart.Style{ - Show: true, - StrokeColor: chart.GetDefaultColor(0).WithAlpha(64), - FillColor: chart.GetDefaultColor(0).WithAlpha(64), - }, - - XValues: a.x, - YValues: a.y, - }, - }, - } - - req := fmt.Sprint(conf.NumRequests) - file, _ := os.Create("results/graph-" + req + ".png") - defer file.Close() - _ = graph.Render(chart.PNG, file) -}