From 42fe704132b7fc343e59ff15a8dbaace19e38e62 Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 10 Jun 2021 12:58:56 -0700 Subject: [PATCH] Add message size in chars and bytes (#1100) * Add message size in chars and bytes * Log hash of message body --- src/Runner.Common/ProcessChannel.cs | 3 +++ .../Configuration/NativeWindowsServiceHelper.cs | 2 +- src/Runner.Sdk/Util/IOUtil.cs | 2 +- src/Runner.Worker/Container/DockerCommandManager.cs | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Runner.Common/ProcessChannel.cs b/src/Runner.Common/ProcessChannel.cs index 14d367e1e..ca493c962 100644 --- a/src/Runner.Common/ProcessChannel.cs +++ b/src/Runner.Common/ProcessChannel.cs @@ -3,6 +3,7 @@ using System.IO; using System.IO.Pipes; using System.Threading; using System.Threading.Tasks; +using GitHub.Runner.Sdk; namespace GitHub.Runner.Common { @@ -68,6 +69,7 @@ namespace GitHub.Runner.Common public async Task SendAsync(MessageType messageType, string body, CancellationToken cancellationToken) { + Trace.Info($"Sending message of length {body.Length}, with hash '{IOUtil.GetSha256Hash(body)}'"); await _writeStream.WriteInt32Async((int)messageType, cancellationToken); await _writeStream.WriteStringAsync(body, cancellationToken); } @@ -77,6 +79,7 @@ namespace GitHub.Runner.Common WorkerMessage result = new WorkerMessage(MessageType.NotInitialized, string.Empty); result.MessageType = (MessageType)await _readStream.ReadInt32Async(cancellationToken); result.Body = await _readStream.ReadStringAsync(cancellationToken); + Trace.Info($"Receiving message of length {result.Body.Length}, with hash '{IOUtil.GetSha256Hash(result.Body)}'"); return result; } diff --git a/src/Runner.Listener/Configuration/NativeWindowsServiceHelper.cs b/src/Runner.Listener/Configuration/NativeWindowsServiceHelper.cs index 76f07d1f0..40c000acc 100644 --- a/src/Runner.Listener/Configuration/NativeWindowsServiceHelper.cs +++ b/src/Runner.Listener/Configuration/NativeWindowsServiceHelper.cs @@ -87,7 +87,7 @@ namespace GitHub.Runner.Listener.Configuration public string GetUniqueRunnerGroupName() { - return RunnerServiceLocalGroupPrefix + IOUtil.GetPathHash(HostContext.GetDirectory(WellKnownDirectory.Bin)).Substring(0, 5); + return RunnerServiceLocalGroupPrefix + IOUtil.GetSha256Hash(HostContext.GetDirectory(WellKnownDirectory.Bin)).Substring(0, 5); } public bool LocalGroupExists(string groupName) diff --git a/src/Runner.Sdk/Util/IOUtil.cs b/src/Runner.Sdk/Util/IOUtil.cs index 45957dee7..a4b98e70d 100644 --- a/src/Runner.Sdk/Util/IOUtil.cs +++ b/src/Runner.Sdk/Util/IOUtil.cs @@ -47,7 +47,7 @@ namespace GitHub.Runner.Sdk return StringUtil.ConvertFromJson(json); } - public static string GetPathHash(string path) + public static string GetSha256Hash(string path) { string hashString = path.ToLowerInvariant(); using (SHA256 sha256hash = SHA256.Create()) diff --git a/src/Runner.Worker/Container/DockerCommandManager.cs b/src/Runner.Worker/Container/DockerCommandManager.cs index 8663e9340..86cf0eeed 100644 --- a/src/Runner.Worker/Container/DockerCommandManager.cs +++ b/src/Runner.Worker/Container/DockerCommandManager.cs @@ -46,7 +46,7 @@ namespace GitHub.Runner.Worker.Container { base.Initialize(hostContext); DockerPath = WhichUtil.Which("docker", true, Trace); - DockerInstanceLabel = IOUtil.GetPathHash(hostContext.GetDirectory(WellKnownDirectory.Root)).Substring(0, 6); + DockerInstanceLabel = IOUtil.GetSha256Hash(hostContext.GetDirectory(WellKnownDirectory.Root)).Substring(0, 6); } public async Task DockerVersion(IExecutionContext context)