@@ -13,18 +13,19 @@ namespace VirtualClient.Monitors
13
13
using System . Threading . Tasks ;
14
14
using global ::VirtualClient . Common . Contracts ;
15
15
using global ::VirtualClient . Common . Extensions ;
16
- using global ::VirtualClient . Common . Platform ;
17
16
using global ::VirtualClient . Common . Telemetry ;
18
17
using global ::VirtualClient . Contracts ;
19
18
using Microsoft . Extensions . DependencyInjection ;
20
19
using Microsoft . Extensions . Logging ;
20
+ using MimeMapping ;
21
21
using Newtonsoft . Json ;
22
- using Polly ;
22
+ using VirtualClient . Common ;
23
23
24
24
/// <summary>
25
25
/// This monitor processes content/file uploads requested by Virtual Client
26
26
/// workload, monitoring and dependency components.
27
27
/// </summary>
28
+ [ SupportedPlatforms ( "linux-arm64,linux-x64,win-arm64,win-x64" ) ]
28
29
public class FileUploadMonitor : VirtualClientComponent
29
30
{
30
31
private IFileSystem fileSystem ;
@@ -66,7 +67,7 @@ protected override Task ExecuteAsync(EventContext telemetryContext, Cancellation
66
67
if ( this . TryGetContentStoreManager ( out IBlobManager blobManager ) )
67
68
{
68
69
await this . ProcessFileUploadsAsync ( blobManager , telemetryContext , cancellationToken ) ;
69
- await this . ProcessSummaryFileUploadsAsync ( blobManager , telemetryContext ) ;
70
+ await this . ProcessStandardLogFileUploadsAsync ( blobManager , telemetryContext ) ;
70
71
}
71
72
} ) ;
72
73
}
@@ -121,22 +122,19 @@ private async Task ProcessFileUploadsAsync(IBlobManager blobManager, EventContex
121
122
}
122
123
}
123
124
124
- private async Task ProcessSummaryFileUploadsAsync ( IBlobManager blobManager , EventContext telemetryContext )
125
+ private async Task ProcessStandardLogFileUploadsAsync ( IBlobManager blobManager , EventContext telemetryContext )
125
126
{
126
127
EventContext relatedContext = telemetryContext . Clone ( ) . AddContext ( "directoryPath" , this . PlatformSpecifics . LogsDirectory ) ;
127
128
128
129
while ( true )
129
130
{
130
131
try
131
132
{
132
- await this . Logger . LogMessageAsync ( $ "{ this . TypeName } .ProcessSummaryFileUploads ", relatedContext , async ( ) =>
133
+ await this . Logger . LogMessageAsync ( $ "{ this . TypeName } .ProcessStandardLogFileUploads ", relatedContext , async ( ) =>
133
134
{
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 ) ;
140
138
} ) ;
141
139
142
140
break ;
@@ -236,64 +234,23 @@ private async Task<bool> UploadFilesAsync(IBlobManager blobManager, EventContext
236
234
return filesFound ;
237
235
}
238
236
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 )
281
238
{
282
239
try
283
240
{
284
241
if ( this . fileSystem . Directory . Exists ( this . PlatformSpecifics . LogsDirectory ) )
285
242
{
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 )
288
245
{
289
- foreach ( var filePath in csvFiles )
246
+ foreach ( var filePath in logFiles )
290
247
{
291
248
try
292
249
{
293
250
FileUploadDescriptor descriptor = this . CreateFileUploadDescriptor (
294
251
new FileContext (
295
252
this . fileSystem . FileInfo . New ( filePath ) ,
296
- "text/csv" ,
253
+ MimeUtility . GetMimeMapping ( filePath ) ,
297
254
Encoding . UTF8 . WebName ,
298
255
this . ExperimentId ,
299
256
this . AgentId ) ) ;
0 commit comments