From 087c71ad37732b4bad32ae9bac9aa7121c8b855b Mon Sep 17 00:00:00 2001 From: anurse Date: Mon, 7 Jul 2014 14:06:43 -0700 Subject: [PATCH] Added EventSource for ChecksumCollector --- src/Catalog/Collecting/ChecksumCollector.cs | 78 ++++++++++++++++++++- src/Catalog/Persistence/AzureStorage.cs | 23 +++--- 2 files changed, 89 insertions(+), 12 deletions(-) diff --git a/src/Catalog/Collecting/ChecksumCollector.cs b/src/Catalog/Collecting/ChecksumCollector.cs index 04b031c6b..6509dca43 100644 --- a/src/Catalog/Collecting/ChecksumCollector.cs +++ b/src/Catalog/Collecting/ChecksumCollector.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.Tracing; using System.IO; using System.Linq; using System.Text; @@ -28,13 +29,23 @@ public ChecksumCollector(int batchSize, ChecksumRecords checksums) : base(batchS Checksums = checksums; } + protected override async Task Fetch(CollectorHttpClient client, Uri index, CollectorCursor last) + { + ChecksumCollectorEventSource.Log.Collecting(index.ToString(), ((DateTime)last).ToString("O")); + var cursor = await base.Fetch(client, index, last); + ChecksumCollectorEventSource.Log.Collected(); + return cursor; + } + protected override Task ProcessBatch(CollectorHttpClient client, IList items, JObject context) { - Trace.TraceInformation("Processing batch {0}...", BatchCount); + ChecksumCollectorEventSource.Log.ProcessingBatch(BatchCount, items.Count); foreach (var item in items) { string type = item.Value("@type"); + string url = item.Value("url"); + ChecksumCollectorEventSource.Log.CollectingItem(type, url); var key = Int32.Parse(item.Value("galleryKey")); if (String.Equals(type, "nuget:Package", StringComparison.Ordinal)) { @@ -51,10 +62,73 @@ protected override Task ProcessBatch(CollectorHttpClient client, IList { Checksums.Data.Remove(key); } + ChecksumCollectorEventSource.Log.CollectedItem(); } - Trace.TraceInformation("Processed batch {0}...", BatchCount); + ChecksumCollectorEventSource.Log.ProcessedBatch(); return Task.FromResult(0); } } + + [EventSource(Name="Outercurve-NuGet-Catalog-ChecksumCollector")] + public class ChecksumCollectorEventSource : EventSource + { + public static readonly ChecksumCollectorEventSource Log = new ChecksumCollectorEventSource(); + private ChecksumCollectorEventSource() { } + + [Event( + eventId: 1, + Level = EventLevel.Informational, + Opcode = EventOpcode.Start, + Task = Tasks.Collecting, + Message = "Collecting catalog nodes from {0} since {1}")] + public void Collecting(string indexUri, string cursor) { WriteEvent(1, indexUri, cursor); } + + [Event( + eventId: 2, + Level = EventLevel.Informational, + Opcode = EventOpcode.Stop, + Task = Tasks.Collecting, + Message = "Collection completed.")] + public void Collected() { WriteEvent(2); } + + [Event( + eventId: 3, + Level = EventLevel.Informational, + Opcode = EventOpcode.Start, + Task = Tasks.ProcessingBatch, + Message = "Processing Batch #{0}, containing {1} items.")] + public void ProcessingBatch(int count, int items) { WriteEvent(3, count, items); } + + [Event( + eventId: 4, + Level = EventLevel.Informational, + Opcode = EventOpcode.Stop, + Task = Tasks.ProcessingBatch, + Message = "Processed Batch.")] + public void ProcessedBatch() { WriteEvent(4); } + + [Event( + eventId: 5, + Level = EventLevel.Verbose, + Opcode = EventOpcode.Start, + Task = Tasks.CollectingItem, + Message = "Collecting {0} item {1}")] + public void CollectingItem(string type, string uri) { WriteEvent(5, type, uri); } + + [Event( + eventId: 6, + Level = EventLevel.Verbose, + Opcode = EventOpcode.Stop, + Task = Tasks.CollectingItem, + Message = "Collecting {0} item {1}")] + public void CollectedItem() { WriteEvent(6); } + + public class Tasks + { + public const EventTask Collecting = (EventTask)0x1; + public const EventTask ProcessingBatch = (EventTask)0x2; + public const EventTask CollectingItem = (EventTask)0x3; + } + } } diff --git a/src/Catalog/Persistence/AzureStorage.cs b/src/Catalog/Persistence/AzureStorage.cs index 0de6145e7..f7753423f 100644 --- a/src/Catalog/Persistence/AzureStorage.cs +++ b/src/Catalog/Persistence/AzureStorage.cs @@ -9,11 +9,14 @@ namespace NuGet.Services.Metadata.Catalog.Persistence { public class AzureStorage : Storage { - private CloudBlobContainer _container; - public AzureStorage(CloudStorageAccount account, string container) + private CloudBlobDirectory _directory; + + public AzureStorage(CloudStorageAccount account, string containerName) : this(account, containerName, String.Empty) { } + public AzureStorage(CloudStorageAccount account, string containerName, string path) { - _container = account.CreateCloudBlobClient().GetContainerReference(container); - BaseAddress = new UriBuilder(_container.Uri) + var container = account.CreateCloudBlobClient().GetContainerReference(containerName); + _directory = container.GetDirectoryReference(path); + BaseAddress = new UriBuilder(_directory.Uri) { Scheme = "http" // Convert base address to http. 'https' can be used for communication but is not part of the names. }.Uri; @@ -32,17 +35,17 @@ public override async Task Save(Uri resourceUri, StorageContent content) Console.WriteLine("save {0}", name); } - if (_container.CreateIfNotExists()) + if (_directory.Container.CreateIfNotExists()) { - _container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); + _directory.Container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); if (Verbose) { - Console.WriteLine("Created '{0}' publish container", _container.Name); + Console.WriteLine("Created '{0}' publish container", _directory.Container.Name); } } - CloudBlockBlob blob = _container.GetBlockBlobReference(name); + CloudBlockBlob blob = _directory.GetBlockBlobReference(name); blob.Properties.ContentType = content.ContentType; blob.Properties.CacheControl = "no-store"; // no for production, just helps with debugging @@ -60,7 +63,7 @@ public override async Task Load(Uri resourceUri) string name = GetName(resourceUri); - CloudBlockBlob blob = _container.GetBlockBlobReference(name); + CloudBlockBlob blob = _directory.GetBlockBlobReference(name); if (blob.Exists()) { @@ -79,7 +82,7 @@ public override async Task Delete(Uri resourceUri) string name = GetName(resourceUri); - CloudBlockBlob blob = _container.GetBlockBlobReference(name); + CloudBlockBlob blob = _directory.GetBlockBlobReference(name); await blob.DeleteAsync(); }