Repository: bojand/ghz
Pull request #144 (2019-11-27 10:19:01)

Add UUID for each call
We have a case where we need a UUID string for each call. Might help others if they have a similar requirements when benchmarking.


Patch:
diff --git a/go.mod b/go.mod
index 5100889..5fc3f26 100644
--- a/go.mod
+++ b/go.mod
@@ -11,6 +11,7 @@ require (
 	github.com/go-playground/validator v9.30.0+incompatible
 	github.com/gogo/protobuf v1.3.1
 	github.com/golang/protobuf v1.3.2
+	github.com/google/uuid v1.1.1
 	github.com/jhump/protoreflect v1.5.0
 	github.com/jinzhu/configor v1.1.1
 	github.com/jinzhu/gorm v1.9.11
diff --git a/go.sum b/go.sum
index fc286a6..a38c357 100644
--- a/go.sum
+++ b/go.sum
@@ -58,6 +58,8 @@ github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
 github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
 github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
 github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
+github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
+github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
 github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
 github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
diff --git a/runner/call_template_data.go b/runner/call_template_data.go
index af31a1f..b3de163 100644
--- a/runner/call_template_data.go
+++ b/runner/call_template_data.go
@@ -5,7 +5,7 @@ import (
 	"encoding/json"
 	"text/template"
 	"time"
-
+    "github.com/google/uuid"
 	"github.com/jhump/protoreflect/desc"
 )
 
@@ -24,11 +24,13 @@ type callTemplateData struct {
 	TimestampUnix      int64  // timestamp of the call as unix time in seconds
 	TimestampUnixMilli int64  // timestamp of the call as unix time in milliseconds
 	TimestampUnixNano  int64  // timestamp of the call as unix time in nanoseconds
+	UUID string // generated UUIDv4 for each call
 }
 
 // newCallTemplateData returns new call template data
 func newCallTemplateData(mtd *desc.MethodDescriptor, workerID string, reqNum int64) *callTemplateData {
 	now := time.Now()
+	newUUID, _ := uuid.NewRandom()
 
 	return &callTemplateData{
 		WorkerID:           workerID,
@@ -44,6 +46,7 @@ func newCallTemplateData(mtd *desc.MethodDescriptor, workerID string, reqNum int
 		TimestampUnix:      now.Unix(),
 		TimestampUnixMilli: now.UnixNano() / 1000000,
 		TimestampUnixNano:  now.UnixNano(),
+		UUID: newUUID.String(),
 	}
 }
 
diff --git a/www/docs/calldata.md b/www/docs/calldata.md
index 71ec49e..70a8c48 100644
--- a/www/docs/calldata.md
+++ b/www/docs/calldata.md
@@ -47,6 +47,9 @@ type callTemplateData struct {
 
 	// timestamp of the call as unix time in nanoseconds
 	TimestampUnixNano      int64
+
+	// generated UUIDv4 for each call
+	UUID	string
 }
 ```
 


Test patch:
diff --git a/runner/call_template_data_test.go b/runner/call_template_data_test.go
index 6afbe89..9523210 100644
--- a/runner/call_template_data_test.go
+++ b/runner/call_template_data_test.go
@@ -29,6 +29,8 @@ func TestCallTemplateData_New(t *testing.T) {
 	assert.NotZero(t, ctd.TimestampUnixMilli)
 	assert.NotZero(t, ctd.TimestampUnixNano)
 	assert.Equal(t, ctd.TimestampUnix, ctd.TimestampUnixMilli/1000)
+	assert.NotEmpty(t, ctd.UUID)
+	assert.Equal(t, 36, len(ctd.UUID))
 }
 
 func TestCallTemplateData_ExecuteData(t *testing.T) {