From cc4808ec925de93d313e1fce9fe3c27052a87949 Mon Sep 17 00:00:00 2001 From: Mirac Kara Date: Mon, 27 Jun 2022 14:17:18 -0500 Subject: [PATCH 01/10] Added tests for custom events configuration --- app_run.go | 3 ++- v3/newrelic/app_run_test.go | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app_run.go b/app_run.go index ae0fb00dd..928ec026a 100644 --- a/app_run.go +++ b/app_run.go @@ -7,7 +7,6 @@ import ( "encoding/json" "strings" "time" - "github.com/newrelic/go-agent/internal" ) @@ -181,6 +180,8 @@ func (run *appRun) MaxErrorEvents() int { return run.limit(internal.MaxErrorEvents, run.ptrErrorEvents) } func (run *appRun) MaxSpanEvents() int { return run.limit(internal.MaxSpanEvents, run.ptrSpanEvents) } +func (run *appRun) MaxSamplesStored() int { return run.limit(internal.MaxSamplesStored, run.ptrCustomEvents) } + func (run *appRun) limit(dflt int, field func() *uint) int { if nil != field() { diff --git a/v3/newrelic/app_run_test.go b/v3/newrelic/app_run_test.go index 308128550..96766ae74 100644 --- a/v3/newrelic/app_run_test.go +++ b/v3/newrelic/app_run_test.go @@ -333,6 +333,27 @@ func TestConfigurableTxnEvents_withCollResponse(t *testing.T) { } } +func TestConfigurableMaxCustomEventsDefault(t *testing.T) { + reply := internal.ConnectReplyDefaults() + expected := 10000 + 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":{ From dba4a20ad499575ad1c604458194e8780176e503 Mon Sep 17 00:00:00 2001 From: Mirac Kara Date: Mon, 27 Jun 2022 14:37:38 -0500 Subject: [PATCH 02/10] Changed from static value to internal value --- v3/newrelic/app_run_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v3/newrelic/app_run_test.go b/v3/newrelic/app_run_test.go index 96766ae74..d8430d45a 100644 --- a/v3/newrelic/app_run_test.go +++ b/v3/newrelic/app_run_test.go @@ -335,7 +335,7 @@ func TestConfigurableTxnEvents_withCollResponse(t *testing.T) { func TestConfigurableMaxCustomEventsDefault(t *testing.T) { reply := internal.ConnectReplyDefaults() - expected := 10000 + expected := internal.MaxCustomEvents cfg := config{Config: defaultConfig()} result := newAppRun(cfg, reply).MaxCustomEvents() if result != expected { From defc96d3d0a16491d72292a2aa5ff0eff856df29 Mon Sep 17 00:00:00 2001 From: Mirac Kara Date: Wed, 29 Jun 2022 11:34:06 -0500 Subject: [PATCH 03/10] Placed max samples stored function in correct file --- app_run.go | 1 - v3/newrelic/app_run.go | 7 +++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app_run.go b/app_run.go index 928ec026a..6e9cfd4fb 100644 --- a/app_run.go +++ b/app_run.go @@ -180,7 +180,6 @@ func (run *appRun) MaxErrorEvents() int { return run.limit(internal.MaxErrorEvents, run.ptrErrorEvents) } func (run *appRun) MaxSpanEvents() int { return run.limit(internal.MaxSpanEvents, run.ptrSpanEvents) } -func (run *appRun) MaxSamplesStored() int { return run.limit(internal.MaxSamplesStored, run.ptrCustomEvents) } func (run *appRun) limit(dflt int, field func() *uint) int { diff --git a/v3/newrelic/app_run.go b/v3/newrelic/app_run.go index 28973e7b8..13a4c9b47 100644 --- a/v3/newrelic/app_run.go +++ b/v3/newrelic/app_run.go @@ -223,6 +223,13 @@ 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 { From aedd70f49d05fb92a40507b32ab67ab556b60b5c Mon Sep 17 00:00:00 2001 From: Mirac Kara Date: Wed, 29 Jun 2022 11:42:47 -0500 Subject: [PATCH 04/10] changed value of max samples stored in test files --- v3/newrelic/config_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/v3/newrelic/config_test.go b/v3/newrelic/config_test.go index 6b159976a..2d3d2cc17 100644 --- a/v3/newrelic/config_test.go +++ b/v3/newrelic/config_test.go @@ -145,7 +145,10 @@ func TestCopyConfigReferenceFieldsPresent(t *testing.T) { "Enabled":true }, "CrossApplicationTracer":{"Enabled":false}, - "CustomInsightsEvents":{"Enabled":true}, + "CustomInsightsEvents":{ + "Enabled":true, + "MaxSamplesStored":10000 + }, "DatastoreTracer":{ "DatabaseNameReporting":{"Enabled":true}, "InstanceReporting":{"Enabled":true}, @@ -333,7 +336,10 @@ func TestCopyConfigReferenceFieldsAbsent(t *testing.T) { "Enabled":true }, "CrossApplicationTracer":{"Enabled":false}, - "CustomInsightsEvents":{"Enabled":true}, + "CustomInsightsEvents":{ + "Enabled":true, + "MaxSamplesStored":10000 + }, "DatastoreTracer":{ "DatabaseNameReporting":{"Enabled":true}, "InstanceReporting":{"Enabled":true}, From 504fef76e3a9c35ac282c7d352a1491047461939 Mon Sep 17 00:00:00 2001 From: Mirac Kara Date: Wed, 29 Jun 2022 11:51:11 -0500 Subject: [PATCH 05/10] Added max custom events parameter --- v3/internal/connect_reply.go | 8 ++++---- v3/internal/connect_reply_test.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/v3/internal/connect_reply.go b/v3/internal/connect_reply.go index 342c140d5..caea20ccf 100644 --- a/v3/internal/connect_reply.go +++ b/v3/internal/connect_reply.go @@ -137,11 +137,11 @@ func (r *ConnectReply) ConfigurablePeriod() time.Duration { func uintPtr(x uint) *uint { return &x } // DefaultEventHarvestConfig provides faster event harvest defaults. -func DefaultEventHarvestConfig(maxTxnEvents, maxLogEvents int) EventHarvestConfig { +func DefaultEventHarvestConfig(maxTxnEvents, maxLogEvents, maxCustomEvents int) EventHarvestConfig { cfg := EventHarvestConfig{} cfg.ReportPeriodMs = DefaultConfigurableEventHarvestMs cfg.Limits.TxnEvents = uintPtr(uint(maxTxnEvents)) - cfg.Limits.CustomEvents = uintPtr(uint(MaxCustomEvents)) + cfg.Limits.CustomEvents = uintPtr(uint(maxCustomEvents)) cfg.Limits.LogEvents = uintPtr(uint(maxLogEvents)) cfg.Limits.ErrorEvents = uintPtr(uint(MaxErrorEvents)) return cfg @@ -149,8 +149,8 @@ func DefaultEventHarvestConfig(maxTxnEvents, maxLogEvents int) EventHarvestConfi // DefaultEventHarvestConfigWithDT is an extended version of DefaultEventHarvestConfig, // with the addition that it takes into account distributed tracer span event harvest limits. -func DefaultEventHarvestConfigWithDT(maxTxnEvents, maxLogEvents, spanEventLimit int, dtEnabled bool) EventHarvestConfig { - cfg := DefaultEventHarvestConfig(maxTxnEvents, maxLogEvents) +func DefaultEventHarvestConfigWithDT(maxTxnEvents, maxLogEvents, maxCustomEvents, spanEventLimit int, dtEnabled bool) EventHarvestConfig { + cfg := DefaultEventHarvestConfig(maxTxnEvents, maxLogEvents, maxCustomEvents) if dtEnabled { cfg.Limits.SpanEvents = uintPtr(uint(spanEventLimit)) } diff --git a/v3/internal/connect_reply_test.go b/v3/internal/connect_reply_test.go index eb9711354..d21366baf 100644 --- a/v3/internal/connect_reply_test.go +++ b/v3/internal/connect_reply_test.go @@ -173,7 +173,7 @@ func TestNegativeHarvestLimits(t *testing.T) { } func TestDefaultEventHarvestConfigJSON(t *testing.T) { - js, err := json.Marshal(DefaultEventHarvestConfig(MaxTxnEvents, MaxLogEvents)) + js, err := json.Marshal(DefaultEventHarvestConfig(MaxTxnEvents, MaxLogEvents, MaxCustomEvents)) if err != nil { t.Error(err) } From b328ef42819476cbdfb9e2be7f325fee3bf61a24 Mon Sep 17 00:00:00 2001 From: Mirac Kara Date: Wed, 29 Jun 2022 14:09:47 -0500 Subject: [PATCH 06/10] 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) + } +} From 4dcb7f01139cf7a0176fc78ce4ca3134e71498f3 Mon Sep 17 00:00:00 2001 From: Mirac Kara <55501260+mirackara@users.noreply.github.com> Date: Wed, 29 Jun 2022 14:12:27 -0500 Subject: [PATCH 07/10] whitespace fixing --- app_run.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_run.go b/app_run.go index 6e9cfd4fb..9d781ab54 100644 --- a/app_run.go +++ b/app_run.go @@ -7,6 +7,7 @@ import ( "encoding/json" "strings" "time" + "github.com/newrelic/go-agent/internal" ) @@ -181,7 +182,6 @@ func (run *appRun) MaxErrorEvents() int { } func (run *appRun) MaxSpanEvents() int { return run.limit(internal.MaxSpanEvents, run.ptrSpanEvents) } - func (run *appRun) limit(dflt int, field func() *uint) int { if nil != field() { return int(*field()) From ae21f84b1d45df78c2eb4bb599845c6c3d2c4656 Mon Sep 17 00:00:00 2001 From: Mirac Kara <55501260+mirackara@users.noreply.github.com> Date: Wed, 29 Jun 2022 14:12:53 -0500 Subject: [PATCH 08/10] Update app_run.go --- app_run.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_run.go b/app_run.go index 9d781ab54..ae0fb00dd 100644 --- a/app_run.go +++ b/app_run.go @@ -7,7 +7,7 @@ import ( "encoding/json" "strings" "time" - + "github.com/newrelic/go-agent/internal" ) From a3a6c6f2d91cf6bfcdfb558d372ebbe9fd1d72f5 Mon Sep 17 00:00:00 2001 From: Mirac Kara <55501260+mirackara@users.noreply.github.com> Date: Wed, 29 Jun 2022 14:13:44 -0500 Subject: [PATCH 09/10] Update app_run_test.go --- v3/newrelic/app_run_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/v3/newrelic/app_run_test.go b/v3/newrelic/app_run_test.go index e5100422a..308128550 100644 --- a/v3/newrelic/app_run_test.go +++ b/v3/newrelic/app_run_test.go @@ -332,6 +332,7 @@ func TestConfigurableTxnEvents_withCollResponse(t *testing.T) { t.Error(fmt.Sprintf("Unexpected max number of txn events, expected %d but got %d", 15, result)) } } + func TestConfigurableTxnEvents_notInCollResponse(t *testing.T) { reply, err := internal.UnmarshalConnectReply([]byte( `{"return_value":{ From f5580d0b7711e75fab213a9dd242358bc27cc73a Mon Sep 17 00:00:00 2001 From: Mirac Kara <55501260+mirackara@users.noreply.github.com> Date: Wed, 29 Jun 2022 14:49:46 -0500 Subject: [PATCH 10/10] Update config_options.go --- v3/newrelic/config_options.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v3/newrelic/config_options.go b/v3/newrelic/config_options.go index b5a4c7813..dbcb666a3 100644 --- a/v3/newrelic/config_options.go +++ b/v3/newrelic/config_options.go @@ -36,7 +36,7 @@ func ConfigDistributedTracerEnabled(enabled bool) ConfigOption { return func(cfg *Config) { cfg.DistributedTracer.Enabled = enabled } } -// ConfigCustomInsightsEventsMaxSamplesLimit alters the sample size allowing control +// ConfigCustomInsightsEventsMaxSamplesStored 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 {