From b328ef42819476cbdfb9e2be7f325fee3bf61a24 Mon Sep 17 00:00:00 2001 From: Mirac Kara Date: Wed, 29 Jun 2022 14:09:47 -0500 Subject: [PATCH] Cleaned up merge conflicts/resolved test cases issues --- v3/newrelic/app_run.go | 7 ------- v3/newrelic/app_run_test.go | 22 ---------------------- v3/newrelic/config.go | 21 +++++++++++++++++---- v3/newrelic/config_options.go | 7 +++++++ v3/newrelic/config_test.go | 10 ++++++++++ 5 files changed, 34 insertions(+), 33 deletions(-) diff --git a/v3/newrelic/app_run.go b/v3/newrelic/app_run.go index 13a4c9b47..28973e7b8 100644 --- a/v3/newrelic/app_run.go +++ b/v3/newrelic/app_run.go @@ -223,13 +223,6 @@ func (run *appRun) LoggingConfig() (config loggingConfig) { func (run *appRun) MaxSpanEvents() int { return run.limit(run.Config.DistributedTracer.ReservoirLimit, run.ptrSpanEvents) } -func (run *appRun) MaxSamplesStored() int { - return run.limit(run.Config.CustomInsightsEvents.MaxSamplesStored, run.ptrCustomEvents) -} - -func (run *appRun) MaxCustomEvents() int { - return run.limit(run.Config.maxCustomEvents(), run.ptrCustomEvents) -} func (run *appRun) limit(dflt int, field func() *uint) int { if field() != nil { diff --git a/v3/newrelic/app_run_test.go b/v3/newrelic/app_run_test.go index d8430d45a..e5100422a 100644 --- a/v3/newrelic/app_run_test.go +++ b/v3/newrelic/app_run_test.go @@ -332,28 +332,6 @@ func TestConfigurableTxnEvents_withCollResponse(t *testing.T) { t.Error(fmt.Sprintf("Unexpected max number of txn events, expected %d but got %d", 15, result)) } } - -func TestConfigurableMaxCustomEventsDefault(t *testing.T) { - reply := internal.ConnectReplyDefaults() - expected := internal.MaxCustomEvents - cfg := config{Config: defaultConfig()} - result := newAppRun(cfg, reply).MaxCustomEvents() - if result != expected { - t.Errorf("Unexpected max number of custom events, expected %d but got %d", expected, result) - } -} - -func TestConfigurableMaxCustomEvents(t *testing.T) { - reply := internal.ConnectReplyDefaults() - expected := 1000 - cfg := config{Config: defaultConfig()} - cfg.CustomInsightsEvents.MaxSamplesStored = expected - result := newAppRun(cfg, reply).MaxCustomEvents() - if result != expected { - t.Errorf("Unexpected max number of custom events, expected %d but got %d", expected, result) - } -} - func TestConfigurableTxnEvents_notInCollResponse(t *testing.T) { reply, err := internal.UnmarshalConnectReply([]byte( `{"return_value":{ diff --git a/v3/newrelic/config.go b/v3/newrelic/config.go index 1abf253a7..ecf7ff45b 100644 --- a/v3/newrelic/config.go +++ b/v3/newrelic/config.go @@ -71,6 +71,8 @@ type Config struct { // custom analytics events. High security mode overrides this // setting. Enabled bool + // MaxSamplesStored sets the desired maximum custom event samples stored + MaxSamplesStored int } // TransactionEvents controls the behavior of transaction analytics @@ -408,6 +410,7 @@ func defaultConfig() Config { c.Enabled = true c.Labels = make(map[string]string) c.CustomInsightsEvents.Enabled = true + c.CustomInsightsEvents.MaxSamplesStored = internal.MaxCustomEvents c.TransactionEvents.Enabled = true c.TransactionEvents.Attributes.Enabled = true c.TransactionEvents.MaxSamplesStored = internal.MaxTxnEvents @@ -545,12 +548,22 @@ func (c Config) maxTxnEvents() int { return configured } -// maxTxnEvents returns the configured maximum number of Transaction Events if it has been configured +// maxCustomEvents returns the configured maximum number of Custom Events if it has been configured +// and is less than the default maximum; otherwise it returns the default max. +func (c Config) maxCustomEvents() int { + configured := c.CustomInsightsEvents.MaxSamplesStored + if configured < 0 || configured > internal.MaxCustomEvents { + return internal.MaxCustomEvents + } + return configured +} + +// maxLogEvents returns the configured maximum number of Log Events if it has been configured // and is less than the default maximum; otherwise it returns the default max. func (c Config) maxLogEvents() int { configured := c.ApplicationLogging.Forwarding.MaxSamplesStored - if configured < 0 || configured > internal.MaxTxnEvents { - return internal.MaxTxnEvents + if configured < 0 || configured > internal.MaxLogEvents { + return internal.MaxLogEvents } return configured } @@ -709,7 +722,7 @@ func configConnectJSONInternal(c Config, pid int, util *utilization.Data, e envi Util: util, SecurityPolicies: securityPolicies, Metadata: metadata, - EventData: internal.DefaultEventHarvestConfigWithDT(c.maxTxnEvents(), c.maxLogEvents(), c.DistributedTracer.ReservoirLimit, c.DistributedTracer.Enabled), + EventData: internal.DefaultEventHarvestConfigWithDT(c.maxTxnEvents(), c.maxLogEvents(), c.maxCustomEvents(), c.DistributedTracer.ReservoirLimit, c.DistributedTracer.Enabled), }}) } diff --git a/v3/newrelic/config_options.go b/v3/newrelic/config_options.go index 55ec64823..b5a4c7813 100644 --- a/v3/newrelic/config_options.go +++ b/v3/newrelic/config_options.go @@ -36,6 +36,13 @@ func ConfigDistributedTracerEnabled(enabled bool) ConfigOption { return func(cfg *Config) { cfg.DistributedTracer.Enabled = enabled } } +// ConfigCustomInsightsEventsMaxSamplesLimit alters the sample size allowing control +// of how many custom events are stored in an agent for a given harvest cycle. +// Alters the CustomInsightsEvents.MaxSamplesStored setting. +func ConfigCustomInsightsEventsMaxSamplesStored(limit int) ConfigOption { + return func(cfg *Config) { cfg.CustomInsightsEvents.MaxSamplesStored = limit } +} + // ConfigDistributedTracerReservoirLimit alters the sample reservoir size (maximum // number of span events to be collected) for distributed tracing instead of // using the built-in default. diff --git a/v3/newrelic/config_test.go b/v3/newrelic/config_test.go index 2d3d2cc17..2d77efe8a 100644 --- a/v3/newrelic/config_test.go +++ b/v3/newrelic/config_test.go @@ -803,3 +803,13 @@ func TestNewInternalConfig(t *testing.T) { t.Error(c.metadata) } } + +func TestConfigurableMaxCustomEvents(t *testing.T) { + expected := 1000 + cfg := config{Config: defaultConfig()} + cfg.CustomInsightsEvents.MaxSamplesStored = expected + result := cfg.maxCustomEvents() + if result != expected { + t.Errorf("Unexpected max number of custom events, expected %d but got %d", expected, result) + } +}