Skip to content

Commit 5eedb9e

Browse files
committed
Merge branch 'v3' into collector-tokenpath
2 parents fefb0ed + e745a32 commit 5eedb9e

File tree

9 files changed

+68
-62
lines changed

9 files changed

+68
-62
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -306,23 +306,3 @@ jobs:
306306
- name: Push load test result
307307
if: ${{ success() && github.ref_name == 'v3'}}
308308
run: git push 'https://github-actions:${{ secrets.GITHUB_TOKEN }}@github.com/nginx/agent.git' benchmark-results:benchmark-results
309-
310-
publish-packages:
311-
name: Publish NGINX Agent v3 packages
312-
if: ${{ github.ref_name == 'v3' &&
313-
!github.event.pull_request.head.repo.fork }}
314-
needs: [ lint, unit-test, performance-tests,
315-
load-tests, official-oss-image-integration-tests,
316-
official-plus-image-integration-tests,
317-
race-condition-test, integration-tests ]
318-
uses: ./.github/workflows/release-branch.yml
319-
secrets: inherit
320-
permissions:
321-
id-token: write
322-
contents: read
323-
with:
324-
packageVersion: "3.0.0"
325-
packageBuildNo: "${{ github.run_number }}"
326-
uploadAzure: true
327-
publishPackages: true
328-
releaseBranch: "v3"

.github/workflows/release-branch.yml

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,35 +39,6 @@ on:
3939
description: 'Location to publish packages to'
4040
required: false
4141
default: "https://up-ap.nginx.com"
42-
workflow_call:
43-
inputs:
44-
githubRelease:
45-
type: boolean
46-
default: false
47-
packageVersion:
48-
type: string
49-
default: "3.0.0"
50-
packageBuildNo:
51-
type: string
52-
default: "1"
53-
uploadAzure:
54-
type: boolean
55-
default: true
56-
publishPackages:
57-
type: boolean
58-
default: true
59-
tagRelease:
60-
type: boolean
61-
default: false
62-
createPullRequest:
63-
type: boolean
64-
default: false
65-
releaseBranch:
66-
type: string
67-
required: true
68-
uploadUrl:
69-
type: string
70-
default: "https://up-ap.nginx.com"
7142

7243
env:
7344
NFPM_VERSION: 'v2.35.3'

internal/collector/nginxplusreceiver/factory.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ import (
99
"errors"
1010
"time"
1111

12+
"go.opentelemetry.io/collector/scraper"
13+
"go.opentelemetry.io/collector/scraper/scraperhelper"
14+
1215
"go.opentelemetry.io/collector/component"
1316
"go.opentelemetry.io/collector/consumer"
1417
"go.opentelemetry.io/collector/receiver"
1518

1619
"github.com/nginx/agent/v3/internal/collector/nginxplusreceiver/internal/metadata"
1720
)
1821

22+
// nolint: ireturn
1923
const defaultTimeout = 10 * time.Second
2024

2125
// nolint: ireturn
@@ -43,6 +47,19 @@ func createMetricsReceiver(
4347
}
4448

4549
nps := newNginxPlusScraper(params, cfg)
50+
npsMetrics, npsMetricsError := scraper.NewMetrics(
51+
nps.Scrape,
52+
scraper.WithStart(nps.Start),
53+
scraper.WithShutdown(nps.Shutdown),
54+
)
55+
if npsMetricsError != nil {
56+
return nil, npsMetricsError
57+
}
4658

47-
return nps, nil
59+
return scraperhelper.NewMetricsController(
60+
&cfg.ControllerConfig,
61+
params,
62+
metricsConsumer,
63+
scraperhelper.AddScraper(metadata.Type, npsMetrics),
64+
)
4865
}

internal/config/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ type (
231231
}
232232

233233
ContainerMetricsReceiver struct {
234-
CollectionInterval time.Duration `yaml:"-" mapstructure:"collection_interval"`
234+
CollectionInterval time.Duration `yaml:"collection_interval" mapstructure:"collection_interval"`
235235
}
236236

237237
HostMetrics struct {

internal/watcher/instance/nginx_process_parser.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ func (npp *NginxProcessParser) getInfo(ctx context.Context, proc *nginxprocess.P
136136
}
137137
}
138138

139+
confPath := getConfPathFromCommand(proc.Cmd)
140+
139141
var nginxInfo *Info
140142

141143
outputBuffer, err := npp.executer.RunCmd(ctx, exePath, "-V")
@@ -148,6 +150,10 @@ func (npp *NginxProcessParser) getInfo(ctx context.Context, proc *nginxprocess.P
148150
nginxInfo.ExePath = exePath
149151
nginxInfo.ProcessID = proc.PID
150152

153+
if nginxInfo.ConfPath = getNginxConfPath(ctx, nginxInfo); confPath != "" {
154+
nginxInfo.ConfPath = confPath
155+
}
156+
151157
loadableModules := getLoadableModules(nginxInfo)
152158
nginxInfo.LoadableModules = loadableModules
153159

@@ -268,7 +274,6 @@ func parseNginxVersionCommandOutput(ctx context.Context, output *bytes.Buffer) *
268274
}
269275

270276
nginxInfo.Prefix = getNginxPrefix(ctx, nginxInfo)
271-
nginxInfo.ConfPath = getNginxConfPath(ctx, nginxInfo)
272277

273278
return nginxInfo
274279
}
@@ -392,3 +397,17 @@ func convertToMap(processes []*nginxprocess.Process) map[int32]*nginxprocess.Pro
392397

393398
return processesByPID
394399
}
400+
401+
func getConfPathFromCommand(command string) string {
402+
commands := strings.Split(command, " ")
403+
404+
for i, command := range commands {
405+
if command == "-c" {
406+
if i < len(commands)-1 {
407+
return commands[i+1]
408+
}
409+
}
410+
}
411+
412+
return ""
413+
}

internal/watcher/instance/nginx_process_parser_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,3 +616,14 @@ func TestNginxProcessParser_GetExe(t *testing.T) {
616616
})
617617
}
618618
}
619+
620+
func TestGetConfigPathFromCommand(t *testing.T) {
621+
result := getConfPathFromCommand("nginx: master process nginx -c /tmp/nginx.conf")
622+
assert.Equal(t, "/tmp/nginx.conf", result)
623+
624+
result = getConfPathFromCommand("nginx: master process nginx -c")
625+
assert.Equal(t, "", result)
626+
627+
result = getConfPathFromCommand("")
628+
assert.Equal(t, "", result)
629+
}

pkg/files/file_helpers.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ package files
88

99
import (
1010
"cmp"
11+
"crypto/sha256"
1112
"crypto/x509"
13+
"encoding/base64"
1214
"fmt"
1315
"net"
1416
"os"
1517
"slices"
1618
"strconv"
1719

18-
"github.com/google/uuid"
19-
2020
mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
2121
"github.com/nginx/agent/v3/internal/datasource/cert"
2222
"google.golang.org/protobuf/types/known/timestamppb"
@@ -135,7 +135,10 @@ func GenerateConfigVersion(fileSlice []*mpi.File) string {
135135

136136
// GenerateHash returns the hash value of a file's contents.
137137
func GenerateHash(b []byte) string {
138-
return uuid.NewMD5(uuid.Nil, b).String()
138+
hash := sha256.New()
139+
hash.Write(b)
140+
141+
return base64.StdEncoding.EncodeToString(hash.Sum(nil))
139142
}
140143

141144
// ConvertToMapOfFiles converts a list of files to a map of files with the file name as the key

pkg/files/file_helpers_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
package files
77

88
import (
9+
"crypto/sha256"
910
"crypto/x509"
11+
"encoding/base64"
1012
"net"
1113
"os"
1214
"testing"
1315

14-
"github.com/google/uuid"
1516
"github.com/stretchr/testify/assert"
1617
"github.com/stretchr/testify/require"
1718

@@ -136,6 +137,10 @@ func Test_GenerateConfigVersion(t *testing.T) {
136137
}
137138

138139
func TestGenerateHash(t *testing.T) {
140+
hash1 := sha256.New()
141+
hash2 := sha256.New()
142+
hash1.Write([]byte(""))
143+
hash2.Write([]byte("test"))
139144
tests := []struct {
140145
name string
141146
expected string
@@ -144,12 +149,12 @@ func TestGenerateHash(t *testing.T) {
144149
{
145150
name: "Test 1: empty byte slice",
146151
input: []byte{},
147-
expected: uuid.NewMD5(uuid.Nil, []byte("")).String(),
152+
expected: base64.StdEncoding.EncodeToString(hash1.Sum(nil)),
148153
},
149154
{
150155
name: "Test 2: non-empty byte slice",
151156
input: []byte("test"),
152-
expected: uuid.NewMD5(uuid.Nil, []byte("test")).String(),
157+
expected: base64.StdEncoding.EncodeToString(hash2.Sum(nil)),
153158
},
154159
}
155160

test/mock/collector/nginx-agent.conf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ allowed_directories:
2828
- /var/run/nginx
2929

3030
client:
31-
timeout: 10s
31+
http:
32+
timeout: 10s
3233

3334
collector:
3435
log:
3536
level: DEBUG
3637
receivers:
3738
container_metrics:
38-
collection_interval: 10s
39+
collection_interval: 1m0s
3940
host_metrics:
4041
collection_interval: 1m0s
4142
initial_delay: 1s
@@ -49,9 +50,8 @@ collector:
4950
- server:
5051
host: "127.0.0.1"
5152
port: 4317
52-
type: 0
5353
auth:
54-
Token: secret-receiver-token
54+
token: secret-receiver-token
5555
tls:
5656
server_name: test-local-server
5757
ca: /tmp/ca.pem

0 commit comments

Comments
 (0)