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
created Stats.CollectAzureCdnLogs job
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierdecoster committed Jun 3, 2015
1 parent 5e994a4 commit e93e095
Show file tree
Hide file tree
Showing 28 changed files with 1,277 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,5 @@ UpgradeLog*.htm
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/
FakesAssemblies/
*.webtestresult
13 changes: 13 additions & 0 deletions Local.testsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="Local" id="04665429-a6c2-4cdf-b720-95461fe06f50" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>These are default test settings for a local test run.</Description>
<Deployment enabled="false" />
<Execution>
<TestTypeSpecific />
<AgentRule name="Execution Agents">
</AgentRule>
</Execution>
<Properties>
<Property name="TestSettingsUIType" value="LoadTest" />
</Properties>
</TestSettings>
20 changes: 20 additions & 0 deletions NuGet.Jobs.sln
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HandlePackageEdits", "src\H
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateLicenseReports", "src\UpdateLicenseReports\UpdateLicenseReports.csproj", "{4646F0C5-EC7A-45F5-8E45-D51C715C1DC9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoadTests", "src\LoadTests\LoadTests.csproj", "{FC4A7438-6EFD-437F-A077-8F5BF4654316}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6078A997-EDEF-4F84-9E9C-163EB1E7454D}"
ProjectSection(SolutionItems) = preProject
Local.testsettings = Local.testsettings
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stats.CollectAzureCdnLogs", "src\Stats.CollectAzureCdnLogs\Stats.CollectAzureCdnLogs.csproj", "{664CA8BB-BCF5-432C-AF68-9F97D308E623}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -135,6 +144,14 @@ Global
{4646F0C5-EC7A-45F5-8E45-D51C715C1DC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4646F0C5-EC7A-45F5-8E45-D51C715C1DC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4646F0C5-EC7A-45F5-8E45-D51C715C1DC9}.Release|Any CPU.Build.0 = Release|Any CPU
{FC4A7438-6EFD-437F-A077-8F5BF4654316}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FC4A7438-6EFD-437F-A077-8F5BF4654316}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC4A7438-6EFD-437F-A077-8F5BF4654316}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC4A7438-6EFD-437F-A077-8F5BF4654316}.Release|Any CPU.Build.0 = Release|Any CPU
{664CA8BB-BCF5-432C-AF68-9F97D308E623}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{664CA8BB-BCF5-432C-AF68-9F97D308E623}.Debug|Any CPU.Build.0 = Debug|Any CPU
{664CA8BB-BCF5-432C-AF68-9F97D308E623}.Release|Any CPU.ActiveCfg = Release|Any CPU
{664CA8BB-BCF5-432C-AF68-9F97D308E623}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -157,5 +174,8 @@ Global
{43B8F81F-3B9C-4737-99A9-BBCFFDACF200} = {57F34E9A-3A98-4E48-BF76-D49CB9CB3323}
{C959B545-51C8-4D83-B9A0-243BBC199E49} = {FA5644B5-4F08-43F6-86B3-039374312A47}
{4646F0C5-EC7A-45F5-8E45-D51C715C1DC9} = {FA5644B5-4F08-43F6-86B3-039374312A47}
{FC4A7438-6EFD-437F-A077-8F5BF4654316} = {6A776396-02B1-475D-A104-26940ADB04AB}
{6078A997-EDEF-4F84-9E9C-163EB1E7454D} = {6A776396-02B1-475D-A104-26940ADB04AB}
{664CA8BB-BCF5-432C-AF68-9F97D308E623} = {3B227DEE-B610-440F-866E-6F79D413B21F}
EndGlobalSection
EndGlobal
3 changes: 2 additions & 1 deletion NuGet.Jobs.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">Copyright (c) .NET Foundation. All rights reserved.&#xD;
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.</s:String></wpf:ResourceDictionary>
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String></wpf:ResourceDictionary>
14 changes: 14 additions & 0 deletions src/LoadTests/DownloadPackageApiV2.webtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<WebTest Name="DownloadPackageApiV2" Id="f0c6d88d-bc9d-4256-b1f0-c70866d59e2e" Owner="" Priority="2147483647" Enabled="True" CssProjectStructure="" CssIteration="" Timeout="0" WorkItemIds="" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" Description="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="default" StopOnError="False" RecordedResultFile="WebTest1.7ffeba66-45d9-4625-9ca6-ca2b95c6c76a.rec.webtestresult" ResultsLocale="">
<Items>
<Request Method="GET" Guid="ea523c76-15f8-4fae-96cd-ac46a2a3fe40" Version="1.1" Url="https://dev.nugettest.org/api/v2/package/Newtonsoft.Json/6.0.1-beta1" ThinkTime="25" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="https://f168.wpc.azureedge.net/80F168/nugetdevlegacy.blob.core.windows.net/packages/newtonsoft.json.6.0.1-beta1.nupkg" ReportingName="Download package through v2 API" IgnoreHttpStatusCode="False" />
</Items>
<ValidationRules>
<ValidationRule Classname="Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidateResponseUrl, Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" DisplayName="Response URL" Description="Validates that the response URL after redirects are followed is the same as the recorded response URL. QueryString parameters are ignored." Level="Low" ExectuionOrder="BeforeDependents" />
<ValidationRule Classname="Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidationRuleResponseTimeGoal, Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" DisplayName="Response Time Goal" Description="Validates that the response time for the request is less than or equal to the response time goal as specified on the request. Response time goals of zero will be ignored." Level="Low" ExectuionOrder="AfterDependents">
<RuleParameters>
<RuleParameter Name="Tolerance" Value="0" />
</RuleParameters>
</ValidationRule>
</ValidationRules>
</WebTest>
84 changes: 84 additions & 0 deletions src/LoadTests/LoadTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{FC4A7438-6EFD-437F-A077-8F5BF4654316}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LoadTests</RootNamespace>
<AssemblyName>LoadTests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TestProjectType>WebTest</TestProjectType>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
<Visible>False</Visible>
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="DownloadPackageApiV2.webtest">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
18 changes: 18 additions & 0 deletions src/LoadTests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("LoadTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LoadTests")]
[assembly: AssemblyCopyright("Copyright © .NET Foundation 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("a44bd48a-4ea1-43a0-b72a-d79cb002590d")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
23 changes: 16 additions & 7 deletions src/NuGet.Jobs.Common/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,18 @@ public static class JobArgumentNames
public const string LicenseReportService = "LicenseReportService";
public const string LicenseReportUser = "LicenseReportUser";
public const string LicenseReportPassword = "LicenseReportPassword";

//Arguments specific to CollectAzureCdnLogs
public const string FtpSourceUri = "FtpSourceUri";
public const string FtpSourceUsername = "FtpSourceUsername";
public const string FtpSourcePassword = "FtpSourcePassword";
public const string AzureCdnAccountNumber = "AzureCdnAccountNumber";
public const string AzureCdnPlatform = "AzureCdnPlatform";
public const string AzureCdnCloudStorageAccount = "AzureCdnCloudStorageAccount";
public const string AzureCdnCloudStorageContainerName = "AzureCdnCloudStorageContainerName";
}
/// <summary>
/// This class is used to retrieve and expose the known azure configuration settings
/// This class is used to retrieve and expose the known azure configuration settings
/// from Environment Variables
/// </summary>
public static class JobConfigManager
Expand Down Expand Up @@ -129,21 +138,21 @@ public static IDictionary<string, string> GetJobArgsDictionary(JobTraceListener
// Or, in singles as a switch '-<switch>'

IDictionary<string, string> argsDictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
for(int i = 0; i < allArgsList.Count; i++)
for (int i = 0; i < allArgsList.Count; i++)
{
if(!allArgsList[i].StartsWith("-"))
if (!allArgsList[i].StartsWith("-"))
{
throw new ArgumentException("Argument Name does not start with a hyphen ('-')");
}

var argName = allArgsList[i].Substring(1);
if(String.IsNullOrEmpty(argName))
if (String.IsNullOrEmpty(argName))
{
throw new ArgumentException("Argument Name is null or empty");
}

var nextString = allArgsList.Count > i + 1 ? allArgsList[i + 1] : null;
if(String.IsNullOrEmpty(nextString) || nextString.StartsWith("-"))
if (String.IsNullOrEmpty(nextString) || nextString.StartsWith("-"))
{
// If the key already exists, don't add. This means that first added value is preferred
// Since command line args are added before args from environment variable, this is the desired behavior
Expand Down Expand Up @@ -186,7 +195,7 @@ public static IDictionary<string, string> GetJobArgsDictionary(JobTraceListener
public static string GetArgument(IDictionary<string, string> jobArgsDictionary, string argName, string fallbackEnvVariable = null)
{
string argValue;
if(!jobArgsDictionary.TryGetValue(argName, out argValue) && !String.IsNullOrEmpty(fallbackEnvVariable))
if (!jobArgsDictionary.TryGetValue(argName, out argValue) && !String.IsNullOrEmpty(fallbackEnvVariable))
{
argValue = Environment.GetEnvironmentVariable(fallbackEnvVariable);
}
Expand Down Expand Up @@ -236,7 +245,7 @@ public static string TryGetArgument(IDictionary<string, string> jobArgsDictionar
{
int intArgument;
string argumentString = TryGetArgument(jobArgsDictionary, argName, fallbackEnvVariable);
if(!String.IsNullOrEmpty(argumentString) && Int32.TryParse(argumentString, out intArgument))
if (!String.IsNullOrEmpty(argumentString) && Int32.TryParse(argumentString, out intArgument))
{
return intArgument;
}
Expand Down
6 changes: 6 additions & 0 deletions src/Stats.CollectAzureCdnLogs/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
13 changes: 13 additions & 0 deletions src/Stats.CollectAzureCdnLogs/AzureCdnPlatform.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Stats.CollectAzureCdnLogs
{
internal enum AzureCdnPlatform
{
HttpLargeObject,
HttpSmallObject,
ApplicationDeliveryNetwork,
FlashMediaStreaming
}
}
61 changes: 61 additions & 0 deletions src/Stats.CollectAzureCdnLogs/Blob/CloudBlobRawLogClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.RetryPolicies;

namespace Stats.CollectAzureCdnLogs.Blob
{
internal sealed class CloudBlobRawLogClient
{
private readonly JobEventSource _jobEventSource;
private readonly CloudStorageAccount _cloudStorageAccount;

public CloudBlobRawLogClient(JobEventSource jobEventSource, CloudStorageAccount cloudStorageAccount)
{
_jobEventSource = jobEventSource;
_cloudStorageAccount = cloudStorageAccount;
}

public async Task<CloudBlobContainer> CreateContainerIfNotExistsAsync(string containerName)
{
var cloudBlobClient = _cloudStorageAccount.CreateCloudBlobClient();
cloudBlobClient.DefaultRequestOptions.RetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(10), 5);

var cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);
await cloudBlobContainer.CreateIfNotExistsAsync();

return cloudBlobContainer;
}

public async Task<bool> UploadBlobAsync(CloudBlobContainer targetContainer, RawLogFileInfo logFile, Stream rawLogStream)
{
try
{
var blobName = logFile.Uri.ToString();
_jobEventSource.BeginningBlobUpload(blobName);
Trace.TraceInformation("Uploading file '{0}'.", logFile.FileName);

var blob = targetContainer.GetBlockBlobReference(logFile.FileName);
blob.Properties.ContentType = logFile.ContentType;

// 3. Upload the file using the original file name.
await blob.UploadFromStreamAsync(rawLogStream);

Trace.TraceInformation("Finished uploading file '{0}' to '{1}'.", logFile.FileName, blob.Uri.AbsoluteUri);
_jobEventSource.FinishingBlobUpload(blobName);
return true;
}
catch (Exception exception)
{
Trace.TraceError(exception.ToString());
}
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Globalization;

namespace Stats.CollectAzureCdnLogs
{
[Serializable]
internal sealed class InvalidRawLogFileNameException
: Exception
{
public InvalidRawLogFileNameException(string fileName)
: base(string.Format(CultureInfo.InvariantCulture, "The file '{0}' is not recognized to comply with the Azure Premium CDN raw log file naming conventions.", fileName))
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Globalization;

namespace Stats.CollectAzureCdnLogs
{
[Serializable]
internal sealed class UnknownAzureCdnPlatformException
: Exception
{
public UnknownAzureCdnPlatformException(string prefix)
: base(string.Format(CultureInfo.InvariantCulture, "The file prefix '{0}' is not recognized as a valid Azure Premium CDN platform.", prefix))
{
}
}
}
Loading

0 comments on commit e93e095

Please sign in to comment.