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

Commit c3a0ad1

Browse files
Re-injecting the dead-letter files through Stats.ImportAzureCdnStatistics could lead to duplicate data (#107)
1 parent 899603f commit c3a0ad1

22 files changed

Lines changed: 1259 additions & 246 deletions

src/Stats.AzureCdnLogs.Common/LogEvents.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class LogEvents
2020
public static EventId UnknownAzureCdnPlatform = new EventId(510, "Unknown Azure CDN platform");
2121
public static EventId InvalidRawLogFileName = new EventId(511, "Invalid raw log filename");
2222
public static EventId FailedToGetFtpResponse = new EventId(512, "Failed to get FTP response");
23+
public static EventId FailedToCheckAlreadyProcessedLogFilePackageStatistics = new EventId(513, "Failed to check already processed package statistics for log file");
24+
public static EventId FailedToCheckAlreadyProcessedLogFileToolStatistics = new EventId(514, "Failed to check already processed tool statistics for log file");
2325
public static EventId JobRunFailed = new EventId(550, "Job run failed");
2426
public static EventId JobInitFailed = new EventId(551, "Job initialization failed");
2527
}

src/Stats.ImportAzureCdnStatistics/ILeasedLogFile.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77

88
namespace Stats.ImportAzureCdnStatistics
99
{
10-
internal interface ILeasedLogFile
10+
public interface ILeasedLogFile
1111
: IDisposable
1212
{
1313
string LeaseId { get; }
1414

1515
string Uri { get; }
1616

17+
string BlobName { get; }
18+
1719
CloudBlockBlob Blob { get; }
1820

1921
Task AcquireInfiniteLeaseAsync();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Stats.AzureCdnLogs.Common;
5+
6+
namespace Stats.ImportAzureCdnStatistics
7+
{
8+
public interface IPackageStatisticsParser
9+
{
10+
PackageStatistics FromCdnLogEntry(CdnLogEntry cdnLogEntry);
11+
}
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.IO;
6+
using System.Threading.Tasks;
7+
8+
namespace Stats.ImportAzureCdnStatistics
9+
{
10+
public interface IStatisticsBlobContainerUtility
11+
{
12+
Task<Stream> OpenCompressedBlobAsync(ILeasedLogFile logFile);
13+
Task CopyToDeadLetterContainerAsync(ILeasedLogFile logFile, Exception e);
14+
Task DeleteSourceBlobAsync(ILeasedLogFile logFile);
15+
Task ArchiveBlobAsync(ILeasedLogFile logFile);
16+
}
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Collections.Generic;
5+
using System.Data;
6+
using System.Threading.Tasks;
7+
using Stats.AzureCdnLogs.Common;
8+
9+
namespace Stats.ImportAzureCdnStatistics
10+
{
11+
public interface IStatisticsWarehouse
12+
{
13+
Task<List<DataTable>> CreateAsync(IReadOnlyCollection<PackageStatistics> sourceData, string logFileName);
14+
Task<List<DataTable>> CreateAsync(IReadOnlyCollection<ToolStatistics> sourceData, string logFileName);
15+
Task<bool> HasImportedToolStatisticsAsync(string logFileName);
16+
Task<bool> HasImportedPackageStatisticsAsync(string logFileName);
17+
Task InsertDownloadFactsAsync(List<DataTable> downloadFactsDataTables, string logFileName);
18+
Task StoreLogFileAggregatesAsync(LogFileAggregates logFileAggregates);
19+
}
20+
}

src/Stats.ImportAzureCdnStatistics/Job.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ public override async Task<bool> Run()
8686

8787
// Create a parser
8888
var warehouse = new Warehouse(_loggerFactory, _targetDatabase);
89-
var logProcessor = new LogFileProcessor(targetBlobContainer, deadLetterBlobContainer, _loggerFactory, warehouse);
89+
var statisticsBlobContainerUtility = new StatisticsBlobContainerUtility(
90+
targetBlobContainer,
91+
deadLetterBlobContainer,
92+
_loggerFactory);
93+
94+
var logProcessor = new LogFileProcessor(statisticsBlobContainerUtility, _loggerFactory, warehouse);
9095

9196
// Get the next to-be-processed raw log file using the cdn raw log file name prefix
9297
var prefix = string.Format(CultureInfo.InvariantCulture, "{0}_{1}_", _azureCdnPlatform.GetRawLogFilePrefix(), _azureCdnAccountNumber);

src/Stats.ImportAzureCdnStatistics/LogFileAggregates.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Stats.ImportAzureCdnStatistics
77
{
8-
internal class LogFileAggregates
8+
public class LogFileAggregates
99
{
1010
public LogFileAggregates(string logFileName)
1111
{

0 commit comments

Comments
 (0)