Skip to content

Commit 57fcce3

Browse files
Add telemetry output splitting support for large process logs (#582)
* Chunking telemetry. * ensure no splitting when it doesn't exceed maxChar * Process Details Clone * Adding test cases. * Cleaning up * foo * fix process details * merge fix * upversion to 2.1.48 * making split telemetry default behavior. * fixing ut * Revert changes in ExecuteCommandMonitor.cs Signed-off-by: Nirjan <165215502+nchapagain001@users.noreply.github.com> * Fixing ut name * UT Fix * UT fix * Fixing clone * Assert.AreNotEqual(process1.Results, process2.Results) are going to be equal. --------- Signed-off-by: Nirjan <165215502+nchapagain001@users.noreply.github.com>
1 parent bed3353 commit 57fcce3

File tree

6 files changed

+406
-12
lines changed

6 files changed

+406
-12
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.47
1+
2.1.48

src/VirtualClient/VirtualClient.Common.UnitTests/ProcessExtensionsTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
namespace VirtualClient.Common
55
{
66
using System;
7+
using System.Collections.Generic;
78
using System.IO;
9+
using System.Linq;
810
using System.Threading;
911
using System.Threading.Tasks;
1012
using NUnit.Framework;
@@ -66,5 +68,42 @@ public void WaitForResponseAsyncExtensionThrowsIfTheExpectedResponseIsNotReceive
6668
Assert.ThrowsAsync<TimeoutException>(
6769
() => this.mockProcess.WaitForResponseAsync("NeverGonnaShow", CancellationToken.None, timeout: TimeSpan.Zero));
6870
}
71+
72+
[Test]
73+
public void ProcessDetailsCloneCreatesANewInstanceWithTheSameValues()
74+
{
75+
ProcessDetails process1 = new ProcessDetails
76+
{
77+
Id = -1,
78+
CommandLine = Guid.NewGuid().ToString(),
79+
ExitTime = DateTime.UtcNow,
80+
ExitCode = -2,
81+
StandardOutput = Guid.NewGuid().ToString(),
82+
StandardError = Guid.NewGuid().ToString(),
83+
StartTime = DateTime.MinValue,
84+
ToolName = Guid.NewGuid().ToString(),
85+
WorkingDirectory = Guid.NewGuid().ToString(),
86+
Results = new[]
87+
{
88+
new KeyValuePair<string, string>(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()),
89+
new KeyValuePair<string, string>(Guid.NewGuid().ToString(), Guid.NewGuid().ToString())
90+
}
91+
};
92+
93+
ProcessDetails process2 = process1.Clone();
94+
95+
Assert.AreNotEqual(process1, process2);
96+
97+
Assert.AreEqual(process1.Id, process2.Id);
98+
Assert.AreEqual(process1.CommandLine, process2.CommandLine);
99+
Assert.AreEqual(process1.ExitTime, process2.ExitTime);
100+
Assert.AreEqual(process1.ExitCode, process2.ExitCode);
101+
Assert.AreEqual(process1.StandardOutput, process2.StandardOutput);
102+
Assert.AreEqual(process1.StandardError, process2.StandardError);
103+
Assert.AreEqual(process1.StartTime, process2.StartTime);
104+
Assert.AreEqual(process1.ToolName, process2.ToolName);
105+
Assert.AreEqual(process1.WorkingDirectory, process2.WorkingDirectory);
106+
Assert.AreEqual(process1.Results.Count(), process2.Results.Count());
107+
}
69108
}
70109
}

src/VirtualClient/VirtualClient.Common/ProcessDetails.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Linq;
67

78
namespace VirtualClient.Common
89
{
@@ -78,5 +79,36 @@ public TimeSpan? ElapsedTime
7879
/// Working Directory.
7980
/// </summary>
8081
public string WorkingDirectory { get; set; }
82+
83+
/// <summary>
84+
/// Returns a clone of the current instance.
85+
/// </summary>
86+
/// <returns>
87+
/// A clone of the current instance.
88+
/// </returns>
89+
public virtual ProcessDetails Clone()
90+
{
91+
ProcessDetails clonedDetails = new ProcessDetails
92+
{
93+
Id = this.Id,
94+
CommandLine = this.CommandLine,
95+
ExitTime = this.ExitTime,
96+
ExitCode = this.ExitCode,
97+
StandardOutput = this.StandardOutput,
98+
StandardError = this.StandardError,
99+
StartTime = this.StartTime,
100+
ToolName = this.ToolName,
101+
WorkingDirectory = this.WorkingDirectory,
102+
Results = new List<KeyValuePair<string, string>>()
103+
};
104+
105+
// Always create a new collection instance when Results is non-null.
106+
if (this.Results != null)
107+
{
108+
clonedDetails.Results = this.Results.ToList();
109+
}
110+
111+
return clonedDetails;
112+
}
81113
}
82114
}

0 commit comments

Comments
 (0)