-
Notifications
You must be signed in to change notification settings - Fork 457
Update capabilities and log worker metadata after specialization #9020
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,7 @@ internal class GrpcWorkerChannel : IRpcWorkerChannel, IDisposable | |
private TaskCompletionSource<List<RawFunctionMetadata>> _functionsIndexingTask = new TaskCompletionSource<List<RawFunctionMetadata>>(TaskCreationOptions.RunContinuationsAsynchronously); | ||
private TimeSpan _functionLoadTimeout = TimeSpan.FromMinutes(1); | ||
private bool _isSharedMemoryDataTransferEnabled; | ||
private bool _cancelCapabilityEnabled; | ||
private bool? _cancelCapabilityEnabled; | ||
private bool _isWorkerApplicationInsightsLoggingEnabled; | ||
|
||
private System.Timers.Timer _timer; | ||
|
@@ -357,6 +357,11 @@ internal WorkerInitRequest GetWorkerInitRequest() | |
internal void FunctionEnvironmentReloadResponse(FunctionEnvironmentReloadResponse res, IDisposable latencyEvent) | ||
{ | ||
_workerChannelLogger.LogDebug("Received FunctionEnvironmentReloadResponse from WorkerProcess with Pid: '{0}'", _rpcWorkerProcess.Id); | ||
|
||
LogWorkerMetadata(res.WorkerMetadata); | ||
UpdateCapabilities(res.Capabilities); | ||
_cancelCapabilityEnabled ??= !string.IsNullOrEmpty(_workerCapabilities.GetCapabilityState(RpcWorkerConstants.HandlesInvocationCancelMessage)); | ||
|
||
if (res.Result.IsFailure(out Exception reloadEnvironmentVariablesException)) | ||
{ | ||
_workerChannelLogger.LogError(reloadEnvironmentVariablesException, "Failed to reload environment variables"); | ||
|
@@ -375,13 +380,10 @@ internal void WorkerInitResponse(GrpcEvent initEvent) | |
_initMessage = initEvent.Message.WorkerInitResponse; | ||
_workerChannelLogger.LogDebug("Worker capabilities: {capabilities}", _initMessage.Capabilities); | ||
|
||
if (_initMessage.WorkerMetadata != null) | ||
{ | ||
_initMessage.UpdateWorkerMetadata(_workerConfig); | ||
var workerMetadata = _initMessage.WorkerMetadata.ToString(); | ||
_metricsLogger.LogEvent(MetricEventNames.WorkerMetadata, functionName: null, workerMetadata); | ||
_workerChannelLogger.LogDebug("Worker metadata: {workerMetadata}", workerMetadata); | ||
} | ||
// In placeholder scenario, the capabilities and worker metadata will not be available | ||
// until specialization is done (env reload request). So these can be removed from worker init response code path. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should check our understanding here with @soninaren as I remember change in flow on placeholder side for the work - selective loading of extensions. |
||
// to do to track this: https://github.com/Azure/azure-functions-host/issues/9019 | ||
LogWorkerMetadata(_initMessage.WorkerMetadata); | ||
|
||
if (_initMessage.Result.IsFailure(out Exception exc)) | ||
{ | ||
|
@@ -395,7 +397,7 @@ internal void WorkerInitResponse(GrpcEvent initEvent) | |
UpdateCapabilities(_initMessage.Capabilities); | ||
|
||
_isSharedMemoryDataTransferEnabled = IsSharedMemoryDataTransferEnabled(); | ||
_cancelCapabilityEnabled = !string.IsNullOrEmpty(_workerCapabilities.GetCapabilityState(RpcWorkerConstants.HandlesInvocationCancelMessage)); | ||
_cancelCapabilityEnabled ??= !string.IsNullOrEmpty(_workerCapabilities.GetCapabilityState(RpcWorkerConstants.HandlesInvocationCancelMessage)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if the value of this capability is set to a false-y string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, this may not be part of this PR but can we update the name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, host code(in various places) checks the existence of the capability instead of the value being truthy. I agree, Ideally it should be a truthy check. but that might involve coordinating with workers to make sure they send the correct value. Currently dotnet worker sends capability when the value is truthy. Ex: https://github.com/Azure/azure-functions-dotnet-worker/blob/14cc88859a1b7bbf68ee43409a1ad45a6e8362cb/src/DotNetWorker.Grpc/GrpcWorker.cs#L222-L229 |
||
|
||
if (!_isSharedMemoryDataTransferEnabled) | ||
{ | ||
|
@@ -413,6 +415,19 @@ internal void WorkerInitResponse(GrpcEvent initEvent) | |
_workerInitTask.TrySetResult(true); | ||
} | ||
|
||
private void LogWorkerMetadata(WorkerMetadata workerMetadata) | ||
{ | ||
if (workerMetadata == null) | ||
{ | ||
return; | ||
} | ||
|
||
workerMetadata.UpdateWorkerMetadata(_workerConfig); | ||
var workerMetadataString = workerMetadata.ToString(); | ||
_metricsLogger.LogEvent(MetricEventNames.WorkerMetadata, functionName: null, workerMetadataString); | ||
_workerChannelLogger.LogDebug("Worker metadata: {workerMetadata}", workerMetadataString); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may not be applicable for the scenario here but wanted to call out that for one of my previous PRs - refer, I got to know that adding log lines here has perf impact. So, we can double check if this log is really needed here and not affecting the perf. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logging was existing code, which I moved to a private method now. So this PR should not make a perf impact as such. But I get your point. We can definitely discuss removing this logging entry as we have this information getting logged to functions metrics as well. Thoughts @liliankasem ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if a detector or other teams are using the information from the log somewhere so I can't say it's 100% safe to remove |
||
} | ||
|
||
// Allow tests to add capabilities, even if not directly supported by the worker. | ||
internal virtual void UpdateCapabilities(IDictionary<string, string> fields) | ||
{ | ||
|
@@ -668,7 +683,7 @@ await SendStreamingMessageAsync(new StreamingMessage | |
InvocationRequest = invocationRequest | ||
}); | ||
|
||
if (_cancelCapabilityEnabled) | ||
if (_cancelCapabilityEnabled != null && _cancelCapabilityEnabled.Value) | ||
{ | ||
context.CancellationToken.Register(() => SendInvocationCancel(invocationRequest.InvocationId)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is not part of this PR. I forgot to include release_notes update in 9023.