Skip to content

Commit 4cb5ded

Browse files
committed
refactor: Eliminate redundant logic in enum-based datastore metric methods
Enum-based overloads in MetricNames now delegate to string-based overloads for GetDatastoreStatement, GetDatastoreInstance, and the three VendorAll variants; cache init lambdas call the string methods instead of inlining identical path-building logic. Remove dead DatastoreVendor overloads from MetricWireModel (TryBuildDatastoreStatementMetric, TryBuildDatastoreVendorOperationMetric, TryBuildDatastoreInstanceMetric) — all call sites in DatastoreSegmentData already use the string-based versions.
1 parent 2f3796b commit 4cb5ded

2 files changed

Lines changed: 8 additions & 41 deletions

File tree

src/Agent/NewRelic/Agent/Core/Metrics/MetricNames.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,27 +175,28 @@ public static class MetricNames
175175
static MetricNames()
176176
{
177177
_databaseVendorAll = GetEnumerationFunc<DatastoreVendor, MetricName>(vendor =>
178-
MetricName.Create(Datastore + PathSeparator + EnumNameCache<DatastoreVendor>.GetName(vendor) + PathSeparator + All));
178+
GetDatastoreVendorAll(EnumNameCache<DatastoreVendor>.GetName(vendor)));
179179
_databaseVendorAllWeb = GetEnumerationFunc<DatastoreVendor, MetricName>(vendor =>
180-
MetricName.Create(Datastore + PathSeparator + EnumNameCache<DatastoreVendor>.GetName(vendor) + PathSeparator + AllWeb));
180+
GetDatastoreVendorAllWeb(EnumNameCache<DatastoreVendor>.GetName(vendor)));
181181
_databaseVendorAllOther = GetEnumerationFunc<DatastoreVendor, MetricName>(vendor =>
182-
MetricName.Create(Datastore + PathSeparator + EnumNameCache<DatastoreVendor>.GetName(vendor) + PathSeparator + AllOther));
182+
GetDatastoreVendorAllOther(EnumNameCache<DatastoreVendor>.GetName(vendor)));
183183

184184
var operations = new HashSet<string>(SqlParser.Operations);
185185
operations.Add(DatastoreUnknownOperationName);
186186
_databaseVendorOperations = GetEnumerationFunc<DatastoreVendor, Func<string, MetricName>>(
187187
vendor =>
188188
{
189+
var vendorName = EnumNameCache<DatastoreVendor>.GetName(vendor);
189190
var dict = new Dictionary<string, MetricName>(operations.Count);
190-
var metricNamePrefix = DatastoreOperation + PathSeparator + EnumNameCache<DatastoreVendor>.GetName(vendor) + PathSeparator;
191+
var metricNamePrefix = DatastoreOperation + PathSeparator + vendorName + PathSeparator;
191192
foreach (var operation in operations)
192193
{
193194
dict[operation] = MetricName.Create(metricNamePrefix + operation);
194195
}
195196

196197
return operation => (dict.TryGetValue(operation, out var name))
197198
? name
198-
: MetricName.Create(DatastoreOperation, EnumNameCache<DatastoreVendor>.GetName(vendor), operation);
199+
: GetDatastoreOperation(vendorName, operation);
199200
});
200201
}
201202

@@ -484,13 +485,12 @@ public static MetricName GetDatastoreOperation(this DatastoreVendor vendor, stri
484485
public static MetricName GetDatastoreStatement(DatastoreVendor vendor, string model,
485486
string operation = null)
486487
{
487-
operation = operation ?? DatastoreUnknownOperationName;
488-
return MetricName.Create(DatastoreStatement, EnumNameCache<DatastoreVendor>.GetName(vendor), model, operation);
488+
return GetDatastoreStatement(EnumNameCache<DatastoreVendor>.GetName(vendor), model, operation);
489489
}
490490

491491
public static MetricName GetDatastoreInstance(DatastoreVendor vendor, string host, string portPathOrId)
492492
{
493-
return MetricName.Create(DatastoreInstance, EnumNameCache<DatastoreVendor>.GetName(vendor), host, portPathOrId);
493+
return GetDatastoreInstance(EnumNameCache<DatastoreVendor>.GetName(vendor), host, portPathOrId);
494494
}
495495

496496
// String-based overloads for custom vendor names via RecordDatastoreSegment()

src/Agent/NewRelic/Agent/Core/WireModels/MetricWireModel.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -440,39 +440,6 @@ public static void TryBuildDatastoreRollupMetrics(DatastoreVendor vendor, TimeSp
440440
}
441441

442442
// Datastore/statement/<vendor>/<model>/<operation>
443-
public static void TryBuildDatastoreStatementMetric(DatastoreVendor vendor, ParsedSqlStatement sqlStatement,
444-
TimeSpan totalTime, TimeSpan exclusiveDuration, TransactionMetricStatsCollection txStats)
445-
{
446-
var proposedName = MetricName.Create(sqlStatement.DatastoreStatementMetricName);
447-
var data = MetricDataWireModel.BuildTimingData(totalTime, exclusiveDuration);
448-
txStats.MergeUnscopedStats(proposedName, data);
449-
txStats.MergeScopedStats(proposedName, data);
450-
}
451-
452-
// Datastore/operation/<vendor>/<operation>
453-
public static void TryBuildDatastoreVendorOperationMetric(DatastoreVendor vendor, string operation,
454-
TimeSpan totalTime, TimeSpan exclusiveDuration, TransactionMetricStatsCollection txStats, bool onlyUnscoped)
455-
{
456-
var proposedName = vendor.GetDatastoreOperation(operation);
457-
var data = MetricDataWireModel.BuildTimingData(totalTime, exclusiveDuration);
458-
txStats.MergeUnscopedStats(proposedName, data);
459-
if (!onlyUnscoped)
460-
{
461-
txStats.MergeScopedStats(proposedName, data);
462-
}
463-
}
464-
465-
//Datastore/instance/datastore/host/port_path_or_id
466-
public static void TryBuildDatastoreInstanceMetric(DatastoreVendor vendor, string host, string portPathOrId,
467-
TimeSpan totalTime, TimeSpan exclusiveDuration, TransactionMetricStatsCollection txStats)
468-
{
469-
var proposedName = MetricNames.GetDatastoreInstance(vendor, host, portPathOrId);
470-
var data = MetricDataWireModel.BuildTimingData(totalTime, exclusiveDuration);
471-
txStats.MergeUnscopedStats(proposedName, data);
472-
}
473-
474-
// String-based overloads for custom vendor names via RecordDatastoreSegment()
475-
476443
public static void TryBuildDatastoreStatementMetric(ParsedSqlStatement sqlStatement,
477444
TimeSpan totalTime, TimeSpan exclusiveDuration, TransactionMetricStatsCollection txStats)
478445
{

0 commit comments

Comments
 (0)