diff --git a/agent/agent.go b/agent/agent.go index 228b28f9..8c1f9f13 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -586,19 +586,6 @@ func (t *transporterServer) Transfer(ctx context.Context, r *Request) (*Response if !strings.HasPrefix(filepath.Base(t.req.DatabaseLogPath), t.req.LogPrefix) { dstDatabaseLogPath = fmt.Sprintf("%s-%d-%s", t.req.LogPrefix, t.req.ServerIndex+1, filepath.Base(t.req.DatabaseLogPath)) } - - srcMonitorResultPath := t.req.MonitorResultPath - dstMonitorResultPath := filepath.Base(t.req.MonitorResultPath) - if !strings.HasPrefix(filepath.Base(t.req.MonitorResultPath), t.req.LogPrefix) { - dstMonitorResultPath = fmt.Sprintf("%s-%d-%s", t.req.LogPrefix, t.req.ServerIndex+1, filepath.Base(t.req.MonitorResultPath)) - } - - srcAgentLogPath := agentLogPath - dstAgentLogPath := filepath.Base(agentLogPath) - if !strings.HasPrefix(filepath.Base(agentLogPath), t.req.LogPrefix) { - dstAgentLogPath = fmt.Sprintf("%s-%d-%s", t.req.LogPrefix, t.req.ServerIndex+1, filepath.Base(agentLogPath)) - } - log.Printf("Uploading %s to %s", srcDatabaseLogPath, dstDatabaseLogPath) var uerr error for k := 0; k < 5; k++ { @@ -610,6 +597,11 @@ func (t *transporterServer) Transfer(ctx context.Context, r *Request) (*Response } } + srcMonitorResultPath := t.req.MonitorResultPath + dstMonitorResultPath := filepath.Base(t.req.MonitorResultPath) + if !strings.HasPrefix(filepath.Base(t.req.MonitorResultPath), t.req.LogPrefix) { + dstMonitorResultPath = fmt.Sprintf("%s-%d-%s", t.req.LogPrefix, t.req.ServerIndex+1, filepath.Base(t.req.MonitorResultPath)) + } log.Printf("Uploading %s to %s", srcMonitorResultPath, dstMonitorResultPath) for k := 0; k < 5; k++ { if uerr = u.UploadFile(t.req.GoogleCloudStorageBucketName, srcMonitorResultPath, dstMonitorResultPath); uerr != nil { @@ -620,6 +612,11 @@ func (t *transporterServer) Transfer(ctx context.Context, r *Request) (*Response } } + srcAgentLogPath := agentLogPath + dstAgentLogPath := filepath.Base(agentLogPath) + if !strings.HasPrefix(filepath.Base(agentLogPath), t.req.LogPrefix) { + dstAgentLogPath = fmt.Sprintf("%s-%d-%s", t.req.LogPrefix, t.req.ServerIndex+1, filepath.Base(agentLogPath)) + } log.Printf("Uploading %s to %s", srcAgentLogPath, dstAgentLogPath) for k := 0; k < 5; k++ { if uerr = u.UploadFile(t.req.GoogleCloudStorageBucketName, srcAgentLogPath, dstAgentLogPath); uerr != nil { diff --git a/bench/main.go b/bench/bench.go similarity index 76% rename from bench/main.go rename to bench/bench.go index fc4b7da2..5f4e6470 100644 --- a/bench/main.go +++ b/bench/bench.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -// bench does benchmark, mostly copied from https://github.com/coreos/etcd/tree/master/tools/benchmark. -package main +// Package bench is modified based on https://github.com/coreos/etcd/tree/master/tools/benchmark. +package bench import ( "fmt" @@ -40,7 +40,10 @@ var ( sample bool noHistogram bool - csvResultPath string + csvResultPath string + googleCloudProjectName string + googleCloudStorageJSONKeyPath string + googleCloudStorageBucketName string bar *pb.ProgressBar results chan result @@ -60,6 +63,9 @@ func init() { Command.PersistentFlags().BoolVar(&noHistogram, "no-histogram", false, "'true' to not show results in histogram.") Command.PersistentFlags().StringVar(&csvResultPath, "csv-result-path", "timeseries.csv", "path to store csv results.") + Command.PersistentFlags().StringVar(&googleCloudProjectName, "google-cloud-project-name", "", "Google cloud project name.") + Command.PersistentFlags().StringVar(&googleCloudStorageJSONKeyPath, "google-cloud-storage-json-key-path", "", "Path of JSON key file.") + Command.PersistentFlags().StringVar(&googleCloudStorageBucketName, "google-cloud-storage-bucket-name", "", "Google cloud storage bucket name.") } func main() { diff --git a/bench/put.go b/bench/put.go index 9215f199..52214c50 100644 --- a/bench/put.go +++ b/bench/put.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package bench import ( "encoding/binary" diff --git a/bench/range.go b/bench/range.go index 263f692d..91a6a3a8 100644 --- a/bench/range.go +++ b/bench/range.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package bench import ( "fmt" diff --git a/bench/report.go b/bench/report.go index 049acada..a81faf87 100644 --- a/bench/report.go +++ b/bench/report.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package bench import ( "fmt" diff --git a/bench/timeseries.go b/bench/timeseries.go index 8fcd382e..08c8e84a 100644 --- a/bench/timeseries.go +++ b/bench/timeseries.go @@ -12,16 +12,20 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package bench import ( "bytes" "encoding/csv" "fmt" + "io/ioutil" "log" + "path/filepath" "sort" "sync" "time" + + "github.com/coreos/dbtester/remotestorage" ) type timeSeries struct { @@ -112,7 +116,29 @@ func (ts TimeSeries) String() string { if err := toFile(txt, csvResultPath); err != nil { log.Fatal(err) } else { - log.Println("time series saved... Please upload to Google cloud storage...") + log.Println("time series saved... Uploading to Google cloud storage...") + kbts, err := ioutil.ReadFile(googleCloudStorageJSONKeyPath) + if err != nil { + log.Fatal(err) + } + u, err := remotestorage.NewGoogleCloudStorage(kbts, googleCloudProjectName) + if err != nil { + log.Fatal(err) + } + + // set up file names + srcCSVResultPath := csvResultPath + dstCSVResultPath := filepath.Base(csvResultPath) + log.Printf("Uploading %s to %s", srcCSVResultPath, dstCSVResultPath) + var uerr error + for k := 0; k < 5; k++ { + if uerr = u.UploadFile(googleCloudStorageBucketName, srcCSVResultPath, dstCSVResultPath); uerr != nil { + log.Println(uerr) + continue + } else { + break + } + } } return fmt.Sprintf("\nSample in one second (unix latency throughput):\n%s", txt) } diff --git a/bench/util.go b/bench/util.go index 3109b0e1..81d74584 100644 --- a/bench/util.go +++ b/bench/util.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package bench import ( "crypto/rand" diff --git a/main.go b/main.go index 2d0146d3..327510cd 100644 --- a/main.go +++ b/main.go @@ -19,12 +19,13 @@ // // Available Commands: // agent Database agent in remote servers. +// bench Low-level benchmark tool for etcd, Zookeeper, etcd2, consul. // start Starts database through RPC calls. // stop Stops database through RPC calls. // restart Restarts database through RPC calls. // // Flags: -// -h, --help[=false]: help for dbtester +// -h, --help help for dbtester // // Use "dbtester [command] --help" for more information about a command. // @@ -35,6 +36,7 @@ import ( "os" "github.com/coreos/dbtester/agent" + "github.com/coreos/dbtester/bench" "github.com/coreos/dbtester/control" "github.com/spf13/cobra" @@ -54,6 +56,7 @@ func init() { func init() { rootCommand.AddCommand(agent.Command) + rootCommand.AddCommand(bench.Command) rootCommand.AddCommand(control.StartCommand) rootCommand.AddCommand(control.StopCommand) rootCommand.AddCommand(control.RestartCommand)