Skip to content

Commit f4a0b59

Browse files
authored
fix: skip go finding output (#305)
* fix: ignore space * deploy: limit golangci-lint concurrency to avoid OOM * fix: ignore go finding output * deploy: limit golangci-lit
1 parent c6a9a2b commit f4a0b59

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

config/linters-config/.golangci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# 这是我们当前内部使用的配置文件,会基于实际的变化和我们的认知而迭代,仅供参考
22

3+
run:
4+
# control the resource usage of golangci-lint to avoid OOM
5+
concurrency: 4
6+
37
linters-settings:
48
paralleltest:
59
# Ignore missing calls to `t.Parallel()` and only report incorrect uses of it.

deploy/reviewbot.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ spec:
4545
imagePullPolicy: Always
4646
resources:
4747
requests:
48-
memory: "8Gi"
49-
cpu: "4"
48+
memory: "10Gi"
49+
cpu: "8"
5050
name: reviewbot
5151
ports:
5252
- containerPort: 8888

internal/linters/go/golangci_lint/golangci_lint.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func parser(log *xlog.Logger, output []byte) (map[string][]linters.LinterOutput,
102102
}
103103

104104
// skip the go download log
105-
if strings.Contains(ex, "go: downloading") {
105+
if strings.Contains(ex, "go: downloading") || strings.Contains(ex, "go: finding") {
106106
continue
107107
}
108108

@@ -134,11 +134,12 @@ func argsApply(log *xlog.Logger, a linters.Agent) linters.Agent {
134134
newArgs := []string{"run"}
135135

136136
var (
137-
timeoutFlag bool
138-
parallelFlag bool
139-
outFormatFlag bool
140-
printFlag bool
141-
configFlag bool
137+
timeoutFlag bool
138+
parallelFlag bool
139+
outFormatFlag bool
140+
printFlag bool
141+
configFlag bool
142+
concurrencyFlag bool
142143
)
143144

144145
for _, arg := range legacyArgs {
@@ -154,13 +155,15 @@ func argsApply(log *xlog.Logger, a linters.Agent) linters.Agent {
154155
printFlag = true
155156
case strings.HasPrefix(arg, "--config"):
156157
configFlag = true
158+
case strings.HasPrefix(arg, "--concurrency"):
159+
concurrencyFlag = true
157160
}
158161

159162
newArgs = append(newArgs, arg)
160163
}
161164

162165
if !timeoutFlag {
163-
newArgs = append(newArgs, "--timeout=5m0s")
166+
newArgs = append(newArgs, "--timeout=15m0s")
164167
}
165168
if !parallelFlag {
166169
newArgs = append(newArgs, "--allow-parallel-runners=true")
@@ -171,6 +174,9 @@ func argsApply(log *xlog.Logger, a linters.Agent) linters.Agent {
171174
if !printFlag {
172175
newArgs = append(newArgs, "--print-issued-lines=false")
173176
}
177+
if !concurrencyFlag {
178+
newArgs = append(newArgs, "--concurrency=8")
179+
}
174180
if !configFlag && config.ConfigPath != "" {
175181
config.ConfigPath = configApply(log, a)
176182
newArgs = append(newArgs, "--config", config.ConfigPath)

internal/linters/go/golangci_lint/golangci_lint_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func TestArgs(t *testing.T) {
118118
LinterConfig: config.Linter{
119119
Enable: &tp,
120120
Command: []string{"golangci-lint"},
121-
Args: []string{"run", "--timeout=5m0s", "--allow-parallel-runners=true", "--out-format=line-number", "--print-issued-lines=false"},
121+
Args: []string{"run", "--timeout=15m0s", "--allow-parallel-runners=true", "--out-format=line-number", "--print-issued-lines=false", "--concurrency=8"},
122122
},
123123
},
124124
},
@@ -135,7 +135,7 @@ func TestArgs(t *testing.T) {
135135
LinterConfig: config.Linter{
136136
Enable: &tp,
137137
Command: []string{"golangci-lint"},
138-
Args: []string{"run", "--timeout=10m", "--out-format=tab", "--config", "golangci-lint.yml", "--allow-parallel-runners=true", "--print-issued-lines=false"},
138+
Args: []string{"run", "--timeout=10m", "--out-format=tab", "--config", "golangci-lint.yml", "--allow-parallel-runners=true", "--print-issued-lines=false", "--concurrency=8"},
139139
},
140140
},
141141
},
@@ -198,7 +198,7 @@ func TestArgs(t *testing.T) {
198198
LinterConfig: config.Linter{
199199
Enable: &tp,
200200
Command: []string{"golangci-lint"},
201-
Args: []string{"run", "--timeout=5m0s", "--allow-parallel-runners=true", "--out-format=line-number", "--print-issued-lines=false", "--config", "config/golangci-lint.yml"},
201+
Args: []string{"run", "--timeout=15m0s", "--allow-parallel-runners=true", "--out-format=line-number", "--print-issued-lines=false", "--concurrency=8", "--config", "config/golangci-lint.yml"},
202202
ConfigPath: "config/golangci-lint.yml",
203203
},
204204
},

internal/linters/linters.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,11 @@ func GeneralHandler(log *xlog.Logger, a Agent, execRun func(a Agent) ([]byte, er
149149
lintResults, unexpected := linterParser(log, output)
150150
if len(unexpected) > 0 {
151151
msg := lintersutil.LimitJoin(unexpected, 1000)
152-
// just log the unexpected lines and notify the webhook, no need to return error
153-
log.Warnf("unexpected lines: %v", msg)
154-
metric.NotifyWebhookByText(ConstructUnknownMsg(linterName, a.PullRequestEvent.Repo.GetFullName(), a.PullRequestEvent.PullRequest.GetHTMLURL(), log.ReqId, msg))
152+
if msg != "" {
153+
// just log the unexpected lines and notify the webhook, no need to return error
154+
log.Warnf("unexpected lines: %v", msg)
155+
metric.NotifyWebhookByText(ConstructUnknownMsg(linterName, a.PullRequestEvent.Repo.GetFullName(), a.PullRequestEvent.PullRequest.GetHTMLURL(), log.ReqId, msg))
156+
}
155157
}
156158

157159
return Report(log, a, lintResults)

0 commit comments

Comments
 (0)