Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
98 changes: 98 additions & 0 deletions go.work.sum

Large diffs are not rendered by default.

27 changes: 26 additions & 1 deletion src/core/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ var (
PriorityTableMaxSize: 1000,
},
},
Features: []string{
FeatureRegistration,
FeatureNginxConfig,
FeatureNginxSSLConfig,
FeatureNginxCounting,
FeatureMetrics,
FeatureMetricsThrottle,
FeatureDataPlaneStatus,
FeatureProcessWatcher,
FeatureFileWatcher,
FeatureActivityEvents,
},
}
AllowedDirectoriesMap map[string]struct{}
)
Expand All @@ -97,7 +109,6 @@ const (
InstanceGroupKey = "instance_group"
ConfigDirsKey = "config_dirs"
TagsKey = "tags"
FeaturesKey = "features"

// viper keys used in config
LogKey = "log"
Expand Down Expand Up @@ -163,6 +174,20 @@ const (

NginxAppProtectReportInterval = NginxAppProtectKey + KeyDelimiter + "report_interval"

// viper keys used in config
FeaturesKey = "features"

FeatureRegistration = FeaturesKey + KeyDelimiter + "registration"
FeatureNginxConfig = FeaturesKey + KeyDelimiter + "nginx-config"
FeatureNginxSSLConfig = FeaturesKey + KeyDelimiter + "nginx-ssl-config"
FeatureNginxCounting = FeaturesKey + KeyDelimiter + "nginx-counting"
FeatureMetrics = FeaturesKey + KeyDelimiter + "metrics"
FeatureMetricsThrottle = FeaturesKey + KeyDelimiter + "metrics-throttle"
FeatureDataPlaneStatus = FeaturesKey + KeyDelimiter + "dataplane-status"
FeatureProcessWatcher = FeaturesKey + KeyDelimiter + "process-watcher"
FeatureFileWatcher = FeaturesKey + KeyDelimiter + "file-watcher"
FeatureActivityEvents = FeaturesKey + KeyDelimiter + "activity-events"

// DEPRECATED KEYS
NginxBinPathKey = "nginx_bin_path"
NginxPIDPathKey = "nginx_pid_path"
Expand Down
43 changes: 34 additions & 9 deletions src/plugins/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ const (

// Nginx is the metadata of our nginx binary
type Nginx struct {
messagePipeline core.MessagePipeInterface
nginxBinary core.NginxBinary
processes []core.Process
env core.Environment
cmdr client.Commander
config *config.Config
isNAPEnabled bool
messagePipeline core.MessagePipeInterface
nginxBinary core.NginxBinary
processes []core.Process
env core.Environment
cmdr client.Commander
config *config.Config
isNAPEnabled bool
isConfUploadEnabled bool
}

type ConfigRollbackResponse struct {
Expand All @@ -51,7 +52,10 @@ func NewNginx(cmdr client.Commander, nginxBinary core.NginxBinary, env core.Envi
if loadedConfig.NginxAppProtect != (config.NginxAppProtect{}) {
isNAPEnabled = true
}
return &Nginx{nginxBinary: nginxBinary, processes: env.Processes(), env: env, cmdr: cmdr, config: loadedConfig, isNAPEnabled: isNAPEnabled}

isConfUploadEnabled := isConfUploadEnabled(loadedConfig)

return &Nginx{nginxBinary: nginxBinary, processes: env.Processes(), env: env, cmdr: cmdr, config: loadedConfig, isNAPEnabled: isNAPEnabled, isConfUploadEnabled: isConfUploadEnabled}
}

// Init initializes the plugin
Expand Down Expand Up @@ -114,6 +118,12 @@ func (n *Nginx) Subscriptions() []string {

func (n *Nginx) uploadConfig(config *proto.ConfigDescriptor, messageId string) error {
log.Debugf("Uploading config for %v", config)

if !n.isConfUploadEnabled {
log.Info("unable to upload config as nginx-config feature is disabled")
return nil
}

if config.GetNginxId() == "" {
return nil
}
Expand Down Expand Up @@ -161,7 +171,11 @@ func (n *Nginx) processCmd(cmd *proto.Command) {

switch commandData.NginxConfig.Action {
case proto.NginxConfigAction_APPLY:
status = n.applyConfig(cmd, commandData)
if n.isConfUploadEnabled {
status = n.applyConfig(cmd, commandData)
} else {
log.Warnf("unable to upload config as nginx-config feature is disabled")
}
case proto.NginxConfigAction_TEST:
// TODO: Test agent config?
status.NginxConfigResponse.Status = newErrStatus("Config test not implemented").CmdStatus
Expand Down Expand Up @@ -372,5 +386,16 @@ func (n *Nginx) syncAgentConfigChange() {
n.isNAPEnabled = false
}

n.isConfUploadEnabled = isConfUploadEnabled(conf)

n.config = conf
}

func isConfUploadEnabled(conf *config.Config) bool {
for _, feature := range conf.Features {
if feature == config.FeatureNginxConfig {
return true
}
}
return false
}
36 changes: 33 additions & 3 deletions src/plugins/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func TestNginx_Config(t *testing.T) {

commandClient := tutils.GetMockCommandClient(test.config)

pluginUnderTest := NewNginx(commandClient, binary, env, &loadedConfig.Config{})
pluginUnderTest := NewNginx(commandClient, binary, env, &loadedConfig.Config{Features: []string{loadedConfig.FeatureNginxConfig}})
messagePipe := core.SetupMockMessagePipe(t, ctx, pluginUnderTest)

messagePipe.Process(core.NewMessage(core.CommNginxConfig, cmd))
Expand Down Expand Up @@ -297,7 +297,7 @@ func TestUploadConfigs(t *testing.T) {
cmdr := tutils.NewMockCommandClient()
cmdr.On("Upload", mock.Anything, mock.Anything).Return(nil)

pluginUnderTest := NewNginx(cmdr, binary, env, &loadedConfig.Config{})
pluginUnderTest := NewNginx(cmdr, binary, env, &loadedConfig.Config{Features: []string{loadedConfig.FeatureNginxConfig}})
messagePipe := core.SetupMockMessagePipe(t, context.Background(), pluginUnderTest)

pluginUnderTest.Init(messagePipe)
Expand All @@ -311,6 +311,36 @@ func TestUploadConfigs(t *testing.T) {
core.ValidateMessages(t, messagePipe, msgTopics)
}

func TestDisableUploadConfigs(t *testing.T) {
msgTopics := []string{
core.NginxPluginConfigured,
core.NginxInstancesFound,
core.DataplaneChanged,
core.NginxPluginConfigured,
core.NginxInstancesFound,
}

env := tutils.GetMockEnvWithProcess()

binary := tutils.NewMockNginxBinary()
binary.On("UpdateNginxDetailsFromProcesses", mock.Anything)
binary.On("GetNginxDetailsMapFromProcesses", mock.Anything).Return(tutils.GetDetailsMap())

cmdr := tutils.NewMockCommandClient()

pluginUnderTest := NewNginx(cmdr, binary, env, &loadedConfig.Config{})
messagePipe := core.SetupMockMessagePipe(t, context.Background(), pluginUnderTest)

pluginUnderTest.Init(messagePipe)
messagePipe.Process(core.NewMessage(core.DataplaneChanged, nil))
messagePipe.Run()

binary.AssertExpectations(t)
env.AssertExpectations(t)

core.ValidateMessages(t, messagePipe, msgTopics)
}

func TestNginxDetailProcUpdate(t *testing.T) {
foundMessage := false
env := tutils.GetMockEnvWithProcess()
Expand Down Expand Up @@ -371,7 +401,7 @@ func TestNginx_Process_NginxConfigUpload(t *testing.T) {

env := tutils.GetMockEnvWithProcess()

pluginUnderTest := NewNginx(cmdr, binary, env, &loadedConfig.Config{})
pluginUnderTest := NewNginx(cmdr, binary, env, &loadedConfig.Config{Features: []string{loadedConfig.FeatureNginxConfig}})
pluginUnderTest.Process(core.NewMessage(core.NginxConfigUpload, configDesc))

binary.AssertExpectations(t)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.