Added EventSource for ChecksumCollector

pull/10111/head
anurse 11 years ago
parent fcc41a3df9
commit 087c71ad37

@ -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<CollectorCursor> 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<JObject> items, JObject context)
{
Trace.TraceInformation("Processing batch {0}...", BatchCount);
ChecksumCollectorEventSource.Log.ProcessingBatch(BatchCount, items.Count);
foreach (var item in items)
{
string type = item.Value<string>("@type");
string url = item.Value<string>("url");
ChecksumCollectorEventSource.Log.CollectingItem(type, url);
var key = Int32.Parse(item.Value<string>("galleryKey"));
if (String.Equals(type, "nuget:Package", StringComparison.Ordinal))
{
@ -51,10 +62,73 @@ protected override Task ProcessBatch(CollectorHttpClient client, IList<JObject>
{
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;
}
}
}

@ -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<StorageContent> 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();
}

Loading…
Cancel
Save