@@ -13,18 +13,19 @@ namespace VirtualClient.Monitors
1313 using System . Threading . Tasks ;
1414 using global ::VirtualClient . Common . Contracts ;
1515 using global ::VirtualClient . Common . Extensions ;
16- using global ::VirtualClient . Common . Platform ;
1716 using global ::VirtualClient . Common . Telemetry ;
1817 using global ::VirtualClient . Contracts ;
1918 using Microsoft . Extensions . DependencyInjection ;
2019 using Microsoft . Extensions . Logging ;
20+ using MimeMapping ;
2121 using Newtonsoft . Json ;
22- using Polly ;
22+ using VirtualClient . Common ;
2323
2424 /// <summary>
2525 /// This monitor processes content/file uploads requested by Virtual Client
2626 /// workload, monitoring and dependency components.
2727 /// </summary>
28+ [ SupportedPlatforms ( "linux-arm64,linux-x64,win-arm64,win-x64" ) ]
2829 public class FileUploadMonitor : VirtualClientComponent
2930 {
3031 private IFileSystem fileSystem ;
@@ -66,7 +67,7 @@ protected override Task ExecuteAsync(EventContext telemetryContext, Cancellation
6667 if ( this . TryGetContentStoreManager ( out IBlobManager blobManager ) )
6768 {
6869 await this . ProcessFileUploadsAsync ( blobManager , telemetryContext , cancellationToken ) ;
69- await this . ProcessSummaryFileUploadsAsync ( blobManager , telemetryContext ) ;
70+ await this . ProcessStandardLogFileUploadsAsync ( blobManager , telemetryContext ) ;
7071 }
7172 } ) ;
7273 }
@@ -121,22 +122,19 @@ private async Task ProcessFileUploadsAsync(IBlobManager blobManager, EventContex
121122 }
122123 }
123124
124- private async Task ProcessSummaryFileUploadsAsync ( IBlobManager blobManager , EventContext telemetryContext )
125+ private async Task ProcessStandardLogFileUploadsAsync ( IBlobManager blobManager , EventContext telemetryContext )
125126 {
126127 EventContext relatedContext = telemetryContext . Clone ( ) . AddContext ( "directoryPath" , this . PlatformSpecifics . LogsDirectory ) ;
127128
128129 while ( true )
129130 {
130131 try
131132 {
132- await this . Logger . LogMessageAsync ( $ "{ this . TypeName } .ProcessSummaryFileUploads ", relatedContext , async ( ) =>
133+ await this . Logger . LogMessageAsync ( $ "{ this . TypeName } .ProcessStandardLogFileUploads ", relatedContext , async ( ) =>
133134 {
134- // Upload the workload summary logs (e.g. metrics.csv) before exiting. We do this at the very end. Same as before, we do not
135- // honor the cancellation token until ALL files have been successfully processed.
136- await this . UploadCsvSummaryFilesAsync ( blobManager , relatedContext ) ;
137-
138- // Upload specific summary.txt at root level of logs directory.
139- await this . UploadSummaryFileAsync ( blobManager , relatedContext ) ;
135+ // Upload the default logs (e.g. vc.metrics, vc.events, metrics.csv, summary.txt) before exiting. We do this at the very end.
136+ // Same as before, we do not honor the cancellation token until ALL files have been successfully processed.
137+ await this . UploadStandardLogFilesAsync ( blobManager , relatedContext ) ;
140138 } ) ;
141139
142140 break ;
@@ -236,64 +234,23 @@ private async Task<bool> UploadFilesAsync(IBlobManager blobManager, EventContext
236234 return filesFound ;
237235 }
238236
239- private async Task UploadSummaryFileAsync ( IBlobManager blobManager , EventContext telemetryContext )
240- {
241- try
242- {
243- string summaryTxtFileLocation = Path . Combine ( this . PlatformSpecifics . LogsDirectory , "summary.txt" ) ;
244- bool summaryTxtFileExists = this . fileSystem . File . Exists ( summaryTxtFileLocation ) ;
245- telemetryContext
246- . AddContext ( nameof ( summaryTxtFileLocation ) , summaryTxtFileLocation )
247- . AddContext ( nameof ( summaryTxtFileExists ) , summaryTxtFileExists ) ;
248-
249- if ( summaryTxtFileExists )
250- {
251- try
252- {
253- FileUploadDescriptor descriptor = this . CreateFileUploadDescriptor (
254- new FileContext (
255- this . fileSystem . FileInfo . New ( summaryTxtFileLocation ) ,
256- "text/plain" ,
257- Encoding . UTF8 . WebName ,
258- this . ExperimentId ,
259- this . AgentId ) ) ;
260-
261- await this . UploadFileAsync ( blobManager , this . fileSystem , descriptor , CancellationToken . None ) ;
262- }
263- catch ( IOException exc ) when ( exc . Message . Contains ( "being used by another process" , StringComparison . OrdinalIgnoreCase ) )
264- {
265- // It is common that there will be read/write access errors at certain times while
266- // upload request files are being created at the same time as attempts to read.
267- }
268- catch ( Exception exc )
269- {
270- this . Logger . LogErrorMessage ( exc , telemetryContext , LogLevel . Warning ) ;
271- }
272- }
273- }
274- catch ( Exception exc )
275- {
276- this . Logger . LogErrorMessage ( exc , telemetryContext , LogLevel . Error ) ;
277- }
278- }
279-
280- private async Task UploadCsvSummaryFilesAsync ( IBlobManager blobManager , EventContext telemetryContext )
237+ private async Task UploadStandardLogFilesAsync ( IBlobManager blobManager , EventContext telemetryContext )
281238 {
282239 try
283240 {
284241 if ( this . fileSystem . Directory . Exists ( this . PlatformSpecifics . LogsDirectory ) )
285242 {
286- IEnumerable < string > csvFiles = this . fileSystem . Directory . GetFiles ( this . PlatformSpecifics . LogsDirectory , "*.csv " , SearchOption . TopDirectoryOnly ) ;
287- if ( csvFiles ? . Any ( ) == true )
243+ IEnumerable < string > logFiles = this . fileSystem . Directory . GetFiles ( this . PlatformSpecifics . LogsDirectory , "*.* " , SearchOption . TopDirectoryOnly ) ;
244+ if ( logFiles ? . Any ( ) == true )
288245 {
289- foreach ( var filePath in csvFiles )
246+ foreach ( var filePath in logFiles )
290247 {
291248 try
292249 {
293250 FileUploadDescriptor descriptor = this . CreateFileUploadDescriptor (
294251 new FileContext (
295252 this . fileSystem . FileInfo . New ( filePath ) ,
296- "text/csv" ,
253+ MimeUtility . GetMimeMapping ( filePath ) ,
297254 Encoding . UTF8 . WebName ,
298255 this . ExperimentId ,
299256 this . AgentId ) ) ;
0 commit comments