99using System . Net ;
1010using System . Threading ;
1111using System . Threading . Tasks ;
12+ using Microsoft . Extensions . Logging ;
1213using Microsoft . WindowsAzure . Storage ;
1314using Microsoft . WindowsAzure . Storage . Blob ;
1415using Microsoft . WindowsAzure . Storage . RetryPolicies ;
@@ -29,6 +30,7 @@ public class CloudDownloadCountService : IDownloadCountService
2930
3031 private readonly ITelemetryService _telemetryService ;
3132 private readonly Func < ICloudBlobClient > _cloudBlobClientFactory ;
33+ private readonly ILogger < CloudDownloadCountService > _logger ;
3234
3335 private readonly object _refreshLock = new object ( ) ;
3436 private bool _isRefreshing ;
@@ -38,10 +40,12 @@ private readonly ConcurrentDictionary<string, ConcurrentDictionary<string, long>
3840
3941 public CloudDownloadCountService (
4042 ITelemetryService telemetryService ,
41- Func < ICloudBlobClient > cloudBlobClientFactory )
43+ Func < ICloudBlobClient > cloudBlobClientFactory ,
44+ ILogger < CloudDownloadCountService > logger )
4245 {
4346 _telemetryService = telemetryService ?? throw new ArgumentNullException ( nameof ( telemetryService ) ) ;
4447 _cloudBlobClientFactory = cloudBlobClientFactory ?? throw new ArgumentNullException ( nameof ( cloudBlobClientFactory ) ) ;
48+ _logger = logger ?? throw new ArgumentNullException ( nameof ( logger ) ) ;
4549 }
4650
4751 public bool TryGetDownloadCountForPackageRegistration ( string id , out long downloadCount )
@@ -158,6 +162,9 @@ private async Task RefreshCoreAsync()
158162 {
159163 try
160164 {
165+ int totalIds = 0 ;
166+ int totalVersions = 0 ;
167+
161168 // The data in downloads.v1.json will be an array of Package records - which has Id, Array of Versions and download count.
162169 // Sample.json : [["AutofacContrib.NSubstitute",["2.4.3.700",406],["2.5.0",137]],["Assman.Core",["2.0.7",138]]....
163170 using ( var blobStream = await GetBlobStreamAsync ( ) )
@@ -189,6 +196,8 @@ private async Task RefreshCoreAsync()
189196 continue ;
190197 }
191198
199+ ++ totalIds ;
200+
192201 var versions = _downloadCounts . GetOrAdd (
193202 id ,
194203 _ => new ConcurrentDictionary < string , long > ( StringComparer . OrdinalIgnoreCase ) ) ;
@@ -199,6 +208,7 @@ private async Task RefreshCoreAsync()
199208 {
200209 var version = token [ 0 ] . ToString ( ) ;
201210 var downloadCount = token [ 1 ] . ToObject < long > ( ) ;
211+ ++ totalVersions ;
202212
203213 if ( versions . ContainsKey ( version ) && downloadCount < versions [ version ] )
204214 {
@@ -232,6 +242,9 @@ private async Task RefreshCoreAsync()
232242 }
233243 }
234244 }
245+
246+ _telemetryService . TrackDownloadJsonTotalPackageIds ( totalIds ) ;
247+ _telemetryService . TrackDownloadJsonTotalPackageVersions ( totalVersions ) ;
235248 }
236249 catch ( Exception ex )
237250 {
@@ -250,6 +263,8 @@ private ISimpleCloudBlob GetBlobReference()
250263 var container = blobClient . GetContainerReference ( StatsContainerName ) ;
251264 var blob = container . GetBlobReference ( DownloadCountBlobName ) ;
252265
266+ _logger . LogInformation ( "Cloud download statistics source: {BlobUri}" , blob . Uri ) ;
267+
253268 return blob ;
254269 }
255270 }
0 commit comments