Azure / Azure/azure-powershell

What kind of XML structure would satisfy the condition in New-AzCloudServiceDiagnosticsExtension?

Open
#18,369 3 comments 0 reactions 0 assignees View on GitHub
act-codegen-extensibility-squad Cloud Service (Ext) question Service Attention
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
3d 14h
Merged PRs (30d)
54

Description

### Description

New-AzCloudServiceDiagnosticsExtension requires StorageAccountName and StorageAccountKey parameters and DiagnosticsConfiguration file path.

The commandlet does pretty much the following:

1. Check if DiagnosticsConfiguration file exists
2. Read the DiagnosticsConfiguration file as XML string
3. Check if the DiagnosticsConfiguration.PublicConfig element contains StorageAccount element. Keep the data if exists, create new if not.
4. Check if DiagnosticsConfiguration.PublicConfig.WadCfg has Metrics element.
5. Check if DiagnosticsConfiguration.PrivateConfig exists. If yes, then use that as protectedSetting. If not, create a new PrivateConfig string and use it as protectedSetting.

The problem lies at step 3 and 5.

The script has $diagnosticsConfigurationXml.PublicConfig XML path hardcoded, meaning it is expecting PublicConfig as the root element in the file.

```xml




TableAndBlob

```

Then at step 5 it looks for $diagnosticsConfigurationXml.PrivateConfig.
If both PublicConfig and PrivateConfig exists in the same XML file, there would be a root element carrying both *Configs. Like this:

```xml





TableAndBlob



```

This would break the hardcoded XML path mentioned above so it wouldn't work.

Of course, we can't write it like this either as there would be two root elements.
```xml




TableAndBlob

```

[Question]

1. How would one configure PublicConfig and PrivateConfig together in the same file? It seems impossible.

### Script or Debug output

```PowerShell
PS> $wadExtension = New-AzCloudServiceDiagnosticsExtension -Name "WADExtension" -ResourceGroupName "resourcegroup" -CloudServiceName "csesname" -TypeHandlerVersion "1.20.0.1" -AutoUpgradeMinorVersion $true -DiagnosticsConfigurationPath "\path\to\diagnostics.wadcfgx" -StorageAccountName "storagename" -StorageAccountKey "access key" -Debug
DEBUG: 5:08:37 PM - GetAzureRMContextCommand end processing.
New-AzCloudServiceDiagnosticsExtension: Cannot convert value "System.Object[]" to type "System.Xml.XmlDocument". Error: "This document already has a 'DocumentElement' node."
```

### Environment data

```PowerShell
Name Value
---- -----
PSVersion 7.2.4
PSEdition Core
GitCommitId 7.2.4
OS Microsoft Windows 10.0.22000
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```

### Module versions

```PowerShell
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.7.5 Az.Accounts {Add-AzEnvironment, Clear-AzContext, Clear-AzD…
Script 1.1.0 Az.CloudService {Get-AzCloudService, Get-AzCloudServiceInstanc…
```

### Error output

```PowerShell
New-AzCloudServiceDiagnosticsExtension: Cannot convert value "System.Object[]" to type "System.Xml.XmlDocument". Error: "This document already has a 'DocumentElement' node."
```
```

Contributor guide

Open the contributing guide

Research direction

Start with the New-AzCloudServiceDiagnosticsExtension entry point and reproduce the provided error using the two XML structures in the issue. Trace how DiagnosticsConfigurationPath is parsed and how PublicConfig and PrivateConfig are combined; done means a valid configuration containing both sections no longer causes the XmlDocument DocumentElement error.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, powershell
Domain
cloud, observability-sre
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.