Skip to content

Commit

Permalink
Cleaned up merge conflicts/resolved test cases issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mirackara committed Jun 29, 2022
1 parent 504fef7 commit b328ef4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 33 deletions.
7 changes: 0 additions & 7 deletions v3/newrelic/app_run.go
Expand Up @@ -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 {
Expand Down
22 changes: 0 additions & 22 deletions v3/newrelic/app_run_test.go
Expand Up @@ -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":{
Expand Down
21 changes: 17 additions & 4 deletions v3/newrelic/config.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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),
}})
}

Expand Down
7 changes: 7 additions & 0 deletions v3/newrelic/config_options.go
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions v3/newrelic/config_test.go
Expand Up @@ -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)
}
}

0 comments on commit b328ef4

Please sign in to comment.