Skip to content

Commit

Permalink
Fixed bug where max event buffer size didn't maintain (#201)
Browse files Browse the repository at this point in the history
* Fixed bug where max event buffer size didn't maintain through background foregrounding

* Tests in new event system test not old
  • Loading branch information
mbruin-NR authored Feb 6, 2024
1 parent b15f0ff commit 39d5adb
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Agent/Analytics/NRMAAnalytics.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

@interface NRMAAnalytics : NSObject <NRMAHarvestAware>
- (void) setMaxEventBufferTime:(unsigned int) seconds;

- (NSUInteger) getMaxEventBufferSize;
- (void) setMaxEventBufferSize:(unsigned int) size;
- (NSUInteger) getMaxEventBufferTime;

- (id) initWithSessionStartTimeMS:(long long) sessionStartTime;

Expand Down
8 changes: 8 additions & 0 deletions Agent/Analytics/NRMAAnalytics.mm
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,30 @@ @implementation NRMAAnalytics
}

- (void) setMaxEventBufferSize:(unsigned int) size {
[NRMAAgentConfiguration setMaxEventBufferSize:size];
if([NRMAFlags shouldEnableNewEventSystem]){
[_eventManager setMaxEventBufferSize:size];
}
else {
_analyticsController->setMaxEventBufferSize(size);
}
}
- (NSUInteger) getMaxEventBufferSize {
return [_eventManager getMaxEventBufferSize];
}
- (void) setMaxEventBufferTime:(unsigned int)seconds
{
[NRMAAgentConfiguration setMaxEventBufferTime:seconds];
if([NRMAFlags shouldEnableNewEventSystem]){
[_eventManager setMaxEventBufferTimeInSeconds:seconds];
}
else {
_analyticsController->setMaxEventBufferTime(seconds);
}
}
- (NSUInteger) getMaxEventBufferTime {
return [_eventManager getMaxEventBufferTimeInSeconds];
}

- (id) initWithSessionStartTimeMS:(long long) sessionStartTime {
self = [super init];
Expand Down
2 changes: 2 additions & 0 deletions Agent/Analytics/NRMAEventManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ NS_ASSUME_NONNULL_BEGIN

- (instancetype)initWithPersistentStore:(PersistentEventStore *)store;
- (void)setMaxEventBufferSize:(NSUInteger)size;
- (NSUInteger)getMaxEventBufferSize;
- (void)setMaxEventBufferTimeInSeconds:(NSUInteger)seconds;
- (NSUInteger)getMaxEventBufferTimeInSeconds;
- (BOOL)didReachMaxQueueTime:(NSTimeInterval)currentTimeMilliseconds;
- (BOOL)addEvent:(id<NRMAAnalyticEventProtocol>)event;
- (void)empty;
Expand Down
10 changes: 9 additions & 1 deletion Agent/Analytics/NRMAEventManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ - (nonnull instancetype)initWithPersistentStore:(PersistentEventStore *)store {
self = [super init];
if (self) {
events = [[NSMutableArray<NRMAAnalyticEventProtocol> alloc] init];
maxBufferSize = kDefaultBufferSize;
maxBufferSize = [NRMAAgentConfiguration getMaxEventBufferSize];
maxBufferTimeSeconds = [NRMAAgentConfiguration getMaxEventBufferTime];
totalAttemptedInserts = 0;
oldestEventTimestamp = 0;
Expand All @@ -50,6 +50,10 @@ - (void)setMaxEventBufferSize:(NSUInteger)size {
maxBufferSize = size;
}

- (NSUInteger)getMaxEventBufferSize {
return maxBufferSize;
}

- (void)setMaxEventBufferTimeInSeconds:(NSUInteger)seconds {
if(seconds < kMinBufferTimeSeconds) {
NRLOG_ERROR(@"Buffer Time cannot be less than %lu Seconds", (unsigned long)kMinBufferTimeSeconds);
Expand All @@ -62,6 +66,10 @@ - (void)setMaxEventBufferTimeInSeconds:(NSUInteger)seconds {
maxBufferTimeSeconds = seconds;
}

- (NSUInteger)getMaxEventBufferTimeInSeconds {
return maxBufferTimeSeconds;
}

- (BOOL)didReachMaxQueueTime:(NSTimeInterval)currentTimeMilliseconds {
if(oldestEventTimestamp == 0) {
return false;
Expand Down
2 changes: 2 additions & 0 deletions Agent/Harvester/DataStore/NRMAAgentConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@
+ (void) setMaxEventBufferTime:(NSUInteger)seconds;
+ (NSUInteger) getMaxEventBufferTime;

+ (void) setMaxEventBufferSize:(NSUInteger)size;
+ (NSUInteger) getMaxEventBufferSize;
@end
8 changes: 8 additions & 0 deletions Agent/Harvester/DataStore/NRMAAgentConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

// Default max event buffer time is 10 minutes (600 seconds).
static NSUInteger __NRMA__maxEventBufferTime = 600;
static NSUInteger __NRMA__maxEventBufferSize = 1000;

@implementation NRMAAgentConfiguration

Expand Down Expand Up @@ -49,6 +50,13 @@ + (NSUInteger) getMaxEventBufferTime {
return __NRMA__maxEventBufferTime;
}

+ (void) setMaxEventBufferSize:(NSUInteger)size {
__NRMA__maxEventBufferSize = size;
}
+ (NSUInteger) getMaxEventBufferSize {
return __NRMA__maxEventBufferSize;
}

- (id) initWithAppToken:(NRMAAppToken*)token
collectorAddress:(NSString*)collectorHost
crashAddress:(NSString*)crashHost {
Expand Down
2 changes: 0 additions & 2 deletions Agent/Public/NewRelic.m
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,6 @@ + (BOOL) recordBreadcrumb:(NSString* __nonnull)name
* harvest cycle.
*/
+ (void) setMaxEventBufferTime:(unsigned int)seconds {
[NRMAAgentConfiguration setMaxEventBufferTime:seconds];

[[NewRelicAgentInternal sharedInstance].analyticsController setMaxEventBufferTime:seconds];
}
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,6 @@ - (void) testJSONEscapeCharacters {

}



- (void) testDuplicateStore {
//todo: reenable test (disabled for beta 1, no persistent store)
// NRMAAnalytics* analytics = [[NRMAAnalytics alloc] initWithSessionStartTimeMS:0];
Expand Down Expand Up @@ -1114,6 +1112,28 @@ - (void) testMidSessionHarvest {
// XCTAssertTrue(array.count == 0, @"dup events should have been cleared out on harvest before.");
}

-(void)testSetMaxEventBufferSize {
NRMAAnalytics* analytics = [[NRMAAnalytics alloc] initWithSessionStartTimeMS:0];

[analytics setMaxEventBufferSize:2000];

XCTAssertEqual([analytics getMaxEventBufferSize], 2000);

analytics = [[NRMAAnalytics alloc] initWithSessionStartTimeMS:0];
XCTAssertEqual([analytics getMaxEventBufferSize], 2000);
}

-(void)testSetMaxEventBufferTime {
NRMAAnalytics* analytics = [[NRMAAnalytics alloc] initWithSessionStartTimeMS:0];

[analytics setMaxEventBufferTime:2000];

XCTAssertEqual([analytics getMaxEventBufferTime], 2000);

analytics = [[NRMAAnalytics alloc] initWithSessionStartTimeMS:0];
XCTAssertEqual([analytics getMaxEventBufferTime], 2000);
}

- (void) testBadInput {
NRMAAnalytics* analytics = [[NRMAAnalytics alloc] initWithSessionStartTimeMS:0];
BOOL result;
Expand Down

0 comments on commit 39d5adb

Please sign in to comment.