From 038517373aae20aa409e0aa37d10f122807d4d8f Mon Sep 17 00:00:00 2001 From: Mirac Kara Date: Fri, 24 Jun 2022 15:12:34 -0400 Subject: [PATCH 1/3] Added Max Samples per Custom Events Setting --- internal/harvest.go | 3 +++ v3/internal/connect_reply.go | 8 ++++---- v3/newrelic/app_run.go | 8 ++++---- v3/newrelic/config.go | 16 ++++++++++++++-- v3/newrelic/config_options.go | 8 ++++++++ v3/newrelic/config_test.go | 5 ++++- 6 files changed, 37 insertions(+), 11 deletions(-) diff --git a/internal/harvest.go b/internal/harvest.go index bfdb3b104..e9618f4b8 100644 --- a/internal/harvest.go +++ b/internal/harvest.go @@ -181,8 +181,11 @@ type HarvestConfigurer interface { MaxSpanEvents() int // MaxCustomEvents returns the maximum number of Custom Events that should be reported per period MaxCustomEvents() int + // MaxSamplesStored returns the maximum number of Custom Event Samples stored in a Custom Event + MaxSamplesStored() int // MaxErrorEvents returns the maximum number of Error Events that should be reported per period MaxErrorEvents() int + MaxTxnEventer } diff --git a/v3/internal/connect_reply.go b/v3/internal/connect_reply.go index 84b5d00b6..820518350 100644 --- a/v3/internal/connect_reply.go +++ b/v3/internal/connect_reply.go @@ -136,19 +136,19 @@ func (r *ConnectReply) ConfigurablePeriod() time.Duration { func uintPtr(x uint) *uint { return &x } // DefaultEventHarvestConfig provides faster event harvest defaults. -func DefaultEventHarvestConfig(maxTxnEvents int) EventHarvestConfig { +func DefaultEventHarvestConfig(maxTxnEvents int, 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.ErrorEvents = uintPtr(uint(MaxErrorEvents)) return cfg } // DefaultEventHarvestConfigWithDT is an extended version of DefaultEventHarvestConfig, // with the addition that it takes into account distributed tracer span event harvest limits. -func DefaultEventHarvestConfigWithDT(maxTxnEvents int, dtEnabled bool, spanEventLimit int) EventHarvestConfig { - cfg := DefaultEventHarvestConfig(maxTxnEvents) +func DefaultEventHarvestConfigWithDT(maxTxnEvents int, dtEnabled bool, spanEventLimit int, maxCustomEvents int) EventHarvestConfig { + cfg := DefaultEventHarvestConfig(maxTxnEvents,maxCustomEvents) if dtEnabled { cfg.Limits.SpanEvents = uintPtr(uint(spanEventLimit)) } diff --git a/v3/newrelic/app_run.go b/v3/newrelic/app_run.go index 3df42ea55..c58208e4f 100644 --- a/v3/newrelic/app_run.go +++ b/v3/newrelic/app_run.go @@ -7,7 +7,6 @@ import ( "encoding/json" "strings" "time" - "github.com/newrelic/go-agent/v3/internal" ) @@ -191,9 +190,7 @@ func (run *appRun) ptrErrorEvents() *uint { return run.Reply.EventData.Limits.E func (run *appRun) ptrSpanEvents() *uint { return run.Reply.EventData.Limits.SpanEvents } func (run *appRun) MaxTxnEvents() int { return run.limit(run.Config.maxTxnEvents(), run.ptrTxnEvents) } -func (run *appRun) MaxCustomEvents() int { - return run.limit(internal.MaxCustomEvents, run.ptrCustomEvents) -} + func (run *appRun) MaxErrorEvents() int { return run.limit(internal.MaxErrorEvents, run.ptrErrorEvents) } @@ -204,6 +201,9 @@ func (run *appRun) MaxErrorEvents() int { func (run *appRun) MaxSpanEvents() int { return run.limit(run.Config.DistributedTracer.ReservoirLimit, run.ptrSpanEvents) } +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/config.go b/v3/newrelic/config.go index fe0f7c7f7..9c7c9f49a 100644 --- a/v3/newrelic/config.go +++ b/v3/newrelic/config.go @@ -71,8 +71,9 @@ type Config struct { // custom analytics events. High security mode overrides this // setting. Enabled bool + // MaxSamplesStored sets the desired maximum custom events stored + MaxSamplesStored int } - // TransactionEvents controls the behavior of transaction analytics // events. TransactionEvents struct { @@ -382,6 +383,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 @@ -503,6 +505,16 @@ func (c Config) validateTraceObserverConfig() (*observerURL, error) { }, nil } +// 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.MaxTxnEvents + } + return configured +} + // maxTxnEvents returns the configured maximum number of Transaction Events if it has been configured // and is less than the default maximum; otherwise it returns the default max. func (c Config) maxTxnEvents() int { @@ -667,7 +679,7 @@ func configConnectJSONInternal(c Config, pid int, util *utilization.Data, e envi Util: util, SecurityPolicies: securityPolicies, Metadata: metadata, - EventData: internal.DefaultEventHarvestConfigWithDT(c.maxTxnEvents(), c.DistributedTracer.Enabled, c.DistributedTracer.ReservoirLimit), + EventData: internal.DefaultEventHarvestConfigWithDT(c.maxTxnEvents(), c.DistributedTracer.Enabled, c.DistributedTracer.ReservoirLimit, c.maxCustomEvents()), }}) } diff --git a/v3/newrelic/config_options.go b/v3/newrelic/config_options.go index 3ba323924..2ce99c08c 100644 --- a/v3/newrelic/config_options.go +++ b/v3/newrelic/config_options.go @@ -36,6 +36,14 @@ 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 b6df1731b..c83972a48 100644 --- a/v3/newrelic/config_test.go +++ b/v3/newrelic/config_test.go @@ -135,7 +135,10 @@ func TestCopyConfigReferenceFieldsPresent(t *testing.T) { "Enabled":true }, "CrossApplicationTracer":{"Enabled":false}, - "CustomInsightsEvents":{"Enabled":true}, + "CustomInsightsEvents":{ + "Enabled":true, + "MaxSamplesStored":1000 + }, "DatastoreTracer":{ "DatabaseNameReporting":{"Enabled":true}, "InstanceReporting":{"Enabled":true}, From e59734ce2d02714688b6cf6da3fe090d7297a7ee Mon Sep 17 00:00:00 2001 From: Mirac Kara Date: Mon, 27 Jun 2022 13:54:16 -0500 Subject: [PATCH 2/3] Changed naming conventions --- v3/integrations/nrgrpc/nrgrpc_server.go | 18 +++++++-------- v3/integrations/nrgrpc/nrgrpc_server_test.go | 24 ++++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/v3/integrations/nrgrpc/nrgrpc_server.go b/v3/integrations/nrgrpc/nrgrpc_server.go index fe5954cb2..6b28c84f0 100644 --- a/v3/integrations/nrgrpc/nrgrpc_server.go +++ b/v3/integrations/nrgrpc/nrgrpc_server.go @@ -198,9 +198,9 @@ func ErrorInterceptorStatusHandler(ctx context.Context, txn *newrelic.Transactio Message: s.Message(), Class: "gRPC Status: " + s.Code().String(), }) - txn.AddAttribute("GrpcStatusLevel", "error") - txn.AddAttribute("GrpcStatusMessage", s.Message()) - txn.AddAttribute("GrpcStatusCode", s.Code().String()) + txn.AddAttribute("grpcStatusLevel", "error") + txn.AddAttribute("grpcStatusMessage", s.Message()) + txn.AddAttribute("grpcStatusCode", s.Code().String()) } // @@ -212,9 +212,9 @@ func ErrorInterceptorStatusHandler(ctx context.Context, txn *newrelic.Transactio // func WarningInterceptorStatusHandler(ctx context.Context, txn *newrelic.Transaction, s *status.Status) { txn.SetWebResponse(nil).WriteHeader(int(codes.OK)) - txn.AddAttribute("GrpcStatusLevel", "warning") - txn.AddAttribute("GrpcStatusMessage", s.Message()) - txn.AddAttribute("GrpcStatusCode", s.Code().String()) + txn.AddAttribute("grpcStatusLevel", "warning") + txn.AddAttribute("grpcStatusMessage", s.Message()) + txn.AddAttribute("grpcStatusCode", s.Code().String()) } // @@ -226,9 +226,9 @@ func WarningInterceptorStatusHandler(ctx context.Context, txn *newrelic.Transact // func InfoInterceptorStatusHandler(ctx context.Context, txn *newrelic.Transaction, s *status.Status) { txn.SetWebResponse(nil).WriteHeader(int(codes.OK)) - txn.AddAttribute("GrpcStatusLevel", "info") - txn.AddAttribute("GrpcStatusMessage", s.Message()) - txn.AddAttribute("GrpcStatusCode", s.Code().String()) + txn.AddAttribute("grpcStatusLevel", "info") + txn.AddAttribute("grpcStatusMessage", s.Message()) + txn.AddAttribute("grpcStatusCode", s.Code().String()) } // diff --git a/v3/integrations/nrgrpc/nrgrpc_server_test.go b/v3/integrations/nrgrpc/nrgrpc_server_test.go index f50b16a5e..103379b61 100644 --- a/v3/integrations/nrgrpc/nrgrpc_server_test.go +++ b/v3/integrations/nrgrpc/nrgrpc_server_test.go @@ -182,9 +182,9 @@ func TestUnaryServerInterceptorError(t *testing.T) { "traceId": internal.MatchAnything, }, UserAttributes: map[string]interface{}{ - "GrpcStatusMessage": "oooooops!", - "GrpcStatusCode": "DataLoss", - "GrpcStatusLevel": "error", + "grpcStatusMessage": "oooooops!", + "grpcStatusCode": "DataLoss", + "grpcStatusLevel": "error", }, AgentAttributes: map[string]interface{}{ "httpResponseCode": 0, @@ -215,9 +215,9 @@ func TestUnaryServerInterceptorError(t *testing.T) { "request.uri": "grpc://bufnet/TestApplication/DoUnaryUnaryError", }, UserAttributes: map[string]interface{}{ - "GrpcStatusMessage": "oooooops!", - "GrpcStatusCode": "DataLoss", - "GrpcStatusLevel": "error", + "grpcStatusMessage": "oooooops!", + "grpcStatusCode": "DataLoss", + "grpcStatusLevel": "error", }, }}) } @@ -592,9 +592,9 @@ func TestStreamServerInterceptorError(t *testing.T) { "traceId": internal.MatchAnything, }, UserAttributes: map[string]interface{}{ - "GrpcStatusLevel": "error", - "GrpcStatusMessage": "oooooops!", - "GrpcStatusCode": "DataLoss", + "grpcStatusLevel": "error", + "grpcStatusMessage": "oooooops!", + "grpcStatusCode": "DataLoss", }, AgentAttributes: map[string]interface{}{ "httpResponseCode": 0, @@ -625,9 +625,9 @@ func TestStreamServerInterceptorError(t *testing.T) { "request.uri": "grpc://bufnet/TestApplication/DoUnaryStreamError", }, UserAttributes: map[string]interface{}{ - "GrpcStatusLevel": "error", - "GrpcStatusMessage": "oooooops!", - "GrpcStatusCode": "DataLoss", + "grpcStatusLevel": "error", + "grpcStatusMessage": "oooooops!", + "grpcStatusCode": "DataLoss", }, }}) } From fd44db5bfaba61f32d5225e65311250e5e29f64b Mon Sep 17 00:00:00 2001 From: Mirac Kara Date: Mon, 27 Jun 2022 13:57:32 -0500 Subject: [PATCH 3/3] Revert "Added Max Samples per Custom Events Setting" This reverts commit 038517373aae20aa409e0aa37d10f122807d4d8f. --- internal/harvest.go | 3 --- v3/internal/connect_reply.go | 8 ++++---- v3/newrelic/app_run.go | 8 ++++---- v3/newrelic/config.go | 16 ++-------------- v3/newrelic/config_options.go | 8 -------- v3/newrelic/config_test.go | 5 +---- 6 files changed, 11 insertions(+), 37 deletions(-) diff --git a/internal/harvest.go b/internal/harvest.go index e9618f4b8..bfdb3b104 100644 --- a/internal/harvest.go +++ b/internal/harvest.go @@ -181,11 +181,8 @@ type HarvestConfigurer interface { MaxSpanEvents() int // MaxCustomEvents returns the maximum number of Custom Events that should be reported per period MaxCustomEvents() int - // MaxSamplesStored returns the maximum number of Custom Event Samples stored in a Custom Event - MaxSamplesStored() int // MaxErrorEvents returns the maximum number of Error Events that should be reported per period MaxErrorEvents() int - MaxTxnEventer } diff --git a/v3/internal/connect_reply.go b/v3/internal/connect_reply.go index 820518350..84b5d00b6 100644 --- a/v3/internal/connect_reply.go +++ b/v3/internal/connect_reply.go @@ -136,19 +136,19 @@ func (r *ConnectReply) ConfigurablePeriod() time.Duration { func uintPtr(x uint) *uint { return &x } // DefaultEventHarvestConfig provides faster event harvest defaults. -func DefaultEventHarvestConfig(maxTxnEvents int, maxCustomEvents int) EventHarvestConfig { +func DefaultEventHarvestConfig(maxTxnEvents 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.ErrorEvents = uintPtr(uint(MaxErrorEvents)) return cfg } // DefaultEventHarvestConfigWithDT is an extended version of DefaultEventHarvestConfig, // with the addition that it takes into account distributed tracer span event harvest limits. -func DefaultEventHarvestConfigWithDT(maxTxnEvents int, dtEnabled bool, spanEventLimit int, maxCustomEvents int) EventHarvestConfig { - cfg := DefaultEventHarvestConfig(maxTxnEvents,maxCustomEvents) +func DefaultEventHarvestConfigWithDT(maxTxnEvents int, dtEnabled bool, spanEventLimit int) EventHarvestConfig { + cfg := DefaultEventHarvestConfig(maxTxnEvents) if dtEnabled { cfg.Limits.SpanEvents = uintPtr(uint(spanEventLimit)) } diff --git a/v3/newrelic/app_run.go b/v3/newrelic/app_run.go index c58208e4f..3df42ea55 100644 --- a/v3/newrelic/app_run.go +++ b/v3/newrelic/app_run.go @@ -7,6 +7,7 @@ import ( "encoding/json" "strings" "time" + "github.com/newrelic/go-agent/v3/internal" ) @@ -190,7 +191,9 @@ func (run *appRun) ptrErrorEvents() *uint { return run.Reply.EventData.Limits.E func (run *appRun) ptrSpanEvents() *uint { return run.Reply.EventData.Limits.SpanEvents } func (run *appRun) MaxTxnEvents() int { return run.limit(run.Config.maxTxnEvents(), run.ptrTxnEvents) } - +func (run *appRun) MaxCustomEvents() int { + return run.limit(internal.MaxCustomEvents, run.ptrCustomEvents) +} func (run *appRun) MaxErrorEvents() int { return run.limit(internal.MaxErrorEvents, run.ptrErrorEvents) } @@ -201,9 +204,6 @@ func (run *appRun) MaxErrorEvents() int { func (run *appRun) MaxSpanEvents() int { return run.limit(run.Config.DistributedTracer.ReservoirLimit, run.ptrSpanEvents) } -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/config.go b/v3/newrelic/config.go index 9c7c9f49a..fe0f7c7f7 100644 --- a/v3/newrelic/config.go +++ b/v3/newrelic/config.go @@ -71,9 +71,8 @@ type Config struct { // custom analytics events. High security mode overrides this // setting. Enabled bool - // MaxSamplesStored sets the desired maximum custom events stored - MaxSamplesStored int } + // TransactionEvents controls the behavior of transaction analytics // events. TransactionEvents struct { @@ -383,7 +382,6 @@ 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 @@ -505,16 +503,6 @@ func (c Config) validateTraceObserverConfig() (*observerURL, error) { }, nil } -// 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.MaxTxnEvents - } - return configured -} - // maxTxnEvents returns the configured maximum number of Transaction Events if it has been configured // and is less than the default maximum; otherwise it returns the default max. func (c Config) maxTxnEvents() int { @@ -679,7 +667,7 @@ func configConnectJSONInternal(c Config, pid int, util *utilization.Data, e envi Util: util, SecurityPolicies: securityPolicies, Metadata: metadata, - EventData: internal.DefaultEventHarvestConfigWithDT(c.maxTxnEvents(), c.DistributedTracer.Enabled, c.DistributedTracer.ReservoirLimit, c.maxCustomEvents()), + EventData: internal.DefaultEventHarvestConfigWithDT(c.maxTxnEvents(), c.DistributedTracer.Enabled, c.DistributedTracer.ReservoirLimit), }}) } diff --git a/v3/newrelic/config_options.go b/v3/newrelic/config_options.go index 2ce99c08c..3ba323924 100644 --- a/v3/newrelic/config_options.go +++ b/v3/newrelic/config_options.go @@ -36,14 +36,6 @@ 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 c83972a48..b6df1731b 100644 --- a/v3/newrelic/config_test.go +++ b/v3/newrelic/config_test.go @@ -135,10 +135,7 @@ func TestCopyConfigReferenceFieldsPresent(t *testing.T) { "Enabled":true }, "CrossApplicationTracer":{"Enabled":false}, - "CustomInsightsEvents":{ - "Enabled":true, - "MaxSamplesStored":1000 - }, + "CustomInsightsEvents":{"Enabled":true}, "DatastoreTracer":{ "DatabaseNameReporting":{"Enabled":true}, "InstanceReporting":{"Enabled":true},