Skip to content

Commit f032abc

Browse files
authored
chore: qol improvements (#98)
1 parent 4b9d220 commit f032abc

File tree

7 files changed

+50
-32
lines changed

7 files changed

+50
-32
lines changed

.golangci.yml

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,48 @@
1-
linters-settings:
2-
lll:
3-
line-length: 140
4-
funlen:
5-
lines: 70
6-
1+
version: "2"
72
linters:
8-
disable-all: true
3+
default: none
94
enable:
105
- bodyclose
11-
- errcheck
126
- dupl
7+
- errcheck
138
- exhaustive
149
- funlen
1510
- goconst
1611
- gocritic
1712
- gocyclo
18-
- gosimple
1913
- govet
20-
- gosec
2114
- ineffassign
2215
- lll
2316
- misspell
2417
- nakedret
25-
- gofumpt
18+
- prealloc
2619
- staticcheck
27-
- stylecheck
28-
- typecheck
2920
- unconvert
3021
- unparam
3122
- unused
3223
- whitespace
33-
- prealloc
34-
35-
service:
36-
golangci-lint-version: 1.55.2 # use the fixed version to not introduce new linters unexpectedly
37-
prepare:
38-
- echo "here I can run custom commands, but no preparation needed for this repo"
24+
settings:
25+
funlen:
26+
lines: 70
27+
lll:
28+
line-length: 140
29+
exclusions:
30+
generated: lax
31+
presets:
32+
- comments
33+
- common-false-positives
34+
- legacy
35+
- std-error-handling
36+
paths:
37+
- third_party$
38+
- builtin$
39+
- examples$
40+
formatters:
41+
enable:
42+
- gofumpt
43+
exclusions:
44+
generated: lax
45+
paths:
46+
- third_party$
47+
- builtin$
48+
- examples$

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
default: run
44

55
init:
6-
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2
7-
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@v0.15.0
6+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.3.0
7+
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@v0.35.0
88

99
clean:
1010
rm -rf ./build

connector.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ func newConnector(cf any, mapper Mapper, sinkResponseHandler dcpElasticsearch.Si
197197

198198
connector.dcp.SetEventHandler(
199199
&DcpEventHandler{
200-
bulk: connector.bulk,
200+
isFinite: dcpConfig.IsDcpModeFinite(),
201+
bulk: connector.bulk,
201202
})
202203

203204
metricCollector := metric.NewMetricCollector(connector.bulk)

couchbase/event.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package couchbase
22

33
import (
4-
"github.com/Trendyol/go-dcp/tracing"
54
"time"
65

6+
"github.com/Trendyol/go-dcp/tracing"
7+
78
"github.com/elastic/go-elasticsearch/v7"
89
)
910

dcp_event_handler.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import (
55
)
66

77
type DcpEventHandler struct {
8-
bulk *bulk.Bulk
8+
bulk *bulk.Bulk
9+
isFinite bool
910
}
1011

1112
func (h *DcpEventHandler) BeforeRebalanceStart() {
@@ -28,6 +29,9 @@ func (h *DcpEventHandler) AfterStreamStart() {
2829
}
2930

3031
func (h *DcpEventHandler) BeforeStreamStop() {
32+
if h.isFinite {
33+
return
34+
}
3135
h.bulk.PrepareStartRebalancing()
3236
}
3337

elasticsearch/bulk/bulk.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ func joinErrors(body map[string]any) (map[string]string, error) {
425425
}
426426
}
427427
}
428-
return ivd, fmt.Errorf(sb.String())
428+
return ivd, fmt.Errorf("%s", sb.String())
429429
}
430430

431431
func (b *Bulk) getIndexName(collectionName, actionIndexName string) string {
@@ -471,7 +471,7 @@ func (b *Bulk) finalizeProcess(batchActions []*document.ESActionDocument, errorD
471471
if b.sinkResponseHandler != nil {
472472
b.sinkResponseHandler.OnError(&dcpElasticsearch.SinkResponseHandlerContext{
473473
Action: action,
474-
Err: fmt.Errorf(errorData[key]),
474+
Err: fmt.Errorf("%s", errorData[key]),
475475
})
476476
}
477477
} else {
@@ -489,9 +489,10 @@ func (b *Bulk) countError(action *document.ESActionDocument) {
489489
b.LockMetrics()
490490
defer b.UnlockMetrics()
491491

492-
if action.Type == document.Index || action.Type == document.DocUpdate || action.Type == document.ScriptUpdate {
492+
switch action.Type {
493+
case document.Index, document.DocUpdate, document.ScriptUpdate:
493494
b.metric.IndexingErrorActionCounter[action.IndexName]++
494-
} else if action.Type == document.Delete {
495+
case document.Delete:
495496
b.metric.DeletionErrorActionCounter[action.IndexName]++
496497
}
497498
}
@@ -500,9 +501,10 @@ func (b *Bulk) countSuccess(action *document.ESActionDocument) {
500501
b.LockMetrics()
501502
defer b.UnlockMetrics()
502503

503-
if action.Type == document.Index || action.Type == document.DocUpdate || action.Type == document.ScriptUpdate {
504+
switch action.Type {
505+
case document.Index, document.DocUpdate, document.ScriptUpdate:
504506
b.metric.IndexingSuccessActionCounter[action.IndexName]++
505-
} else if action.Type == document.Delete {
507+
case document.Delete:
506508
b.metric.DeletionSuccessActionCounter[action.IndexName]++
507509
}
508510
}

elasticsearch/client/fasthttp_transport.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ func (t *transport) copyRequest(dst *fasthttp.Request, src *http.Request) *fasth
8181
func (t *transport) copyResponse(dst *http.Response, src *fasthttp.Response) *http.Response {
8282
dst.StatusCode = src.StatusCode()
8383

84-
src.Header.VisitAll(func(k, v []byte) {
84+
for k, v := range src.Header.All() {
8585
dst.Header.Set(string(k), string(v))
86-
})
86+
}
8787

8888
// Cast to a string to make a copy seeing as src.Body() won't
8989
// be valid after the response is released back to the pool (fasthttp.ReleaseResponse).

0 commit comments

Comments
 (0)