Skip to content

Commit 0b30861

Browse files
[Backport 7.76.x] Replace custom golangci-lint build with depguard rule (#45680)
Backport e2fe6b7 from #45521. ___ ### What does this PR do? Migrate the custom `pkgconfigusage` plugin for `golangci-lint` to an equivalent `depguard` rule, eliminating the need for rebuilding `golangci-lint` from downloaded sources. Changes: - migration of `pkgconfigusage` itself, from a `golangci-lint` plugin (#28382, #39367) to a rule for the depguard (v2) plugin, while preserving its name for traceability, - move file exclusions to that rule configuration, while removing those that no longer exist or are no longer violating the rule: - `comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go`, - `comp/core/agenttelemetry/impl/config.go`, - `comp/core/config/config_mock.go`, - `comp/core/workloadfilter/def/utils.go`, - `comp/core/workloadmeta/collectors/internal/process/process_collector.go`, - `comp/core/workloadmeta/collectors/util/process_util_linux.go`, - `comp/dogstatsd/listeners/udp.go`, - `comp/remote-config/rcservice/rcserviceimpl/rcservice.go`, - `comp/remote-config/rcservicemrf/rcservicemrfimpl/rcservicemrf.go`, - conversely move locally inhibited `// nolint:pkgconfigusage` to file exclusions: - `comp/core/config/params.go`, - `comp/core/workloadfilter/baseimpl/filter_utils.go`, - `comp/core/workloadfilter/catalog/filter_config.go`, - ~update `pkgconfigusage_test` to validate the effectiveness of the rule configuration defined in `.golangci.yml`,~ - remove custom `golangci-lint` build infrastructure. ### Motivation This change kills several birds with one stone: 1. preparation step for the Go build migration to Bazel ([ABLD-317]): while looking for an isolated component with minimal dependencies to introduce the first Go toolchain as part of the ongoing Bazel migration, the custom `golangci-lint` build initially seemed to be a good candidate, but it turns out we can spare time by removing the said build at all, 2. standardization: the `golangci-lint` v2 upgrade (#43501) introduced `depguard` v2 support with file-based import restrictions using `glob` patterns, enabling the same architectural enforcement without a custom plugin, 3. reliability: the custom plugin build process obviously takes time and **occasionally failed in CI** and locally with: ``` Error: build process: clone golangci-lint: git clone --branch v2.7.0 --single-branch --depth 1 -c advice.detachedHead=false -q https://github.com/golangci/golangci-lint.git: exit status 128 ``` ([example CI log](https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/1369979128#L98)) [ABLD-317]: https://datadoghq.atlassian.net/browse/ABLD-317?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Co-authored-by: sabrina.lu <[email protected]>
1 parent bbd996d commit 0b30861

File tree

187 files changed

+132
-960
lines changed

Some content is hidden

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

187 files changed

+132
-960
lines changed

.custom-gcl.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

.github/CODEOWNERS

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
/.go-version @DataDog/agent-runtimes @DataDog/agent-build
2020
# Go linters and pre-commit config
2121
/.golangci.yml @DataDog/agent-devx
22-
/.custom-gcl.yml @DataDog/agent-devx
2322
/.pre-commit-config.yaml @DataDog/agent-devx
2423
/.vscode/ @DataDog/agent-devx
2524

@@ -589,9 +588,6 @@
589588
/pkg/util/testutil/docker @DataDog/universal-service-monitoring @DataDog/ebpf-platform
590589
/pkg/util/trie @DataDog/container-integrations
591590
/pkg/languagedetection @DataDog/container-experiences @DataDog/agent-discovery
592-
/pkg/linters/ @DataDog/agent-devx
593-
/pkg/linters/components/ @DataDog/agent-runtimes
594-
/pkg/linters/components/pkgconfigusage @DataDog/agent-configuration
595591
/pkg/logs/ @DataDog/agent-log-pipelines
596592
/pkg/logs/launchers/container @DataDog/agent-log-pipelines @DataDog/container-integrations
597593
/pkg/logs/tailers/container @DataDog/agent-log-pipelines @DataDog/container-integrations

.gitlab/.pre/deps_fetch/deps_fetch.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ go_deps:
5454
- $CI_PROJECT_DIR/modcache.tar.xz
5555
cache:
5656
# The `cache:key:files` only accepts up to two paths ([docs](https://docs.gitlab.com/ee/ci/yaml/#cachekeyfiles)).
57-
# Ideally, we should also include the https://github.com/DataDog/datadog-agent/blob/main/.custom-gcl.yml file to
58-
# avoid issues if a plugin is added in one PR and enabled in another. However, we decided to accept this limitation
59-
# because the probability for this to happen is very low and go mod files are modified frequently so the risk of
60-
# failing a job because of a network issue when building the custom binary is very low, but still exists.
6157
# We should also include the file this job is defined in to invalicate the cache when this job is modified.
6258
- key:
6359
files:

.golangci.yml

Lines changed: 125 additions & 376 deletions
Large diffs are not rendered by default.

comp/api/api/def/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ replace (
102102
github.com/DataDog/datadog-agent/pkg/fips => ../../../../pkg/fips
103103
github.com/DataDog/datadog-agent/pkg/fleet/installer => ../../../../pkg/fleet/installer
104104
github.com/DataDog/datadog-agent/pkg/gohai => ../../../../pkg/gohai
105-
github.com/DataDog/datadog-agent/pkg/linters/components/pkgconfigusage => ../../../../pkg/linters/components/pkgconfigusage
106105
github.com/DataDog/datadog-agent/pkg/logs/client => ../../../../pkg/logs/client
107106
github.com/DataDog/datadog-agent/pkg/logs/diagnostic => ../../../../pkg/logs/diagnostic
108107
github.com/DataDog/datadog-agent/pkg/logs/message => ../../../../pkg/logs/message

comp/core/agenttelemetry/def/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ replace (
112112
github.com/DataDog/datadog-agent/pkg/fips => ../../../../pkg/fips
113113
github.com/DataDog/datadog-agent/pkg/fleet/installer => ../../../../pkg/fleet/installer
114114
github.com/DataDog/datadog-agent/pkg/gohai => ../../../../pkg/gohai
115-
github.com/DataDog/datadog-agent/pkg/linters/components/pkgconfigusage => ../../../../pkg/linters/components/pkgconfigusage
116115
github.com/DataDog/datadog-agent/pkg/logs/client => ../../../../pkg/logs/client
117116
github.com/DataDog/datadog-agent/pkg/logs/diagnostic => ../../../../pkg/logs/diagnostic
118117
github.com/DataDog/datadog-agent/pkg/logs/message => ../../../../pkg/logs/message

comp/core/agenttelemetry/fx/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ replace (
199199
github.com/DataDog/datadog-agent/pkg/fips => ../../../../pkg/fips
200200
github.com/DataDog/datadog-agent/pkg/fleet/installer => ../../../../pkg/fleet/installer
201201
github.com/DataDog/datadog-agent/pkg/gohai => ../../../../pkg/gohai
202-
github.com/DataDog/datadog-agent/pkg/linters/components/pkgconfigusage => ../../../../pkg/linters/components/pkgconfigusage
203202
github.com/DataDog/datadog-agent/pkg/logs/client => ../../../../pkg/logs/client
204203
github.com/DataDog/datadog-agent/pkg/logs/diagnostic => ../../../../pkg/logs/diagnostic
205204
github.com/DataDog/datadog-agent/pkg/logs/message => ../../../../pkg/logs/message

comp/core/agenttelemetry/impl/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ replace (
203203
github.com/DataDog/datadog-agent/pkg/fips => ../../../../pkg/fips
204204
github.com/DataDog/datadog-agent/pkg/fleet/installer => ../../../../pkg/fleet/installer
205205
github.com/DataDog/datadog-agent/pkg/gohai => ../../../../pkg/gohai
206-
github.com/DataDog/datadog-agent/pkg/linters/components/pkgconfigusage => ../../../../pkg/linters/components/pkgconfigusage
207206
github.com/DataDog/datadog-agent/pkg/logs/client => ../../../../pkg/logs/client
208207
github.com/DataDog/datadog-agent/pkg/logs/diagnostic => ../../../../pkg/logs/diagnostic
209208
github.com/DataDog/datadog-agent/pkg/logs/message => ../../../../pkg/logs/message

comp/core/config/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ replace (
172172
github.com/DataDog/datadog-agent/pkg/fips => ../../../pkg/fips
173173
github.com/DataDog/datadog-agent/pkg/fleet/installer => ../../../pkg/fleet/installer
174174
github.com/DataDog/datadog-agent/pkg/gohai => ../../../pkg/gohai
175-
github.com/DataDog/datadog-agent/pkg/linters/components/pkgconfigusage => ../../../pkg/linters/components/pkgconfigusage
176175
github.com/DataDog/datadog-agent/pkg/logs/client => ../../../pkg/logs/client
177176
github.com/DataDog/datadog-agent/pkg/logs/diagnostic => ../../../pkg/logs/diagnostic
178177
github.com/DataDog/datadog-agent/pkg/logs/message => ../../../pkg/logs/message

comp/core/config/params.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
package config
77

88
import (
9-
"github.com/DataDog/datadog-agent/pkg/config/setup" // nolint:pkgconfigusage
9+
"github.com/DataDog/datadog-agent/pkg/config/setup"
1010
)
1111

1212
// Params defines the parameters for the config component.

0 commit comments

Comments
 (0)