Skip to content

Commit 8813863

Browse files
fix(lints): update files according to the latest linter rules
Signed-off-by: Dusan Malusev <[email protected]>
1 parent 624f176 commit 8813863

File tree

7 files changed

+77
-47
lines changed

7 files changed

+77
-47
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ linters:
7676
- pattern: ^print(ln)?$
7777
msg: "Use log package instead of fmt"
7878
gocyclo:
79-
min-complexity: 19
79+
min-complexity: 20
8080
govet:
8181
enable-all: true
8282
settings:

internal/version/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ func newGithubClient() *githubClient {
6868
}
6969

7070
// Performs an HTTP GET request and decodes the JSON response to the target
71-
func (g *githubClient) getJSON(path string, target interface{}) error {
71+
func (g *githubClient) getJSON(path string, target any) error {
7272
url := g.baseURL + path
73-
req, err := http.NewRequest("GET", url, nil)
73+
req, err := http.NewRequest(http.MethodGet, url, nil)
7474
if err != nil {
7575
return fmt.Errorf("failed to create request: %w", err)
7676
}

internal/version/version_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ func TestGetDriverVersionWithEnvVar(t *testing.T) {
176176
originalRepo := os.Getenv("GOCQL_REPO")
177177
originalVersion := os.Getenv("GOCQL_VERSION")
178178
defer func() {
179-
os.Setenv("GOCQL_REPO", originalRepo)
180-
os.Setenv("GOCQL_VERSION", originalVersion)
179+
t.Setenv("GOCQL_REPO", originalRepo)
180+
t.Setenv("GOCQL_VERSION", originalVersion)
181181
}()
182182

183-
os.Setenv("GOCQL_REPO", "github.com/testowner/gocql")
184-
os.Setenv("GOCQL_VERSION", "1234567890abcdef")
183+
t.Setenv("GOCQL_REPO", "github.com/testowner/gocql")
184+
t.Setenv("GOCQL_VERSION", "1234567890abcdef")
185185

186186
info := getDriverVersionInfo()
187187
if info.Version == "" {

main.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919

2020
"github.com/scylladb/scylla-bench/internal/version"
2121
"github.com/scylladb/scylla-bench/pkg/results"
22-
2322
//nolint:revive
2423
. "github.com/scylladb/scylla-bench/pkg/workloads"
2524
"github.com/scylladb/scylla-bench/random"
@@ -120,7 +119,10 @@ func Query(session *gocql.Session, request string) {
120119

121120
func PrepareDatabase(session *gocql.Session, replicationFactor int) {
122121
//nolint:lll
123-
Query(session, fmt.Sprintf("CREATE KEYSPACE IF NOT EXISTS %s WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'replication_factor' : %d }", keyspaceName, replicationFactor))
122+
Query(
123+
session,
124+
fmt.Sprintf("CREATE KEYSPACE IF NOT EXISTS %s WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'replication_factor' : %d }", keyspaceName, replicationFactor),
125+
)
124126

125127
switch mode {
126128
case "counter_update":
@@ -315,7 +317,12 @@ func main() {
315317
flag.BoolVar(&provideUpperBound, "provide-upper-bound", false, "whether read requests should provide an upper bound")
316318
flag.BoolVar(&inRestriction, "in-restriction", false, "use IN restriction in read requests")
317319
//nolint:lll
318-
flag.StringVar(&selectOrderBy, "select-order-by", "none", "controls order part 'order by ck asc/desc' of the read query, you can set it to: none,asc,desc or to the list of them, i.e. 'none,asc', in such case it will run queries with these orders one by one")
320+
flag.StringVar(
321+
&selectOrderBy,
322+
"select-order-by",
323+
"none",
324+
"controls order part 'order by ck asc/desc' of the read query, you can set it to: none,asc,desc or to the list of them, i.e. 'none,asc', in such case it will run queries with these orders one by one",
325+
)
319326
flag.BoolVar(&noLowerBound, "no-lower-bound", false, "do not provide lower bound in read requests")
320327
flag.BoolVar(&bypassCache, "bypass-cache", false, "Execute queries with the \"BYPASS CACHE\" CQL clause")
321328
flag.IntVar(&rangeCount, "range-count", 1, "number of ranges to split the token space into (relevant only for scan mode)")
@@ -357,7 +364,12 @@ func main() {
357364
flag.StringVar(&datacenter, "datacenter", "", "datacenter for the rack-aware policy")
358365
//nolint:lll
359366
flag.StringVar(&rack, "rack", "", "rack for the rack-aware policy")
360-
flag.IntVar(&maxErrorsAtRow, "error-at-row-limit", 0, "set limit of errors caught by one thread at row after which workflow will be terminated and error reported. Set it to 0 if you want to haven no limit")
367+
flag.IntVar(
368+
&maxErrorsAtRow,
369+
"error-at-row-limit",
370+
0,
371+
"set limit of errors caught by one thread at row after which workflow will be terminated and error reported. Set it to 0 if you want to haven no limit",
372+
)
361373
flag.IntVar(
362374
&maxErrors,
363375
"error-limit", 0,

modes.go

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"crypto/sha256"
66
"encoding/binary"
7+
stdErrors "errors"
78
"fmt"
89
"log"
910
"math"
@@ -17,13 +18,10 @@ import (
1718
"github.com/gocql/gocql"
1819
"github.com/pkg/errors"
1920

20-
stdErrors "errors"
21-
2221
"github.com/scylladb/scylla-bench/pkg/results"
23-
"github.com/scylladb/scylla-bench/random"
24-
2522
//nolint
2623
. "github.com/scylladb/scylla-bench/pkg/workloads"
24+
"github.com/scylladb/scylla-bench/random"
2725
)
2826

2927
var reportInterval = 1 * time.Second
@@ -157,7 +155,7 @@ func RunTest(
157155
threadResult *results.TestThreadResult,
158156
workload WorkloadGenerator,
159157
rateLimiter RateLimiter,
160-
test func(rb *results.TestThreadResult) (error, time.Duration),
158+
test func(rb *results.TestThreadResult) (time.Duration, error),
161159
) {
162160
start := time.Now()
163161
partialStart := start
@@ -171,7 +169,7 @@ func RunTest(
171169
expectedStartTime = time.Now()
172170
}
173171

174-
err, rawLatency := test(threadResult)
172+
rawLatency, err := test(threadResult)
175173
endTime := time.Now()
176174
switch {
177175
case err == nil:
@@ -381,7 +379,7 @@ func handleSbRetryError(queryStr string, err error, currentAttempts int) error {
381379
}
382380

383381
func DoWrites(session *gocql.Session, threadResult *results.TestThreadResult, workload WorkloadGenerator, rateLimiter RateLimiter, validateData bool) {
384-
RunTest(threadResult, workload, rateLimiter, func(rb *results.TestThreadResult) (error, time.Duration) {
382+
RunTest(threadResult, workload, rateLimiter, func(rb *results.TestThreadResult) (time.Duration, error) {
385383
request := fmt.Sprintf("INSERT INTO %s.%s (pk, ck, v) VALUES (?, ?, ?)", keyspaceName, tableName)
386384
query := session.Query(request)
387385
defer query.Release()
@@ -403,8 +401,7 @@ func DoWrites(session *gocql.Session, threadResult *results.TestThreadResult, wo
403401
if err == nil {
404402
rb.IncOps()
405403
rb.IncRows()
406-
latency := requestEnd.Sub(requestStart)
407-
return nil, latency
404+
return requestEnd.Sub(requestStart), nil
408405
}
409406
if retryHandler == "sb" {
410407
if queryStr == "" {
@@ -417,7 +414,7 @@ func DoWrites(session *gocql.Session, threadResult *results.TestThreadResult, wo
417414
err = handleSbRetryError(queryStr, err, currentAttempts)
418415
}
419416
if err != nil {
420-
return err, time.Duration(0)
417+
return time.Duration(0), err
421418
}
422419
currentAttempts++
423420
}
@@ -427,7 +424,7 @@ func DoWrites(session *gocql.Session, threadResult *results.TestThreadResult, wo
427424
func DoBatchedWrites(session *gocql.Session, threadResult *results.TestThreadResult, workload WorkloadGenerator, rateLimiter RateLimiter, validateData bool) {
428425
request := fmt.Sprintf("INSERT INTO %s.%s (pk, ck, v) VALUES (?, ?, ?)", keyspaceName, tableName)
429426

430-
RunTest(threadResult, workload, rateLimiter, func(rb *results.TestThreadResult) (error, time.Duration) {
427+
RunTest(threadResult, workload, rateLimiter, func(rb *results.TestThreadResult) (time.Duration, error) {
431428
batch := session.Batch(gocql.UnloggedBatch)
432429
batchSize := 0
433430

@@ -436,7 +433,7 @@ func DoBatchedWrites(session *gocql.Session, threadResult *results.TestThreadRes
436433
valuesSizesSummary := 0
437434
for !workload.IsPartitionDone() && batchSize < rowsPerRequest {
438435
if atomic.LoadUint32(&stopAll) != 0 {
439-
return errDoNotRegister, 0
436+
return time.Duration(0), errDoNotRegister
440437
}
441438
ck := workload.NextClusteringKey()
442439
if batchSize == 0 {
@@ -452,7 +449,7 @@ func DoBatchedWrites(session *gocql.Session, threadResult *results.TestThreadRes
452449
batch.Query(request, currentPk, ck, value)
453450
}
454451
if batchSize == 0 {
455-
return errDoNotRegister, 0
452+
return time.Duration(0), errDoNotRegister
456453
}
457454
endingCk := int(startingCk) + batchSize - 1
458455
avgValueSize := valuesSizesSummary / batchSize
@@ -467,8 +464,7 @@ func DoBatchedWrites(session *gocql.Session, threadResult *results.TestThreadRes
467464
if err == nil {
468465
rb.IncOps()
469466
rb.AddRows(batchSize)
470-
latency := requestEnd.Sub(requestStart)
471-
return nil, latency
467+
return requestEnd.Sub(requestStart), nil
472468
}
473469
if retryHandler == "sb" {
474470
if queryStr == "" {
@@ -479,15 +475,15 @@ func DoBatchedWrites(session *gocql.Session, threadResult *results.TestThreadRes
479475
err = handleSbRetryError(queryStr, err, currentAttempts)
480476
}
481477
if err != nil {
482-
return err, time.Duration(0)
478+
return time.Duration(0), err
483479
}
484480
currentAttempts++
485481
}
486482
})
487483
}
488484

489485
func DoCounterUpdates(session *gocql.Session, threadResult *results.TestThreadResult, workload WorkloadGenerator, rateLimiter RateLimiter, _ bool) {
490-
RunTest(threadResult, workload, rateLimiter, func(rb *results.TestThreadResult) (error, time.Duration) {
486+
RunTest(threadResult, workload, rateLimiter, func(rb *results.TestThreadResult) (time.Duration, error) {
491487
pk := workload.NextPartitionKey()
492488
ck := workload.NextClusteringKey()
493489

@@ -504,8 +500,7 @@ func DoCounterUpdates(session *gocql.Session, threadResult *results.TestThreadRe
504500
if err == nil {
505501
rb.IncOps()
506502
rb.IncRows()
507-
latency := requestEnd.Sub(requestStart)
508-
return nil, latency
503+
return requestEnd.Sub(requestStart), nil
509504
}
510505
if retryHandler == "sb" {
511506
if queryStr == "" {
@@ -514,7 +509,7 @@ func DoCounterUpdates(session *gocql.Session, threadResult *results.TestThreadRe
514509
err = handleSbRetryError(queryStr, err, currentAttempts)
515510
}
516511
if err != nil {
517-
return err, time.Duration(0)
512+
return time.Duration(0), err
518513
}
519514
currentAttempts++
520515
}
@@ -562,10 +557,17 @@ func BuildReadQuery(table, orderBy string, session *gocql.Session) *gocql.Query
562557
return session.Query(BuildReadQueryString(table, orderBy))
563558
}
564559

565-
//nolint:lll
566-
func DoReadsFromTable(table string, session *gocql.Session, threadResult *results.TestThreadResult, workload WorkloadGenerator, rateLimiter RateLimiter, validateData bool) {
560+
// nolint:gocyclo
561+
func DoReadsFromTable(
562+
table string,
563+
session *gocql.Session,
564+
threadResult *results.TestThreadResult,
565+
workload WorkloadGenerator,
566+
rateLimiter RateLimiter,
567+
validateData bool,
568+
) {
567569
counter, numOfOrderings := 0, len(selectOrderByParsed)
568-
RunTest(threadResult, workload, rateLimiter, func(rb *results.TestThreadResult) (error, time.Duration) {
570+
RunTest(threadResult, workload, rateLimiter, func(rb *results.TestThreadResult) (time.Duration, error) {
569571
counter++
570572
pk := workload.NextPartitionKey()
571573
query := BuildReadQuery(table, selectOrderByParsed[counter%numOfOrderings], session)
@@ -636,7 +638,7 @@ func DoReadsFromTable(table string, session *gocql.Session, threadResult *result
636638

637639
if err == nil {
638640
rb.IncOps()
639-
return nil, requestEnd.Sub(requestStart)
641+
return requestEnd.Sub(requestStart), nil
640642
}
641643
if retryHandler == "sb" {
642644
if queryStr == "" {
@@ -645,7 +647,7 @@ func DoReadsFromTable(table string, session *gocql.Session, threadResult *result
645647
err = handleSbRetryError(queryStr, err, currentAttempts)
646648
}
647649
if err != nil {
648-
return err, time.Duration(0)
650+
return time.Duration(0), err
649651
}
650652
currentAttempts++
651653
}
@@ -654,7 +656,7 @@ func DoReadsFromTable(table string, session *gocql.Session, threadResult *result
654656

655657
func DoScanTable(session *gocql.Session, threadResult *results.TestThreadResult, workload WorkloadGenerator, rateLimiter RateLimiter, _ bool) {
656658
request := fmt.Sprintf("SELECT * FROM %s.%s WHERE token(pk) >= ? AND token(pk) <= ?", keyspaceName, tableName)
657-
RunTest(threadResult, workload, rateLimiter, func(rb *results.TestThreadResult) (error, time.Duration) {
659+
RunTest(threadResult, workload, rateLimiter, func(rb *results.TestThreadResult) (time.Duration, error) {
658660
query := session.Query(request)
659661
currentRange := workload.NextTokenRange()
660662
currentAttempts := 0
@@ -671,8 +673,7 @@ func DoScanTable(session *gocql.Session, threadResult *results.TestThreadResult,
671673

672674
if err == nil {
673675
rb.IncOps()
674-
latency := requestEnd.Sub(requestStart)
675-
return nil, latency
676+
return requestEnd.Sub(requestStart), nil
676677
}
677678
if retryHandler == "sb" {
678679
if queryStr == "" {
@@ -681,7 +682,7 @@ func DoScanTable(session *gocql.Session, threadResult *results.TestThreadResult,
681682
err = handleSbRetryError(queryStr, err, currentAttempts)
682683
}
683684
if err != nil {
684-
return err, time.Duration(0)
685+
return time.Duration(0), err
685686
}
686687
currentAttempts++
687688
}

pkg/results/merged_result.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,23 @@ func (mr *MergedResult) PrintPartialResult() {
130130
if globalResultConfiguration.measureLatency {
131131
scale := globalResultConfiguration.hdrLatencyScale
132132
latencyHist := mr.getLatencyHistogram()
133-
fmt.Printf(withLatencyLineFmt, Round(mr.Time), mr.Operations, mr.ClusteringRows, mr.Errors,
134-
Round(time.Duration(latencyHist.Max()*scale)), Round(time.Duration(latencyHist.ValueAtQuantile(99.9)*scale)), Round(time.Duration(latencyHist.ValueAtQuantile(99)*scale)),
135-
Round(time.Duration(latencyHist.ValueAtQuantile(95)*scale)), Round(time.Duration(latencyHist.ValueAtQuantile(90)*scale)),
136-
Round(time.Duration(latencyHist.ValueAtQuantile(50)*scale)), Round(time.Duration(latencyHist.Mean()*float64(scale))),
137-
latencyError)
133+
fmt.Printf(
134+
withLatencyLineFmt,
135+
Round(mr.Time),
136+
mr.Operations,
137+
mr.ClusteringRows,
138+
mr.Errors,
139+
Round(
140+
time.Duration(latencyHist.Max()*scale),
141+
),
142+
Round(time.Duration(latencyHist.ValueAtQuantile(99.9)*scale)),
143+
Round(time.Duration(latencyHist.ValueAtQuantile(99)*scale)),
144+
Round(time.Duration(latencyHist.ValueAtQuantile(95)*scale)),
145+
Round(time.Duration(latencyHist.ValueAtQuantile(90)*scale)),
146+
Round(time.Duration(latencyHist.ValueAtQuantile(50)*scale)),
147+
Round(time.Duration(latencyHist.Mean()*float64(scale))),
148+
latencyError,
149+
)
138150
} else {
139151
fmt.Printf(withoutLatencyLineFmt, Round(mr.Time), mr.Operations, mr.ClusteringRows, mr.Errors)
140152
}

pkg/workloads/workloads.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ type RandomUniform struct {
9595

9696
func NewRandomUniform(i int, partitionCount, partitionOffset, clusteringRowCount int64) *RandomUniform {
9797
generator := rand.New(rand.NewSource(int64(time.Now().Nanosecond() * (i + 1))))
98-
return &RandomUniform{generator, int64(partitionCount), int64(partitionOffset), int64(clusteringRowCount)}
98+
return &RandomUniform{
99+
Generator: generator,
100+
PartitionCount: partitionCount,
101+
PartitionOffset: partitionOffset,
102+
ClusteringRowCount: clusteringRowCount,
103+
}
99104
}
100105

101106
func (ru *RandomUniform) NextTokenRange() TokenRange {
@@ -138,7 +143,7 @@ type TimeSeriesWrite struct {
138143
}
139144

140145
func NewTimeSeriesWriter(threadID, threadCount int, pkCount, basicPkOffset, ckCount int64, startTime time.Time, rate int64) *TimeSeriesWrite {
141-
period := time.Duration(int64(time.Second.Nanoseconds()) * (pkCount / int64(threadCount)) / rate)
146+
period := time.Duration(time.Second.Nanoseconds() * (pkCount / int64(threadCount)) / rate)
142147
pkStride := int64(threadCount)
143148
pkOffset := int64(threadID) + basicPkOffset
144149
return &TimeSeriesWrite{

0 commit comments

Comments
 (0)