From 42f1ec25c26edf03c9f7c6ca5c0cde43fe64272e Mon Sep 17 00:00:00 2001 From: mirackara Date: Mon, 15 Aug 2022 12:44:53 -0500 Subject: [PATCH 1/7] Added Integration Tests to Harvest Cycle --- v3/internal/connect_reply.go | 24 ++++++ v3/newrelic/reservoir_limits_test.go | 118 +++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 v3/newrelic/reservoir_limits_test.go diff --git a/v3/internal/connect_reply.go b/v3/internal/connect_reply.go index 41bde1564..1805e86fc 100644 --- a/v3/internal/connect_reply.go +++ b/v3/internal/connect_reply.go @@ -255,6 +255,30 @@ func CreateFullTxnName(input string, reply *ConnectReply, isWeb bool) string { return reply.SegmentTerms.apply(afterNameRules) } +type RequestEventLimits struct { + CustomEvents int +} + +const ( + //CustomEventHarvestsPerMinute is the number of times per minute custom events are harvested + CustomEventHarvestsPerMinute = 5 +) + +func (r *ConnectReply) MockConnectReplyEventLimits(limits *RequestEventLimits) { + r.SetSampleEverything() + + r.EventData.Limits.CustomEvents = uintPtr(uint(limits.CustomEvents) / (60 / CustomEventHarvestsPerMinute)) + + // The mock server will be limited to a maximum of 100,000 events per minute + if limits.CustomEvents > 100000 { + r.EventData.Limits.CustomEvents = uintPtr(uint(100000) / (60 / CustomEventHarvestsPerMinute)) + } + + if limits.CustomEvents <= 0 { + r.EventData.Limits.CustomEvents = uintPtr(uint(0) / (60 / CustomEventHarvestsPerMinute)) + } +} + // SetSampleEverything is used for testing to ensure span events get saved. func (r *ConnectReply) SetSampleEverything() { // These constants are not large enough to sample everything forever, diff --git a/v3/newrelic/reservoir_limits_test.go b/v3/newrelic/reservoir_limits_test.go new file mode 100644 index 000000000..3c89498dc --- /dev/null +++ b/v3/newrelic/reservoir_limits_test.go @@ -0,0 +1,118 @@ +// Copyright 2020 New Relic Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package newrelic + +import ( + "testing" + + "github.com/newrelic/go-agent/v3/internal" +) + +// Check Default Value +func TestCustomLimitsBasic(t *testing.T) { + limit := internal.MaxCustomEvents + limits := &internal.RequestEventLimits{ + CustomEvents: limit, + } + // This function will mock a connect reply from the server + mockReplyFunction := func(reply *internal.ConnectReply) { + reply.MockConnectReplyEventLimits(limits) + } + testApp := newTestApp( + mockReplyFunction, + ConfigCustomInsightsEventsMaxSamplesStored(limit), + ) + + customEventRate := limit / (60 / internal.CustomEventHarvestsPerMinute) + + // Check if custom event queue capacity == rate + if customEventRate != testApp.app.testHarvest.CustomEvents.capacity() { + t.Errorf("Custom Events Rate is not equal to harvest: expected %d, actual %d", customEventRate, testApp.app.testHarvest.CustomEvents.capacity()) + } +} +func TestCustomEventLimitUserSet(t *testing.T) { + limit := 7000 + limits := &internal.RequestEventLimits{ + CustomEvents: limit, + } + mockReplyFunction := func(reply *internal.ConnectReply) { + reply.MockConnectReplyEventLimits(limits) + } + testApp := newTestApp( + mockReplyFunction, + ConfigCustomInsightsEventsMaxSamplesStored(limit), + ) + + customEventRate := limit / (60 / internal.CustomEventHarvestsPerMinute) + + if customEventRate != testApp.app.testHarvest.CustomEvents.capacity() { + t.Errorf("Custom Events Rate is not equal to harvest: expected %d, actual %d", customEventRate, testApp.app.testHarvest.CustomEvents.capacity()) + } +} + +func TestCustomLimitEnthusiast(t *testing.T) { + limit := 100000 + limits := &internal.RequestEventLimits{ + CustomEvents: limit, + } + // This function will mock a connect reply from the server + mockReplyFunction := func(reply *internal.ConnectReply) { + reply.MockConnectReplyEventLimits(limits) + } + testApp := newTestApp( + mockReplyFunction, + ConfigCustomInsightsEventsMaxSamplesStored(limit), + ) + + customEventRate := limit / (60 / internal.CustomEventHarvestsPerMinute) + + // Check if custom event queue capacity == rate + if customEventRate != testApp.app.testHarvest.CustomEvents.capacity() { + t.Errorf("Custom Events Rate is not equal to harvest: expected %d, actual %d", customEventRate, testApp.app.testHarvest.CustomEvents.capacity()) + } +} + +func TestCustomLimitsTypo(t *testing.T) { + limit := 1000000 + limits := &internal.RequestEventLimits{ + CustomEvents: limit, + } + // This function will mock a connect reply from the server + mockReplyFunction := func(reply *internal.ConnectReply) { + reply.MockConnectReplyEventLimits(limits) + } + testApp := newTestApp( + mockReplyFunction, + ConfigCustomInsightsEventsMaxSamplesStored(limit), + ) + + customEventRate := limit / (60 / internal.CustomEventHarvestsPerMinute) + + // Check if custom event queue capacity == rate + if customEventRate != testApp.app.testHarvest.CustomEvents.capacity() { + t.Errorf("Custom Events Rate is not equal to harvest: expected %d, actual %d", 8333, testApp.app.testHarvest.CustomEvents.capacity()) + } +} + +func TestCustomLimitZero(t *testing.T) { + limit := 0 + limits := &internal.RequestEventLimits{ + CustomEvents: limit, + } + // This function will mock a connect reply from the server + mockReplyFunction := func(reply *internal.ConnectReply) { + reply.MockConnectReplyEventLimits(limits) + } + testApp := newTestApp( + mockReplyFunction, + ConfigCustomInsightsEventsMaxSamplesStored(limit), + ) + + customEventRate := limit / (60 / internal.CustomEventHarvestsPerMinute) + + // Check if custom event queue capacity == rate + if customEventRate != testApp.app.testHarvest.CustomEvents.capacity() { + t.Errorf("Custom Events Rate is not equal to harvest: expected %d, actual %d", customEventRate, testApp.app.testHarvest.CustomEvents.capacity()) + } +} From 8d611c25f8cf6901863daa2768a3321e409ab442 Mon Sep 17 00:00:00 2001 From: mirackara Date: Mon, 15 Aug 2022 12:50:10 -0500 Subject: [PATCH 2/7] Fixed typo in test --- v3/newrelic/reservoir_limits_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v3/newrelic/reservoir_limits_test.go b/v3/newrelic/reservoir_limits_test.go index 3c89498dc..3c5f8f8e6 100644 --- a/v3/newrelic/reservoir_limits_test.go +++ b/v3/newrelic/reservoir_limits_test.go @@ -87,7 +87,7 @@ func TestCustomLimitsTypo(t *testing.T) { ConfigCustomInsightsEventsMaxSamplesStored(limit), ) - customEventRate := limit / (60 / internal.CustomEventHarvestsPerMinute) + customEventRate := 100000 / (60 / internal.CustomEventHarvestsPerMinute) // Check if custom event queue capacity == rate if customEventRate != testApp.app.testHarvest.CustomEvents.capacity() { From 8ed6e5dea6d933ec66dd043df2d6b8260fa6567b Mon Sep 17 00:00:00 2001 From: mirackara Date: Mon, 15 Aug 2022 12:56:22 -0500 Subject: [PATCH 3/7] Linter fixes --- v3/internal/connect_reply.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/v3/internal/connect_reply.go b/v3/internal/connect_reply.go index 1805e86fc..e915a0d7f 100644 --- a/v3/internal/connect_reply.go +++ b/v3/internal/connect_reply.go @@ -255,6 +255,7 @@ func CreateFullTxnName(input string, reply *ConnectReply, isWeb bool) string { return reply.SegmentTerms.apply(afterNameRules) } +// Limits set by reservior testing type RequestEventLimits struct { CustomEvents int } @@ -264,6 +265,7 @@ const ( CustomEventHarvestsPerMinute = 5 ) +// Sets up a mock connect reply to test event limits func (r *ConnectReply) MockConnectReplyEventLimits(limits *RequestEventLimits) { r.SetSampleEverything() From 70d6532f3fd1428ceeba1efcc891628ddff305c3 Mon Sep 17 00:00:00 2001 From: mirackara Date: Mon, 15 Aug 2022 13:23:17 -0500 Subject: [PATCH 4/7] Linter Fix --- v3/internal/connect_reply.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/v3/internal/connect_reply.go b/v3/internal/connect_reply.go index e915a0d7f..0987b0032 100644 --- a/v3/internal/connect_reply.go +++ b/v3/internal/connect_reply.go @@ -255,17 +255,17 @@ func CreateFullTxnName(input string, reply *ConnectReply, isWeb bool) string { return reply.SegmentTerms.apply(afterNameRules) } -// Limits set by reservior testing +// RequestEventLimits sets limits for reservior testing type RequestEventLimits struct { CustomEvents int } const ( - //CustomEventHarvestsPerMinute is the number of times per minute custom events are harvested + // CustomEventHarvestsPerMinute is the number of times per minute custom events are harvested CustomEventHarvestsPerMinute = 5 ) -// Sets up a mock connect reply to test event limits +// MockConnectReplyEventLimits sets up a mock connect reply to test event limits func (r *ConnectReply) MockConnectReplyEventLimits(limits *RequestEventLimits) { r.SetSampleEverything() From 9991a3ee66aad4643f12b691790a7a104ff5da4a Mon Sep 17 00:00:00 2001 From: mirackara Date: Mon, 15 Aug 2022 13:24:58 -0500 Subject: [PATCH 5/7] Removed broken v2 integration test --- .github/workflows/ci.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e98575f41..714f0e932 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -51,8 +51,6 @@ jobs: - go-version: 1.13.x dirs: _integrations/nrecho pin: github.com/labstack/echo@v3.3.10 - - go-version: 1.13.x - dirs: _integrations/nrgin/v1 - go-version: 1.13.x dirs: _integrations/nrgorilla/v1 - go-version: 1.13.x From bb76c82ea254a93ae47803422480086608fd6cbe Mon Sep 17 00:00:00 2001 From: mirackara Date: Tue, 16 Aug 2022 11:43:16 -0500 Subject: [PATCH 6/7] Custom Events Harvest Limit Increase --- v3/internal/limits.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v3/internal/limits.go b/v3/internal/limits.go index a7becf544..b0f8228ec 100644 --- a/v3/internal/limits.go +++ b/v3/internal/limits.go @@ -15,7 +15,7 @@ const ( MaxPayloadSizeInBytes = 1000 * 1000 // MaxCustomEvents is the maximum number of Transaction Events that can be captured // per 60-second harvest cycle - MaxCustomEvents = 10 * 1000 + MaxCustomEvents = 30 * 1000 // MaxLogEvents is the maximum number of Log Events that can be captured per // 60-second harvest cycle MaxLogEvents = 10 * 1000 From 9a02b177605b91a29c750766e0aab00b96d6716b Mon Sep 17 00:00:00 2001 From: Emilio Garcia Date: Fri, 21 Oct 2022 10:20:28 -0400 Subject: [PATCH 7/7] add config option to toggle customEvents --- .github/workflows/ci.yaml | 2 ++ v3/newrelic/config_options.go | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 714f0e932..e98575f41 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -51,6 +51,8 @@ jobs: - go-version: 1.13.x dirs: _integrations/nrecho pin: github.com/labstack/echo@v3.3.10 + - go-version: 1.13.x + dirs: _integrations/nrgin/v1 - go-version: 1.13.x dirs: _integrations/nrgorilla/v1 - go-version: 1.13.x diff --git a/v3/newrelic/config_options.go b/v3/newrelic/config_options.go index c0ae9b0b8..aea7d4026 100644 --- a/v3/newrelic/config_options.go +++ b/v3/newrelic/config_options.go @@ -47,6 +47,11 @@ func ConfigCustomInsightsEventsMaxSamplesStored(limit int) ConfigOption { return func(cfg *Config) { cfg.CustomInsightsEvents.MaxSamplesStored = limit } } +// ConfigCustomInsightsEventsEnabled enables or disables the collection of custom insight events. +func ConfigCustomInsightsEventsEnabled(enabled bool) ConfigOption { + return func(cfg *Config) { cfg.CustomInsightsEvents.Enabled = enabled } +} + // ConfigDistributedTracerReservoirLimit alters the sample reservoir size (maximum // number of span events to be collected) for distributed tracing instead of // using the built-in default.