Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/collector/otel_collector_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ func (oc *Collector) checkForNewReceivers(nginxConfigContext *model.NginxConfigC
if tcplogReceiversFound {
reloadCollector = true
}
} else {
slog.Warn("NAP logs feature disabled", "enabled_features", oc.config.Features)
}

return reloadCollector
Expand Down
10 changes: 5 additions & 5 deletions internal/command/command_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (cp *CommandPlugin) Process(ctx context.Context, msg *bus.Message) {

func (cp *CommandPlugin) processResourceUpdate(ctx context.Context, msg *bus.Message) {
if resource, ok := msg.Data.(*mpi.Resource); ok {
if !cp.commandService.IsConnected() && cp.config.IsFeatureEnabled(pkgConfig.FeatureConnection) {
if !cp.commandService.IsConnected() {
cp.createConnection(ctx, resource)
} else {
statusErr := cp.commandService.UpdateDataPlaneStatus(ctx, resource)
Expand Down Expand Up @@ -237,8 +237,8 @@ func (cp *CommandPlugin) handleAPIActionRequest(ctx context.Context, message *mp
} else {
slog.WarnContext(
ctx,
"API Action Request feature disabled. Unable to process API action request",
"request", message,
"API action feature disabled. Unable to process API action request",
"request", message, "enabled_features", cp.config.Features,
)

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

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

err := cp.commandService.SendDataPlaneResponse(newCtx, &mpi.DataPlaneResponse{
Expand Down
3 changes: 0 additions & 3 deletions internal/command/command_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ func TestCommandPlugin_monitorSubscribeChannel(t *testing.T) {
request: "APIActionRequest",
configFeatures: []string{
pkg.FeatureConfiguration,
pkg.FeatureConnection,
pkg.FeatureMetrics,
pkg.FeatureFileWatcher,
pkg.FeatureAPIAction,
Expand Down Expand Up @@ -278,7 +277,6 @@ func TestCommandPlugin_FeatureDisabled(t *testing.T) {
expectedLog: "Configuration feature disabled. Unable to process config upload request",
request: "UploadRequest",
configFeatures: []string{
pkg.FeatureConnection,
pkg.FeatureMetrics,
pkg.FeatureFileWatcher,
},
Expand All @@ -293,7 +291,6 @@ func TestCommandPlugin_FeatureDisabled(t *testing.T) {
expectedLog: "Configuration feature disabled. Unable to process config apply request",
request: "ApplyRequest",
configFeatures: []string{
pkg.FeatureConnection,
pkg.FeatureMetrics,
pkg.FeatureFileWatcher,
},
Expand Down
1 change: 0 additions & 1 deletion internal/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ const (
func DefaultFeatures() []string {
return []string{
pkg.FeatureConfiguration,
pkg.FeatureConnection,
pkg.FeatureMetrics,
pkg.FeatureFileWatcher,
}
Expand Down
8 changes: 8 additions & 0 deletions internal/plugin/plugin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"context"
"log/slog"

pkg "github.com/nginx/agent/v3/pkg/config"

"github.com/nginx/agent/v3/internal/collector"
"github.com/nginx/agent/v3/internal/command"
"github.com/nginx/agent/v3/internal/file"
Expand Down Expand Up @@ -58,6 +60,12 @@ func addCommandAndFilePlugins(ctx context.Context, plugins []bus.Plugin, agentCo
}

func addCollectorPlugin(ctx context.Context, agentConfig *config.Config, plugins []bus.Plugin) []bus.Plugin {
if !agentConfig.IsFeatureEnabled(pkg.FeatureMetrics) {
slog.WarnContext(ctx, "Metrics feature disabled, no metrics will be collected",
"enabled_features", agentConfig.Features)

return plugins
}
if agentConfig.IsACollectorExporterConfigured() {
oTelCollector, err := collector.New(agentConfig)
if err == nil {
Expand Down
68 changes: 66 additions & 2 deletions internal/plugin/plugin_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"context"
"testing"

pkg "github.com/nginx/agent/v3/pkg/config"

"github.com/nginx/agent/v3/internal/collector"
"github.com/nginx/agent/v3/internal/command"
"github.com/nginx/agent/v3/internal/file"
Expand All @@ -35,7 +37,8 @@ func TestLoadPlugins(t *testing.T) {
&resource.Resource{},
&watcher.Watcher{},
},
}, {
},
{
name: "Test 2: Load file and command plugins",
input: &config.Config{
Command: &config.Command{
Expand All @@ -53,21 +56,82 @@ func TestLoadPlugins(t *testing.T) {
&file.FilePlugin{},
&watcher.Watcher{},
},
}, {
},
{
name: "Test 3: Load metrics collector plugin",
input: &config.Config{
Collector: &config.Collector{
Exporters: config.Exporters{
Debug: &config.DebugExporter{},
},
},
Features: config.DefaultFeatures(),
},
expected: []bus.Plugin{
&resource.Resource{},
&collector.Collector{},
&watcher.Watcher{},
},
},
{
name: "Test 4: Metrics collector plugin, feature disabled",
input: &config.Config{
Command: &config.Command{
Server: &config.ServerConfig{
Host: "127.0.0.1",
Port: 443,
Type: config.Grpc,
},
},
Collector: &config.Collector{
Exporters: config.Exporters{
Debug: &config.DebugExporter{},
},
},
Features: []string{
pkg.FeatureConfiguration,
pkg.FeatureFileWatcher,
},
},
expected: []bus.Plugin{
&resource.Resource{},
&command.CommandPlugin{},
&file.FilePlugin{},
&watcher.Watcher{},
},
},
{
name: "Test 7: All features enabled",
input: &config.Config{
Command: &config.Command{
Server: &config.ServerConfig{
Host: "127.0.0.1",
Port: 443,
Type: config.Grpc,
},
},
Collector: &config.Collector{
Exporters: config.Exporters{
Debug: &config.DebugExporter{},
},
},
Features: []string{
pkg.FeatureConfiguration,
pkg.FeatureMetrics,
pkg.FeatureFileWatcher,
pkg.FeatureCertificates,
pkg.FeatureAPIAction,
pkg.FeatureLogsNap,
},
},
expected: []bus.Plugin{
&resource.Resource{},
&command.CommandPlugin{},
&file.FilePlugin{},
&collector.Collector{},
&watcher.Watcher{},
},
},
}

for _, test := range tests {
Expand Down
13 changes: 10 additions & 3 deletions internal/watcher/instance/nginx_config_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"strconv"
"strings"

pkg "github.com/nginx/agent/v3/pkg/config"

mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
"github.com/nginx/agent/v3/internal/config"
"github.com/nginx/agent/v3/internal/model"
Expand Down Expand Up @@ -147,9 +149,14 @@ func (ncp *NginxConfigParser) createNginxConfigContext(
}
case "ssl_certificate", "proxy_ssl_certificate", "ssl_client_certificate",
"ssl_trusted_certificate":
sslCertFile := ncp.sslCert(ctx, directive.Args[0], rootDir)
if !ncp.isDuplicateFile(nginxConfigContext.Files, sslCertFile) {
nginxConfigContext.Files = append(nginxConfigContext.Files, sslCertFile)
if ncp.agentConfig.IsFeatureEnabled(pkg.FeatureCertificates) {
sslCertFile := ncp.sslCert(ctx, directive.Args[0], rootDir)
if !ncp.isDuplicateFile(nginxConfigContext.Files, sslCertFile) {
nginxConfigContext.Files = append(nginxConfigContext.Files, sslCertFile)
}
} else {
slog.InfoContext(ctx, "Certificate feature is disabled, skipping cert",
"enabled_features", ncp.agentConfig.Features)
}

case "app_protect_security_log":
Expand Down
3 changes: 3 additions & 0 deletions internal/watcher/watcher_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func (w *Watcher) Init(ctx context.Context, messagePipe bus.MessagePipeInterface

if w.agentConfig.IsFeatureEnabled(pkgConfig.FeatureFileWatcher) {
go w.fileWatcherService.Watch(watcherContext, w.fileUpdatesChannel)
} else {
slog.InfoContext(watcherContext, "File watcher feature is disabled",
"enabled_features", w.agentConfig.Features)
}

go w.monitorWatchers(watcherContext)
Expand Down
18 changes: 7 additions & 11 deletions pkg/config/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@
package config

const (
FeatureCertificates = "certificates"
FeatureConfiguration = "configuration"
FeatureConnection = "connection"
FeatureMetrics = "metrics"
FeatureMetricsContainer = "metrics-container"
FeatureMetricsHost = "metrics-host"
FeatureMetricsInstance = "metrics-instance"
FeatureFileWatcher = "file-watcher"
FeatureAgentAPI = "agent-api"
FeatureAPIAction = "api-action"
FeatureLogsNap = "logs-nap"
FeatureCertificates = "certificates"
FeatureConfiguration = "configuration"
FeatureMetrics = "metrics"
FeatureFileWatcher = "file-watcher"
FeatureAPIAction = "api-action"
// FeatureLogsNap experimental feature
FeatureLogsNap = "logs-nap"
)