Skip to content
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

[Azure.Monitor.Query] Add sovereign/government cloud support #41653

Merged
merged 27 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
27 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
5 changes: 4 additions & 1 deletion sdk/monitor/Azure.Monitor.Query/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Release History

## 1.3.0-beta.3 (Unreleased)
## 1.3.0 (2023-31-01)

### Features Added

### Breaking Changes

### Bugs Fixed
- Enable national cloud support for US Gov and China clouds
nisha-bhatia marked this conversation as resolved.
Show resolved Hide resolved

### Other Changes
- Removed the `MetricsBatchQueryClient` client to support batch querying of metrics. This client is currently only available in beta release.
- Removed `QueryBatch` and `QueryBatchAsync` methods to `MetricsBatchQueryClient`. These methods are currently only available in beta release.

## 1.3.0-beta.2 (2023-12-05)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ public partial class LogsBatchQuery
public LogsBatchQuery() { }
public virtual string AddWorkspaceQuery(string workspaceId, string query, Azure.Monitor.Query.QueryTimeRange timeRange, Azure.Monitor.Query.LogsQueryOptions options = null) { throw null; }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct LogsQueryAudience : System.IEquatable<Azure.Monitor.Query.LogsQueryAudience>
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public LogsQueryAudience(string value) { throw null; }
public static Azure.Monitor.Query.LogsQueryAudience AzureChina { get { throw null; } }
public static Azure.Monitor.Query.LogsQueryAudience AzureGovernment { get { throw null; } }
public static Azure.Monitor.Query.LogsQueryAudience AzurePublicCloud { get { throw null; } }
public bool Equals(Azure.Monitor.Query.LogsQueryAudience other) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override bool Equals(object obj) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override int GetHashCode() { throw null; }
public static bool operator ==(Azure.Monitor.Query.LogsQueryAudience left, Azure.Monitor.Query.LogsQueryAudience right) { throw null; }
public static implicit operator Azure.Monitor.Query.LogsQueryAudience (string value) { throw null; }
public static bool operator !=(Azure.Monitor.Query.LogsQueryAudience left, Azure.Monitor.Query.LogsQueryAudience right) { throw null; }
public override string ToString() { throw null; }
}
public partial class LogsQueryClient
{
protected LogsQueryClient() { }
Expand All @@ -28,6 +47,7 @@ public LogsQueryClient(System.Uri endpoint, Azure.Core.TokenCredential credentia
public partial class LogsQueryClientOptions : Azure.Core.ClientOptions
{
public LogsQueryClientOptions(Azure.Monitor.Query.LogsQueryClientOptions.ServiceVersion version = Azure.Monitor.Query.LogsQueryClientOptions.ServiceVersion.V1) { }
public Azure.Monitor.Query.LogsQueryAudience? Audience { get { throw null; } set { } }
public enum ServiceVersion
{
V1 = 1,
Expand All @@ -42,21 +62,24 @@ public LogsQueryOptions() { }
public bool IncludeVisualization { get { throw null; } set { } }
public System.TimeSpan? ServerTimeout { get { throw null; } set { } }
}
public partial class MetricsBatchQueryClient
{
protected MetricsBatchQueryClient() { }
public MetricsBatchQueryClient(System.Uri endpoint, Azure.Core.TokenCredential credential, Azure.Monitor.Query.MetricsBatchQueryClientOptions options = null) { }
public System.Uri Endpoint { get { throw null; } }
public virtual Azure.Response<Azure.Monitor.Query.Models.MetricsBatchResult> QueryBatch(System.Collections.Generic.List<string> resourceIds, System.Collections.Generic.List<string> metricNames, string metricNamespace, Azure.Monitor.Query.MetricsQueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Monitor.Query.Models.MetricsBatchResult>> QueryBatchAsync(System.Collections.Generic.List<string> resourceIds, System.Collections.Generic.List<string> metricNames, string metricNamespace, Azure.Monitor.Query.MetricsQueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
public partial class MetricsBatchQueryClientOptions : Azure.Core.ClientOptions
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct MetricsQueryAudience : System.IEquatable<Azure.Monitor.Query.MetricsQueryAudience>
{
public MetricsBatchQueryClientOptions(Azure.Monitor.Query.MetricsBatchQueryClientOptions.ServiceVersion version = Azure.Monitor.Query.MetricsBatchQueryClientOptions.ServiceVersion.V2023_05_01_PREVIEW) { }
public enum ServiceVersion
{
V2023_05_01_PREVIEW = 1,
}
private readonly object _dummy;
private readonly int _dummyPrimitive;
public MetricsQueryAudience(string value) { throw null; }
public static Azure.Monitor.Query.MetricsQueryAudience AzureChina { get { throw null; } }
public static Azure.Monitor.Query.MetricsQueryAudience AzureGovernment { get { throw null; } }
public static Azure.Monitor.Query.MetricsQueryAudience AzurePublicCloud { get { throw null; } }
public bool Equals(Azure.Monitor.Query.MetricsQueryAudience other) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override bool Equals(object obj) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override int GetHashCode() { throw null; }
public static bool operator ==(Azure.Monitor.Query.MetricsQueryAudience left, Azure.Monitor.Query.MetricsQueryAudience right) { throw null; }
public static implicit operator Azure.Monitor.Query.MetricsQueryAudience (string value) { throw null; }
public static bool operator !=(Azure.Monitor.Query.MetricsQueryAudience left, Azure.Monitor.Query.MetricsQueryAudience right) { throw null; }
public override string ToString() { throw null; }
}
public partial class MetricsQueryClient
{
Expand All @@ -75,6 +98,7 @@ public MetricsQueryClient(System.Uri endpoint, Azure.Core.TokenCredential creden
public partial class MetricsQueryClientOptions : Azure.Core.ClientOptions
{
public MetricsQueryClientOptions(Azure.Monitor.Query.MetricsQueryClientOptions.ServiceVersion version = Azure.Monitor.Query.MetricsQueryClientOptions.ServiceVersion.V2018_01_01) { }
public Azure.Monitor.Query.MetricsQueryAudience? Audience { get { throw null; } set { } }
public enum ServiceVersion
{
V2018_01_01 = 1,
Expand Down
10 changes: 9 additions & 1 deletion sdk/monitor/Azure.Monitor.Query/src/LogsQueryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ public LogsQueryClient(Uri endpoint, TokenCredential credential, LogsQueryClient

Endpoint = endpoint;
options ??= new LogsQueryClientOptions();
var scope = $"{endpoint.AbsoluteUri}/.default";
string scope;
nisha-bhatia marked this conversation as resolved.
Show resolved Hide resolved
if (string.IsNullOrEmpty(options.Audience?.ToString()))
{
scope = $"{endpoint.AbsoluteUri}/.default";
nisha-bhatia marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
scope = $"{options.Audience}/.default";
}

endpoint = new Uri(endpoint, options.GetVersionString());
_clientDiagnostics = new ClientDiagnostics(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,11 @@ internal string GetVersionString()
_ => throw new ArgumentException(@"Unknown version {_version}")
};
}

/// <summary>
/// Gets or sets the audience to use for authentication with Microsoft Entra ID. The audience is not considered when using a shared key.
/// </summary>
/// <value>If <c>null</c>, <see cref="LogsQueryAudience.AzurePublicCloud" /> will be assumed.</value>
public LogsQueryAudience? Audience { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Azure.Monitor.Query
/// <summary>
/// The <see cref="MetricsBatchQueryClient"/> allows you to query multiple Azure Monitor Metric services.
/// </summary>
public class MetricsBatchQueryClient
internal class MetricsBatchQueryClient
nisha-bhatia marked this conversation as resolved.
Show resolved Hide resolved
{
private readonly MetricsBatchRestClient _metricBatchClient;
private readonly ClientDiagnostics _clientDiagnostics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Azure.Monitor.Query
/// <summary>
/// Provides the client configuration options for connecting to Azure Monitor Metrics service.
/// </summary>
public class MetricsBatchQueryClientOptions: ClientOptions
internal class MetricsBatchQueryClientOptions: ClientOptions
{
private readonly ServiceVersion _version;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,11 @@ public enum ServiceVersion
V2018_01_01 = 1,
#pragma warning restore CA1707 // Identifiers should not contain underscores
}

/// <summary>
/// Gets or sets the audience to use for authentication with Microsoft Entra ID. The audience is not considered when using a shared key.
/// </summary>
/// <value>If <c>null</c>, <see cref="MetricsQueryAudience.AzurePublicCloud" /> will be assumed.</value>
public MetricsQueryAudience? Audience { get; set; }
nisha-bhatia marked this conversation as resolved.
Show resolved Hide resolved
}
}
59 changes: 59 additions & 0 deletions sdk/monitor/Azure.Monitor.Query/src/Models/LogsQueryAudience.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.ComponentModel;
using Azure.Core;

namespace Azure.Monitor.Query
{
/// <summary> Cloud audiences available for Query. </summary>
public readonly partial struct LogsQueryAudience : IEquatable<LogsQueryAudience>
{
private readonly string _value;

/// <summary>
/// Initializes a new instance of the <see cref="LogsQueryAudience"/> object.
/// </summary>
/// <param name="value">The Microsoft Entra audience to use when forming authorization scopes. For the language service, this value corresponds to a URL that identifies the Azure cloud where the resource is located. For more information: <see href="https://learn.microsoft.com/azure/azure-government/documentation-government-cognitiveservices" />.</param>
nisha-bhatia marked this conversation as resolved.
Show resolved Hide resolved
/// <exception cref="ArgumentNullException"> <paramref name="value"/> is null. </exception>
/// <remarks>Use one of the constant members over creating a custom value, unless you have special needs for doing so.</remarks>
public LogsQueryAudience(string value)
{
Argument.AssertNotNullOrEmpty(value, nameof(value));
_value = value;
}

private const string AzureChinaValue = "https://api.loganalytics.azure.cn";
private const string AzureGovernmentValue = "https://api.loganalytics.us";
private const string AzurePublicCloudValue = "https://api.loganalytics.io";

/// <summary> Azure China. </summary>
public static LogsQueryAudience AzureChina { get; } = new LogsQueryAudience(AzureChinaValue);

/// <summary> Azure US Government. </summary>
public static LogsQueryAudience AzureGovernment { get; } = new LogsQueryAudience(AzureGovernmentValue);

/// <summary> Azure Public Cloud. </summary>
public static LogsQueryAudience AzurePublicCloud { get; } = new LogsQueryAudience(AzurePublicCloudValue);

/// <summary> Determines if two <see cref="LogsQueryAudience"/> values are the same. </summary>
public static bool operator ==(LogsQueryAudience left, LogsQueryAudience right) => left.Equals(right);
/// <summary> Determines if two <see cref="LogsQueryAudience"/> values are not the same. </summary>
public static bool operator !=(LogsQueryAudience left, LogsQueryAudience right) => !left.Equals(right);
/// <summary> Converts a string to a <see cref="LogsQueryAudience"/>. </summary>
public static implicit operator LogsQueryAudience(string value) => new LogsQueryAudience(value);

/// <inheritdoc />
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj) => obj is LogsQueryAudience other && Equals(other);
/// <inheritdoc />
public bool Equals(LogsQueryAudience other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase);

/// <inheritdoc />
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
/// <inheritdoc />
public override string ToString() => _value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.ComponentModel;
using Azure.Core;

namespace Azure.Monitor.Query
{
/// <summary> Cloud audiences available for Query. </summary>
public readonly partial struct MetricsQueryAudience : IEquatable<MetricsQueryAudience>
{
private readonly string _value;

/// <summary>
/// Initializes a new instance of the <see cref="MetricsQueryAudience"/> object.
/// </summary>
/// <param name="value">The Microsoft Entra audience to use when forming authorization scopes. For the language service, this value corresponds to a URL that identifies the Azure cloud where the resource is located. For more information: <see href="https://learn.microsoft.com/azure/azure-government/documentation-government-cognitiveservices" />.</param>
/// <exception cref="ArgumentNullException"> <paramref name="value"/> is null. </exception>
/// <remarks>Use one of the constant members over creating a custom value, unless you have special needs for doing so.</remarks>
public MetricsQueryAudience(string value)
{
Argument.AssertNotNullOrEmpty(value, nameof(value));
_value = value;
}

private const string AzureChinaValue = "https://management.chinacloudapi.cn";
private const string AzureGovernmentValue = "https://management.usgovcloudapi.net";
private const string AzurePublicCloudValue = "https://management.azure.com";

/// <summary> Azure China. </summary>
public static MetricsQueryAudience AzureChina { get; } = new MetricsQueryAudience(AzureChinaValue);

/// <summary> Azure US Government. </summary>
public static MetricsQueryAudience AzureGovernment { get; } = new MetricsQueryAudience(AzureGovernmentValue);

/// <summary> Azure Public Cloud. </summary>
public static MetricsQueryAudience AzurePublicCloud { get; } = new MetricsQueryAudience(AzurePublicCloudValue);

/// <summary> Determines if two <see cref="MetricsQueryAudience"/> values are the same. </summary>
public static bool operator ==(MetricsQueryAudience left, MetricsQueryAudience right) => left.Equals(right);
/// <summary> Determines if two <see cref="MetricsQueryAudience"/> values are not the same. </summary>
public static bool operator !=(MetricsQueryAudience left, MetricsQueryAudience right) => !left.Equals(right);
/// <summary> Converts a string to a <see cref="MetricsQueryAudience"/>. </summary>
public static implicit operator MetricsQueryAudience(string value) => new MetricsQueryAudience(value);

/// <inheritdoc />
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj) => obj is MetricsQueryAudience other && Equals(other);
/// <inheritdoc />
public bool Equals(MetricsQueryAudience other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase);

/// <inheritdoc />
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
/// <inheritdoc />
public override string ToString() => _value;
}
}
8 changes: 8 additions & 0 deletions sdk/monitor/Azure.Monitor.Query/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@ extends:
template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml
parameters:
ServiceDirectory: monitor
CloudConfig:
Public:
SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources)
UsGov:
SubscriptionConfiguration: $(sub-config-gov-test-resources)
China:
SubscriptionConfiguration: $(sub-config-cn-test-resources)
SupportedClouds: 'Public,UsGov,China'
nisha-bhatia marked this conversation as resolved.
Show resolved Hide resolved
Project: Azure.Monitor.Query
TimeoutInMinutes: 120
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ private LogsQueryClient CreateClient()
TestEnvironment.Credential,
InstrumentClientOptions(new LogsQueryClientOptions()
{
Diagnostics = { IsLoggingContentEnabled = true }
Diagnostics = { IsLoggingContentEnabled = true },
Audience = TestEnvironment.GetLogsAudience()
})
));
}
Expand Down
Loading
Loading