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

Remove Santize from MetricsLogger hotpath #9489

Merged
merged 3 commits into from
Aug 28, 2023
Merged
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
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
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));
pragnagopa marked this conversation as resolved.
Show resolved Hide resolved

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