Skip to content

Commit ac0ecab

Browse files
changed logging
1 parent ba174d9 commit ac0ecab

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

Extensions/AzureBlob/Cosmos.DataTransfer.AzureBlobStorage/AzureBlobDataSink.cs

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Azure.Identity;
1+
using System.Diagnostics;
2+
using Azure.Identity;
23
using Azure.Storage.Blobs;
34
using Azure.Storage.Blobs.Models;
45
using Azure.Storage.Blobs.Specialized;
@@ -40,20 +41,45 @@ public async Task WriteToTargetAsync(Func<Stream, Task> writeToStream, IConfigur
4041

4142
logger.LogInformation("Saving file '{File}' to Azure Blob Container '{ContainerName}'", settings.BlobName, settings.ContainerName);
4243

44+
var lastLogTime = DateTime.MinValue;
45+
var logInterval = TimeSpan.FromMinutes(1);
46+
long totalBytes = 0;
47+
48+
var sw = new Stopwatch();
49+
sw.Start();
4350
await using var blobStream = await blob.OpenWriteAsync(true, new BlockBlobOpenWriteOptions
4451
{
4552
BufferSize = settings.MaxBlockSizeinKB * 1024L,
4653
ProgressHandler = new Progress<long>(l =>
4754
{
48-
logger.LogInformation("Transferred {UploadedBytes} bytes to Azure Blob", l);
55+
if (DateTime.UtcNow - lastLogTime >= logInterval)
56+
{
57+
logger.LogInformation("Transferred {TotalMiB} bytes to Azure Blob", l/1024/1024);
58+
lastLogTime = DateTime.UtcNow;
59+
}
60+
61+
totalBytes = l;
4962
})
63+
5064
}, cancellationToken);
5165
await writeToStream(blobStream);
66+
67+
sw.Stop();
68+
69+
var totalMib = totalBytes / 1024 / 1024;
70+
var rate = totalMib / sw.ElapsedMilliseconds / 1000;
71+
72+
logger.LogInformation("Transferred {TotalMiB} Mib to Azure Blob in {TotalTime} minutes ({Rate} MiB/s).", totalMib, sw.ElapsedMilliseconds/1000/60, rate);
5273
}
5374

5475
public IEnumerable<IDataExtensionSettings> GetSettings()
5576
{
5677
yield return new AzureBlobSinkSettings();
5778
}
79+
80+
private void LogBytes()
81+
{
82+
83+
}
5884
}
5985
}

Extensions/Json/Cosmos.DataTransfer.JsonExtension/Settings/JsonFormatWriterSettings.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ public class JsonFormatWriterSettings : IDataExtensionSettings
66
{
77
public bool IncludeNullFields { get; set; }
88
public bool Indented { get; set; }
9-
public int BufferSizeMB { get; set; } = 50;
9+
public int BufferSizeMB { get; set; } = 200;
1010
}
1111
}

0 commit comments

Comments
 (0)