Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NR-347591 added a synchronized lock to the deferredMetrics #348

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Agent/Measurements/NRMASupportMetricHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import <Foundation/Foundation.h>
#import "NewRelicFeatureFlags.h"

static NSMutableArray *deferredMetrics = NULL;
static NSMutableArray *deferredMetrics;

@interface NRMASupportMetricHelper : NSObject
+ (void) enqueueDataUseMetric:(NSString*)subDestination size:(long)size received:(long)received;
Expand Down
91 changes: 45 additions & 46 deletions Agent/Measurements/NRMASupportMetricHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

@implementation NRMASupportMetricHelper

static NSMutableArray<NRMAMetric *> *deferredMetrics;

+ (void) initialize {
deferredMetrics = [NSMutableArray array];
}

// The value _additionalValue being non-nil means that this is a Data Usage Supportability Metric.
+ (void) enqueueDataUseMetric:(NSString*)subDestination size:(long)size received:(long)received {
NSString* nativePlatform = [NewRelicInternalUtils osName];
Expand All @@ -31,24 +37,22 @@ + (void) enqueueFeatureFlagMetric:(BOOL)enabled features:(NRMAFeatureFlags)featu
for (NSString *name in [NRMAFlags namesForFlags:features]) {
NSString* featureFlagString = [NSString stringWithFormat:@"Supportability/Mobile/%@/%@/API/%@/%@",
nativePlatform, kPlatformPlaceholder, enabled ? @"enableFeature" : @"disableFeature", name];
if (deferredMetrics == nil) {
deferredMetrics = [NSMutableArray array];
@synchronized (deferredMetrics) {
[deferredMetrics addObject:[[NRMAMetric alloc] initWithName:featureFlagString
value:[NSNumber numberWithLongLong:1]
scope:@""
produceUnscoped:YES
additionalValue:nil]];
}
[deferredMetrics addObject:[[NRMAMetric alloc] initWithName:featureFlagString
value:[NSNumber numberWithLongLong:1]
scope:@""
produceUnscoped:YES
additionalValue:nil]];
}
}

+ (void) enqueueInstallMetric {
if (deferredMetrics == nil) {
deferredMetrics = [NSMutableArray array];
@synchronized (deferredMetrics) {
[deferredMetrics addObject:[[NRMAMetric alloc] initWithName:kNRMAAppInstallMetric
value:@1
scope:nil]];
}
[deferredMetrics addObject:[[NRMAMetric alloc] initWithName:kNRMAAppInstallMetric
value:@1
scope:nil]];
}

+ (void) enqueueMaxPayloadSizeLimitMetric:(NSString*)endpoint {
Expand All @@ -68,32 +72,29 @@ + (void) enqueueOfflinePayloadMetric:(long)size {
}

+ (void) enqueueUpgradeMetric {
if (deferredMetrics == nil) {
deferredMetrics = [NSMutableArray array];
@synchronized (deferredMetrics) {
[deferredMetrics addObject:[[NRMAMetric alloc] initWithName:kNRMAAppUpgradeMetric
value:@1
scope:nil]];
}
[deferredMetrics addObject:[[NRMAMetric alloc] initWithName:kNRMAAppUpgradeMetric
value:@1
scope:nil]];
}

+ (void) enqueueStopAgentMetric {
if (deferredMetrics == nil) {
deferredMetrics = [NSMutableArray array];
@synchronized (deferredMetrics) {
NSString* metricString = [NSString stringWithFormat:kNRMAStopAgentMetricFormatString, [NewRelicInternalUtils osName], kPlatformPlaceholder];
[deferredMetrics addObject:[[NRMAMetric alloc] initWithName:metricString
value:@1
scope:nil]];
}
NSString* metricString = [NSString stringWithFormat:kNRMAStopAgentMetricFormatString, [NewRelicInternalUtils osName], kPlatformPlaceholder];
[deferredMetrics addObject:[[NRMAMetric alloc] initWithName:metricString
value:@1
scope:nil]];
}

+ (void) enqueueConfigurationUpdateMetric {
if (deferredMetrics == nil) {
deferredMetrics = [NSMutableArray array];
@synchronized (deferredMetrics) {
NSString* metricString = [NSString stringWithFormat:kNRMAConfigurationUpdated, [NewRelicInternalUtils osName], kPlatformPlaceholder];
[deferredMetrics addObject:[[NRMAMetric alloc] initWithName:metricString
value:@1
scope:nil]];
}
NSString* metricString = [NSString stringWithFormat:kNRMAConfigurationUpdated, [NewRelicInternalUtils osName], kPlatformPlaceholder];
[deferredMetrics addObject:[[NRMAMetric alloc] initWithName:metricString
value:@1
scope:nil]];
}

// Logging
Expand Down Expand Up @@ -140,26 +141,24 @@ + (void) processDeferredMetrics {
}

// Handle any deferred supportability metrics.
if (deferredMetrics == nil) { return; }

for (NRMAMetric *metric in deferredMetrics) {

NSString* platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform:[NRMAAgentConfiguration connectionInformation].deviceInformation.platform];
NSString *deferredMetricName = metric.name;

if ([metric.name containsString:kPlatformPlaceholder]) {
deferredMetricName = [metric.name stringByReplacingOccurrencesOfString:kPlatformPlaceholder withString:platform];
@synchronized (deferredMetrics) {
for (NRMAMetric *metric in deferredMetrics) {
NSString* platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform:[NRMAAgentConfiguration connectionInformation].deviceInformation.platform];
NSString *deferredMetricName = metric.name;

if ([metric.name containsString:kPlatformPlaceholder]) {
deferredMetricName = [metric.name stringByReplacingOccurrencesOfString:kPlatformPlaceholder withString:platform];
}

[NRMATaskQueue queue:[[NRMAMetric alloc] initWithName:deferredMetricName
value:[NSNumber numberWithLongLong:1]
scope:@""
produceUnscoped:YES
additionalValue:nil]];
}

[NRMATaskQueue queue:[[NRMAMetric alloc] initWithName:deferredMetricName
value:[NSNumber numberWithLongLong:1]
scope:@""
produceUnscoped:YES
additionalValue:nil]];
[deferredMetrics removeAllObjects];
}

[deferredMetrics removeAllObjects];
deferredMetrics = nil;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ - (void) setUp {

if (deferredMetrics != nil) {
[deferredMetrics removeAllObjects];
deferredMetrics = nil;
}
helper = [[NRMAMeasurementConsumerHelper alloc] initWithType:NRMAMT_NamedValue];
[NRMAMeasurements initializeMeasurements];
Expand Down
Loading