Skip to content

Commit 02ac8a9

Browse files
author
Hovsep
committed
Merge pull request Azure#1614 from yantang-msft/IaaS
Improve diagnostics extension command
2 parents b477224 + f979353 commit 02ac8a9

23 files changed

+8434
-314
lines changed

src/Common/Commands.ScenarioTests.Common/Constants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class Category
2828

2929
public const string CloudService = "CloudService";
3030

31+
public const string DiagnosticsExtension = "DiagnosticsExtension";
32+
3133
public const string Management = "Management";
3234

3335
public const string MediaServices = "MediaServices";

src/ServiceManagement/Common/Commands.ScenarioTest/Commands.ScenarioTest.csproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@
203203
<None Include="Resources\CredentialTests\Common.ps1">
204204
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
205205
</None>
206+
<None Include="Resources\DiagnosticsExtension\DiagnosticsExtensionTests.ps1">
207+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
208+
</None>
209+
<None Include="Resources\DiagnosticsExtension\Files\diagnostics.wadcfgx">
210+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
211+
</None>
206212
<None Include="Resources\DscExtension\DscExtensionTests.ps1">
207213
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
208214
</None>
@@ -242,6 +248,12 @@
242248
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.AutomationTests\TestAutomationSuspendAndResumeJob.json">
243249
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
244250
</None>
251+
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.DiagnosticsExtensionTests\TestAzureServiceDiagnosticsExtensionBasic.json">
252+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
253+
</None>
254+
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.DiagnosticsExtensionTests\TestAzureServiceDiagnosticsExtensionConfigurationArray.json">
255+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
256+
</None>
245257
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.DscExtensionTests\TestGetAzureVMDscExtension.json">
246258
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
247259
</None>
@@ -356,6 +368,7 @@
356368
<Compile Include="CredentialTests\AddAccountForArmTests.cs" />
357369
<Compile Include="CredentialTests\CredentialTestBase.cs" />
358370
<Compile Include="CredentialTests\CredentialTestHelper.cs" />
371+
<Compile Include="DiagnosticsExtension\DiagnosticsExtensionTests.cs" />
359372
<Compile Include="DscExtension\DscExtensionTests.cs" />
360373
<Compile Include="MediaServicesTests\MediaServicesTests.cs" />
361374
<Compile Include="Properties\Resources.Designer.cs">
@@ -582,6 +595,9 @@
582595
</ProjectReference>
583596
</ItemGroup>
584597
<ItemGroup>
598+
<Content Include="Resources\DiagnosticsExtension\Files\CloudServiceConfig.xml">
599+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
600+
</Content>
585601
<None Include="Resources\CloudService\Cache\index.js">
586602
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
587603
</None>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Common.Authentication;
16+
using Microsoft.Azure.Test;
17+
using Microsoft.VisualStudio.TestTools.UnitTesting;
18+
using Microsoft.WindowsAzure.Management;
19+
using Microsoft.WindowsAzure.Management.Compute;
20+
using Microsoft.WindowsAzure.Management.Network;
21+
using Microsoft.WindowsAzure.Management.Storage;
22+
using System.Collections.Generic;
23+
using Xunit;
24+
25+
namespace Microsoft.WindowsAzure.Commands.ScenarioTest
26+
{
27+
[TestClass]
28+
public class DiagnosticsExtensionTests
29+
{
30+
private EnvironmentSetupHelper helper = new EnvironmentSetupHelper();
31+
32+
protected void SetupManagementClients()
33+
{
34+
var rdfeTestFactory = new RDFETestEnvironmentFactory();
35+
var managementClient = TestBase.GetServiceClient<ManagementClient>(rdfeTestFactory);
36+
var computeClient = TestBase.GetServiceClient<ComputeManagementClient>(rdfeTestFactory);
37+
var networkClient = TestBase.GetServiceClient<NetworkManagementClient>(rdfeTestFactory);
38+
var storageClient = TestBase.GetServiceClient<StorageManagementClient>(rdfeTestFactory);
39+
40+
helper.SetupSomeOfManagementClients(
41+
managementClient,
42+
computeClient,
43+
networkClient,
44+
storageClient);
45+
}
46+
47+
protected void RunPowerShellTest(params string[] scripts)
48+
{
49+
using (UndoContext context = UndoContext.Current)
50+
{
51+
context.Start(TestUtilities.GetCallingClass(1), TestUtilities.GetCurrentMethodName(2));
52+
53+
SetupManagementClients();
54+
55+
var modules = new List<string>
56+
{
57+
"Resources\\DiagnosticsExtension\\DiagnosticsExtensionTests.ps1",
58+
"Resources\\ServiceManagement\\Common.ps1",
59+
"Common.ps1",
60+
@"..\..\..\..\..\Package\Debug\ServiceManagement\Azure\Azure.psd1",
61+
@"..\..\..\..\..\Package\Debug\ServiceManagement\Azure\Compute\AzurePreview.psd1",
62+
@"..\..\..\..\..\Package\Debug\ServiceManagement\Azure\Compute\PIR.psd1"
63+
};
64+
65+
helper.SetupEnvironment(AzureModule.AzureServiceManagement);
66+
helper.SetupModules(modules.ToArray());
67+
68+
helper.RunPowerShellTest(scripts);
69+
}
70+
}
71+
72+
[Fact]
73+
[Trait(Category.Service, Category.DiagnosticsExtension)]
74+
[Trait(Category.AcceptanceType, Category.CheckIn)]
75+
[Trait(Category.AcceptanceType, Category.BVT)]
76+
public void TestAzureServiceDiagnosticsExtensionBasic()
77+
{
78+
this.RunPowerShellTest("Test-AzureServiceDiagnosticsExtensionBasic");
79+
}
80+
81+
[Fact]
82+
[Trait(Category.Service, Category.DiagnosticsExtension)]
83+
[Trait(Category.AcceptanceType, Category.CheckIn)]
84+
[Trait(Category.AcceptanceType, Category.BVT)]
85+
public void TestAzureServiceDiagnosticsExtensionConfigurationArray()
86+
{
87+
this.RunPowerShellTest("Test-AzureServiceDiagnosticsExtensionConfigurationArray");
88+
}
89+
}
90+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<#
2+
.SYNOPSIS
3+
Basic end to end diagnostics extension.
4+
#>
5+
function Test-AzureServiceDiagnosticsExtensionBasic
6+
{
7+
Set-StrictMode -Version latest; $ErrorActionPreference = 'Stop'
8+
9+
# Setup
10+
$location = Get-DefaultLocation
11+
$svcName = Get-CloudServiceName
12+
$storageName = getAssetName
13+
$svcName = "onesdk5266"
14+
$storageName = "onesdk383"
15+
16+
try
17+
{
18+
# Initialize
19+
New-AzureStorageAccount -StorageAccountName $storageName -Location $location
20+
Set-CurrentStorageAccountName $storageName
21+
22+
$testMode = Get-ComputeTestMode;
23+
if ($testMode.ToLower() -ne 'playback')
24+
{
25+
$cscpkg = '.\Resources\ServiceManagement\Files\OneWebOneWorker.cspkg';
26+
}
27+
else
28+
{
29+
$cscpkg = "https://${storageName}.blob.azure.windows.net/blob/OneWebOneWorker.cspkg";
30+
}
31+
$cscfg = '.\Resources\ServiceManagement\Files\OneWebOneWorker.cscfg'
32+
New-AzureService -ServiceName $svcName -Location $location
33+
New-AzureDeployment -ServiceName $svcName -Slot Production -Package $cscpkg -Configuration $cscfg
34+
35+
$extension = Get-AzureServiceDiagnosticsExtension -ServiceName $svcName
36+
Assert-Null $extension "The default deployment shouldn't have diagnostics extension enabled"
37+
38+
$configFilePath = '.\Resources\DiagnosticsExtension\Files\CloudServiceConfig.xml'
39+
Set-AzureServiceDiagnosticsExtension -ServiceName $svcName -StorageAccountName $storageName -DiagnosticsConfigurationPath $configFilePath
40+
$extension = Get-AzureServiceDiagnosticsExtension -ServiceName $svcName
41+
Assert-NotNull $extension "Diagnostics extension should be enabled"
42+
43+
Remove-AzureServiceDiagnosticsExtension -ServiceName $svcName
44+
$extension = Get-AzureServiceDiagnosticsExtension -ServiceName $svcName
45+
Assert-Null $extension "The diagnostics extension should have been removed"
46+
}
47+
finally
48+
{
49+
# Cleanup
50+
Remove-AzureStorageAccount -StorageAccountName $storageName -ErrorAction SilentlyContinue
51+
Cleanup-CloudService $svcName
52+
}
53+
}
54+
55+
<#
56+
.SYNOPSIS
57+
Test Set command can accept diagnostics configuration array and update multiple roles with differen configuration.
58+
This test also include some other usage of the command:
59+
1) Can accept both .xml config and .wadcfgx as config file
60+
2) The Get command can accept -Role parameter and filter the result accordingly
61+
#>
62+
function Test-AzureServiceDiagnosticsExtensionConfigurationArray
63+
{
64+
Set-StrictMode -Version latest; $ErrorActionPreference = 'Stop'
65+
66+
# Setup
67+
$location = Get-DefaultLocation
68+
$svcName = Get-CloudServiceName
69+
$storageName = getAssetName
70+
$svcName = "onesdk5266"
71+
$storageName = "onesdk383"
72+
73+
try
74+
{
75+
# Initialize
76+
New-AzureStorageAccount -StorageAccountName $storageName -Location $location
77+
Set-CurrentStorageAccountName $storageName
78+
79+
$testMode = Get-ComputeTestMode;
80+
if ($testMode.ToLower() -ne 'playback')
81+
{
82+
$cscpkg = '.\Resources\ServiceManagement\Files\OneWebOneWorker.cspkg';
83+
}
84+
else
85+
{
86+
$cscpkg = "https://${storageName}.blob.azure.windows.net/blob/OneWebOneWorker.cspkg";
87+
}
88+
$cscfg = '.\Resources\ServiceManagement\Files\OneWebOneWorker.cscfg'
89+
New-AzureService -ServiceName $svcName -Location $location
90+
New-AzureDeployment -ServiceName $svcName -Slot Production -Package $cscpkg -Configuration $cscfg
91+
92+
$xmlConfig = '.\Resources\DiagnosticsExtension\Files\CloudServiceConfig.xml'
93+
$workerRoleConfig = New-AzureServiceDiagnosticsExtensionConfig -Role "WorkerRole1" -StorageAccountName $storageName -DiagnosticsConfigurationPath $xmlConfig
94+
95+
$wadcfgxConfig = '.\Resources\DiagnosticsExtension\Files\diagnostics.wadcfgx'
96+
$webRoleConfig = New-AzureServiceDiagnosticsExtensionConfig -Role "WebRole1" -StorageAccountName $storageName -DiagnosticsConfigurationPath $wadcfgxConfig
97+
98+
Set-AzureServiceDiagnosticsExtension -ServiceName $svcName -DiagnosticsConfiguration @($workerRoleConfig, $webRoleConfig)
99+
$extensions = Get-AzureServiceDiagnosticsExtension -ServiceName $svcName
100+
Assert-AreEqual $extensions.length 2 "There should be two diagnostics extensions enabled"
101+
102+
$extension = Get-AzureServiceDiagnosticsExtension -ServiceName $svcName -Role "WorkerRole1"
103+
Assert-AreEqual $extension.Role.RoleName "WorkerRole1" "Get command should filter the result given Role parameter"
104+
}
105+
finally
106+
{
107+
# Cleanup
108+
Remove-AzureStorageAccount -StorageAccountName $storageName -ErrorAction SilentlyContinue
109+
Cleanup-CloudService $svcName
110+
}
111+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<PublicConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
3+
<WadCfg>
4+
<DiagnosticMonitorConfiguration overallQuotaInMB="1024">
5+
<DiagnosticInfrastructureLogs scheduledTransferLogLevelFilter="Error" />
6+
<Directories scheduledTransferPeriod="PT1M">
7+
<IISLogs containerName="wad-iis-logfiles" />
8+
<FailedRequestLogs containerName="wad-failedrequestlogs" />
9+
</Directories>
10+
<PerformanceCounters scheduledTransferPeriod="PT2M">
11+
<PerformanceCounterConfiguration counterSpecifier="\Memory\Available MBytes" sampleRate="PT1M" />
12+
<PerformanceCounterConfiguration counterSpecifier="\Web Service(_Total)\ISAPI Extension Requests/sec" sampleRate="PT3M" />
13+
<PerformanceCounterConfiguration counterSpecifier="\Web Service(_Total)\Bytes Total/Sec" sampleRate="PT1M" />
14+
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET Applications(__Total__)\Requests/Sec" sampleRate="PT3M" />
15+
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET Applications(__Total__)\Errors Total/Sec" sampleRate="PT3M" />
16+
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET\Requests Queued" sampleRate="PT3M" />
17+
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET\Requests Rejected" sampleRate="PT3M" />
18+
<PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% Processor Time" sampleRate="PT3M" />
19+
</PerformanceCounters>
20+
<WindowsEventLog scheduledTransferPeriod="PT1M">
21+
<DataSource name="Application!*[System[(Level=1 or Level=2)]]" />
22+
<DataSource name="Windows Azure!*[System[(Level=1 or Level=2)]]" />
23+
</WindowsEventLog>
24+
<CrashDumps>
25+
<CrashDumpConfiguration processName="WaIISHost.exe" />
26+
<CrashDumpConfiguration processName="WaWorkerHost.exe" />
27+
<CrashDumpConfiguration processName="w3wp.exe" />
28+
</CrashDumps>
29+
<Logs scheduledTransferPeriod="PT3M" />
30+
</DiagnosticMonitorConfiguration>
31+
</WadCfg>
32+
<StorageAccount></StorageAccount>
33+
</PublicConfig>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<DiagnosticsConfiguration xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
3+
<PublicConfig>
4+
<WadCfg>
5+
<DiagnosticMonitorConfiguration overallQuotaInMB="4096">
6+
<DiagnosticInfrastructureLogs scheduledTransferLogLevelFilter="Error" />
7+
<Logs scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Error" />
8+
<Directories scheduledTransferPeriod="PT1M">
9+
<IISLogs containerName="wad-iis-logfiles" />
10+
<FailedRequestLogs containerName="wad-failedrequestlogs" />
11+
</Directories>
12+
<WindowsEventLog scheduledTransferPeriod="PT1M">
13+
<DataSource name="Application!*[System[(Level=1 or Level=2 or Level=3)]]" />
14+
<DataSource name="Windows Azure!*[System[(Level=1 or Level=2 or Level=3 or Level=4)]]" />
15+
</WindowsEventLog>
16+
<CrashDumps containerName="wad-crashdumps" dumpType="Mini">
17+
<CrashDumpConfiguration processName="WaIISHost.exe" />
18+
<CrashDumpConfiguration processName="WaWorkerHost.exe" />
19+
<CrashDumpConfiguration processName="w3wp.exe" />
20+
</CrashDumps>
21+
<PerformanceCounters scheduledTransferPeriod="PT1M">
22+
<PerformanceCounterConfiguration counterSpecifier="\Memory\Available MBytes" sampleRate="PT3M" />
23+
<PerformanceCounterConfiguration counterSpecifier="\Web Service(_Total)\ISAPI Extension Requests/sec" sampleRate="PT3M" />
24+
<PerformanceCounterConfiguration counterSpecifier="\Web Service(_Total)\Bytes Total/Sec" sampleRate="PT3M" />
25+
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET Applications(__Total__)\Requests/Sec" sampleRate="PT3M" />
26+
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET Applications(__Total__)\Errors Total/Sec" sampleRate="PT3M" />
27+
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET\Requests Queued" sampleRate="PT3M" />
28+
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET\Requests Rejected" sampleRate="PT3M" />
29+
<PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% Processor Time" sampleRate="PT3M" />
30+
</PerformanceCounters>
31+
</DiagnosticMonitorConfiguration>
32+
</WadCfg>
33+
<StorageAccount></StorageAccount>
34+
</PublicConfig>
35+
<PrivateConfig>
36+
<StorageAccount name="" key="" endpoint="" />
37+
</PrivateConfig>
38+
<IsEnabled>true</IsEnabled>
39+
</DiagnosticsConfiguration>

src/ServiceManagement/Common/Commands.ScenarioTest/SessionRecords/Microsoft.WindowsAzure.Commands.ScenarioTest.DiagnosticsExtensionTests/TestAzureServiceDiagnosticsExtensionBasic.json

Lines changed: 3807 additions & 0 deletions
Large diffs are not rendered by default.

src/ServiceManagement/Common/Commands.ScenarioTest/SessionRecords/Microsoft.WindowsAzure.Commands.ScenarioTest.DiagnosticsExtensionTests/TestAzureServiceDiagnosticsExtensionConfigurationArray.json

Lines changed: 3414 additions & 0 deletions
Large diffs are not rendered by default.

src/ServiceManagement/Common/Commands.ServiceManagement.Common/Commands.ServiceManagement.Common.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@
151151
<Compile Include="CloudBaseCmdlet.cs" />
152152
<Compile Include="AzureSMCmdlet.cs" />
153153
<Compile Include="ConfigurationConstants.cs" />
154-
<Compile Include="DiagnosticsHelper.cs" />
155154
<Compile Include="ErrorHelper.cs" />
156155
<Compile Include="IdnHelper.cs" />
157156
<Compile Include="ManagementOperationContext.cs" />

0 commit comments

Comments
 (0)