Skip to content

Commit

Permalink
Remove Santize from MetricsLogger hotpath (#9489)
Browse files Browse the repository at this point in the history
  • Loading branch information
pragnagopa authored Aug 28, 2023
1 parent ebaf1af commit 6a08852
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/WebJobs.Script.Grpc/Channel/GrpcWorkerChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ private void LogWorkerMetadata(WorkerMetadata workerMetadata)

workerMetadata.UpdateWorkerMetadata(_workerConfig);
var workerMetadataString = workerMetadata.ToString();
_metricsLogger.LogEvent(MetricEventNames.WorkerMetadata, functionName: null, workerMetadataString);
_metricsLogger.LogEvent(MetricEventNames.WorkerMetadata, functionName: null, Sanitizer.Sanitize(workerMetadataString));
_workerChannelLogger.LogDebug("Worker metadata: {workerMetadata}", workerMetadataString);
}

Expand Down Expand Up @@ -670,7 +670,7 @@ internal FunctionLoadRequest GetFunctionLoadRequest(FunctionMetadata metadata, M

if (binding.SupportsDeferredBinding() && !binding.SkipDeferredBinding())
{
_metricsLogger.LogEvent(MetricEventNames.FunctionBindingDeferred, functionName: metadata.Name);
_metricsLogger.LogEvent(MetricEventNames.FunctionBindingDeferred, functionName: Sanitizer.Sanitize(metadata.Name));
}
}

Expand Down Expand Up @@ -757,8 +757,7 @@ internal async Task SendInvocationRequest(ScriptInvocationContext context)
var invocationRequest = await context.ToRpcInvocationRequest(_workerChannelLogger, _workerCapabilities, _isSharedMemoryDataTransferEnabled, _sharedMemoryManager);
AddAdditionalTraceContext(invocationRequest.TraceContext.Attributes, context);
_executingInvocations.TryAdd(invocationRequest.InvocationId, context);

_metricsLogger.LogEvent(string.Format(MetricEventNames.WorkerInvoked, Id), functionName: context.FunctionMetadata.Name);
_metricsLogger.LogEvent(string.Format(MetricEventNames.WorkerInvoked, Id), functionName: Sanitizer.Sanitize(context.FunctionMetadata.Name));

await SendStreamingMessageAsync(new StreamingMessage
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Host.Loggers;
using Microsoft.Azure.WebJobs.Logging;
using Microsoft.Azure.WebJobs.Script.Description;
using Microsoft.Azure.WebJobs.Script.Diagnostics;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -112,7 +113,7 @@ private void EndFunction(FunctionInstanceLogEntry item)
data = string.Format(Microsoft.Azure.WebJobs.Script.Properties.Resources.FunctionInvocationMetricsData, startedEvent.FunctionMetadata.Language, functionName, success, Stopwatch.IsHighResolution);
_eventDataCache[key] = data;
}
_metrics.LogEvent(eventName, startedEvent.FunctionName, data);
_metrics.LogEvent(eventName, startedEvent.FunctionName, Sanitizer.Sanitize(data));

startedEvent.Data = data;
_metrics.EndEvent(startedEvent);
Expand Down
2 changes: 0 additions & 2 deletions src/WebJobs.Script.WebHost/Diagnostics/MetricsEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ public void LogEvent(string eventName, string functionName = null, string data =
{
ArgumentNullException.ThrowIfNull(eventName);

eventName = Sanitizer.Sanitize(eventName);

string key = GetAggregateKey(eventName, functionName);
QueuedEvents.AddOrUpdate(key,
(name) =>
Expand Down
4 changes: 2 additions & 2 deletions src/WebJobs.Script/Host/ScriptHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,12 @@ public async Task InitializeAsync(CancellationToken cancellationToken = default)
IEnumerable<FunctionMetadata> functionMetadataList = GetFunctionsMetadata();

string workerRuntime = _environment.GetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime);
_logger.FunctionsWorkerRuntimeValue(workerRuntime);
_logger.FunctionsWorkerRuntimeValue(Sanitizer.Sanitize(workerRuntime));

if (workerRuntime is null)
{
workerRuntime = Utility.GetWorkerRuntime(functionMetadataList);
_logger.ResolvedWorkerRuntimeFromMetadata(workerRuntime);
_logger.ResolvedWorkerRuntimeFromMetadata(Sanitizer.Sanitize(workerRuntime));
}

if (!_environment.IsPlaceholderModeEnabled())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Logging;
using Microsoft.Azure.WebJobs.Script.Configuration;
using Microsoft.Azure.WebJobs.Script.Description;
using Microsoft.Azure.WebJobs.Script.Diagnostics;
Expand Down Expand Up @@ -126,7 +127,8 @@ public MetricsEventManagerTests()
[InlineData("{ \"AzureWebJobsStorage\": \"DefaultEndpointsProtocol=https;AccountName=testAccount1;AccountKey=mykey1;EndpointSuffix=core.windows.net\", \"AnotherKey\": \"AnotherValue\" }", "{ \"azurewebjobsstorage\": \"[hidden credential]\", \"anotherkey\": \"anothervalue\" }")]
public void LogEvent_QueuesPendingEvent(string eventName, string expectedEventName)
{
_metricsLogger.LogEvent(eventName);
//Note: Caller is responsible for sanitizing the string
_metricsLogger.LogEvent(Sanitizer.Sanitize(eventName));

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

0 comments on commit 6a08852

Please sign in to comment.