Skip to content

Commit 1eb7cc5

Browse files
committed
Support multiple event hub and storage account sinks for diagnostics extension.
1 parent 3d592ee commit 1eb7cc5

File tree

13 files changed

+969
-71
lines changed

13 files changed

+969
-71
lines changed

src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@
244244
<Compile Include="Extension\Diagnostics\GetAzureRmVMDiagnosticsExtension.cs" />
245245
<Compile Include="Extension\Diagnostics\RemoveAzureRmVMDiagnosticsExtension.cs" />
246246
<Compile Include="Extension\Diagnostics\SetAzureRmVMDiagnosticsExtension.cs" />
247+
<Compile Include="Extension\Diagnostics\WADPrivateConfigSchema.cs" />
247248
<Compile Include="Extension\DSC\GetAzureVMDscExtensionStatusCommand.cs" />
248249
<Compile Include="Extension\DSC\GetDscResourceException.cs" />
249250
<Compile Include="Extension\DSC\DscExtensionPublishCmdletCommonBase.cs" />

src/ResourceManager/Compute/Commands.Compute/Common/DiagnosticsHelper.cs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
using System.Text;
3131
using System.Xml;
3232
using System.Xml.Linq;
33+
using System.Xml.Serialization;
3334

3435
namespace Microsoft.Azure.Commands.Compute.Common
3536
{
@@ -255,11 +256,50 @@ public static Hashtable GetPrivateDiagnosticsConfiguration(string configurationP
255256
string storageAccountName, string storageKey, string endpoint)
256257
{
257258
var privateConfig = new Hashtable();
258-
privateConfig.Add(StorageAccountNameTag, storageAccountName);
259-
privateConfig.Add(StorageAccountKeyTag, storageKey);
260-
privateConfig.Add(StorageAccountEndPointTag, endpoint);
259+
var configFileType = GetConfigFileType(configurationPath);
260+
261+
if (configFileType == ConfigFileType.Xml)
262+
{
263+
var doc = XDocument.Load(configurationPath);
264+
var privateConfigElement = doc.Descendants().FirstOrDefault(d => d.Name.LocalName == PrivateConfigElemStr);
265+
266+
if (privateConfigElement != null)
267+
{
268+
// Unfortunately, there is no easy way to convert the xml config to json config without involving a schema file.
269+
// We take the schema file generated by the .xsd file, and let the serializer doing the conversion work for us.
270+
// NOTE: this file need to be updated whenever the private schema is changed.
271+
XmlSerializer serializer = new XmlSerializer(typeof(Cis.Monitoring.Wad.PrivateConfigConverter.PrivateConfig));
272+
using (StringReader sr = new StringReader(privateConfigElement.ToString()))
273+
{
274+
var config = (Cis.Monitoring.Wad.PrivateConfigConverter.PrivateConfig)serializer.Deserialize(sr);
275+
276+
// Set the StorageAccount element as null, so it won't appear after serialize to json
277+
config.StorageAccount = null;
278+
279+
var privateConfigInJson = JsonConvert.SerializeObject(config,
280+
new JsonSerializerSettings
281+
{
282+
NullValueHandling = NullValueHandling.Ignore
283+
});
284+
privateConfig = JsonConvert.DeserializeObject<Hashtable>(privateConfigInJson);
285+
}
286+
}
287+
}
288+
else if (configFileType == ConfigFileType.Json)
289+
{
290+
// Find the PrivateConfig
291+
var jsonConfig = JsonConvert.DeserializeObject<JObject>(File.ReadAllText(configurationPath));
292+
var hasPrivateConfig = jsonConfig.Properties().Any(p => p.Name.Equals(PrivateConfigElemStr));
293+
294+
if (hasPrivateConfig)
295+
{
296+
privateConfig = JsonConvert.DeserializeObject<Hashtable>(jsonConfig[PrivateConfigElemStr].ToString());
297+
}
298+
}
261299

262-
AddEventHubPrivateConfig(privateConfig, configurationPath);
300+
privateConfig[StorageAccountNameTag] = storageAccountName;
301+
privateConfig[StorageAccountKeyTag] = storageKey;
302+
privateConfig[StorageAccountEndPointTag] = endpoint;
263303

264304
return privateConfig;
265305
}
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
// Runtime Version:4.0.30319.42000
5+
//
6+
// Changes to this file may cause incorrect behavior and will be lost if
7+
// the code is regenerated.
8+
// </auto-generated>
9+
//------------------------------------------------------------------------------
10+
11+
//
12+
// This source code was auto-generated by xsd, Version=4.0.30319.17929.
13+
//
14+
namespace Microsoft.Cis.Monitoring.Wad.PrivateConfigConverter {
15+
using System.Xml.Serialization;
16+
17+
18+
/// <remarks/>
19+
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
20+
[System.SerializableAttribute()]
21+
[System.Diagnostics.DebuggerStepThroughAttribute()]
22+
[System.ComponentModel.DesignerCategoryAttribute("code")]
23+
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration")]
24+
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration", IsNullable=false)]
25+
public partial class PrivateConfig {
26+
27+
private StorageAccount storageAccountField;
28+
29+
private EventHub eventHubField;
30+
31+
private SecondaryStorageAccounts secondaryStorageAccountsField;
32+
33+
private SecondaryEventHubs secondaryEventHubsField;
34+
35+
/// <remarks/>
36+
public StorageAccount StorageAccount {
37+
get {
38+
return this.storageAccountField;
39+
}
40+
set {
41+
this.storageAccountField = value;
42+
}
43+
}
44+
45+
/// <remarks/>
46+
public EventHub EventHub {
47+
get {
48+
return this.eventHubField;
49+
}
50+
set {
51+
this.eventHubField = value;
52+
}
53+
}
54+
55+
/// <remarks/>
56+
public SecondaryStorageAccounts SecondaryStorageAccounts {
57+
get {
58+
return this.secondaryStorageAccountsField;
59+
}
60+
set {
61+
this.secondaryStorageAccountsField = value;
62+
}
63+
}
64+
65+
/// <remarks/>
66+
public SecondaryEventHubs SecondaryEventHubs {
67+
get {
68+
return this.secondaryEventHubsField;
69+
}
70+
set {
71+
this.secondaryEventHubsField = value;
72+
}
73+
}
74+
}
75+
76+
/// <remarks/>
77+
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
78+
[System.SerializableAttribute()]
79+
[System.Diagnostics.DebuggerStepThroughAttribute()]
80+
[System.ComponentModel.DesignerCategoryAttribute("code")]
81+
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration")]
82+
public partial class StorageAccount {
83+
84+
private string nameField;
85+
86+
private string keyField;
87+
88+
private string endpointField;
89+
90+
public StorageAccount() {
91+
this.keyField = "";
92+
this.endpointField = "https://core.windows.net";
93+
}
94+
95+
/// <remarks/>
96+
[System.Xml.Serialization.XmlAttributeAttribute()]
97+
public string name {
98+
get {
99+
return this.nameField;
100+
}
101+
set {
102+
this.nameField = value;
103+
}
104+
}
105+
106+
/// <remarks/>
107+
[System.Xml.Serialization.XmlAttributeAttribute()]
108+
[System.ComponentModel.DefaultValueAttribute("")]
109+
public string key {
110+
get {
111+
return this.keyField;
112+
}
113+
set {
114+
this.keyField = value;
115+
}
116+
}
117+
118+
/// <remarks/>
119+
[System.Xml.Serialization.XmlAttributeAttribute(DataType="anyURI")]
120+
[System.ComponentModel.DefaultValueAttribute("https://core.windows.net")]
121+
public string endpoint {
122+
get {
123+
return this.endpointField;
124+
}
125+
set {
126+
this.endpointField = value;
127+
}
128+
}
129+
}
130+
131+
/// <remarks/>
132+
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
133+
[System.SerializableAttribute()]
134+
[System.Diagnostics.DebuggerStepThroughAttribute()]
135+
[System.ComponentModel.DesignerCategoryAttribute("code")]
136+
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration")]
137+
public partial class SecondaryEventHubs {
138+
139+
private EventHub[] eventHubField;
140+
141+
/// <remarks/>
142+
[System.Xml.Serialization.XmlElementAttribute("EventHub")]
143+
public EventHub[] EventHub {
144+
get {
145+
return this.eventHubField;
146+
}
147+
set {
148+
this.eventHubField = value;
149+
}
150+
}
151+
}
152+
153+
/// <remarks/>
154+
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
155+
[System.SerializableAttribute()]
156+
[System.Diagnostics.DebuggerStepThroughAttribute()]
157+
[System.ComponentModel.DesignerCategoryAttribute("code")]
158+
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration")]
159+
public partial class EventHub {
160+
161+
private string urlField;
162+
163+
private string sharedAccessKeyNameField;
164+
165+
private string sharedAccessKeyField;
166+
167+
/// <remarks/>
168+
[System.Xml.Serialization.XmlAttributeAttribute(DataType="anyURI")]
169+
public string Url {
170+
get {
171+
return this.urlField;
172+
}
173+
set {
174+
this.urlField = value;
175+
}
176+
}
177+
178+
/// <remarks/>
179+
[System.Xml.Serialization.XmlAttributeAttribute()]
180+
public string SharedAccessKeyName {
181+
get {
182+
return this.sharedAccessKeyNameField;
183+
}
184+
set {
185+
this.sharedAccessKeyNameField = value;
186+
}
187+
}
188+
189+
/// <remarks/>
190+
[System.Xml.Serialization.XmlAttributeAttribute()]
191+
public string SharedAccessKey {
192+
get {
193+
return this.sharedAccessKeyField;
194+
}
195+
set {
196+
this.sharedAccessKeyField = value;
197+
}
198+
}
199+
}
200+
201+
/// <remarks/>
202+
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
203+
[System.SerializableAttribute()]
204+
[System.Diagnostics.DebuggerStepThroughAttribute()]
205+
[System.ComponentModel.DesignerCategoryAttribute("code")]
206+
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration")]
207+
public partial class SecondaryStorageAccounts {
208+
209+
private StorageAccount[] storageAccountField;
210+
211+
/// <remarks/>
212+
[System.Xml.Serialization.XmlElementAttribute("StorageAccount")]
213+
public StorageAccount[] StorageAccount {
214+
get {
215+
return this.storageAccountField;
216+
}
217+
set {
218+
this.storageAccountField = value;
219+
}
220+
}
221+
}
222+
}

src/ServiceManagement/Compute/Commands.ServiceManagement.Test/Commands.ServiceManagement.Test.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,18 @@
471471
<None Include="AzureRTComplete_Full_Diff.playlist" />
472472
<None Include="AzureRTExtensions.playlist" />
473473
<None Include="AzureRTFull.playlist" />
474+
<Content Include="Resources\Diagnostics\PurePublic.xml">
475+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
476+
</Content>
477+
<Content Include="Resources\Diagnostics\PlainText.xml">
478+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
479+
</Content>
480+
<None Include="Resources\Diagnostics\PlainText.json">
481+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
482+
</None>
483+
<None Include="Resources\Diagnostics\PurePublic.json">
484+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
485+
</None>
474486
<None Include="Resources\HelloWorld_SDK20.cspkg">
475487
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
476488
</None>

0 commit comments

Comments
 (0)