Skip to content

Commit 5c87492

Browse files
committed
merge main
2 parents f5d93b8 + b70dcc7 commit 5c87492

File tree

22 files changed

+403
-182
lines changed

22 files changed

+403
-182
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ jobs:
9393
strategy:
9494
matrix:
9595
container:
96+
- image: "ubuntu"
97+
version: "24.04"
9698
- image: "redhatenterprise"
9799
version: "9"
98100
- image: "alpine"
99-
version: "3.19"
101+
version: "3.22"
100102
steps:
101103
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
102104
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0

.github/workflows/scorecards.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ jobs:
3737
with:
3838
results_file: results.sarif
3939
results_format: sarif
40-
repo_token: ${{ secrets.SCORECARD_TOKEN }}
4140

4241
# Publish the results for public repositories to enable scorecard badges. For more details, see
4342
# https://github.com/ossf/scorecard-action#publishing-results.

.github/workflows/upload-release-assets.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,23 @@ jobs:
6464
echo "${{secrets.PUBTEST_CERT}}" > pubtest.crt
6565
echo "${{secrets.PUBTEST_KEY}}" > pubtest.key
6666
PKG_REPO=${{inputs.pkgRepo}} CERT=pubtest.crt KEY=pubtest.key DL=1 scripts/packages/package-check.sh ${{inputs.pkgVersion}}
67+
for i in $(find ${{inputs.pkgRepo}}/nginx-agent | grep -e "nginx-agent[_-]${{inputs.pkgVersion}}"); do
68+
if [[ "$i" == *.deb ]]; then
69+
echo "Renaming ${i} to ${i/_/-}"
70+
mv "${i}" "${i/_/-}"
71+
fi
72+
if [[ "$i" == *.apk ]]; then
73+
ver=$(echo "$i" | grep -o -e "v[0-9]*\.[0-9]*")
74+
arch=$(echo "$i" | grep -o -F -e "x86_64" -e "aarch64")
75+
dest="$(dirname "$i")/nginx-agent-${{inputs.pkgVersion}}-$ver-$arch.apk"
76+
echo "Renaming ${i} to ${dest}"
77+
mv "${i}" "${dest}"
78+
fi
79+
done
6780
find ${{inputs.pkgRepo}}/nginx-agent | grep -e "nginx-agent[_-]${{inputs.pkgVersion}}"
6881

6982
- name: GitHub Upload
83+
continue-on-error: true
7084
if: ${{ needs.vars.outputs.github_release == 'true' }}
7185
env:
7286
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -88,11 +102,6 @@ jobs:
88102
inlineScript: |
89103
for i in $(find ${{inputs.pkgRepo}}/nginx-agent | grep -e "nginx-agent[_-]${{inputs.pkgVersion}}"); do
90104
dest="nginx-agent/${GITHUB_REF##*/}/${i##*/}"
91-
if [[ "$i" == *.apk ]]; then
92-
ver=$(echo "$i" | grep -o -e "v[0-9]*\.[0-9]*")
93-
arch=$(echo "$i" | grep -o -F -e "x86_64" -e "aarch64")
94-
dest="nginx-agent/${GITHUB_REF##*/}/nginx-agent-$VER-$ver-$arch.apk"
95-
fi
96105
echo "Uploading ${i} to ${dest}"
97106
az storage blob upload --auth-mode=login -f "$i" -c ${{ secrets.AZURE_CONTAINER_NAME }} \
98107
--account-name ${{ secrets.AZURE_ACCOUNT_NAME }} --overwrite -n ${dest}

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ GOBIN ?= $$(go env GOPATH)/bin
2222
# | redhatenterprise | 8, 9 | |
2323
# | rockylinux | 8, 9 | |
2424
# | almalinux | 8, 9 | |
25-
# | alpine | 3.17, 3.18, 3.19, 3.20, 3.21 | |
25+
# | alpine | 3.18, 3.19, 3.20, 3.21 3.22 | |
2626
# | oraclelinux | 8, 9 | |
27-
# | suse | sles12sp5, sle15 | |
27+
# | suse | sle15 | |
2828
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2929
OS_RELEASE ?= ubuntu
30-
OS_VERSION ?= 22.04
30+
OS_VERSION ?= 24.04
3131
BASE_IMAGE = "docker.io/$(OS_RELEASE):$(OS_VERSION)"
3232
IMAGE_TAG = "agent_$(OS_RELEASE)_$(OS_VERSION)"
3333
DOCKERFILE_PATH = "./test/docker/nginx-oss/$(CONTAINER_OS_TYPE)/Dockerfile"
@@ -62,7 +62,7 @@ APK_PACKAGE := ./build/$(PACKAGE_NAME).apk
6262
DEB_PACKAGE := ./build/$(PACKAGE_NAME).deb
6363
RPM_PACKAGE := ./build/$(PACKAGE_NAME).rpm
6464

65-
MOCK_MANAGEMENT_PLANE_CONFIG_DIRECTORY ?=
65+
MOCK_MANAGEMENT_PLANE_CONFIG_DIRECTORY ?=
6666
MOCK_MANAGEMENT_PLANE_LOG_LEVEL ?= INFO
6767
MOCK_MANAGEMENT_PLANE_GRPC_ADDRESS ?= 127.0.0.1:0
6868
MOCK_MANAGEMENT_PLANE_API_ADDRESS ?= 127.0.0.1:0

Makefile.packaging

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ TARBALL_NAME := $(PACKAGE_PREFIX).tar.gz
1414

1515
DEB_DISTROS ?= ubuntu-noble-24.04 ubuntu-jammy-22.04 ubuntu-focal-20.04 debian-bookworm-12 debian-bullseye-11
1616
DEB_ARCHS ?= arm64 amd64
17-
RPM_DISTROS ?= oraclelinux-8-x86_64 oraclelinux-9-x86_64 suse-12-x86_64 suse-15-x86_64
17+
RPM_DISTROS ?= oraclelinux-8-x86_64 oraclelinux-9-x86_64 suse-15-x86_64
1818
RPM_ARCH := x86_64
1919
REDHAT_VERSIONS ?= redhatenterprise-8 redhatenterprise-9
2020
REDHAT_ARCHS ?= aarch64 x86_64
2121
ROCKY_VERSIONS ?= rocky-8 rocky-9
2222
ROCKY_ARCHS ?= aarch64 x86_64
2323
FREEBSD_DISTROS ?= "FreeBSD:13:amd64" "FreeBSD:14:amd64"
24-
APK_VERSIONS ?= 3.18 3.19 3.20 3.21
24+
APK_VERSIONS ?= 3.18 3.19 3.20 3.21 3.22
2525
APK_ARCHS ?= aarch64 x86_64
2626
APK_REVISION ?= 1
2727
ALMA_VERSIONS ?= almalinux-8 almalinux-9

internal/collector/containermetricsreceiver/internal/utils.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,20 @@ func ReadLines(filename string) ([]string, error) {
2222
}
2323

2424
// nolint: revive
25-
func ReadLinesOffsetN(filename string, offset uint, n int) ([]string, error) {
25+
func ReadLinesOffsetN(filename string, offset uint, n int) (lines []string, err error) {
2626
f, err := os.Open(filename)
27+
defer func() {
28+
closeErr := f.Close()
29+
if closeErr != nil {
30+
if err == nil {
31+
err = closeErr
32+
}
33+
}
34+
}()
35+
2736
if err != nil {
2837
return []string{}, err
2938
}
30-
defer f.Close()
3139

3240
var ret []string
3341

internal/config/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,10 @@ func (c *Config) AreReceiversConfigured() bool {
433433
}
434434

435435
func isAllowedDir(dir string, allowedDirs []string) bool {
436+
if !strings.HasSuffix(dir, "/") && filepath.Ext(dir) == "" {
437+
dir += "/"
438+
}
439+
436440
for _, allowedDirectory := range allowedDirs {
437441
if strings.HasPrefix(dir, allowedDirectory) {
438442
return true

internal/config/types_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ func TestTypes_IsDirectoryAllowed(t *testing.T) {
2525
allowed: true,
2626
allowedDirs: []string{
2727
AgentDirName,
28-
"/etc/nginx",
28+
"/etc/nginx/",
2929
"/var/log/nginx/",
3030
},
31-
fileDir: "/etc/nginx/nginx.conf",
31+
fileDir: "/etc/nginx",
3232
},
3333
{
3434
name: "Test 2: directory not allowed",

internal/datasource/config/nginx_config_parser.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (ncp *NginxConfigParser) Parse(ctx context.Context, instance *mpi.Instance)
100100
return ncp.createNginxConfigContext(ctx, instance, payload)
101101
}
102102

103-
// nolint: cyclop,revive,gocognit
103+
// nolint: cyclop,revive,gocognit,gocyclo
104104
func (ncp *NginxConfigParser) createNginxConfigContext(
105105
ctx context.Context,
106106
instance *mpi.Instance,
@@ -138,6 +138,10 @@ func (ncp *NginxConfigParser) createNginxConfigContext(
138138
err := ncp.crossplaneConfigTraverse(ctx, &conf,
139139
func(ctx context.Context, parent, directive *crossplane.Directive) error {
140140
switch directive.Directive {
141+
case "include":
142+
include := ncp.parseIncludeDirective(directive)
143+
144+
nginxConfigContext.Includes = append(nginxConfigContext.Includes, include)
141145
case "log_format":
142146
formatMap = ncp.formatMap(directive)
143147
case "access_log":
@@ -214,6 +218,17 @@ func (ncp *NginxConfigParser) createNginxConfigContext(
214218
return nginxConfigContext, nil
215219
}
216220

221+
func (ncp *NginxConfigParser) parseIncludeDirective(directive *crossplane.Directive) string {
222+
var include string
223+
if filepath.IsAbs(directive.Args[0]) {
224+
include = directive.Args[0]
225+
} else {
226+
include = filepath.Join(filepath.Dir(directive.File), directive.Args[0])
227+
}
228+
229+
return include
230+
}
231+
217232
func (ncp *NginxConfigParser) addAccessLog(accessLog *model.AccessLog,
218233
accessLogs []*model.AccessLog,
219234
) []*model.AccessLog {

internal/datasource/host/info.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,17 @@ func (i *Info) containerID() string {
205205
// mountInfo is the path: "/proc/self/mountinfo"
206206
func containerIDFromMountInfo(mountInfo string) (string, error) {
207207
mInfoFile, err := os.Open(mountInfo)
208-
if err != nil {
209-
return "", fmt.Errorf("could not read %s: %w", mountInfo, err)
210-
}
211208
defer func(f *os.File, fileName string) {
212209
closeErr := f.Close()
213210
if closeErr != nil {
214211
slog.Error("Unable to close file", "file", fileName, "error", closeErr)
215212
}
216213
}(mInfoFile, mountInfo)
217214

215+
if err != nil {
216+
return "", fmt.Errorf("could not read %s: %w", mountInfo, err)
217+
}
218+
218219
fileScanner := bufio.NewScanner(mInfoFile)
219220
fileScanner.Split(bufio.ScanLines)
220221

@@ -308,15 +309,15 @@ func (i *Info) releaseInfo(ctx context.Context, osReleaseLocation string) (relea
308309

309310
func readOsRelease(path string) (map[string]string, error) {
310311
f, err := os.Open(path)
311-
if err != nil {
312-
return nil, fmt.Errorf("release file %s is unreadable: %w", path, err)
313-
}
314312
defer func(f *os.File, fileName string) {
315313
closeErr := f.Close()
316314
if closeErr != nil {
317315
slog.Error("Unable to close file", "file", fileName, "error", closeErr)
318316
}
319317
}(f, path)
318+
if err != nil {
319+
return nil, fmt.Errorf("release file %s is unreadable: %w", path, err)
320+
}
320321

321322
info, err := parseOsReleaseFile(f)
322323
if err != nil {

0 commit comments

Comments
 (0)