From 0739e29a1ac88fdb1d6b825319c560c3a920b0ce Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Sun, 14 Feb 2021 17:55:04 +0000 Subject: [PATCH] [add] Included RedisGraphVersion in DBSpecificConfigs json property --- go.mod | 2 ++ redisgraph-bechmark-go.go | 51 ++++++++++++++++++++++++++++++++++++--- test_result.go | 2 +- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 1e7cb66..64dbd17 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,9 @@ require ( github.com/RedisGraph/redisgraph-go v1.0.1-0.20210122150500-aa0feaa960ce github.com/gomodule/redigo v2.0.0+incompatible github.com/google/go-cmp v0.5.4 // indirect + github.com/mitchellh/gox v1.0.1 // indirect github.com/olekukonko/tablewriter v0.0.4 github.com/stretchr/testify v1.7.0 // indirect + github.com/tcnksm/ghr v0.13.0 // indirect golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 ) diff --git a/redisgraph-bechmark-go.go b/redisgraph-bechmark-go.go index 55a4a84..fe8faa5 100644 --- a/redisgraph-bechmark-go.go +++ b/redisgraph-bechmark-go.go @@ -37,8 +37,8 @@ func main() { if len(benchmarkQueries) < 1 { log.Fatalf("You need to specify at least a query with the -query parameter. For example: -query=\"CREATE (n)\"") } - fmt.Printf("Debug level: %d.\n", *debug) - fmt.Printf("Using random seed: %d.\n", *randomSeed) + log.Printf("Debug level: %d.\n", *debug) + log.Printf("Using random seed: %d.\n", *randomSeed) rand.Seed(*randomSeed) testResult := NewTestResult("", uint(*clients), *numberRequests, uint64(*rps), "") testResult.SetUsedRandomSeed(*randomSeed) @@ -60,9 +60,9 @@ func main() { // a WaitGroup for the goroutines to tell us they've stopped wg := sync.WaitGroup{} if !*loop { - fmt.Printf("Total clients: %d. Commands per client: %d Total commands: %d\n", *clients, samplesPerClient, *numberRequests) + log.Printf("Total clients: %d. Commands per client: %d Total commands: %d\n", *clients, samplesPerClient, *numberRequests) } else { - fmt.Printf("Running in loop until you hit Ctrl+C\n") + log.Printf("Running in loop until you hit Ctrl+C\n") } queries := make([]string, len(benchmarkQueries)) cmdRates := make([]float64, len(benchmarkQueries)) @@ -84,6 +84,16 @@ func main() { c1 := make(chan os.Signal, 1) signal.Notify(c1, os.Interrupt) + graphC, _ := getStandaloneConn(*graphKey, "tcp", connectionStr, *password) + log.Printf("Trying to extract RedisGraph version info\n") + + redisgraphVersion, err := getRedisGraphVersion(graphC) + if err != nil { + log.Println(fmt.Sprintf("Unable to retrieve RedisGraph version. Continuing anayway. Error: %v\n", err)) + } else { + log.Println(fmt.Sprintf("Detected RedisGraph version %d\n", redisgraphVersion)) + } + tick := time.NewTicker(time.Duration(client_update_tick) * time.Second) dataPointProcessingWg.Add(1) @@ -116,6 +126,7 @@ func main() { testResult.OverallGraphInternalLatencies = GetOverallLatencies(queries, serverSide_PerQuery_GraphInternalTime_OverallLatencies, serverSide_AllQueries_GraphInternalTime_OverallLatencies) testResult.OverallClientLatencies = GetOverallLatencies(queries, clientSide_PerQuery_OverallLatencies, clientSide_AllQueries_OverallLatencies) testResult.OverallQueryRates = GetOverallRatesMap(duration, queries, clientSide_PerQuery_OverallLatencies, clientSide_AllQueries_OverallLatencies) + testResult.DBSpecificConfigs = GetDBConfigsMap(redisgraphVersion) testResult.Totals = GetTotalsMap(queries, clientSide_PerQuery_OverallLatencies, clientSide_AllQueries_OverallLatencies, errorsPerQuery, totalNodesCreatedPerQuery, totalNodesDeletedPerQuery, totalLabelsAddedPerQuery, totalPropertiesSetPerQuery, totalRelationshipsCreatedPerQuery, totalRelationshipsDeletedPerQuery) // final merge of pending stats @@ -125,3 +136,35 @@ func main() { saveJsonResult(testResult, jsonOutputFile) } } + +func GetDBConfigsMap(version int64) map[string]interface{} { + dbConfigsMap := map[string]interface{}{} + dbConfigsMap["RedisGraphVersion"] = version + return dbConfigsMap +} + +// getRedisGraphVersion returns RedisGraph version by issuing "MODULE LIST" command +// and iterating through the availabe modules up until "graph" is found as the name property +func getRedisGraphVersion(graphClient redisgraph.Graph) (version int64, err error) { + var values []interface{} + var moduleInfo []interface{} + var moduleName string + values, err = redis.Values(graphClient.Conn.Do("MODULE", "LIST")) + if err != nil { + return + } + for _, rawModule := range values { + moduleInfo, err = redis.Values(rawModule, err) + if err != nil { + return + } + moduleName, err = redis.String(moduleInfo[1], err) + if err != nil { + return + } + if moduleName == "graph" { + version, err = redis.Int64(moduleInfo[3], err) + } + } + return +} diff --git a/test_result.go b/test_result.go index 3cd5d78..15f69a6 100644 --- a/test_result.go +++ b/test_result.go @@ -153,7 +153,7 @@ func saveJsonResult(testResult *TestResult, jsonOutputFile *string) { if err != nil { log.Fatal(err) } - fmt.Printf("Saving JSON results file to %s\n", *jsonOutputFile) + log.Printf("Saving JSON results file to %s\n", *jsonOutputFile) err = ioutil.WriteFile(*jsonOutputFile, file, 0644) if err != nil { log.Fatal(err)