Skip to content

Commit fb3deab

Browse files
committed
adding lint comments
1 parent 486e673 commit fb3deab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+191
-236
lines changed

.golangci.yml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ linters:
3939
- nilnil
4040
- nlreturn
4141
- noctx
42-
# - nolintlint
42+
- nolintlint
4343
- nosprintfhostport
4444
- perfsprint
4545
- prealloc
@@ -66,7 +66,7 @@ linters:
6666
- zerologlint
6767
settings:
6868
cyclop:
69-
max-complexity: 10
69+
max-complexity: 12
7070
package-average: 0
7171
errorlint:
7272
errorf: true
@@ -217,19 +217,19 @@ linters:
217217
- chan
218218
nlreturn:
219219
block-size: 2
220-
# nolintlint:
221-
# # Disable to ensure that all nolint directives actually have an effect.
222-
# # Default: false
223-
# allow-unused: true
224-
# # Exclude following linters from requiring an explanation.
225-
# # Default: []
226-
# allow-no-explanation: [ ]
227-
# # Enable to require an explanation of nonzero length after each nolint directive.
228-
# # Default: false
229-
# require-explanation: true
230-
# # Enable to require nolint directives to mention the specific linter being suppressed.
231-
# # Default: false
232-
# require-specific: true
220+
nolintlint:
221+
# Disable to ensure that all nolint directives actually have an effect.
222+
# Default: false
223+
allow-unused: true
224+
# Exclude following linters from requiring an explanation.
225+
# Default: []
226+
allow-no-explanation: [ ]
227+
# Enable to require an explanation of nonzero length after each nolint directive.
228+
# Default: false
229+
require-explanation: true
230+
# Enable to require nolint directives to mention the specific linter being suppressed.
231+
# Default: false
232+
require-specific: true
233233
prealloc:
234234
simple: true
235235
range-loops: true
@@ -286,7 +286,7 @@ linters:
286286
disabled: false
287287
- name: cognitive-complexity
288288
arguments:
289-
- 10
289+
- 12
290290
severity: warning
291291
disabled: false
292292
- name: comment-spacings
@@ -311,7 +311,7 @@ linters:
311311
disabled: false
312312
- name: cyclomatic
313313
arguments:
314-
- 10
314+
- 12
315315
severity: warning
316316
disabled: false
317317
- name: datarace

api/grpc/mpi/v1/command.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/mpi/v1/common.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/mpi/v1/files.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/backoff/backoff.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ func WaitUntil(
6565

6666
// WaitUntilWithData Implementation of backoff operations that increases the back off period for each retry
6767
// attempt using a randomization function that grows exponentially. This does not allow for parameters.
68-
// nolint: ireturn
68+
//
69+
//nolint:ireturn // must return an interface
6970
func WaitUntilWithData[T any](
7071
ctx context.Context,
7172
backoffSettings *config.BackOff,
@@ -76,7 +77,7 @@ func WaitUntilWithData[T any](
7677
return backoff.RetryWithData(operation, backoffWithContext)
7778
}
7879

79-
// nolint: ireturn
80+
//nolint:ireturn // must return an interface
8081
func Context(ctx context.Context, backoffSettings *config.BackOff) backoff.BackOffContext {
8182
eb := backoff.NewExponentialBackOff()
8283
eb.InitialInterval = backoffSettings.InitialInterval

internal/collector/containermetricsreceiver/factory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/nginx/agent/v3/internal/collector/containermetricsreceiver/internal/metadata"
2222
)
2323

24-
// nolint: ireturn
24+
//nolint:ireturn // must return metrics interface
2525
func NewFactory() receiver.Factory {
2626
return receiver.NewFactory(
2727
metadata.Type,
@@ -33,7 +33,7 @@ func NewFactory() receiver.Factory {
3333
)
3434
}
3535

36-
// nolint: ireturn
36+
//nolint:ireturn // must return metrics interface
3737
func createMetricsReceiver(
3838
_ context.Context,
3939
params receiver.Settings,

internal/collector/containermetricsreceiver/internal/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type Config struct {
1414
scraperhelper.ControllerConfig `mapstructure:",squash"`
1515
}
1616

17-
// nolint: ireturn
17+
//nolint:ireturn // must return a default metrics controller interface
1818
func CreateDefaultConfig() component.Config {
1919
cfg := scraperhelper.NewDefaultControllerConfig()
2020
return &Config{

internal/collector/containermetricsreceiver/internal/scraper/cpuscraper/factory.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import (
1515
"go.opentelemetry.io/collector/scraper"
1616
)
1717

18-
// NewFactory for CPU scraper.
19-
// nolint: ireturn
18+
//nolint:ireturn // must return a CPU scraper interface.
2019
func NewFactory() scraper.Factory {
2120
return scraper.NewFactory(
2221
metadata.Type,
@@ -25,16 +24,14 @@ func NewFactory() scraper.Factory {
2524
)
2625
}
2726

28-
// createDefaultConfig creates the default configuration for the Scraper.
29-
// nolint: ireturn
27+
//nolint:ireturn // must create the default configuration for the Scraper.
3028
func createDefaultConfig() component.Config {
3129
return &Config{
3230
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
3331
}
3432
}
3533

36-
// createMetricsScraper creates a scraper based on provided config.
37-
// nolint: ireturn
34+
//nolint:ireturn // must create and return a scraper based on provided config.
3835
func createMetricsScraper(
3936
ctx context.Context,
4037
settings scraper.Settings,

internal/collector/containermetricsreceiver/internal/scraper/cpuscraper/internal/cgroup/cpu.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ func (cs *CPUSource) Collect() (ContainerCPUStats, error) {
7272
return cpuStats, nil
7373
}
7474

75-
// nolint: mnd
7675
func (cs *CPUSource) collectCPUStats() (ContainerCPUStats, error) {
7776
clockTicks, err := clockTicks()
77+
const nanosecondsPerMillisecond = 1000
7878
if err != nil {
7979
return ContainerCPUStats{}, err
8080
}
@@ -84,7 +84,7 @@ func (cs *CPUSource) collectCPUStats() (ContainerCPUStats, error) {
8484
userKey := V2UserKey
8585
sysKey := V2SystemKey
8686
convertUsage := func(usage float64) float64 {
87-
return usage * 1000
87+
return usage * nanosecondsPerMillisecond
8888
}
8989

9090
if !cs.isCgroupV2 { // cgroup v1
@@ -161,7 +161,7 @@ func (cs *CPUSource) cpuUsageTimes(filePath, userKey, systemKey string) (*Contai
161161
return cpuTimes, nil
162162
}
163163

164-
// nolint: revive, gocritic
164+
//nolint:revive // cognitive complexity is 14
165165
func systemCPUUsage(clockTicks int) (float64, error) {
166166
lines, err := internal.ReadLines(CPUStatsPath)
167167
if err != nil {
@@ -170,8 +170,7 @@ func systemCPUUsage(clockTicks int) (float64, error) {
170170

171171
for _, line := range lines {
172172
parts := strings.Fields(line)
173-
switch parts[0] {
174-
case "cpu":
173+
if parts[0] == "cpu" {
175174
if len(parts) < CPUStatsFileLineLength {
176175
return 0, errors.New("unable to process " + CPUStatsPath + ". Invalid number of fields for cpu line")
177176
}

internal/collector/containermetricsreceiver/internal/scraper/memoryscraper/factory.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import (
1616
)
1717

1818
// NewFactory for CPU scraper.
19-
// nolint: ireturn
19+
//
20+
//nolint:ireturn // must return a CPU scraper
2021
func NewFactory() scraper.Factory {
2122
return scraper.NewFactory(
2223
metadata.Type,
@@ -26,15 +27,17 @@ func NewFactory() scraper.Factory {
2627
}
2728

2829
// createDefaultConfig creates the default configuration for the Scraper.
29-
// nolint: ireturn
30+
//
31+
//nolint:ireturn // must return a default configuration for scraper
3032
func createDefaultConfig() component.Config {
3133
return &Config{
3234
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
3335
}
3436
}
3537

3638
// createMetricsScraper creates a scraper based on provided config.
37-
// nolint: ireturn
39+
//
40+
//nolint:ireturn // must return a metric scraper interface
3841
func createMetricsScraper(
3942
ctx context.Context,
4043
settings scraper.Settings,

0 commit comments

Comments
 (0)