Skip to content

Improve diagnostics extension command #1614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Common/Commands.ScenarioTests.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class Category

public const string CloudService = "CloudService";

public const string DiagnosticsExtension = "DiagnosticsExtension";

public const string Management = "Management";

public const string MediaServices = "MediaServices";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@
<None Include="Resources\CredentialTests\Common.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Resources\DiagnosticsExtension\DiagnosticsExtensionTests.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Resources\DiagnosticsExtension\Files\diagnostics.wadcfgx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Resources\DscExtension\DscExtensionTests.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -242,6 +248,12 @@
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.AutomationTests\TestAutomationSuspendAndResumeJob.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.DiagnosticsExtensionTests\TestAzureServiceDiagnosticsExtensionBasic.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.DiagnosticsExtensionTests\TestAzureServiceDiagnosticsExtensionConfigurationArray.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.DscExtensionTests\TestGetAzureVMDscExtension.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -356,6 +368,7 @@
<Compile Include="CredentialTests\AddAccountForArmTests.cs" />
<Compile Include="CredentialTests\CredentialTestBase.cs" />
<Compile Include="CredentialTests\CredentialTestHelper.cs" />
<Compile Include="DiagnosticsExtension\DiagnosticsExtensionTests.cs" />
<Compile Include="DscExtension\DscExtensionTests.cs" />
<Compile Include="MediaServicesTests\MediaServicesTests.cs" />
<Compile Include="Properties\Resources.Designer.cs">
Expand Down Expand Up @@ -582,6 +595,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Resources\DiagnosticsExtension\Files\CloudServiceConfig.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Resources\CloudService\Cache\index.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Common.Authentication;
using Microsoft.Azure.Test;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.WindowsAzure.Management;
using Microsoft.WindowsAzure.Management.Compute;
using Microsoft.WindowsAzure.Management.Network;
using Microsoft.WindowsAzure.Management.Storage;
using System.Collections.Generic;
using Xunit;

namespace Microsoft.WindowsAzure.Commands.ScenarioTest
{
[TestClass]
public class DiagnosticsExtensionTests
{
private EnvironmentSetupHelper helper = new EnvironmentSetupHelper();

protected void SetupManagementClients()
{
var rdfeTestFactory = new RDFETestEnvironmentFactory();
var managementClient = TestBase.GetServiceClient<ManagementClient>(rdfeTestFactory);
var computeClient = TestBase.GetServiceClient<ComputeManagementClient>(rdfeTestFactory);
var networkClient = TestBase.GetServiceClient<NetworkManagementClient>(rdfeTestFactory);
var storageClient = TestBase.GetServiceClient<StorageManagementClient>(rdfeTestFactory);

helper.SetupSomeOfManagementClients(
managementClient,
computeClient,
networkClient,
storageClient);
}

protected void RunPowerShellTest(params string[] scripts)
{
using (UndoContext context = UndoContext.Current)
{
context.Start(TestUtilities.GetCallingClass(1), TestUtilities.GetCurrentMethodName(2));

SetupManagementClients();

var modules = new List<string>
{
"Resources\\DiagnosticsExtension\\DiagnosticsExtensionTests.ps1",
"Resources\\ServiceManagement\\Common.ps1",
"Common.ps1",
@"..\..\..\..\..\Package\Debug\ServiceManagement\Azure\Azure.psd1",
@"..\..\..\..\..\Package\Debug\ServiceManagement\Azure\Compute\AzurePreview.psd1",
@"..\..\..\..\..\Package\Debug\ServiceManagement\Azure\Compute\PIR.psd1"
};

helper.SetupEnvironment(AzureModule.AzureServiceManagement);
helper.SetupModules(modules.ToArray());

helper.RunPowerShellTest(scripts);
}
}

[Fact]
[Trait(Category.Service, Category.DiagnosticsExtension)]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.AcceptanceType, Category.BVT)]
public void TestAzureServiceDiagnosticsExtensionBasic()
{
this.RunPowerShellTest("Test-AzureServiceDiagnosticsExtensionBasic");
}

[Fact]
[Trait(Category.Service, Category.DiagnosticsExtension)]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.AcceptanceType, Category.BVT)]
public void TestAzureServiceDiagnosticsExtensionConfigurationArray()
{
this.RunPowerShellTest("Test-AzureServiceDiagnosticsExtensionConfigurationArray");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<#
.SYNOPSIS
Basic end to end diagnostics extension.
#>
function Test-AzureServiceDiagnosticsExtensionBasic
{
Set-StrictMode -Version latest; $ErrorActionPreference = 'Stop'

# Setup
$location = Get-DefaultLocation
$svcName = Get-CloudServiceName
$storageName = getAssetName
$svcName = "onesdk5266"
$storageName = "onesdk383"

try
{
# Initialize
New-AzureStorageAccount -StorageAccountName $storageName -Location $location
Set-CurrentStorageAccountName $storageName

$testMode = Get-ComputeTestMode;
if ($testMode.ToLower() -ne 'playback')
{
$cscpkg = '.\Resources\ServiceManagement\Files\OneWebOneWorker.cspkg';
}
else
{
$cscpkg = "https://${storageName}.blob.azure.windows.net/blob/OneWebOneWorker.cspkg";
}
$cscfg = '.\Resources\ServiceManagement\Files\OneWebOneWorker.cscfg'
New-AzureService -ServiceName $svcName -Location $location
New-AzureDeployment -ServiceName $svcName -Slot Production -Package $cscpkg -Configuration $cscfg

$extension = Get-AzureServiceDiagnosticsExtension -ServiceName $svcName
Assert-Null $extension "The default deployment shouldn't have diagnostics extension enabled"

$configFilePath = '.\Resources\DiagnosticsExtension\Files\CloudServiceConfig.xml'
Set-AzureServiceDiagnosticsExtension -ServiceName $svcName -StorageAccountName $storageName -DiagnosticsConfigurationPath $configFilePath
$extension = Get-AzureServiceDiagnosticsExtension -ServiceName $svcName
Assert-NotNull $extension "Diagnostics extension should be enabled"

Remove-AzureServiceDiagnosticsExtension -ServiceName $svcName
$extension = Get-AzureServiceDiagnosticsExtension -ServiceName $svcName
Assert-Null $extension "The diagnostics extension should have been removed"
}
finally
{
# Cleanup
Remove-AzureStorageAccount -StorageAccountName $storageName -ErrorAction SilentlyContinue
Cleanup-CloudService $svcName
}
}

<#
.SYNOPSIS
Test Set command can accept diagnostics configuration array and update multiple roles with differen configuration.
This test also include some other usage of the command:
1) Can accept both .xml config and .wadcfgx as config file
2) The Get command can accept -Role parameter and filter the result accordingly
#>
function Test-AzureServiceDiagnosticsExtensionConfigurationArray
{
Set-StrictMode -Version latest; $ErrorActionPreference = 'Stop'

# Setup
$location = Get-DefaultLocation
$svcName = Get-CloudServiceName
$storageName = getAssetName
$svcName = "onesdk5266"
$storageName = "onesdk383"

try
{
# Initialize
New-AzureStorageAccount -StorageAccountName $storageName -Location $location
Set-CurrentStorageAccountName $storageName

$testMode = Get-ComputeTestMode;
if ($testMode.ToLower() -ne 'playback')
{
$cscpkg = '.\Resources\ServiceManagement\Files\OneWebOneWorker.cspkg';
}
else
{
$cscpkg = "https://${storageName}.blob.azure.windows.net/blob/OneWebOneWorker.cspkg";
}
$cscfg = '.\Resources\ServiceManagement\Files\OneWebOneWorker.cscfg'
New-AzureService -ServiceName $svcName -Location $location
New-AzureDeployment -ServiceName $svcName -Slot Production -Package $cscpkg -Configuration $cscfg

$xmlConfig = '.\Resources\DiagnosticsExtension\Files\CloudServiceConfig.xml'
$workerRoleConfig = New-AzureServiceDiagnosticsExtensionConfig -Role "WorkerRole1" -StorageAccountName $storageName -DiagnosticsConfigurationPath $xmlConfig

$wadcfgxConfig = '.\Resources\DiagnosticsExtension\Files\diagnostics.wadcfgx'
$webRoleConfig = New-AzureServiceDiagnosticsExtensionConfig -Role "WebRole1" -StorageAccountName $storageName -DiagnosticsConfigurationPath $wadcfgxConfig

Set-AzureServiceDiagnosticsExtension -ServiceName $svcName -DiagnosticsConfiguration @($workerRoleConfig, $webRoleConfig)
$extensions = Get-AzureServiceDiagnosticsExtension -ServiceName $svcName
Assert-AreEqual $extensions.length 2 "There should be two diagnostics extensions enabled"

$extension = Get-AzureServiceDiagnosticsExtension -ServiceName $svcName -Role "WorkerRole1"
Assert-AreEqual $extension.Role.RoleName "WorkerRole1" "Get command should filter the result given Role parameter"
}
finally
{
# Cleanup
Remove-AzureStorageAccount -StorageAccountName $storageName -ErrorAction SilentlyContinue
Cleanup-CloudService $svcName
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<PublicConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
<WadCfg>
<DiagnosticMonitorConfiguration overallQuotaInMB="1024">
<DiagnosticInfrastructureLogs scheduledTransferLogLevelFilter="Error" />
<Directories scheduledTransferPeriod="PT1M">
<IISLogs containerName="wad-iis-logfiles" />
<FailedRequestLogs containerName="wad-failedrequestlogs" />
</Directories>
<PerformanceCounters scheduledTransferPeriod="PT2M">
<PerformanceCounterConfiguration counterSpecifier="\Memory\Available MBytes" sampleRate="PT1M" />
<PerformanceCounterConfiguration counterSpecifier="\Web Service(_Total)\ISAPI Extension Requests/sec" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\Web Service(_Total)\Bytes Total/Sec" sampleRate="PT1M" />
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET Applications(__Total__)\Requests/Sec" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET Applications(__Total__)\Errors Total/Sec" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET\Requests Queued" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET\Requests Rejected" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% Processor Time" sampleRate="PT3M" />
</PerformanceCounters>
<WindowsEventLog scheduledTransferPeriod="PT1M">
<DataSource name="Application!*[System[(Level=1 or Level=2)]]" />
<DataSource name="Windows Azure!*[System[(Level=1 or Level=2)]]" />
</WindowsEventLog>
<CrashDumps>
<CrashDumpConfiguration processName="WaIISHost.exe" />
<CrashDumpConfiguration processName="WaWorkerHost.exe" />
<CrashDumpConfiguration processName="w3wp.exe" />
</CrashDumps>
<Logs scheduledTransferPeriod="PT3M" />
</DiagnosticMonitorConfiguration>
</WadCfg>
<StorageAccount></StorageAccount>
</PublicConfig>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<DiagnosticsConfiguration xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
<PublicConfig>
<WadCfg>
<DiagnosticMonitorConfiguration overallQuotaInMB="4096">
<DiagnosticInfrastructureLogs scheduledTransferLogLevelFilter="Error" />
<Logs scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Error" />
<Directories scheduledTransferPeriod="PT1M">
<IISLogs containerName="wad-iis-logfiles" />
<FailedRequestLogs containerName="wad-failedrequestlogs" />
</Directories>
<WindowsEventLog scheduledTransferPeriod="PT1M">
<DataSource name="Application!*[System[(Level=1 or Level=2 or Level=3)]]" />
<DataSource name="Windows Azure!*[System[(Level=1 or Level=2 or Level=3 or Level=4)]]" />
</WindowsEventLog>
<CrashDumps containerName="wad-crashdumps" dumpType="Mini">
<CrashDumpConfiguration processName="WaIISHost.exe" />
<CrashDumpConfiguration processName="WaWorkerHost.exe" />
<CrashDumpConfiguration processName="w3wp.exe" />
</CrashDumps>
<PerformanceCounters scheduledTransferPeriod="PT1M">
<PerformanceCounterConfiguration counterSpecifier="\Memory\Available MBytes" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\Web Service(_Total)\ISAPI Extension Requests/sec" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\Web Service(_Total)\Bytes Total/Sec" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET Applications(__Total__)\Requests/Sec" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET Applications(__Total__)\Errors Total/Sec" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET\Requests Queued" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET\Requests Rejected" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% Processor Time" sampleRate="PT3M" />
</PerformanceCounters>
</DiagnosticMonitorConfiguration>
</WadCfg>
<StorageAccount></StorageAccount>
</PublicConfig>
<PrivateConfig>
<StorageAccount name="" key="" endpoint="" />
</PrivateConfig>
<IsEnabled>true</IsEnabled>
</DiagnosticsConfiguration>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@
<Compile Include="CloudBaseCmdlet.cs" />
<Compile Include="AzureSMCmdlet.cs" />
<Compile Include="ConfigurationConstants.cs" />
<Compile Include="DiagnosticsHelper.cs" />
<Compile Include="ErrorHelper.cs" />
<Compile Include="IdnHelper.cs" />
<Compile Include="ManagementOperationContext.cs" />
Expand Down
Loading