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

Adjust APIs in preparation to UX study #22260

Merged
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 @@ -199,12 +199,14 @@ public ResponseError(string? code, string? message, Azure.Core.ResponseInnerErro
public Azure.Core.ResponseInnerError? InnerError { get { throw null; } }
public string? Message { get { throw null; } }
public string? Target { get { throw null; } }
public override string ToString() { throw null; }
}
public sealed partial class ResponseInnerError
{
internal ResponseInnerError() { }
public string? Code { get { throw null; } }
public Azure.Core.ResponseInnerError? InnerError { get { throw null; } }
public string? Message { get { throw null; } }
public override string ToString() { throw null; }
}
}
32 changes: 32 additions & 0 deletions sdk/core/Azure.Core.Experimental/src/ResponseError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

Expand Down Expand Up @@ -119,5 +121,35 @@ public override void Write(Utf8JsonWriter writer, ResponseError? value, JsonSeri
throw new NotImplementedException();
}
}

/// <inheritdoc />
public override string ToString()
{
var builder = new StringBuilder();

builder.AppendFormat(CultureInfo.InvariantCulture, "{0}: {1}{2}", Code, Message, Environment.NewLine);

if (Target != null)
{
builder.AppendFormat(CultureInfo.InvariantCulture, "Target: {0}{1}", Target, Environment.NewLine);
}

if (InnerError != null)
{
builder.AppendLine("Inner Error:");
builder.Append(InnerError);
}

if (Details.Count > 0)
{
builder.AppendLine("Details:");
foreach (var detail in Details)
{
builder.Append(detail);
}
}

return builder.ToString();
}
}
}
17 changes: 17 additions & 0 deletions sdk/core/Azure.Core.Experimental/src/ResponseInnerError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the MIT License.

using System;
using System.Globalization;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

Expand Down Expand Up @@ -77,5 +79,20 @@ public override void Write(Utf8JsonWriter writer, ResponseInnerError? value, Jso
throw new NotImplementedException();
}
}

/// <inheritdoc />
public override string ToString()
{
var builder = new StringBuilder();

builder.AppendFormat(CultureInfo.InvariantCulture, "{0}: {1}{2}", Code, Message, Environment.NewLine);
if (InnerError != null)
{
builder.AppendLine("Inner Error:");
builder.Append(InnerError);
}

return builder.ToString();
}
}
}
16 changes: 16 additions & 0 deletions sdk/core/Azure.Core.Experimental/tests/ResponseErrorTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Text.Json;
using NUnit.Framework;

Expand Down Expand Up @@ -35,6 +36,11 @@ public void CanDeserializeSimple()
Assert.AreEqual("MoreDetailedBadError", error.InnerError.Code);
Assert.AreEqual("Inner message", error.InnerError.Message);
Assert.Null(error.InnerError.InnerError);
Assert.AreEqual("BadError: Something wasn't awesome" + Environment.NewLine +
"Target: Error target" + Environment.NewLine +
"Inner Error:" + Environment.NewLine +
"MoreDetailedBadError: Inner message" + Environment.NewLine,
error.ToString());
}

[Test]
Expand Down Expand Up @@ -80,6 +86,16 @@ public void CanDeserializeComplex()
Assert.AreEqual(2, error.Details.Count);

Assert.Null(error.InnerError.InnerError.InnerError);

Assert.AreEqual("BadError: Something wasn't awesome" + Environment.NewLine +
"Target: Error target" + Environment.NewLine +
"Inner Error:" + Environment.NewLine +
"MoreDetailedBadError: Inner message" + Environment.NewLine +
"Inner Error:" + Environment.NewLine +
"InnerMoreDetailedBadError: Inner Inner message" + Environment.NewLine +
"Details:" + Environment.NewLine +
"Code 1: Message 1" + Environment.NewLine +
"Code 2: Message 2" + Environment.NewLine, error.ToString());
}
}
}
31 changes: 16 additions & 15 deletions sdk/monitor/Azure.Monitor.Query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ We guarantee that all client instance methods are thread-safe and independent of
You can query logs using the `LogsClient.QueryAsync`. The result would be returned as a table with a collection of rows:

```C# Snippet:QueryLogsAsTable
Uri endpoint = new Uri("https://api.loganalytics.io");
var endpoint = new Uri("https://api.loganalytics.io");
string workspaceId = "<workspace_id>";

LogsQueryClient client = new LogsQueryClient(endpoint, new DefaultAzureCredential());
var client = new LogsQueryClient(endpoint, new DefaultAzureCredential());
Response<LogsQueryResult> response = await client.QueryAsync(workspaceId, "AzureActivity | top 10 by TimeGenerated", TimeSpan.FromDays(1));

LogsQueryResultTable table = response.Value.PrimaryTable;
Expand All @@ -90,7 +90,7 @@ public class MyLogEntryModel
```

```C# Snippet:QueryLogsAsModels
LogsQueryClient client = new LogsQueryClient(TestEnvironment.LogsEndpoint, new DefaultAzureCredential());
var client = new LogsQueryClient(TestEnvironment.LogsEndpoint, new DefaultAzureCredential());
string workspaceId = "<workspace_id>";

// Query TOP 10 resource groups by event count
Expand All @@ -109,10 +109,10 @@ foreach (var logEntryModel in response.Value)
If your query return a single column (or a single value) of a primitive type you can use `LogsClient.QueryAsync<T>` overload to deserialize it:

```C# Snippet:QueryLogsAsPrimitive
Uri endpoint = new Uri("https://api.loganalytics.io");
var endpoint = new Uri("https://api.loganalytics.io");
string workspaceId = "<workspace_id>";

LogsQueryClient client = new LogsQueryClient(endpoint, new DefaultAzureCredential());
var client = new LogsQueryClient(endpoint, new DefaultAzureCredential());

// Query TOP 10 resource groups by event count
Response<IReadOnlyList<string>> response = await client.QueryAsync<string>(workspaceId,
Expand All @@ -130,14 +130,15 @@ foreach (var resourceGroup in response.Value)
You can execute multiple queries in on request using the `LogsClient.CreateBatchQuery`:

```C# Snippet:BatchQuery
Uri endpoint = new Uri("https://api.loganalytics.io");
var endpoint = new Uri("https://api.loganalytics.io");
string workspaceId = "<workspace_id>";

LogsQueryClient client = new LogsQueryClient(endpoint, new DefaultAzureCredential());
var client = new LogsQueryClient(endpoint, new DefaultAzureCredential());

// Query TOP 10 resource groups by event count
// And total event count
LogsBatchQuery batch = new LogsBatchQuery();
var batch = new LogsBatchQuery();

string countQueryId = batch.AddQuery(workspaceId, "AzureActivity | count", TimeSpan.FromDays(1));
string topQueryId = batch.AddQuery(workspaceId, "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count", TimeSpan.FromDays(1));

Expand All @@ -158,10 +159,10 @@ foreach (var logEntryModel in topEntries)
You can also dynamically inspect the list of columns. The following example prints the result of the query as a table:

```C# Snippet:QueryLogsPrintTable
Uri endpoint = new Uri("https://api.loganalytics.io");
var endpoint = new Uri("https://api.loganalytics.io");
string workspaceId = "<workspace_id>";

LogsQueryClient client = new LogsQueryClient(endpoint, new DefaultAzureCredential());
var client = new LogsQueryClient(endpoint, new DefaultAzureCredential());
Response<LogsQueryResult> response = await client.QueryAsync(workspaceId, "AzureActivity | top 10 by TimeGenerated", TimeSpan.FromDays(1));

LogsQueryResultTable table = response.Value.PrimaryTable;
Expand Down Expand Up @@ -190,10 +191,10 @@ foreach (var row in table.Rows)
Some Logs queries take longer than 3 minutes to execute. The default server timeout is 3 minutes. You can increase the server timeout to a maximum of 10 minutes. In the following example, the `LogsQueryOptions` object's `ServerTimeout` property is used to set the server timeout to 10 minutes:

```C# Snippet:QueryLogsWithTimeout
Uri endpoint = new Uri("https://api.loganalytics.io");
var endpoint = new Uri("https://api.loganalytics.io");
string workspaceId = "<workspace_id>";

LogsQueryClient client = new LogsQueryClient(endpoint, new DefaultAzureCredential());
var client = new LogsQueryClient(endpoint, new DefaultAzureCredential());

// Query TOP 10 resource groups by event count
Response<IReadOnlyList<int>> response = await client.QueryAsync<int>(workspaceId,
Expand All @@ -215,7 +216,7 @@ foreach (var resourceGroup in response.Value)
You can query metrics using the `MetricsClient.QueryAsync`. For every requested metric a set of aggregated values would be returned inside the `TimeSeries` collection.

```C# Snippet:QueryMetrics
Uri endpoint = new Uri("https://management.azure.com");
var endpoint = new Uri("https://management.azure.com");
string resourceId =
"/subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/Microsoft.OperationalInsights/workspaces/<workspace_name>";

Expand Down Expand Up @@ -250,10 +251,10 @@ When you interact with the Azure Monitor Query client library using the .NET SDK
For example, if you submit an invalid query a `400` error is returned, indicating "Bad Request".

```C# Snippet:BadRequest
Uri endpoint = new Uri("https://api.loganalytics.io");
var endpoint = new Uri("https://api.loganalytics.io");
string workspaceId = "<workspace_id>";

LogsQueryClient client = new LogsQueryClient(endpoint, new DefaultAzureCredential());
var client = new LogsQueryClient(endpoint, new DefaultAzureCredential());

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public LogsQueryClient(Azure.Core.TokenCredential credential, Azure.Monitor.Quer
public LogsQueryClient(System.Uri endpoint, Azure.Core.TokenCredential credential) { }
public LogsQueryClient(System.Uri endpoint, Azure.Core.TokenCredential credential, Azure.Monitor.Query.LogsQueryClientOptions options) { }
public static string CreateQuery(System.FormattableString filter) { throw null; }
public virtual Azure.Response<Azure.Monitor.Query.Models.LogsQueryResult> Query(string workspace, string query, Azure.Core.DateTimeRange timeRange, Azure.Monitor.Query.LogsQueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Monitor.Query.Models.LogsQueryResult>> QueryAsync(string workspace, string query, Azure.Core.DateTimeRange timeRange, Azure.Monitor.Query.LogsQueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<T>>> QueryAsync<T>(string workspace, string query, Azure.Core.DateTimeRange timeRange, Azure.Monitor.Query.LogsQueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Monitor.Query.Models.LogsQueryResult> Query(string workspaceId, string query, Azure.Core.DateTimeRange timeRange, Azure.Monitor.Query.LogsQueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Monitor.Query.Models.LogsQueryResult>> QueryAsync(string workspaceId, string query, Azure.Core.DateTimeRange timeRange, Azure.Monitor.Query.LogsQueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<T>>> QueryAsync<T>(string workspaceId, string query, Azure.Core.DateTimeRange timeRange, Azure.Monitor.Query.LogsQueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Monitor.Query.Models.LogsBatchQueryResults> QueryBatch(Azure.Monitor.Query.LogsBatchQuery batch, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Monitor.Query.Models.LogsBatchQueryResults>> QueryBatchAsync(Azure.Monitor.Query.LogsBatchQuery batch, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<System.Collections.Generic.IReadOnlyList<T>> Query<T>(string workspace, string query, Azure.Core.DateTimeRange timeRange, Azure.Monitor.Query.LogsQueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<System.Collections.Generic.IReadOnlyList<T>> Query<T>(string workspaceId, string query, Azure.Core.DateTimeRange timeRange, Azure.Monitor.Query.LogsQueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
public partial class LogsQueryClientOptions : Azure.Core.ClientOptions
{
Expand Down Expand Up @@ -124,15 +124,16 @@ public partial class LogsQueryResult
internal LogsQueryResult() { }
public Azure.Core.ResponseError Error { get { throw null; } }
public Azure.Monitor.Query.Models.LogsQueryResultTable PrimaryTable { get { throw null; } }
public System.BinaryData Statistics { get { throw null; } }
public System.Collections.Generic.IReadOnlyList<Azure.Monitor.Query.Models.LogsQueryResultTable> Tables { get { throw null; } }
public System.BinaryData Visualization { get { throw null; } }
public System.BinaryData GetStatistics() { throw null; }
public System.BinaryData GetVisualization() { throw null; }
}
public partial class LogsQueryResultColumn
{
internal LogsQueryResultColumn() { }
public string Name { get { throw null; } }
public Azure.Monitor.Query.Models.LogsColumnType Type { get { throw null; } }
public override string ToString() { throw null; }
}
public partial class LogsQueryResultRow
{
Expand Down Expand Up @@ -164,6 +165,7 @@ internal LogsQueryResultRow() { }
public System.TimeSpan GetTimeSpan(string name) { throw null; }
public bool IsNull(int index) { throw null; }
public bool IsNull(string name) { throw null; }
public override string ToString() { throw null; }
}
public partial class LogsQueryResultTable
{
Expand All @@ -172,6 +174,7 @@ internal LogsQueryResultTable() { }
public string Name { get { throw null; } }
public System.Collections.Generic.IReadOnlyList<Azure.Monitor.Query.Models.LogsQueryResultRow> Rows { get { throw null; } }
public System.Collections.Generic.IReadOnlyList<T> Deserialize<T>() { throw null; }
public override string ToString() { throw null; }
}
public partial class Metric
{
Expand Down
Loading