Skip to content

Commit 6a08852

Browse files
authored
Remove Santize from MetricsLogger hotpath (#9489)
1 parent ebaf1af commit 6a08852

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

src/WebJobs.Script.Grpc/Channel/GrpcWorkerChannel.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ private void LogWorkerMetadata(WorkerMetadata workerMetadata)
423423

424424
workerMetadata.UpdateWorkerMetadata(_workerConfig);
425425
var workerMetadataString = workerMetadata.ToString();
426-
_metricsLogger.LogEvent(MetricEventNames.WorkerMetadata, functionName: null, workerMetadataString);
426+
_metricsLogger.LogEvent(MetricEventNames.WorkerMetadata, functionName: null, Sanitizer.Sanitize(workerMetadataString));
427427
_workerChannelLogger.LogDebug("Worker metadata: {workerMetadata}", workerMetadataString);
428428
}
429429

@@ -670,7 +670,7 @@ internal FunctionLoadRequest GetFunctionLoadRequest(FunctionMetadata metadata, M
670670

671671
if (binding.SupportsDeferredBinding() && !binding.SkipDeferredBinding())
672672
{
673-
_metricsLogger.LogEvent(MetricEventNames.FunctionBindingDeferred, functionName: metadata.Name);
673+
_metricsLogger.LogEvent(MetricEventNames.FunctionBindingDeferred, functionName: Sanitizer.Sanitize(metadata.Name));
674674
}
675675
}
676676

@@ -757,8 +757,7 @@ internal async Task SendInvocationRequest(ScriptInvocationContext context)
757757
var invocationRequest = await context.ToRpcInvocationRequest(_workerChannelLogger, _workerCapabilities, _isSharedMemoryDataTransferEnabled, _sharedMemoryManager);
758758
AddAdditionalTraceContext(invocationRequest.TraceContext.Attributes, context);
759759
_executingInvocations.TryAdd(invocationRequest.InvocationId, context);
760-
761-
_metricsLogger.LogEvent(string.Format(MetricEventNames.WorkerInvoked, Id), functionName: context.FunctionMetadata.Name);
760+
_metricsLogger.LogEvent(string.Format(MetricEventNames.WorkerInvoked, Id), functionName: Sanitizer.Sanitize(context.FunctionMetadata.Name));
762761

763762
await SendStreamingMessageAsync(new StreamingMessage
764763
{

src/WebJobs.Script.WebHost/Diagnostics/FunctionInstanceLogger.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Threading;
88
using System.Threading.Tasks;
99
using Microsoft.Azure.WebJobs.Host.Loggers;
10+
using Microsoft.Azure.WebJobs.Logging;
1011
using Microsoft.Azure.WebJobs.Script.Description;
1112
using Microsoft.Azure.WebJobs.Script.Diagnostics;
1213
using Microsoft.Extensions.Configuration;
@@ -112,7 +113,7 @@ private void EndFunction(FunctionInstanceLogEntry item)
112113
data = string.Format(Microsoft.Azure.WebJobs.Script.Properties.Resources.FunctionInvocationMetricsData, startedEvent.FunctionMetadata.Language, functionName, success, Stopwatch.IsHighResolution);
113114
_eventDataCache[key] = data;
114115
}
115-
_metrics.LogEvent(eventName, startedEvent.FunctionName, data);
116+
_metrics.LogEvent(eventName, startedEvent.FunctionName, Sanitizer.Sanitize(data));
116117

117118
startedEvent.Data = data;
118119
_metrics.EndEvent(startedEvent);

src/WebJobs.Script.WebHost/Diagnostics/MetricsEventManager.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ public void LogEvent(string eventName, string functionName = null, string data =
119119
{
120120
ArgumentNullException.ThrowIfNull(eventName);
121121

122-
eventName = Sanitizer.Sanitize(eventName);
123-
124122
string key = GetAggregateKey(eventName, functionName);
125123
QueuedEvents.AddOrUpdate(key,
126124
(name) =>

src/WebJobs.Script/Host/ScriptHost.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,12 @@ public async Task InitializeAsync(CancellationToken cancellationToken = default)
279279
IEnumerable<FunctionMetadata> functionMetadataList = GetFunctionsMetadata();
280280

281281
string workerRuntime = _environment.GetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime);
282-
_logger.FunctionsWorkerRuntimeValue(workerRuntime);
282+
_logger.FunctionsWorkerRuntimeValue(Sanitizer.Sanitize(workerRuntime));
283283

284284
if (workerRuntime is null)
285285
{
286286
workerRuntime = Utility.GetWorkerRuntime(functionMetadataList);
287-
_logger.ResolvedWorkerRuntimeFromMetadata(workerRuntime);
287+
_logger.ResolvedWorkerRuntimeFromMetadata(Sanitizer.Sanitize(workerRuntime));
288288
}
289289

290290
if (!_environment.IsPlaceholderModeEnabled())

test/WebJobs.Script.Tests.Integration/Diagnostics/MetricsEventManagerTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Text;
1010
using System.Threading;
1111
using System.Threading.Tasks;
12+
using Microsoft.Azure.WebJobs.Logging;
1213
using Microsoft.Azure.WebJobs.Script.Configuration;
1314
using Microsoft.Azure.WebJobs.Script.Description;
1415
using Microsoft.Azure.WebJobs.Script.Diagnostics;
@@ -126,7 +127,8 @@ public MetricsEventManagerTests()
126127
[InlineData("{ \"AzureWebJobsStorage\": \"DefaultEndpointsProtocol=https;AccountName=testAccount1;AccountKey=mykey1;EndpointSuffix=core.windows.net\", \"AnotherKey\": \"AnotherValue\" }", "{ \"azurewebjobsstorage\": \"[hidden credential]\", \"anotherkey\": \"anothervalue\" }")]
127128
public void LogEvent_QueuesPendingEvent(string eventName, string expectedEventName)
128129
{
129-
_metricsLogger.LogEvent(eventName);
130+
//Note: Caller is responsible for sanitizing the string
131+
_metricsLogger.LogEvent(Sanitizer.Sanitize(eventName));
130132

131133
Assert.Equal(1, _metricsEventManager.QueuedEvents.Count);
132134
SystemMetricEvent evt = _metricsEventManager.QueuedEvents.Values.Single();

0 commit comments

Comments
 (0)