Skip to content

Commit efbb0bc

Browse files
committed
Merge branch 'main' into collector-tokenpath
2 parents 3f7c081 + b9b8428 commit efbb0bc

File tree

79 files changed

+221
-5496
lines changed

Some content is hidden

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

79 files changed

+221
-5496
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ on:
1515
- reopened
1616
- synchronize
1717

18+
permissions:
19+
contents: read
20+
1821
env:
1922
NFPM_VERSION: 'v2.35.3'
2023

.github/workflows/codeql.yml

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -55,57 +55,9 @@ jobs:
5555
permissions:
5656
actions: read # for github/codeql-action/init to get workflow details
5757
contents: read # for actions/checkout to fetch code
58+
packages: read
5859
security-events: write # for github/codeql-action/autobuild to send a status report
5960
name: Analyze
60-
runs-on: ubuntu-24.04
61-
62-
strategy:
63-
fail-fast: false
64-
matrix:
65-
language: ["go"]
66-
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
67-
# Use only 'java' to analyze code written in Java, Kotlin or both
68-
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
69-
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
70-
71-
steps:
72-
- name: Checkout repository
73-
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
74-
75-
# Initializes the CodeQL tools for scanning.
76-
- name: Initialize CodeQL
77-
uses: github/codeql-action/init@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3
78-
with:
79-
languages: ${{ matrix.language }}
80-
# If you wish to specify custom queries, you can do so here or in a config file.
81-
# By default, queries listed here will override any specified in a config file.
82-
# Prefix the list here with "+" to use these queries and those in the config file.
83-
84-
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
85-
# queries: security-extended,security-and-quality
86-
87-
- name: Setup Golang Environment
88-
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
89-
with:
90-
go-version-file: go.mod
91-
if: matrix.language == 'go'
92-
93-
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
94-
# If this step fails, then you should remove it and run the build manually (see below)
95-
- name: Autobuild
96-
uses: github/codeql-action/autobuild@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3
97-
98-
# ℹ️ Command-line programs to run using the OS shell.
99-
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
100-
101-
# If the Autobuild fails above, remove it and uncomment the following three lines.
102-
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
103-
104-
# - run: |
105-
# echo "Run, Build Application using script"
106-
# ./location_of_script_within_repo/buildscript.sh
107-
108-
- name: Perform CodeQL Analysis
109-
uses: github/codeql-action/analyze@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3
110-
with:
111-
category: "/language:${{matrix.language}}"
61+
uses: nginxinc/compliance-rules/.github/workflows/codeql.yml@c903bfe6c668eaba362cde6a7882278bc1564401 # v0.1
62+
with:
63+
requested_languages: go

.github/workflows/label-pr.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
pull_request_target:
55
types: [opened, reopened, synchronize]
66

7+
permissions:
8+
contents: read
9+
710
jobs:
811
label-pr:
912
permissions:

.github/workflows/release-branch.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
runs-on: ubuntu-22.04
8787
needs: [vars]
8888
permissions:
89-
contents: write
89+
contents: write # Needed to create draft release
9090
outputs:
9191
release_id: ${{ steps.vars.outputs.RELEASE_ID }}
9292
steps:
@@ -210,7 +210,7 @@ jobs:
210210
needs: [vars,release-draft,tag-release]
211211
permissions:
212212
id-token: write
213-
contents: write
213+
contents: write # Needed to update a github release
214214
steps:
215215
- name: Checkout Repository
216216
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2

.golangci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ linters-settings:
7777
field-writes-are-uses: true
7878
# Treat IncDec statement (e.g. `i++` or `i--`) as both read and write operation instead of just wr◊ite. Default: false
7979
post-statements-are-reads: true
80-
# Mark all exported identifiers as used. Default: true
81-
exported-is-used: true
8280
# Mark all exported fields as used. Default: true
8381
exported-fields-are-used: false
8482
# Mark all function parameters as used. Default: true
@@ -770,7 +768,7 @@ linters-settings:
770768
# Enforce using attributes only (overrides no-mixed-args, incompatible with kv-only). Default: false
771769
attr-only: false
772770
# Enforce using methods that accept a context. Default: false
773-
context-only: false
771+
context: ""
774772
# Enforce using static values for log messages. Default: false
775773
static-msg: false
776774
# Enforce using constants instead of raw keys. Default: false

Makefile.tools

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
OAPICODEGEN = github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@v2.1.0
22
LEFTHOOK = github.com/evilmartians/lefthook@v1.6.9
3-
GOLANGCILINT = github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0
3+
GOLANGCILINT = github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.8
44
PROTOCGENGO = google.golang.org/protobuf/cmd/protoc-gen-go@v1.32.0
55
GOFUMPT = mvdan.cc/gofumpt@v0.6.0
66
COUNTERFEITER = github.com/maxbrunsfeld/counterfeiter/v6@v6.8.1

README.md

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ NGINX Agent is a companion daemon for your NGINX Open Source or NGINX Plus insta
1313
- Notifications of NGINX events
1414

1515
## Development Environment Setup
16+
1617
### Installing Prerequisite Packages
18+
1719
The following packages need to be installed:
18-
- make
19-
- golang (https://go.dev/doc/install)
20-
- protoc (https://grpc.io/docs/protoc-installation/)
21-
- mdatagen (There is currently an issue installing mdatagen https://github.com/open-telemetry/opentelemetry-collector/issues/9281. See instructions below for workaround.)
20+
21+
- make
22+
- golang (<https://go.dev/doc/install>)
23+
- protoc (<https://grpc.io/docs/protoc-installation/>)
24+
- mdatagen (There is currently an [issue installing mdatagen](https://github.com/open-telemetry/opentelemetry-collector/issues/9281). See instructions below for workaround.)
2225

2326
#### Workaround to install mdatagen
24-
```
27+
28+
```console
2529
git clone https://github.com/open-telemetry/opentelemetry-collector.git
2630
cd opentelemetry-collector
2731
git checkout v0.124.0
@@ -30,47 +34,60 @@ go install
3034
```
3135

3236
Before starting development on the NGINX Agent, it is important to download and install the necessary tool and dependencies required by the NGINX Agent. You can do this by running the following `make` command:
33-
```
37+
38+
```console
3439
make install-tools
3540
```
3641

3742
### Building NGINX Agent from Source Code
43+
3844
Build NGINX Agent deb package:
39-
```
45+
46+
```console
4047
OSARCH=<operating system archiecture> make local-deb-package
4148
```
49+
4250
Build NGINX Agent rpm package:
43-
```
51+
52+
```console
4453
OSARCH=<operating system archiecture> make local-rpm-package
4554
```
55+
4656
Build NGINX Agent apk package:
47-
```
57+
58+
```console
4859
OSARCH=<operating system archiecture> make local-apk-package
4960
```
5061

5162
### Testing NGINX Agent
5263

5364
#### Unit tests
65+
5466
To run unit tests and check that there is enough test coverage run the following
55-
```
67+
68+
```console
5669
make unit-test coverge
5770
```
71+
5872
To check for race conditions, the unit tests can also be run with a race condition detector
59-
```
73+
74+
```console
6075
make race-condition-test
6176
```
6277

6378
#### Integration tests
79+
6480
To run integration tests, run the following
65-
```
81+
82+
```console
6683
make integration-test
6784
```
6885

6986
#### Testing with a mock management plane
87+
7088
For testing command operations, there is a mock management gRPC server that can be used. See here: [mock management gRPC server](test/mock/grpc/README.md) \
7189
For testing metrics, there is a mock management OTel collector that can be used. See here: [mock management OTel collector](test/mock/collector/README.md)
7290

73-
7491
## NGINX Agent Technical Specifications
7592

7693
### Supported Distributions
@@ -97,7 +114,7 @@ TBD
97114

98115
## Community
99116

100-
- Our [Slack channel #nginx-agent](https://nginxcommunity.slack.com/), is the go-to place to start asking questions and sharing your thoughts.
117+
- Our [NGINX Community Forum ](https://community.nginx.org/tag/agent) is the go-to place to ask questions and share your thoughts.
101118

102119
- Our [GitHub issues page](https://github.com/nginx/agent/issues) offers space for a more technical discussion at your own pace.
103120

internal/collector/nginxplusreceiver/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type APIDetails struct {
3232
}
3333

3434
// Validate checks if the receiver configuration is valid
35+
// nolint: ireturn
3536
func (cfg *Config) Validate() error {
3637
if cfg.APIDetails.URL == "" {
3738
return errors.New("endpoint cannot be empty for nginxplusreceiver")

internal/collector/otel_collector_plugin.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,16 @@ func (oc *Collector) processReceivers(ctx context.Context, receivers []config.Ot
161161
}
162162
}
163163

164+
// nolint: revive, cyclop
164165
func (oc *Collector) bootup(ctx context.Context) error {
165166
errChan := make(chan error)
166167

167168
go func() {
169+
if oc.service == nil {
170+
errChan <- fmt.Errorf("unable to start OTel collector: service is nil")
171+
return
172+
}
173+
168174
appErr := oc.service.Run(ctx)
169175
if appErr != nil {
170176
errChan <- appErr
@@ -177,8 +183,11 @@ func (oc *Collector) bootup(ctx context.Context) error {
177183
case err := <-errChan:
178184
return err
179185
default:
180-
state := oc.service.GetState()
186+
if oc.service == nil {
187+
return fmt.Errorf("unable to start otel collector: service is nil")
188+
}
181189

190+
state := oc.service.GetState()
182191
switch state {
183192
case otelcol.StateStarting:
184193
// NoOp
@@ -212,9 +221,9 @@ func (oc *Collector) Close(ctx context.Context) error {
212221
oc.service.Shutdown()
213222
oc.cancel()
214223

215-
settings := oc.config.Client.Backoff
224+
settings := *oc.config.Client.Backoff
216225
settings.MaxElapsedTime = maxTimeToWaitForShutdown
217-
err := backoff.WaitUntil(ctx, settings, func() error {
226+
err := backoff.WaitUntil(ctx, &settings, func() error {
218227
if oc.service.GetState() == otelcol.StateClosed {
219228
return nil
220229
}
@@ -263,7 +272,7 @@ func (oc *Collector) handleNginxConfigUpdate(ctx context.Context, msg *bus.Messa
263272
return
264273
}
265274

266-
reloadCollector := oc.checkForNewReceivers(nginxConfigContext)
275+
reloadCollector := oc.checkForNewReceivers(ctx, nginxConfigContext)
267276

268277
if reloadCollector {
269278
slog.InfoContext(ctx, "Reloading OTel collector config, nginx config updated")
@@ -394,7 +403,7 @@ func (oc *Collector) restartCollector(ctx context.Context) {
394403
}
395404
}
396405

397-
func (oc *Collector) checkForNewReceivers(nginxConfigContext *model.NginxConfigContext) bool {
406+
func (oc *Collector) checkForNewReceivers(ctx context.Context, nginxConfigContext *model.NginxConfigContext) bool {
398407
nginxReceiverFound, reloadCollector := oc.updateExistingNginxPlusReceiver(nginxConfigContext)
399408

400409
if !nginxReceiverFound && nginxConfigContext.PlusAPI.URL != "" {
@@ -410,10 +419,12 @@ func (oc *Collector) checkForNewReceivers(nginxConfigContext *model.NginxConfigC
410419
CollectionInterval: defaultCollectionInterval,
411420
},
412421
)
422+
slog.DebugContext(ctx, "NGINX Plus API found, NGINX Plus receiver enabled to scrape metrics")
413423

414424
reloadCollector = true
415425
} else if nginxConfigContext.PlusAPI.URL == "" {
416-
reloadCollector = oc.addNginxOssReceiver(nginxConfigContext)
426+
slog.WarnContext(ctx, "NGINX Plus API is not configured, searching for stub status endpoint")
427+
reloadCollector = oc.addNginxOssReceiver(ctx, nginxConfigContext)
417428
}
418429

419430
if oc.config.IsFeatureEnabled(pkgConfig.FeatureLogsNap) {
@@ -428,7 +439,7 @@ func (oc *Collector) checkForNewReceivers(nginxConfigContext *model.NginxConfigC
428439
return reloadCollector
429440
}
430441

431-
func (oc *Collector) addNginxOssReceiver(nginxConfigContext *model.NginxConfigContext) bool {
442+
func (oc *Collector) addNginxOssReceiver(ctx context.Context, nginxConfigContext *model.NginxConfigContext) bool {
432443
nginxReceiverFound, reloadCollector := oc.updateExistingNginxOSSReceiver(nginxConfigContext)
433444

434445
if !nginxReceiverFound && nginxConfigContext.StubStatus.URL != "" {
@@ -445,8 +456,11 @@ func (oc *Collector) addNginxOssReceiver(nginxConfigContext *model.NginxConfigCo
445456
CollectionInterval: defaultCollectionInterval,
446457
},
447458
)
459+
slog.DebugContext(ctx, "Stub status endpoint found, OSS receiver enabled to scrape metrics")
448460

449461
reloadCollector = true
462+
} else if nginxConfigContext.StubStatus.URL == "" {
463+
slog.WarnContext(ctx, "Stub status endpoint not found, NGINX metrics not available")
450464
}
451465

452466
return reloadCollector

internal/datasource/host/info_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,12 @@ func TestInfo_ContainerInfo(t *testing.T) {
526526
info := NewInfo()
527527
info.mountInfoLocation = mountInfoFile.Name()
528528
info.exec = execMock
529+
info.osReleaseLocation = "/non/existent"
529530
containerInfo := info.ContainerInfo(ctx)
530531

531532
assert.Equal(tt, test.expectContainerID, containerInfo.ContainerInfo.GetContainerId())
532533
assert.Equal(tt, test.expectHostname, containerInfo.ContainerInfo.GetHostname())
533-
assert.Equal(t, releaseInfo, containerInfo.ContainerInfo.GetReleaseInfo())
534+
assert.Equal(tt, releaseInfo, containerInfo.ContainerInfo.GetReleaseInfo())
534535
})
535536
}
536537
}

0 commit comments

Comments
 (0)