Repository: bojand/ghz (go)

Issue:
UnixTimestamp call template in milliseconds
**Is your feature request related to a problem? Please describe.**
My GPRC interface accepts unix epoch time in milliseconds but the current call template only returns values in seconds.

**Describe the solution you'd like**
I would like an additional call template variable that returns the unix timestamp in milliseconds.


Pull request:
Add timestamp unix milliseconds
Add Unix Millisecond timestamp. Fixes #141.


Patch:
diff --git a/.gitignore b/.gitignore
index 261d25f..f83d890 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,3 +27,4 @@ node_modules
 coverage.html
 
 .idea
+.orig
diff --git a/runner/call_template_data.go b/runner/call_template_data.go
index 4a590eb..af31a1f 100644
--- a/runner/call_template_data.go
+++ b/runner/call_template_data.go
@@ -22,6 +22,7 @@ type callTemplateData struct {
 	IsServerStreaming  bool   // whether this call is server streaming
 	Timestamp          string // timestamp of the call in RFC3339 format
 	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
 }
 
@@ -41,6 +42,7 @@ func newCallTemplateData(mtd *desc.MethodDescriptor, workerID string, reqNum int
 		IsServerStreaming:  mtd.IsServerStreaming(),
 		Timestamp:          now.Format(time.RFC3339),
 		TimestampUnix:      now.Unix(),
+		TimestampUnixMilli: now.UnixNano() / 1000000,
 		TimestampUnixNano:  now.UnixNano(),
 	}
 }
diff --git a/www/docs/calldata.md b/www/docs/calldata.md
index 4cfc74d..71ec49e 100644
--- a/www/docs/calldata.md
+++ b/www/docs/calldata.md
@@ -42,6 +42,9 @@ type callTemplateData struct {
 	// timestamp of the call as unix time in seconds
 	TimestampUnix      int64
 
+	// timestamp of the call as unix time in milliseconds
+	TimestampUnixMilli      int64
+
 	// timestamp of the call as unix time in nanoseconds
 	TimestampUnixNano      int64
 }


Test patch:
diff --git a/runner/call_template_data_test.go b/runner/call_template_data_test.go
index 4e0fc3a..6afbe89 100644
--- a/runner/call_template_data_test.go
+++ b/runner/call_template_data_test.go
@@ -26,7 +26,9 @@ func TestCallTemplateData_New(t *testing.T) {
 	assert.Equal(t, false, ctd.IsServerStreaming)
 	assert.NotEmpty(t, ctd.Timestamp)
 	assert.NotZero(t, ctd.TimestampUnix)
+	assert.NotZero(t, ctd.TimestampUnixMilli)
 	assert.NotZero(t, ctd.TimestampUnixNano)
+	assert.Equal(t, ctd.TimestampUnix, ctd.TimestampUnixMilli/1000)
 }
 
 func TestCallTemplateData_ExecuteData(t *testing.T) {