Skip to content

Commit 46ed65b

Browse files
cjhillbrandCJ Hillbrand
authored andcommitted
Add Method to 'FileUploadMonitor' to upload Summary.txt (#521)
* Add extra method to upload summary.txt * add back in file header. --------- Co-authored-by: CJ Hillbrand <cjhillbrand@microsoft.com>
1 parent 2aec349 commit 46ed65b

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.20
1+
2.0.21

src/VirtualClient/VirtualClient.Core/Logging/SummaryFile/SummaryFileLogger.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ public SummaryFileLogger(string filePath, IAsyncPolicy retryPolicy = null)
5757
if (string.IsNullOrWhiteSpace(filePath))
5858
{
5959
PlatformSpecifics tempPlatformSpecifics = new PlatformSpecifics(Environment.OSVersion.Platform, RuntimeInformation.ProcessArchitecture);
60-
filePath = tempPlatformSpecifics.Combine(tempPlatformSpecifics.LogsDirectory, "summary.txt");
60+
ISystemInfo systemInfo = new SystemManagement();
61+
string experimentId = systemInfo.ExperimentId;
62+
string suffix = string.IsNullOrEmpty(experimentId) ? string.Empty : $"-{experimentId}";
63+
filePath = tempPlatformSpecifics.Combine(tempPlatformSpecifics.LogsDirectory, $"summary{suffix}.txt");
6164
}
6265

6366
this.filePath = filePath;

src/VirtualClient/VirtualClient.Monitors/FileUploadMonitor.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ await this.Logger.LogMessageAsync($"{this.TypeName}.ProcessSummaryFileUploads",
134134
// Upload the workload summary logs (e.g. metrics.csv) before exiting. We do this at the very end. Same as before, we do not
135135
// honor the cancellation token until ALL files have been successfully processed.
136136
await this.UploadCsvSummaryFilesAsync(blobManager, relatedContext);
137+
138+
// Upload specific summary.txt at root level of logs directory.
139+
await this.UploadSummaryFileAsync(blobManager, relatedContext);
137140
});
138141

139142
break;
@@ -233,6 +236,48 @@ private async Task<bool> UploadFilesAsync(IBlobManager blobManager, EventContext
233236
return filesFound;
234237
}
235238

239+
private async Task UploadSummaryFileAsync(IBlobManager blobManager, EventContext telemetryContext)
240+
{
241+
try
242+
{
243+
string suffix = string.IsNullOrEmpty(this.ExperimentId) ? string.Empty : $"-{this.ExperimentId}";
244+
string summaryTxtFileLocation = Path.Combine(this.PlatformSpecifics.LogsDirectory, $"summary{suffix}.txt");
245+
bool summaryTxtFileExists = this.fileSystem.File.Exists(summaryTxtFileLocation);
246+
telemetryContext
247+
.AddContext(nameof(summaryTxtFileLocation), summaryTxtFileLocation)
248+
.AddContext(nameof(summaryTxtFileExists), summaryTxtFileExists);
249+
250+
if (summaryTxtFileExists)
251+
{
252+
try
253+
{
254+
FileUploadDescriptor descriptor = this.CreateFileUploadDescriptor(
255+
new FileContext(
256+
this.fileSystem.FileInfo.New(summaryTxtFileLocation),
257+
"text/plain",
258+
Encoding.UTF8.WebName,
259+
this.ExperimentId,
260+
this.AgentId));
261+
262+
await this.UploadFileAsync(blobManager, this.fileSystem, descriptor, CancellationToken.None);
263+
}
264+
catch (IOException exc) when (exc.Message.Contains("being used by another process", StringComparison.OrdinalIgnoreCase))
265+
{
266+
// It is common that there will be read/write access errors at certain times while
267+
// upload request files are being created at the same time as attempts to read.
268+
}
269+
catch (Exception exc)
270+
{
271+
this.Logger.LogErrorMessage(exc, telemetryContext, LogLevel.Warning);
272+
}
273+
}
274+
}
275+
catch (Exception exc)
276+
{
277+
this.Logger.LogErrorMessage(exc, telemetryContext, LogLevel.Error);
278+
}
279+
}
280+
236281
private async Task UploadCsvSummaryFilesAsync(IBlobManager blobManager, EventContext telemetryContext)
237282
{
238283
try

0 commit comments

Comments
 (0)