Skip to content

Support multiple event hub and storage account sinks for diagnostics … #2449

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 1 commit into from
Jun 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
<Compile Include="Extension\Diagnostics\GetAzureRmVMDiagnosticsExtension.cs" />
<Compile Include="Extension\Diagnostics\RemoveAzureRmVMDiagnosticsExtension.cs" />
<Compile Include="Extension\Diagnostics\SetAzureRmVMDiagnosticsExtension.cs" />
<Compile Include="Extension\Diagnostics\WADPrivateConfigSchema.cs" />
<Compile Include="Extension\DSC\GetAzureVMDscExtensionStatusCommand.cs" />
<Compile Include="Extension\DSC\GetDscResourceException.cs" />
<Compile Include="Extension\DSC\DscExtensionPublishCmdletCommonBase.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;

namespace Microsoft.Azure.Commands.Compute.Common
{
Expand Down Expand Up @@ -255,11 +256,50 @@ public static Hashtable GetPrivateDiagnosticsConfiguration(string configurationP
string storageAccountName, string storageKey, string endpoint)
{
var privateConfig = new Hashtable();
privateConfig.Add(StorageAccountNameTag, storageAccountName);
privateConfig.Add(StorageAccountKeyTag, storageKey);
privateConfig.Add(StorageAccountEndPointTag, endpoint);
var configFileType = GetConfigFileType(configurationPath);

if (configFileType == ConfigFileType.Xml)
{
var doc = XDocument.Load(configurationPath);
var privateConfigElement = doc.Descendants().FirstOrDefault(d => d.Name.LocalName == PrivateConfigElemStr);

if (privateConfigElement != null)
{
// Unfortunately, there is no easy way to convert the xml config to json config without involving a schema file.
// We take the schema file generated by the .xsd file, and let the serializer doing the conversion work for us.
// NOTE: this file need to be updated whenever the private schema is changed.
XmlSerializer serializer = new XmlSerializer(typeof(Cis.Monitoring.Wad.PrivateConfigConverter.PrivateConfig));
using (StringReader sr = new StringReader(privateConfigElement.ToString()))
{
var config = (Cis.Monitoring.Wad.PrivateConfigConverter.PrivateConfig)serializer.Deserialize(sr);

// Set the StorageAccount element as null, so it won't appear after serialize to json
config.StorageAccount = null;

var privateConfigInJson = JsonConvert.SerializeObject(config,
new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
});
privateConfig = JsonConvert.DeserializeObject<Hashtable>(privateConfigInJson);
}
}
}
else if (configFileType == ConfigFileType.Json)
{
// Find the PrivateConfig
var jsonConfig = JsonConvert.DeserializeObject<JObject>(File.ReadAllText(configurationPath));
var hasPrivateConfig = jsonConfig.Properties().Any(p => p.Name.Equals(PrivateConfigElemStr));

if (hasPrivateConfig)
{
privateConfig = JsonConvert.DeserializeObject<Hashtable>(jsonConfig[PrivateConfigElemStr].ToString());
}
}

AddEventHubPrivateConfig(privateConfig, configurationPath);
privateConfig[StorageAccountNameTag] = storageAccountName;
privateConfig[StorageAccountKeyTag] = storageKey;
privateConfig[StorageAccountEndPointTag] = endpoint;

return privateConfig;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

//
// This source code was auto-generated by xsd, Version=4.0.30319.17929.
//
namespace Microsoft.Cis.Monitoring.Wad.PrivateConfigConverter {
using System.Xml.Serialization;


/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration", IsNullable=false)]
public partial class PrivateConfig {

private StorageAccount storageAccountField;

private EventHub eventHubField;

private SecondaryStorageAccounts secondaryStorageAccountsField;

private SecondaryEventHubs secondaryEventHubsField;

/// <remarks/>
public StorageAccount StorageAccount {
get {
return this.storageAccountField;
}
set {
this.storageAccountField = value;
}
}

/// <remarks/>
public EventHub EventHub {
get {
return this.eventHubField;
}
set {
this.eventHubField = value;
}
}

/// <remarks/>
public SecondaryStorageAccounts SecondaryStorageAccounts {
get {
return this.secondaryStorageAccountsField;
}
set {
this.secondaryStorageAccountsField = value;
}
}

/// <remarks/>
public SecondaryEventHubs SecondaryEventHubs {
get {
return this.secondaryEventHubsField;
}
set {
this.secondaryEventHubsField = value;
}
}
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration")]
public partial class StorageAccount {

private string nameField;

private string keyField;

private string endpointField;

public StorageAccount() {
this.keyField = "";
this.endpointField = "https://core.windows.net";
}

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string name {
get {
return this.nameField;
}
set {
this.nameField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
[System.ComponentModel.DefaultValueAttribute("")]
public string key {
get {
return this.keyField;
}
set {
this.keyField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(DataType="anyURI")]
[System.ComponentModel.DefaultValueAttribute("https://core.windows.net")]
public string endpoint {
get {
return this.endpointField;
}
set {
this.endpointField = value;
}
}
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration")]
public partial class SecondaryEventHubs {

private EventHub[] eventHubField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("EventHub")]
public EventHub[] EventHub {
get {
return this.eventHubField;
}
set {
this.eventHubField = value;
}
}
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration")]
public partial class EventHub {

private string urlField;

private string sharedAccessKeyNameField;

private string sharedAccessKeyField;

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(DataType="anyURI")]
public string Url {
get {
return this.urlField;
}
set {
this.urlField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string SharedAccessKeyName {
get {
return this.sharedAccessKeyNameField;
}
set {
this.sharedAccessKeyNameField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string SharedAccessKey {
get {
return this.sharedAccessKeyField;
}
set {
this.sharedAccessKeyField = value;
}
}
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration")]
public partial class SecondaryStorageAccounts {

private StorageAccount[] storageAccountField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("StorageAccount")]
public StorageAccount[] StorageAccount {
get {
return this.storageAccountField;
}
set {
this.storageAccountField = value;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,18 @@
<None Include="AzureRTComplete_Full_Diff.playlist" />
<None Include="AzureRTExtensions.playlist" />
<None Include="AzureRTFull.playlist" />
<Content Include="Resources\Diagnostics\PurePublic.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Resources\Diagnostics\PlainText.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Resources\Diagnostics\PlainText.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Resources\Diagnostics\PurePublic.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Resources\HelloWorld_SDK20.cspkg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Loading