Skip to content

Commit 78cd6d5

Browse files
committed
Merge branch 'v3' into dynamically-add-otel-receiver-after-config-apply
2 parents 725e59d + a68504b commit 78cd6d5

38 files changed

+731
-262
lines changed

Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,22 @@ build-mock-management-otel-collector-image: build-mock-management-otel-collector
231231
.PHONY: run-mock-management-otel-collector
232232
run-mock-management-otel-collector: ## Run mock management plane OTel collector
233233
@echo "🚀 Running mock management plane OTel collector"
234-
AGENT_IMAGE_WITH_NGINX_PLUS=nginx_plus_$(IMAGE_TAG):latest AGENT_IMAGE_WITH_NGINX_OSS=nginx_oss_$(IMAGE_TAG):latest AGENT_IMAGE_WITH_NGINX_PLUS_AND_NAP=nginx_plus_and_nap_$(IMAGE_TAG):latest $(CONTAINER_COMPOSE) -f ./test/mock/collector/docker-compose.yaml up -d
234+
AGENT_IMAGE_WITH_NGINX_PLUS=nginx_plus_$(IMAGE_TAG):latest AGENT_IMAGE_WITH_NGINX_OSS=nginx_oss_$(IMAGE_TAG):latest AGENT_IMAGE_WITH_NGINX_PLUS_AND_NAP=nginx_plus_and_nap_$(IMAGE_TAG):latest $(CONTAINER_COMPOSE) -f ./test/mock/collector/nginx-plus-and-nap/docker-compose.yaml up -d
235235

236236
.PHONY: stop-mock-management-otel-collector
237237
stop-mock-management-otel-collector: ## Stop running mock management plane OTel collector
238238
@echo "Stopping mock management plane OTel collector"
239-
AGENT_IMAGE_WITH_NGINX_PLUS=nginx_plus_$(IMAGE_TAG):latest AGENT_IMAGE_WITH_NGINX_OSS=nginx_oss_$(IMAGE_TAG):latest AGENT_IMAGE_WITH_NGINX_PLUS_AND_NAP=nginx_plus_and_nap_$(IMAGE_TAG):latest $(CONTAINER_COMPOSE) -f ./test/mock/collector/docker-compose.yaml down
239+
AGENT_IMAGE_WITH_NGINX_PLUS=nginx_plus_$(IMAGE_TAG):latest AGENT_IMAGE_WITH_NGINX_OSS=nginx_oss_$(IMAGE_TAG):latest AGENT_IMAGE_WITH_NGINX_PLUS_AND_NAP=nginx_plus_and_nap_$(IMAGE_TAG):latest $(CONTAINER_COMPOSE) -f ./test/mock/collector/nginx-plus-and-nap/docker-compose.yaml down
240+
241+
.PHONY: run-mock-otel-collector-without-nap
242+
run-mock-otel-collector-without-nap:
243+
@echo "🚀 Running mock management plane OTel collector without NAP"
244+
AGENT_IMAGE_WITH_NGINX_PLUS=nginx_plus_$(IMAGE_TAG):latest AGENT_IMAGE_WITH_NGINX_OSS=nginx_oss_$(IMAGE_TAG):latest $(CONTAINER_COMPOSE) -f ./test/mock/collector/docker-compose.yaml up -d
245+
246+
.PHONY: stop-mock-otel-collector-without-nap
247+
stop-mock-otel-collector-without-nap: ## Stop running mock management plane OTel collector
248+
@echo "Stopping mock management plane OTel collector without NAP"
249+
AGENT_IMAGE_WITH_NGINX_PLUS=nginx_plus_$(IMAGE_TAG):latest AGENT_IMAGE_WITH_NGINX_OSS=nginx_oss_$(IMAGE_TAG):latest $(CONTAINER_COMPOSE) -f ./test/mock/collector/docker-compose.yaml down
240250

241251
generate: ## Generate golang code
242252
@echo "🗄️ Generating proto files"

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/docker/docker v27.3.1+incompatible
1212
github.com/fsnotify/fsnotify v1.8.0
1313
github.com/go-resty/resty/v2 v2.16.2
14+
github.com/goccy/go-yaml v1.17.1
1415
github.com/google/go-cmp v0.6.0
1516
github.com/google/uuid v1.6.0
1617
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
179179
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
180180
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
181181
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
182+
github.com/goccy/go-yaml v1.17.1 h1:LI34wktB2xEE3ONG/2Ar54+/HJVBriAGJ55PHls4YuY=
183+
github.com/goccy/go-yaml v1.17.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
182184
github.com/gogo/googleapis v1.4.1 h1:1Yx4Myt7BxzvUr5ldGSbwYiZG6t9wGBZ+8/fX3Wvtq0=
183185
github.com/gogo/googleapis v1.4.1/go.mod h1:2lpHqI5OcWCtVElxXnPt+s8oJvMpySlOyM6xDCrzib4=
184186
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=

internal/collector/otel_collector_plugin.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ func (oc *Collector) checkForNewReceivers(nginxConfigContext *model.NginxConfigC
418418
if tcplogReceiversFound {
419419
reloadCollector = true
420420
}
421+
} else {
422+
slog.Debug("NAP logs feature disabled", "enabled_features", oc.config.Features)
421423
}
422424

423425
return reloadCollector

internal/collector/otel_collector_plugin_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func TestCollector_ProcessResourceUpdateTopic(t *testing.T) {
324324
Server: &config.ServerConfig{
325325
Host: "",
326326
Port: 0,
327-
Type: 0,
327+
Type: config.Grpc,
328328
},
329329
TLS: &config.TLSConfig{
330330
Cert: "",
@@ -408,7 +408,7 @@ func TestCollector_ProcessResourceUpdateTopicFails(t *testing.T) {
408408
Server: &config.ServerConfig{
409409
Host: "",
410410
Port: 0,
411-
Type: 0,
411+
Type: config.Grpc,
412412
},
413413
TLS: &config.TLSConfig{
414414
Cert: "",

internal/collector/otelcol.tmpl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ receivers:
3737
{{- range $index, $otlpReceiver := .Receivers.OtlpReceivers }}
3838
otlp/{{$index}}:
3939
protocols:
40-
{{- if eq .Server.Type 0 }}
41-
grpc:
42-
endpoint: "{{ .Server.Host }}:{{ .Server.Port }}"
43-
{{- if and .OtlpTLSConfig (or (gt (len .OtlpTLSConfig.Key) 0) (gt (len .OtlpTLSConfig.Cert) 0) (gt (len .OtlpTLSConfig.Key) 0)) }}
40+
{{- if eq .Server.Type "http" }}
41+
http:
42+
endpoint: "{{- .Server.Host -}}:{{- .Server.Port -}}"
43+
{{- if .OtlpTLSConfig }}
4444
tls:
4545
{{ if gt (len .OtlpTLSConfig.Cert) 0 -}}
4646
cert_file: {{ .OtlpTLSConfig.Cert }}
@@ -53,9 +53,9 @@ receivers:
5353
{{- end }}
5454
{{- end }}
5555
{{- else }}
56-
http:
57-
endpoint: "{{- .Server.Host -}}:{{- .Server.Port -}}"
58-
{{- if .OtlpTLSConfig }}
56+
grpc:
57+
endpoint: "{{ .Server.Host }}:{{ .Server.Port }}"
58+
{{- if and .OtlpTLSConfig (or (gt (len .OtlpTLSConfig.Key) 0) (gt (len .OtlpTLSConfig.Cert) 0) (gt (len .OtlpTLSConfig.Key) 0)) }}
5959
tls:
6060
{{ if gt (len .OtlpTLSConfig.Cert) 0 -}}
6161
cert_file: {{ .OtlpTLSConfig.Cert }}

internal/collector/settings_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestTemplateWrite(t *testing.T) {
6868
Server: &config.ServerConfig{
6969
Host: "localhost",
7070
Port: 9876,
71-
Type: 0,
71+
Type: config.Grpc,
7272
},
7373
TLS: nil,
7474
}
@@ -106,7 +106,7 @@ func TestTemplateWrite(t *testing.T) {
106106
Server: &config.ServerConfig{
107107
Host: "localhost",
108108
Port: 4317,
109-
Type: 0,
109+
Type: config.Grpc,
110110
},
111111
OtlpTLSConfig: &config.OtlpTLSConfig{
112112
Cert: "/tmp/cert.pem",

internal/command/command_plugin.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (cp *CommandPlugin) Process(ctx context.Context, msg *bus.Message) {
104104

105105
func (cp *CommandPlugin) processResourceUpdate(ctx context.Context, msg *bus.Message) {
106106
if resource, ok := msg.Data.(*mpi.Resource); ok {
107-
if !cp.commandService.IsConnected() && cp.config.IsFeatureEnabled(pkgConfig.FeatureConnection) {
107+
if !cp.commandService.IsConnected() {
108108
cp.createConnection(ctx, resource)
109109
} else {
110110
statusErr := cp.commandService.UpdateDataPlaneStatus(ctx, resource)
@@ -237,8 +237,8 @@ func (cp *CommandPlugin) handleAPIActionRequest(ctx context.Context, message *mp
237237
} else {
238238
slog.WarnContext(
239239
ctx,
240-
"API Action Request feature disabled. Unable to process API action request",
241-
"request", message,
240+
"API action feature disabled. Unable to process API action request",
241+
"request", message, "enabled_features", cp.config.Features,
242242
)
243243

244244
err := cp.commandService.SendDataPlaneResponse(ctx, &mpi.DataPlaneResponse{
@@ -263,7 +263,7 @@ func (cp *CommandPlugin) handleConfigApplyRequest(newCtx context.Context, messag
263263
slog.WarnContext(
264264
newCtx,
265265
"Configuration feature disabled. Unable to process config apply request",
266-
"request", message,
266+
"request", message, "enabled_features", cp.config.Features,
267267
)
268268

269269
err := cp.commandService.SendDataPlaneResponse(newCtx, &mpi.DataPlaneResponse{
@@ -288,7 +288,7 @@ func (cp *CommandPlugin) handleConfigUploadRequest(newCtx context.Context, messa
288288
slog.WarnContext(
289289
newCtx,
290290
"Configuration feature disabled. Unable to process config upload request",
291-
"request", message,
291+
"request", message, "enabled_features", cp.config.Features,
292292
)
293293

294294
err := cp.commandService.SendDataPlaneResponse(newCtx, &mpi.DataPlaneResponse{

internal/command/command_plugin_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ func TestCommandPlugin_monitorSubscribeChannel(t *testing.T) {
204204
request: "APIActionRequest",
205205
configFeatures: []string{
206206
pkg.FeatureConfiguration,
207-
pkg.FeatureConnection,
208207
pkg.FeatureMetrics,
209208
pkg.FeatureFileWatcher,
210209
pkg.FeatureAPIAction,
@@ -278,7 +277,6 @@ func TestCommandPlugin_FeatureDisabled(t *testing.T) {
278277
expectedLog: "Configuration feature disabled. Unable to process config upload request",
279278
request: "UploadRequest",
280279
configFeatures: []string{
281-
pkg.FeatureConnection,
282280
pkg.FeatureMetrics,
283281
pkg.FeatureFileWatcher,
284282
},
@@ -293,7 +291,6 @@ func TestCommandPlugin_FeatureDisabled(t *testing.T) {
293291
expectedLog: "Configuration feature disabled. Unable to process config apply request",
294292
request: "ApplyRequest",
295293
configFeatures: []string{
296-
pkg.FeatureConnection,
297294
pkg.FeatureMetrics,
298295
pkg.FeatureFileWatcher,
299296
},

internal/config/config.go

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

88
import (
9+
"bytes"
910
"context"
1011
"encoding/json"
1112
"errors"
@@ -22,6 +23,7 @@ import (
2223

2324
"github.com/nginx/agent/v3/internal/datasource/file"
2425

26+
"github.com/goccy/go-yaml"
2527
uuidLibrary "github.com/nginx/agent/v3/pkg/id"
2628
selfsignedcerts "github.com/nginx/agent/v3/pkg/tls"
2729
"github.com/spf13/cobra"
@@ -127,7 +129,6 @@ func ResolveConfig() (*Config, error) {
127129
checkCollectorConfiguration(collector, config)
128130

129131
slog.Debug("Agent config", "config", config)
130-
slog.Info("Enabled features", "features", config.Features)
131132
slog.Info("Excluded files from being watched for file changes", "exclude_files",
132133
config.Watchers.FileWatcher.ExcludeFiles)
133134

@@ -529,6 +530,11 @@ func getConfigFilePaths() []string {
529530
}
530531

531532
func loadPropertiesFromFile(cfg string) error {
533+
validationError := validateYamlFile(cfg)
534+
if validationError != nil {
535+
return validationError
536+
}
537+
532538
viperInstance.SetConfigFile(cfg)
533539
viperInstance.SetConfigType("yaml")
534540
err := viperInstance.MergeInConfig()
@@ -539,6 +545,20 @@ func loadPropertiesFromFile(cfg string) error {
539545
return nil
540546
}
541547

548+
func validateYamlFile(filePath string) error {
549+
fileContents, readError := os.ReadFile(filePath)
550+
if readError != nil {
551+
return fmt.Errorf("failed to read file %s: %w", filePath, readError)
552+
}
553+
554+
decoder := yaml.NewDecoder(bytes.NewReader(fileContents), yaml.DisallowUnknownField())
555+
if err := decoder.Decode(&Config{}); err != nil {
556+
return errors.New(yaml.FormatError(err, false, false))
557+
}
558+
559+
return nil
560+
}
561+
542562
func normalizeFunc(f *flag.FlagSet, name string) flag.NormalizedName {
543563
from := []string{"_", "."}
544564
to := "-"

0 commit comments

Comments
 (0)