Skip to content

Commit

Permalink
Add message size in chars and bytes (#1100)
Browse files Browse the repository at this point in the history
* Add message size in chars and bytes

* Log hash of message body
  • Loading branch information
nodeselector authored Jun 10, 2021
1 parent a1bcd59 commit 42fe704
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Runner.Common/ProcessChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO.Pipes;
using System.Threading;
using System.Threading.Tasks;
using GitHub.Runner.Sdk;

namespace GitHub.Runner.Common
{
Expand Down Expand Up @@ -68,6 +69,7 @@ public void StartClient(string pipeNameInput, string pipeNameOutput)

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);
}
Expand All @@ -77,6 +79,7 @@ public async Task<WorkerMessage> ReceiveAsync(CancellationToken cancellationToke
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public override void Initialize(IHostContext hostContext)

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)
Expand Down
2 changes: 1 addition & 1 deletion src/Runner.Sdk/Util/IOUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static T LoadObject<T>(string path)
return StringUtil.ConvertFromJson<T>(json);
}

public static string GetPathHash(string path)
public static string GetSha256Hash(string path)
{
string hashString = path.ToLowerInvariant();
using (SHA256 sha256hash = SHA256.Create())
Expand Down
2 changes: 1 addition & 1 deletion src/Runner.Worker/Container/DockerCommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override void Initialize(IHostContext hostContext)
{
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> DockerVersion(IExecutionContext context)
Expand Down

0 comments on commit 42fe704

Please sign in to comment.