Skip to content

Commit

Permalink
NR-357941-in-progress: Sync NRMASupportMetricHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
cdillard-NewRelic committed Dec 10, 2024
1 parent 87338c4 commit cbd0224
Showing 1 changed file with 120 additions and 94 deletions.
214 changes: 120 additions & 94 deletions Agent/Measurements/NRMASupportMetricHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,149 +17,175 @@ @implementation NRMASupportMetricHelper

// 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];
NSString* platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform:[NRMAAgentConfiguration connectionInformation].deviceInformation.platform];
[NRMATaskQueue queue:[[NRMAMetric alloc] initWithName:[NSString stringWithFormat:kNRMABytesOutSupportabilityFormatString, nativePlatform, platform, kNRMACollectorDest, subDestination]
value:[NSNumber numberWithLongLong:size]
scope:@""
produceUnscoped:YES
additionalValue:[NSNumber numberWithLongLong:received]]];
@synchronized(self) {
NSString* nativePlatform = [NewRelicInternalUtils osName];
NSString* platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform:[NRMAAgentConfiguration connectionInformation].deviceInformation.platform];
[NRMATaskQueue queue:[[NRMAMetric alloc] initWithName:[NSString stringWithFormat:kNRMABytesOutSupportabilityFormatString, nativePlatform, platform, kNRMACollectorDest, subDestination]
value:[NSNumber numberWithLongLong:size]
scope:@""
produceUnscoped:YES
additionalValue:[NSNumber numberWithLongLong:received]]];
}
}

+ (void) enqueueFeatureFlagMetric:(BOOL)enabled features:(NRMAFeatureFlags)features {
NSString* nativePlatform = [NewRelicInternalUtils osName];
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(self) {
NSString* nativePlatform = [NewRelicInternalUtils osName];
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];
}
[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(self) {
if (deferredMetrics == nil) {
deferredMetrics = [NSMutableArray array];
}
[deferredMetrics addObject:[[NRMAMetric alloc] initWithName:kNRMAAppInstallMetric
value:@1
scope:nil]];
}
[deferredMetrics addObject:[[NRMAMetric alloc] initWithName:kNRMAAppInstallMetric
value:@1
scope:nil]];
}

+ (void) enqueueMaxPayloadSizeLimitMetric:(NSString*)endpoint {
NSString* nativePlatform = [NewRelicInternalUtils osName];
NSString* platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform:[NRMAAgentConfiguration connectionInformation].deviceInformation.platform];
[NRMATaskQueue queue:[[NRMAMetric alloc] initWithName:[NSString stringWithFormat: kNRMAMaxPayloadSizeLimitSupportabilityFormatString, nativePlatform, platform, kNRMACollectorDest, endpoint]
value:@1
scope:nil]];
@synchronized(self) {
NSString* nativePlatform = [NewRelicInternalUtils osName];
NSString* platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform:[NRMAAgentConfiguration connectionInformation].deviceInformation.platform];
[NRMATaskQueue queue:[[NRMAMetric alloc] initWithName:[NSString stringWithFormat: kNRMAMaxPayloadSizeLimitSupportabilityFormatString, nativePlatform, platform, kNRMACollectorDest, endpoint]
value:@1
scope:nil]];
}
}

+ (void) enqueueOfflinePayloadMetric:(long)size {
NSString* nativePlatform = [NewRelicInternalUtils osName];
NSString* platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform:[NRMAAgentConfiguration connectionInformation].deviceInformation.platform];
[NRMATaskQueue queue:[[NRMAMetric alloc] initWithName:[NSString stringWithFormat: kNRMAOfflineSupportabilityFormatString, nativePlatform, platform, kNRMACollectorDest]
value:[NSNumber numberWithLongLong:size]
scope:nil]];
@synchronized(self) {
NSString* nativePlatform = [NewRelicInternalUtils osName];
NSString* platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform:[NRMAAgentConfiguration connectionInformation].deviceInformation.platform];
[NRMATaskQueue queue:[[NRMAMetric alloc] initWithName:[NSString stringWithFormat: kNRMAOfflineSupportabilityFormatString, nativePlatform, platform, kNRMACollectorDest]
value:[NSNumber numberWithLongLong:size]
scope:nil]];
}
}

+ (void) enqueueUpgradeMetric {
if (deferredMetrics == nil) {
deferredMetrics = [NSMutableArray array];
@synchronized(self) {
if (deferredMetrics == nil) {
deferredMetrics = [NSMutableArray array];
}
[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(self) {
if (deferredMetrics == nil) {
deferredMetrics = [NSMutableArray array];
}
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(self) {

if (deferredMetrics == nil) {
deferredMetrics = [NSMutableArray array];
}
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

+ (void) enqueueLogSuccessMetric:(long)size {
NSString* nativePlatform = [NewRelicInternalUtils osName];
NSString* platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform:[NRMAAgentConfiguration connectionInformation].deviceInformation.platform];
[NRMATaskQueue queue:[[NRMAMetric alloc] initWithName:[NSString stringWithFormat:kNRMALoggingMetricSuccessfulSize, nativePlatform, platform]
value:[NSNumber numberWithLongLong:size]
scope:@""
produceUnscoped:YES
additionalValue:nil]];
@synchronized(self) {
NSString* nativePlatform = [NewRelicInternalUtils osName];
NSString* platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform:[NRMAAgentConfiguration connectionInformation].deviceInformation.platform];
[NRMATaskQueue queue:[[NRMAMetric alloc] initWithName:[NSString stringWithFormat:kNRMALoggingMetricSuccessfulSize, nativePlatform, platform]
value:[NSNumber numberWithLongLong:size]
scope:@""
produceUnscoped:YES
additionalValue:nil]];
}
}

+ (void) enqueueLogFailedMetric {
NSString* nativePlatform = [NewRelicInternalUtils osName];
NSString* platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform:[NRMAAgentConfiguration connectionInformation].deviceInformation.platform];
[NRMATaskQueue queue:[[NRMAMetric alloc] initWithName:[NSString stringWithFormat: kNRMALoggingMetricFailedUpload, nativePlatform, platform]
value:@1
scope:nil]];
@synchronized(self) {
NSString* nativePlatform = [NewRelicInternalUtils osName];
NSString* platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform:[NRMAAgentConfiguration connectionInformation].deviceInformation.platform];
[NRMATaskQueue queue:[[NRMAMetric alloc] initWithName:[NSString stringWithFormat: kNRMALoggingMetricFailedUpload, nativePlatform, platform]
value:@1
scope:nil]];
}

}

// End Logging

+ (void) processDeferredMetrics {
// Handle any deferred app start metrics
if ([[NRMAStartTimer sharedInstance] appLaunchDuration] != 0) {
[NRMATaskQueue queue:[[NRMAMetric alloc] initWithName:NRMA_METRIC_APP_LAUNCH_COLD
value:[NSNumber numberWithDouble:[[NRMAStartTimer sharedInstance] appLaunchDuration]]
scope:@""
produceUnscoped:YES
additionalValue:nil]];
[NRMAStartTimer sharedInstance].appLaunchDuration = 0;
}
@synchronized(self) {

// Handle any deferred app start metrics
if ([[NRMAStartTimer sharedInstance] appLaunchDuration] != 0) {
[NRMATaskQueue queue:[[NRMAMetric alloc] initWithName:NRMA_METRIC_APP_LAUNCH_COLD
value:[NSNumber numberWithDouble:[[NRMAStartTimer sharedInstance] appLaunchDuration]]
scope:@""
produceUnscoped:YES
additionalValue:nil]];
[NRMAStartTimer sharedInstance].appLaunchDuration = 0;
}

if ([[NRMAStartTimer sharedInstance] appResumeDuration] != 0) {
[NRMATaskQueue queue:[[NRMAMetric alloc] initWithName:NRMA_METRIC_APP_LAUNCH_RESUME
value:[NSNumber numberWithDouble:[[NRMAStartTimer sharedInstance] appResumeDuration]]
scope:@""
produceUnscoped:YES
additionalValue:nil]];
[NRMAStartTimer sharedInstance].appResumeDuration = 0;
}
if ([[NRMAStartTimer sharedInstance] appResumeDuration] != 0) {
[NRMATaskQueue queue:[[NRMAMetric alloc] initWithName:NRMA_METRIC_APP_LAUNCH_RESUME
value:[NSNumber numberWithDouble:[[NRMAStartTimer sharedInstance] appResumeDuration]]
scope:@""
produceUnscoped:YES
additionalValue:nil]];
[NRMAStartTimer sharedInstance].appResumeDuration = 0;
}

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

for (NRMAMetric *metric in deferredMetrics) {
for (NRMAMetric *metric in deferredMetrics) {

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

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

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 = nil;
}

[deferredMetrics removeAllObjects];
deferredMetrics = nil;
}

@end

0 comments on commit cbd0224

Please sign in to comment.