Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
/ NuGet.Jobs Public archive

Commit

Permalink
CollectAzureCdnLogs should properly handle files ending in .tmp (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Bommarito authored Nov 28, 2018
1 parent e9a40a1 commit ced7785
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
8 changes: 3 additions & 5 deletions src/Stats.CollectAzureCdnLogs/Ftp/FtpRawLogClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public async Task DeleteAsync(Uri uri)
}
}

public async Task<IEnumerable<RawLogFileInfo>> GetRawLogFiles(Uri uri)
public async Task<IEnumerable<Uri>> GetRawLogFileUris(Uri uri)
{
if (uri == null)
{
Expand All @@ -124,15 +124,13 @@ public async Task<IEnumerable<RawLogFileInfo>> GetRawLogFiles(Uri uri)

var fileNames = directoryList.Split(Environment.NewLine.ToCharArray(),
StringSplitOptions.RemoveEmptyEntries);
var rawLogFiles = fileNames.Select(fn => new RawLogFileInfo(new Uri(uri.EnsureTrailingSlash(), fn)));

return rawLogFiles;
return fileNames.Select(fn => new Uri(uri.EnsureTrailingSlash(), fn));
}
catch (Exception e)
{
Logger.LogError(LogEvents.FailedBlobListing, e, "Failed to get raw log files.");

return Enumerable.Empty<RawLogFileInfo>();
return Enumerable.Empty<Uri>();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Stats.CollectAzureCdnLogs/IRawLogClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Stats.CollectAzureCdnLogs
{
internal interface IRawLogClient
{
Task<IEnumerable<RawLogFileInfo>> GetRawLogFiles(Uri uri);
Task<IEnumerable<Uri>> GetRawLogFileUris(Uri uri);
Task<Stream> OpenReadAsync(Uri uri);
Task<bool> RenameAsync(Uri uri, string newFileName);
Task DeleteAsync(Uri uri);
Expand Down
6 changes: 4 additions & 2 deletions src/Stats.CollectAzureCdnLogs/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,17 @@ public override async Task Run()
var azureClient = new CloudBlobRawLogClient(LoggerFactory, _cloudStorageAccount);

// Collect directory listing.
var rawLogFiles = await ftpClient.GetRawLogFiles(_ftpServerUri);
var rawLogFileUris = await ftpClient.GetRawLogFileUris(_ftpServerUri);

// Prepare cloud storage blob container.
var cloudBlobContainer = await azureClient.CreateContainerIfNotExistsAsync(_cloudStorageContainerName);

foreach (var rawLogFile in rawLogFiles)
foreach (var rawLogFileUri in rawLogFileUris)
{
try
{
var rawLogFile = new RawLogFileInfo(rawLogFileUri);

if (_azureCdnPlatform != rawLogFile.AzureCdnPlatform
|| !_azureCdnAccountNumber.Equals(rawLogFile.AzureCdnAccountNumber, StringComparison.InvariantCultureIgnoreCase))
{
Expand Down
18 changes: 6 additions & 12 deletions src/Stats.CollectAzureCdnLogs/RawLogFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ private void TryParseFileName()
if (Extension.EndsWith(FileExtensions.Gzip, StringComparison.InvariantCultureIgnoreCase))
{
ContentType = _contentTypeGzip;
}
else
{
throw new InvalidRawLogFileNameException(FileName);

return;
}
}
else if (lastPart.Count() == 4)
Expand All @@ -85,17 +83,13 @@ private void TryParseFileName()
{
IsPendingDownload = true;
ContentType = _contentTypeGzip;

return;
}
}
else
{
throw new InvalidRawLogFileNameException(FileName);
}
}
else
{
throw new InvalidRawLogFileNameException(FileName);
}

throw new InvalidRawLogFileNameException(FileName);
}

private int TryParseRollingFileNumber(string rollingFileNumberString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void ThrowsWhenInvalidUri()
[InlineData("ftp://someserver/logs/wpc_A000_20150603_0058.log")]
[InlineData("ftp://someserver/logs/wpc_A000_20151342_0058.log.gz")]
[InlineData("ftp://someserver/logs/wpc_A000_20150603_0058.log.download")]
[InlineData("ftp://someserver/logs/wpc_A000_20150603_0058.log.gz.tmp")]
public void ThrowsWhenInvalidRawLogFileName(string uriString)
{
Assert.Throws<InvalidRawLogFileNameException>(() => new RawLogFileInfo(new Uri(uriString)));
Expand Down

0 comments on commit ced7785

Please sign in to comment.