Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit ced7785

Browse files
author
Scott Bommarito
authored
CollectAzureCdnLogs should properly handle files ending in .tmp (#673)
1 parent e9a40a1 commit ced7785

5 files changed

Lines changed: 15 additions & 20 deletions

File tree

src/Stats.CollectAzureCdnLogs/Ftp/FtpRawLogClient.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public async Task DeleteAsync(Uri uri)
9797
}
9898
}
9999

100-
public async Task<IEnumerable<RawLogFileInfo>> GetRawLogFiles(Uri uri)
100+
public async Task<IEnumerable<Uri>> GetRawLogFileUris(Uri uri)
101101
{
102102
if (uri == null)
103103
{
@@ -124,15 +124,13 @@ public async Task<IEnumerable<RawLogFileInfo>> GetRawLogFiles(Uri uri)
124124

125125
var fileNames = directoryList.Split(Environment.NewLine.ToCharArray(),
126126
StringSplitOptions.RemoveEmptyEntries);
127-
var rawLogFiles = fileNames.Select(fn => new RawLogFileInfo(new Uri(uri.EnsureTrailingSlash(), fn)));
128-
129-
return rawLogFiles;
127+
return fileNames.Select(fn => new Uri(uri.EnsureTrailingSlash(), fn));
130128
}
131129
catch (Exception e)
132130
{
133131
Logger.LogError(LogEvents.FailedBlobListing, e, "Failed to get raw log files.");
134132

135-
return Enumerable.Empty<RawLogFileInfo>();
133+
return Enumerable.Empty<Uri>();
136134
}
137135
}
138136
}

src/Stats.CollectAzureCdnLogs/IRawLogClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Stats.CollectAzureCdnLogs
1010
{
1111
internal interface IRawLogClient
1212
{
13-
Task<IEnumerable<RawLogFileInfo>> GetRawLogFiles(Uri uri);
13+
Task<IEnumerable<Uri>> GetRawLogFileUris(Uri uri);
1414
Task<Stream> OpenReadAsync(Uri uri);
1515
Task<bool> RenameAsync(Uri uri, string newFileName);
1616
Task DeleteAsync(Uri uri);

src/Stats.CollectAzureCdnLogs/Job.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,17 @@ public override async Task Run()
114114
var azureClient = new CloudBlobRawLogClient(LoggerFactory, _cloudStorageAccount);
115115

116116
// Collect directory listing.
117-
var rawLogFiles = await ftpClient.GetRawLogFiles(_ftpServerUri);
117+
var rawLogFileUris = await ftpClient.GetRawLogFileUris(_ftpServerUri);
118118

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

122-
foreach (var rawLogFile in rawLogFiles)
122+
foreach (var rawLogFileUri in rawLogFileUris)
123123
{
124124
try
125125
{
126+
var rawLogFile = new RawLogFileInfo(rawLogFileUri);
127+
126128
if (_azureCdnPlatform != rawLogFile.AzureCdnPlatform
127129
|| !_azureCdnAccountNumber.Equals(rawLogFile.AzureCdnAccountNumber, StringComparison.InvariantCultureIgnoreCase))
128130
{

src/Stats.CollectAzureCdnLogs/RawLogFileInfo.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,8 @@ private void TryParseFileName()
7070
if (Extension.EndsWith(FileExtensions.Gzip, StringComparison.InvariantCultureIgnoreCase))
7171
{
7272
ContentType = _contentTypeGzip;
73-
}
74-
else
75-
{
76-
throw new InvalidRawLogFileNameException(FileName);
73+
74+
return;
7775
}
7876
}
7977
else if (lastPart.Count() == 4)
@@ -85,17 +83,13 @@ private void TryParseFileName()
8583
{
8684
IsPendingDownload = true;
8785
ContentType = _contentTypeGzip;
86+
87+
return;
8888
}
8989
}
90-
else
91-
{
92-
throw new InvalidRawLogFileNameException(FileName);
93-
}
94-
}
95-
else
96-
{
97-
throw new InvalidRawLogFileNameException(FileName);
9890
}
91+
92+
throw new InvalidRawLogFileNameException(FileName);
9993
}
10094

10195
private int TryParseRollingFileNumber(string rollingFileNumberString)

tests/Tests.Stats.CollectAzureCdnLogs/RawLogFileInfoTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public void ThrowsWhenInvalidUri()
6060
[InlineData("ftp://someserver/logs/wpc_A000_20150603_0058.log")]
6161
[InlineData("ftp://someserver/logs/wpc_A000_20151342_0058.log.gz")]
6262
[InlineData("ftp://someserver/logs/wpc_A000_20150603_0058.log.download")]
63+
[InlineData("ftp://someserver/logs/wpc_A000_20150603_0058.log.gz.tmp")]
6364
public void ThrowsWhenInvalidRawLogFileName(string uriString)
6465
{
6566
Assert.Throws<InvalidRawLogFileNameException>(() => new RawLogFileInfo(new Uri(uriString)));

0 commit comments

Comments
 (0)