diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Docs/LiveMetricsClient.xml b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Docs/LiveMetricsClient.xml new file mode 100644 index 000000000000..77f79765e1d8 --- /dev/null +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Docs/LiveMetricsClient.xml @@ -0,0 +1,671 @@ + + + + + +This sample shows how to call IsSubscribedAsync. + response = await client.IsSubscribedAsync(""); +]]> +This sample shows how to call IsSubscribedAsync with all parameters. +", +1234, +"", +"", +"", +"", +true, +true) +{ + Timestamp = DateTimeOffset.Parse("2022-05-10T14:57:31.2311892-04:00"), + TransmissionTime = DateTimeOffset.Parse("2022-05-10T14:57:31.2311892-04:00"), + Metrics = { new MetricPoint("", 123.45, 1234) }, + Documents = {new Models.Request + { + Name = "", + Url = new Uri("http://localhost:3000"), + ResponseCode = "", + Duration = "", + DocumentStreamIds = {""}, + Properties = {new KeyValuePairStringString("", "")}, + }}, + TopCpuProcesses = { new ProcessCpuData("", 1234) }, + CollectionConfigurationErrors = {new CollectionConfigurationError(CollectionConfigurationErrorType.Unknown, "", "", new KeyValuePairStringString[] + { + default + })}, +}; +Response response = await client.IsSubscribedAsync("", monitoringDataPoint: monitoringDataPoint, transmissionTime: 1234L, machineName: "", instanceName: "", streamId: "", roleName: "", invariantVersion: "", configurationEtag: ""); +]]> + + + +This sample shows how to call IsSubscribed. + response = client.IsSubscribed(""); +]]> +This sample shows how to call IsSubscribed with all parameters. +", +1234, +"", +"", +"", +"", +true, +true) +{ + Timestamp = DateTimeOffset.Parse("2022-05-10T14:57:31.2311892-04:00"), + TransmissionTime = DateTimeOffset.Parse("2022-05-10T14:57:31.2311892-04:00"), + Metrics = { new MetricPoint("", 123.45, 1234) }, + Documents = {new Models.Request + { + Name = "", + Url = new Uri("http://localhost:3000"), + ResponseCode = "", + Duration = "", + DocumentStreamIds = {""}, + Properties = {new KeyValuePairStringString("", "")}, + }}, + TopCpuProcesses = { new ProcessCpuData("", 1234) }, + CollectionConfigurationErrors = {new CollectionConfigurationError(CollectionConfigurationErrorType.Unknown, "", "", new KeyValuePairStringString[] + { + default + })}, +}; +Response response = client.IsSubscribed("", monitoringDataPoint: monitoringDataPoint, transmissionTime: 1234L, machineName: "", instanceName: "", streamId: "", roleName: "", invariantVersion: "", configurationEtag: ""); +]]> + + + +This sample shows how to call IsSubscribedAsync and parse the result. +", content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("ETag").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Id").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("TelemetryType").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("FieldName").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Predicate").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Comparand").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Projection").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Aggregation").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("BackEndAggregation").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("Id").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("TelemetryType").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("FieldName").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Predicate").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Comparand").ToString()); +]]> +This sample shows how to call IsSubscribedAsync with all parameters and request content and parse the result. +", + InvariantVersion = 1234, + Instance = "", + RoleName = "", + MachineName = "", + StreamId = "", + Timestamp = "2022-05-10T14:57:31.2311892-04:00", + TransmissionTime = "2022-05-10T14:57:31.2311892-04:00", + IsWebApp = true, + PerformanceCollectionSupported = true, + Metrics = new object[] + { + new + { + Name = "", + Value = 123.45, + Weight = 1234, + } + }, + Documents = new object[] + { + new + { + Name = "", + Url = "http://localhost:3000", + ResponseCode = "", + Duration = "", + DocumentType = "Request", + DocumentStreamIds = new object[] + { + "" + }, + Properties = new object[] + { + new + { + key = "", + value = "", + } + }, + } + }, + TopCpuProcesses = new object[] + { + new + { + ProcessName = "", + CpuPercentage = 1234, + } + }, + CollectionConfigurationErrors = new object[] + { + new + { + CollectionConfigurationErrorType = "Unknown", + Message = "", + FullException = "", + Data = new object[] + { + null + }, + } + }, +}); +Response response = await client.IsSubscribedAsync("", content, transmissionTime: 1234L, machineName: "", instanceName: "", streamId: "", roleName: "", invariantVersion: "", configurationEtag: ""); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("ETag").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Id").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("TelemetryType").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("FieldName").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Predicate").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Comparand").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Projection").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Aggregation").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("BackEndAggregation").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("Id").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("TelemetryType").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("FieldName").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Predicate").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Comparand").ToString()); +Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("InitialQuota").ToString()); +Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("MaxQuota").ToString()); +Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("QuotaAccrualRatePerSec").ToString()); +]]> + + + +This sample shows how to call IsSubscribed and parse the result. +", content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("ETag").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Id").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("TelemetryType").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("FieldName").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Predicate").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Comparand").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Projection").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Aggregation").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("BackEndAggregation").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("Id").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("TelemetryType").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("FieldName").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Predicate").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Comparand").ToString()); +]]> +This sample shows how to call IsSubscribed with all parameters and request content and parse the result. +", + InvariantVersion = 1234, + Instance = "", + RoleName = "", + MachineName = "", + StreamId = "", + Timestamp = "2022-05-10T14:57:31.2311892-04:00", + TransmissionTime = "2022-05-10T14:57:31.2311892-04:00", + IsWebApp = true, + PerformanceCollectionSupported = true, + Metrics = new object[] + { + new + { + Name = "", + Value = 123.45, + Weight = 1234, + } + }, + Documents = new object[] + { + new + { + Name = "", + Url = "http://localhost:3000", + ResponseCode = "", + Duration = "", + DocumentType = "Request", + DocumentStreamIds = new object[] + { + "" + }, + Properties = new object[] + { + new + { + key = "", + value = "", + } + }, + } + }, + TopCpuProcesses = new object[] + { + new + { + ProcessName = "", + CpuPercentage = 1234, + } + }, + CollectionConfigurationErrors = new object[] + { + new + { + CollectionConfigurationErrorType = "Unknown", + Message = "", + FullException = "", + Data = new object[] + { + null + }, + } + }, +}); +Response response = client.IsSubscribed("", content, transmissionTime: 1234L, machineName: "", instanceName: "", streamId: "", roleName: "", invariantVersion: "", configurationEtag: ""); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("ETag").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Id").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("TelemetryType").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("FieldName").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Predicate").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Comparand").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Projection").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Aggregation").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("BackEndAggregation").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("Id").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("TelemetryType").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("FieldName").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Predicate").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Comparand").ToString()); +Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("InitialQuota").ToString()); +Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("MaxQuota").ToString()); +Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("QuotaAccrualRatePerSec").ToString()); +]]> + + + +This sample shows how to call PublishAsync. + response = await client.PublishAsync(""); +]]> +This sample shows how to call PublishAsync with all parameters. + response = await client.PublishAsync("", monitoringDataPoints: new MonitoringDataPoint[] +{ + new MonitoringDataPoint( + "", + 1234, + "", + "", + "", + "", + true, + true) + { + Timestamp = DateTimeOffset.Parse("2022-05-10T14:57:31.2311892-04:00"), + TransmissionTime = DateTimeOffset.Parse("2022-05-10T14:57:31.2311892-04:00"), + Metrics = {new MetricPoint("", 123.45, 1234)}, + Documents = {new Models.Request + { + Name = "", + Url = new Uri("http://localhost:3000"), + ResponseCode = "", + Duration = "", + DocumentStreamIds = {""}, + Properties = {new KeyValuePairStringString("", "")}, + }}, + TopCpuProcesses = {new ProcessCpuData("", 1234)}, + CollectionConfigurationErrors = {new CollectionConfigurationError(CollectionConfigurationErrorType.Unknown, "", "", new KeyValuePairStringString[] + { + default + })}, + } +}, configurationEtag: "", transmissionTime: 1234L); +]]> + + + +This sample shows how to call Publish. + response = client.Publish(""); +]]> +This sample shows how to call Publish with all parameters. + response = client.Publish("", monitoringDataPoints: new MonitoringDataPoint[] +{ + new MonitoringDataPoint( + "", + 1234, + "", + "", + "", + "", + true, + true) + { + Timestamp = DateTimeOffset.Parse("2022-05-10T14:57:31.2311892-04:00"), + TransmissionTime = DateTimeOffset.Parse("2022-05-10T14:57:31.2311892-04:00"), + Metrics = {new MetricPoint("", 123.45, 1234)}, + Documents = {new Models.Request + { + Name = "", + Url = new Uri("http://localhost:3000"), + ResponseCode = "", + Duration = "", + DocumentStreamIds = {""}, + Properties = {new KeyValuePairStringString("", "")}, + }}, + TopCpuProcesses = {new ProcessCpuData("", 1234)}, + CollectionConfigurationErrors = {new CollectionConfigurationError(CollectionConfigurationErrorType.Unknown, "", "", new KeyValuePairStringString[] + { + default + })}, + } +}, configurationEtag: "", transmissionTime: 1234L); +]]> + + + +This sample shows how to call PublishAsync and parse the result. +", content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("ETag").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Id").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("TelemetryType").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("FieldName").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Predicate").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Comparand").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Projection").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Aggregation").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("BackEndAggregation").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("Id").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("TelemetryType").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("FieldName").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Predicate").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Comparand").ToString()); +]]> +This sample shows how to call PublishAsync with all parameters and request content and parse the result. +", + InvariantVersion = 1234, + Instance = "", + RoleName = "", + MachineName = "", + StreamId = "", + Timestamp = "2022-05-10T14:57:31.2311892-04:00", + TransmissionTime = "2022-05-10T14:57:31.2311892-04:00", + IsWebApp = true, + PerformanceCollectionSupported = true, + Metrics = new object[] + { + new + { + Name = "", + Value = 123.45, + Weight = 1234, + } + }, + Documents = new object[] + { + new + { + Name = "", + Url = "http://localhost:3000", + ResponseCode = "", + Duration = "", + DocumentType = "Request", + DocumentStreamIds = new object[] + { + "" + }, + Properties = new object[] + { + new + { + key = "", + value = "", + } + }, + } + }, + TopCpuProcesses = new object[] + { + new + { + ProcessName = "", + CpuPercentage = 1234, + } + }, + CollectionConfigurationErrors = new object[] + { + new + { + CollectionConfigurationErrorType = "Unknown", + Message = "", + FullException = "", + Data = new object[] + { + null + }, + } + }, + } +}); +Response response = await client.PublishAsync("", content, configurationEtag: "", transmissionTime: 1234L); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("ETag").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Id").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("TelemetryType").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("FieldName").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Predicate").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Comparand").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Projection").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Aggregation").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("BackEndAggregation").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("Id").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("TelemetryType").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("FieldName").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Predicate").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Comparand").ToString()); +Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("InitialQuota").ToString()); +Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("MaxQuota").ToString()); +Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("QuotaAccrualRatePerSec").ToString()); +]]> + + + +This sample shows how to call Publish and parse the result. +", content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("ETag").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Id").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("TelemetryType").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("FieldName").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Predicate").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Comparand").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Projection").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Aggregation").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("BackEndAggregation").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("Id").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("TelemetryType").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("FieldName").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Predicate").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Comparand").ToString()); +]]> +This sample shows how to call Publish with all parameters and request content and parse the result. +", + InvariantVersion = 1234, + Instance = "", + RoleName = "", + MachineName = "", + StreamId = "", + Timestamp = "2022-05-10T14:57:31.2311892-04:00", + TransmissionTime = "2022-05-10T14:57:31.2311892-04:00", + IsWebApp = true, + PerformanceCollectionSupported = true, + Metrics = new object[] + { + new + { + Name = "", + Value = 123.45, + Weight = 1234, + } + }, + Documents = new object[] + { + new + { + Name = "", + Url = "http://localhost:3000", + ResponseCode = "", + Duration = "", + DocumentType = "Request", + DocumentStreamIds = new object[] + { + "" + }, + Properties = new object[] + { + new + { + key = "", + value = "", + } + }, + } + }, + TopCpuProcesses = new object[] + { + new + { + ProcessName = "", + CpuPercentage = 1234, + } + }, + CollectionConfigurationErrors = new object[] + { + new + { + CollectionConfigurationErrorType = "Unknown", + Message = "", + FullException = "", + Data = new object[] + { + null + }, + } + }, + } +}); +Response response = client.Publish("", content, configurationEtag: "", transmissionTime: 1234L); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("ETag").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Id").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("TelemetryType").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("FieldName").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Predicate").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Comparand").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Projection").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Aggregation").ToString()); +Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("BackEndAggregation").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("Id").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("TelemetryType").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("FieldName").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Predicate").ToString()); +Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Comparand").ToString()); +Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("InitialQuota").ToString()); +Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("MaxQuota").ToString()); +Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("QuotaAccrualRatePerSec").ToString()); +]]> + + + \ No newline at end of file diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Internal/ModelSerializationExtensions.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Internal/ModelSerializationExtensions.cs index 20ed94831bbd..dae7504308bd 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Internal/ModelSerializationExtensions.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Internal/ModelSerializationExtensions.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; @@ -164,13 +165,16 @@ public static void WriteNumberValue(this Utf8JsonWriter writer, DateTimeOffset v writer.WriteNumberValue(value.ToUnixTimeSeconds()); } - public static void WriteObjectValue(this Utf8JsonWriter writer, object value) + public static void WriteObjectValue(this Utf8JsonWriter writer, object value, ModelReaderWriterOptions options = null) { switch (value) { case null: writer.WriteNullValue(); break; + case IJsonModel jsonModel: + jsonModel.Write(writer, options ?? new ModelReaderWriterOptions("W")); + break; case IUtf8JsonSerializable serializable: serializable.Write(writer); break; @@ -225,7 +229,7 @@ public static void WriteObjectValue(this Utf8JsonWriter writer, object value) foreach (var pair in enumerable) { writer.WritePropertyName(pair.Key); - writer.WriteObjectValue(pair.Value); + writer.WriteObjectValue(pair.Value, options); } writer.WriteEndObject(); break; @@ -233,7 +237,7 @@ public static void WriteObjectValue(this Utf8JsonWriter writer, object value) writer.WriteStartArray(); foreach (var item in objectEnumerable) { - writer.WriteObjectValue(item); + writer.WriteObjectValue(item, options); } writer.WriteEndArray(); break; @@ -245,9 +249,9 @@ public static void WriteObjectValue(this Utf8JsonWriter writer, object value) } } - public static void WriteObjectValue(this Utf8JsonWriter writer, object value) + public static void WriteObjectValue(this Utf8JsonWriter writer, object value, ModelReaderWriterOptions options = null) { - writer.WriteObjectValue(value); + writer.WriteObjectValue(value, options); } internal static class TypeFormatters diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Internal/RequestContentHelper.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Internal/RequestContentHelper.cs index 6c3da17ac855..c58b14c27327 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Internal/RequestContentHelper.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Internal/RequestContentHelper.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure.Core; @@ -21,7 +22,7 @@ public static RequestContent FromEnumerable(IEnumerable enumerable) content.JsonWriter.WriteStartArray(); foreach (var item in enumerable) { - content.JsonWriter.WriteObjectValue(item); + content.JsonWriter.WriteObjectValue(item, new ModelReaderWriterOptions("W")); } content.JsonWriter.WriteEndArray(); @@ -63,7 +64,7 @@ public static RequestContent FromDictionary(IDictionary foreach (var item in dictionary) { content.JsonWriter.WritePropertyName(item.Key); - content.JsonWriter.WriteObjectValue(item.Value); + content.JsonWriter.WriteObjectValue(item.Value, new ModelReaderWriterOptions("W")); } content.JsonWriter.WriteEndObject(); @@ -101,7 +102,7 @@ public static RequestContent FromDictionary(IDictionary dict public static RequestContent FromObject(object value) { Utf8JsonRequestContent content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(value); + content.JsonWriter.WriteObjectValue(value, new ModelReaderWriterOptions("W")); return content; } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/LiveMetricsClient.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/LiveMetricsClient.cs new file mode 100644 index 000000000000..ce88eb29ba38 --- /dev/null +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/LiveMetricsClient.cs @@ -0,0 +1,408 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Monitor.OpenTelemetry.LiveMetrics.Models; + +namespace Azure.Monitor.OpenTelemetry.LiveMetrics +{ + // Data plane generated client. + /// Live Metrics REST APIs. + public partial class LiveMetricsClient + { + private static readonly string[] AuthorizationScopes = new string[] { "https://monitor.azure.com/.default" }; + private readonly TokenCredential _tokenCredential; + private readonly HttpPipeline _pipeline; + private readonly Uri _endpoint; + private readonly string _apiVersion; + + /// The ClientDiagnostics is used to provide tracing support for the client library. + internal ClientDiagnostics ClientDiagnostics { get; } + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual HttpPipeline Pipeline => _pipeline; + + /// Initializes a new instance of LiveMetricsClient for mocking. + protected LiveMetricsClient() + { + } + + /// Initializes a new instance of LiveMetricsClient. + /// A credential used to authenticate to an Azure Service. + /// is null. + public LiveMetricsClient(TokenCredential credential) : this(new Uri((Uri)null), credential, new LiveMetricsClientOptions()) + { + } + + /// Initializes a new instance of LiveMetricsClient. + /// The endpoint of the Live Metrics service. + /// A credential used to authenticate to an Azure Service. + /// The options for configuring the client. + /// or is null. + public LiveMetricsClient(Uri endpoint, TokenCredential credential, LiveMetricsClientOptions options) + { + Argument.AssertNotNull(endpoint, nameof(endpoint)); + Argument.AssertNotNull(credential, nameof(credential)); + options ??= new LiveMetricsClientOptions(); + + ClientDiagnostics = new ClientDiagnostics(options, true); + _tokenCredential = credential; + _pipeline = HttpPipelineBuilder.Build(options, Array.Empty(), new HttpPipelinePolicy[] { new BearerTokenAuthenticationPolicy(_tokenCredential, AuthorizationScopes) }, new ResponseClassifier()); + _endpoint = endpoint; + _apiVersion = options.Version; + } + + /// Determine whether there is any subscription to the metrics and documents. + /// The instrumentation key of the target Application Insights component for which the client checks whether there's any subscription to it. + /// Data contract between Application Insights client SDK and Live Metrics. /QuickPulseService.svc/ping uses this as a backup source of machine name, instance name and invariant version. + /// Timestamp when the client transmits the metrics and documents to Live Metrics. A 8-byte long type of ticks. + /// Computer name where Application Insights SDK lives. Live Metrics uses machine name with instance name as a backup. + /// Service instance name where Application Insights SDK lives. Live Metrics uses machine name with instance name as a backup. + /// Identifies an Application Insights SDK as trusted agent to report metrics and documents. + /// Cloud role name of the service. + /// Version/generation of the data contract (MonitoringDataPoint) between the client and Live Metrics. + /// An encoded string that indicates whether the collection configuration is changed. + /// The cancellation token to use. + /// is null. + /// + public virtual async Task> IsSubscribedAsync(string ikey, MonitoringDataPoint monitoringDataPoint = null, long? transmissionTime = null, string machineName = null, string instanceName = null, string streamId = null, string roleName = null, string invariantVersion = null, string configurationEtag = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(ikey, nameof(ikey)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = monitoringDataPoint?.ToRequestContent(); + Response response = await IsSubscribedAsync(ikey, content, transmissionTime, machineName, instanceName, streamId, roleName, invariantVersion, configurationEtag, context).ConfigureAwait(false); + return Response.FromValue(CollectionConfigurationInfo.FromResponse(response), response); + } + + /// Determine whether there is any subscription to the metrics and documents. + /// The instrumentation key of the target Application Insights component for which the client checks whether there's any subscription to it. + /// Data contract between Application Insights client SDK and Live Metrics. /QuickPulseService.svc/ping uses this as a backup source of machine name, instance name and invariant version. + /// Timestamp when the client transmits the metrics and documents to Live Metrics. A 8-byte long type of ticks. + /// Computer name where Application Insights SDK lives. Live Metrics uses machine name with instance name as a backup. + /// Service instance name where Application Insights SDK lives. Live Metrics uses machine name with instance name as a backup. + /// Identifies an Application Insights SDK as trusted agent to report metrics and documents. + /// Cloud role name of the service. + /// Version/generation of the data contract (MonitoringDataPoint) between the client and Live Metrics. + /// An encoded string that indicates whether the collection configuration is changed. + /// The cancellation token to use. + /// is null. + /// + public virtual Response IsSubscribed(string ikey, MonitoringDataPoint monitoringDataPoint = null, long? transmissionTime = null, string machineName = null, string instanceName = null, string streamId = null, string roleName = null, string invariantVersion = null, string configurationEtag = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(ikey, nameof(ikey)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = monitoringDataPoint?.ToRequestContent(); + Response response = IsSubscribed(ikey, content, transmissionTime, machineName, instanceName, streamId, roleName, invariantVersion, configurationEtag, context); + return Response.FromValue(CollectionConfigurationInfo.FromResponse(response), response); + } + + /// + /// [Protocol Method] Determine whether there is any subscription to the metrics and documents. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The instrumentation key of the target Application Insights component for which the client checks whether there's any subscription to it. + /// The content to send as the body of the request. + /// Timestamp when the client transmits the metrics and documents to Live Metrics. A 8-byte long type of ticks. + /// Computer name where Application Insights SDK lives. Live Metrics uses machine name with instance name as a backup. + /// Service instance name where Application Insights SDK lives. Live Metrics uses machine name with instance name as a backup. + /// Identifies an Application Insights SDK as trusted agent to report metrics and documents. + /// Cloud role name of the service. + /// Version/generation of the data contract (MonitoringDataPoint) between the client and Live Metrics. + /// An encoded string that indicates whether the collection configuration is changed. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual async Task IsSubscribedAsync(string ikey, RequestContent content, long? transmissionTime = null, string machineName = null, string instanceName = null, string streamId = null, string roleName = null, string invariantVersion = null, string configurationEtag = null, RequestContext context = null) + { + Argument.AssertNotNull(ikey, nameof(ikey)); + + using var scope = ClientDiagnostics.CreateScope("LiveMetricsClient.IsSubscribed"); + scope.Start(); + try + { + using HttpMessage message = CreateIsSubscribedRequest(ikey, content, transmissionTime, machineName, instanceName, streamId, roleName, invariantVersion, configurationEtag, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (System.Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Determine whether there is any subscription to the metrics and documents. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The instrumentation key of the target Application Insights component for which the client checks whether there's any subscription to it. + /// The content to send as the body of the request. + /// Timestamp when the client transmits the metrics and documents to Live Metrics. A 8-byte long type of ticks. + /// Computer name where Application Insights SDK lives. Live Metrics uses machine name with instance name as a backup. + /// Service instance name where Application Insights SDK lives. Live Metrics uses machine name with instance name as a backup. + /// Identifies an Application Insights SDK as trusted agent to report metrics and documents. + /// Cloud role name of the service. + /// Version/generation of the data contract (MonitoringDataPoint) between the client and Live Metrics. + /// An encoded string that indicates whether the collection configuration is changed. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual Response IsSubscribed(string ikey, RequestContent content, long? transmissionTime = null, string machineName = null, string instanceName = null, string streamId = null, string roleName = null, string invariantVersion = null, string configurationEtag = null, RequestContext context = null) + { + Argument.AssertNotNull(ikey, nameof(ikey)); + + using var scope = ClientDiagnostics.CreateScope("LiveMetricsClient.IsSubscribed"); + scope.Start(); + try + { + using HttpMessage message = CreateIsSubscribedRequest(ikey, content, transmissionTime, machineName, instanceName, streamId, roleName, invariantVersion, configurationEtag, context); + return _pipeline.ProcessMessage(message, context); + } + catch (System.Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Publish live metrics to the Live Metrics service when there is an active subscription to the metrics. + /// The instrumentation key of the target Application Insights component for which the client checks whether there's any subscription to it. + /// Data contract between the client and Live Metrics. /QuickPulseService.svc/ping uses this as a backup source of machine name, instance name and invariant version. + /// An encoded string that indicates whether the collection configuration is changed. + /// Timestamp when the client transmits the metrics and documents to Live Metrics. A 8-byte long type of ticks. + /// The cancellation token to use. + /// is null. + /// + public virtual async Task> PublishAsync(string ikey, IEnumerable monitoringDataPoints = null, string configurationEtag = null, long? transmissionTime = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(ikey, nameof(ikey)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = monitoringDataPoints != null ? RequestContentHelper.FromEnumerable(monitoringDataPoints) : null; + Response response = await PublishAsync(ikey, content, configurationEtag, transmissionTime, context).ConfigureAwait(false); + return Response.FromValue(CollectionConfigurationInfo.FromResponse(response), response); + } + + /// Publish live metrics to the Live Metrics service when there is an active subscription to the metrics. + /// The instrumentation key of the target Application Insights component for which the client checks whether there's any subscription to it. + /// Data contract between the client and Live Metrics. /QuickPulseService.svc/ping uses this as a backup source of machine name, instance name and invariant version. + /// An encoded string that indicates whether the collection configuration is changed. + /// Timestamp when the client transmits the metrics and documents to Live Metrics. A 8-byte long type of ticks. + /// The cancellation token to use. + /// is null. + /// + public virtual Response Publish(string ikey, IEnumerable monitoringDataPoints = null, string configurationEtag = null, long? transmissionTime = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(ikey, nameof(ikey)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = monitoringDataPoints != null ? RequestContentHelper.FromEnumerable(monitoringDataPoints) : null; + Response response = Publish(ikey, content, configurationEtag, transmissionTime, context); + return Response.FromValue(CollectionConfigurationInfo.FromResponse(response), response); + } + + /// + /// [Protocol Method] Publish live metrics to the Live Metrics service when there is an active subscription to the metrics. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The instrumentation key of the target Application Insights component for which the client checks whether there's any subscription to it. + /// The content to send as the body of the request. + /// An encoded string that indicates whether the collection configuration is changed. + /// Timestamp when the client transmits the metrics and documents to Live Metrics. A 8-byte long type of ticks. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual async Task PublishAsync(string ikey, RequestContent content, string configurationEtag = null, long? transmissionTime = null, RequestContext context = null) + { + Argument.AssertNotNull(ikey, nameof(ikey)); + + using var scope = ClientDiagnostics.CreateScope("LiveMetricsClient.Publish"); + scope.Start(); + try + { + using HttpMessage message = CreatePublishRequest(ikey, content, configurationEtag, transmissionTime, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (System.Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Publish live metrics to the Live Metrics service when there is an active subscription to the metrics. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The instrumentation key of the target Application Insights component for which the client checks whether there's any subscription to it. + /// The content to send as the body of the request. + /// An encoded string that indicates whether the collection configuration is changed. + /// Timestamp when the client transmits the metrics and documents to Live Metrics. A 8-byte long type of ticks. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual Response Publish(string ikey, RequestContent content, string configurationEtag = null, long? transmissionTime = null, RequestContext context = null) + { + Argument.AssertNotNull(ikey, nameof(ikey)); + + using var scope = ClientDiagnostics.CreateScope("LiveMetricsClient.Publish"); + scope.Start(); + try + { + using HttpMessage message = CreatePublishRequest(ikey, content, configurationEtag, transmissionTime, context); + return _pipeline.ProcessMessage(message, context); + } + catch (System.Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateIsSubscribedRequest(string ikey, RequestContent content, long? transmissionTime, string machineName, string instanceName, string streamId, string roleName, string invariantVersion, string configurationEtag, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/QuickPulseService.svc/ping", false); + uri.AppendQuery("ikey", ikey, true); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + if (transmissionTime != null) + { + request.Headers.Add("x-ms-qps-transmission-time", transmissionTime.Value); + } + if (machineName != null) + { + request.Headers.Add("x-ms-qps-machine-name", machineName); + } + if (instanceName != null) + { + request.Headers.Add("x-ms-qps-instance-name", instanceName); + } + if (streamId != null) + { + request.Headers.Add("x-ms-qps-stream-id", streamId); + } + if (roleName != null) + { + request.Headers.Add("x-ms-qps-role-name", roleName); + } + if (invariantVersion != null) + { + request.Headers.Add("x-ms-qps-invariant-version", invariantVersion); + } + if (configurationEtag != null) + { + request.Headers.Add("x-ms-qps-configuration-etag", configurationEtag); + } + request.Headers.Add("Content-Type", "application/json"); + request.Content = content; + return message; + } + + internal HttpMessage CreatePublishRequest(string ikey, RequestContent content, string configurationEtag, long? transmissionTime, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/QuickPulseService.svc/post", false); + uri.AppendQuery("ikey", ikey, true); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + if (configurationEtag != null) + { + request.Headers.Add("x-ms-qps-configuration-etag", configurationEtag); + } + if (transmissionTime != null) + { + request.Headers.Add("x-ms-qps-transmission-time", transmissionTime.Value); + } + request.Headers.Add("Content-Type", "application/json"); + request.Content = content; + return message; + } + + private static RequestContext DefaultRequestContext = new RequestContext(); + internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default) + { + if (!cancellationToken.CanBeCanceled) + { + return DefaultRequestContext; + } + + return new RequestContext() { CancellationToken = cancellationToken }; + } + + private static ResponseClassifier _responseClassifier200; + private static ResponseClassifier ResponseClassifier200 => _responseClassifier200 ??= new StatusCodeClassifier(stackalloc ushort[] { 200 }); + } +} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/LiveMetricsClientOptions.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/LiveMetricsClientOptions.cs new file mode 100644 index 000000000000..274dac0e37f6 --- /dev/null +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/LiveMetricsClientOptions.cs @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.Monitor.OpenTelemetry.LiveMetrics +{ + /// Client options for LiveMetricsClient. + public partial class LiveMetricsClientOptions : ClientOptions + { + private const ServiceVersion LatestVersion = ServiceVersion.V2024_04_01_Preview; + + /// The version of the service to use. + public enum ServiceVersion + { + /// Service version "2024-04-01-preview". + V2024_04_01_Preview = 1, + } + + internal string Version { get; } + + /// Initializes new instance of LiveMetricsClientOptions. + public LiveMetricsClientOptions(ServiceVersion version = LatestVersion) + { + Version = version switch + { + ServiceVersion.V2024_04_01_Preview => "2024-04-01-preview", + _ => throw new NotSupportedException() + }; + } + } +} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/AggregationType.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/AggregationType.cs new file mode 100644 index 000000000000..a35af4d9af83 --- /dev/null +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/AggregationType.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models +{ + /// Aggregation type. + public readonly partial struct AggregationType : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public AggregationType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string AvgValue = "Avg"; + private const string SumValue = "Sum"; + private const string MinValue = "Min"; + private const string MaxValue = "Max"; + + /// Average. + public static AggregationType Avg { get; } = new AggregationType(AvgValue); + /// Sum. + public static AggregationType Sum { get; } = new AggregationType(SumValue); + /// Minimum. + public static AggregationType Min { get; } = new AggregationType(MinValue); + /// Maximum. + public static AggregationType Max { get; } = new AggregationType(MaxValue); + /// Determines if two values are the same. + public static bool operator ==(AggregationType left, AggregationType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(AggregationType left, AggregationType right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator AggregationType(string value) => new AggregationType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is AggregationType other && Equals(other); + /// + public bool Equals(AggregationType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationError.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationError.Serialization.cs index 21584fa6a72f..911c1a5afb39 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationError.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationError.Serialization.cs @@ -5,42 +5,165 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class CollectionConfigurationError : IUtf8JsonSerializable + internal partial class CollectionConfigurationError : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CollectionConfigurationError)} does not support writing '{format}' format."); + } + writer.WriteStartObject(); - if (Optional.IsDefined(CollectionConfigurationErrorType)) + writer.WritePropertyName("CollectionConfigurationErrorType"u8); + writer.WriteStringValue(CollectionConfigurationErrorType.ToString()); + writer.WritePropertyName("Message"u8); + writer.WriteStringValue(Message); + writer.WritePropertyName("FullException"u8); + writer.WriteStringValue(FullException); + writer.WritePropertyName("Data"u8); + writer.WriteStartArray(); + foreach (var item in Data) { - writer.WritePropertyName("CollectionConfigurationErrorType"u8); - writer.WriteStringValue(CollectionConfigurationErrorType.Value.ToString()); + writer.WriteObjectValue(item, options); } - if (Optional.IsDefined(Message)) + writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) { - writer.WritePropertyName("Message"u8); - writer.WriteStringValue(Message); + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } } - if (Optional.IsDefined(FullException)) + writer.WriteEndObject(); + } + + CollectionConfigurationError IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") { - writer.WritePropertyName("FullException"u8); - writer.WriteStringValue(FullException); + throw new FormatException($"The model {nameof(CollectionConfigurationError)} does not support reading '{format}' format."); } - if (Optional.IsCollectionDefined(Data)) + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCollectionConfigurationError(document.RootElement, options); + } + + internal static CollectionConfigurationError DeserializeCollectionConfigurationError(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) { - writer.WritePropertyName("Data"u8); - writer.WriteStartArray(); - foreach (var item in Data) + return null; + } + CollectionConfigurationErrorType collectionConfigurationErrorType = default; + string message = default; + string fullException = default; + IList data = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("CollectionConfigurationErrorType"u8)) + { + collectionConfigurationErrorType = new CollectionConfigurationErrorType(property.Value.GetString()); + continue; + } + if (property.NameEquals("Message"u8)) + { + message = property.Value.GetString(); + continue; + } + if (property.NameEquals("FullException"u8)) + { + fullException = property.Value.GetString(); + continue; + } + if (property.NameEquals("Data"u8)) { - writer.WriteObjectValue(item); + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(KeyValuePairStringString.DeserializeKeyValuePairStringString(item, options)); + } + data = array; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); } - writer.WriteEndArray(); } - writer.WriteEndObject(); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new CollectionConfigurationError(collectionConfigurationErrorType, message, fullException, data, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(CollectionConfigurationError)} does not support writing '{options.Format}' format."); + } + } + + CollectionConfigurationError IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeCollectionConfigurationError(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CollectionConfigurationError)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static CollectionConfigurationError FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeCollectionConfigurationError(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationError.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationError.cs index 7692433bc9b9..64817b61e814 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationError.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationError.cs @@ -5,39 +5,92 @@ #nullable disable +using System; using System.Collections.Generic; +using System.Linq; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - /// Represents an error while SDK parsing and applying an instance of CollectionConfigurationInfo. + /// Represents an error while SDK parses and applies an instance of CollectionConfigurationInfo. internal partial class CollectionConfigurationError { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . - public CollectionConfigurationError() + /// Error type. + /// Error message. + /// Exception that led to the creation of the configuration error. + /// Custom properties to add more information to the error. + /// , or is null. + public CollectionConfigurationError(CollectionConfigurationErrorType collectionConfigurationErrorType, string message, string fullException, IEnumerable data) { - Data = new ChangeTrackingList(); + Argument.AssertNotNull(message, nameof(message)); + Argument.AssertNotNull(fullException, nameof(fullException)); + Argument.AssertNotNull(data, nameof(data)); + + CollectionConfigurationErrorType = collectionConfigurationErrorType; + Message = message; + FullException = fullException; + Data = data.ToList(); } /// Initializes a new instance of . - /// Collection configuration error type reported by SDK. + /// Error type. /// Error message. - /// Exception that leads to the creation of the configuration error. + /// Exception that led to the creation of the configuration error. /// Custom properties to add more information to the error. - internal CollectionConfigurationError(CollectionConfigurationErrorType? collectionConfigurationErrorType, string message, string fullException, IList data) + /// Keeps track of any properties unknown to the library. + internal CollectionConfigurationError(CollectionConfigurationErrorType collectionConfigurationErrorType, string message, string fullException, IList data, IDictionary serializedAdditionalRawData) { CollectionConfigurationErrorType = collectionConfigurationErrorType; Message = message; FullException = fullException; Data = data; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal CollectionConfigurationError() + { } - /// Collection configuration error type reported by SDK. - public CollectionConfigurationErrorType? CollectionConfigurationErrorType { get; set; } + /// Error type. + public CollectionConfigurationErrorType CollectionConfigurationErrorType { get; } /// Error message. - public string Message { get; set; } - /// Exception that leads to the creation of the configuration error. - public string FullException { get; set; } + public string Message { get; } + /// Exception that led to the creation of the configuration error. + public string FullException { get; } /// Custom properties to add more information to the error. - public IList Data { get; } + public IList Data { get; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationErrorType.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationErrorType.cs index 70720b3a08a1..507104b1de66 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationErrorType.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationErrorType.cs @@ -10,7 +10,7 @@ namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - /// Collection configuration error type reported by SDK. + /// Collection configuration error type reported by the client SDK. internal readonly partial struct CollectionConfigurationErrorType : IEquatable { private readonly string _value; @@ -36,31 +36,31 @@ public CollectionConfigurationErrorType(string value) private const string FilterFailureToCreateUnexpectedValue = "FilterFailureToCreateUnexpected"; private const string CollectionConfigurationFailureToCreateUnexpectedValue = "CollectionConfigurationFailureToCreateUnexpected"; - /// Unknown. + /// Unknown error type. public static CollectionConfigurationErrorType Unknown { get; } = new CollectionConfigurationErrorType(UnknownValue); - /// PerformanceCounterParsing. + /// Performance counter parsing error. public static CollectionConfigurationErrorType PerformanceCounterParsing { get; } = new CollectionConfigurationErrorType(PerformanceCounterParsingValue); - /// PerformanceCounterUnexpected. + /// Performance counter unexpected error. public static CollectionConfigurationErrorType PerformanceCounterUnexpected { get; } = new CollectionConfigurationErrorType(PerformanceCounterUnexpectedValue); - /// PerformanceCounterDuplicateIds. + /// Performance counter duplicate ids. public static CollectionConfigurationErrorType PerformanceCounterDuplicateIds { get; } = new CollectionConfigurationErrorType(PerformanceCounterDuplicateIdsValue); - /// DocumentStreamDuplicateIds. + /// Document stream duplication ids. public static CollectionConfigurationErrorType DocumentStreamDuplicateIds { get; } = new CollectionConfigurationErrorType(DocumentStreamDuplicateIdsValue); - /// DocumentStreamFailureToCreate. + /// Document stream failed to create. public static CollectionConfigurationErrorType DocumentStreamFailureToCreate { get; } = new CollectionConfigurationErrorType(DocumentStreamFailureToCreateValue); - /// DocumentStreamFailureToCreateFilterUnexpected. + /// Document stream failed to create filter unexpectedly. public static CollectionConfigurationErrorType DocumentStreamFailureToCreateFilterUnexpected { get; } = new CollectionConfigurationErrorType(DocumentStreamFailureToCreateFilterUnexpectedValue); - /// MetricDuplicateIds. + /// Metric duplicate ids. public static CollectionConfigurationErrorType MetricDuplicateIds { get; } = new CollectionConfigurationErrorType(MetricDuplicateIdsValue); - /// MetricTelemetryTypeUnsupported. + /// Metric telemetry type unsupported. public static CollectionConfigurationErrorType MetricTelemetryTypeUnsupported { get; } = new CollectionConfigurationErrorType(MetricTelemetryTypeUnsupportedValue); - /// MetricFailureToCreate. + /// Metric failed to create. public static CollectionConfigurationErrorType MetricFailureToCreate { get; } = new CollectionConfigurationErrorType(MetricFailureToCreateValue); - /// MetricFailureToCreateFilterUnexpected. + /// Metric failed to create filter unexpectedly. public static CollectionConfigurationErrorType MetricFailureToCreateFilterUnexpected { get; } = new CollectionConfigurationErrorType(MetricFailureToCreateFilterUnexpectedValue); - /// FilterFailureToCreateUnexpected. + /// Filter failed to create unexpectedly. public static CollectionConfigurationErrorType FilterFailureToCreateUnexpected { get; } = new CollectionConfigurationErrorType(FilterFailureToCreateUnexpectedValue); - /// CollectionConfigurationFailureToCreateUnexpected. + /// Collection configuration failed to create unexpectedly. public static CollectionConfigurationErrorType CollectionConfigurationFailureToCreateUnexpected { get; } = new CollectionConfigurationErrorType(CollectionConfigurationFailureToCreateUnexpectedValue); /// Determines if two values are the same. public static bool operator ==(CollectionConfigurationErrorType left, CollectionConfigurationErrorType right) => left.Equals(right); diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationInfo.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationInfo.Serialization.cs index 3a9550b038a9..9ede7a26ea39 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationInfo.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationInfo.Serialization.cs @@ -5,54 +5,115 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class CollectionConfigurationInfo + public partial class CollectionConfigurationInfo : IUtf8JsonSerializable, IJsonModel { - internal static CollectionConfigurationInfo DeserializeCollectionConfigurationInfo(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CollectionConfigurationInfo)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("ETag"u8); + writer.WriteStringValue(ETag); + writer.WritePropertyName("Metrics"u8); + writer.WriteStartArray(); + foreach (var item in Metrics) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + writer.WritePropertyName("DocumentStreams"u8); + writer.WriteStartArray(); + foreach (var item in DocumentStreams) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + if (Optional.IsDefined(QuotaInfo)) + { + writer.WritePropertyName("QuotaInfo"u8); + writer.WriteObjectValue(QuotaInfo, options); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + CollectionConfigurationInfo IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CollectionConfigurationInfo)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCollectionConfigurationInfo(document.RootElement, options); + } + + internal static CollectionConfigurationInfo DeserializeCollectionConfigurationInfo(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } - string etag = default; + string eTag = default; IReadOnlyList metrics = default; IReadOnlyList documentStreams = default; QuotaConfigurationInfo quotaInfo = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("Etag"u8)) + if (property.NameEquals("ETag"u8)) { - etag = property.Value.GetString(); + eTag = property.Value.GetString(); continue; } if (property.NameEquals("Metrics"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(DerivedMetricInfo.DeserializeDerivedMetricInfo(item)); + array.Add(DerivedMetricInfo.DeserializeDerivedMetricInfo(item, options)); } metrics = array; continue; } if (property.NameEquals("DocumentStreams"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(DocumentStreamInfo.DeserializeDocumentStreamInfo(item)); + array.Add(DocumentStreamInfo.DeserializeDocumentStreamInfo(item, options)); } documentStreams = array; continue; @@ -63,11 +124,63 @@ internal static CollectionConfigurationInfo DeserializeCollectionConfigurationIn { continue; } - quotaInfo = QuotaConfigurationInfo.DeserializeQuotaConfigurationInfo(property.Value); + quotaInfo = QuotaConfigurationInfo.DeserializeQuotaConfigurationInfo(property.Value, options); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new CollectionConfigurationInfo(eTag, metrics, documentStreams, quotaInfo, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(CollectionConfigurationInfo)} does not support writing '{options.Format}' format."); + } + } + + CollectionConfigurationInfo IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeCollectionConfigurationInfo(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CollectionConfigurationInfo)} does not support reading '{options.Format}' format."); } - return new CollectionConfigurationInfo(etag, metrics ?? new ChangeTrackingList(), documentStreams ?? new ChangeTrackingList(), quotaInfo); + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static CollectionConfigurationInfo FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeCollectionConfigurationInfo(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationInfo.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationInfo.cs index 77a9791997ef..0ac23a5ba5bb 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationInfo.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/CollectionConfigurationInfo.cs @@ -5,40 +5,90 @@ #nullable disable +using System; using System.Collections.Generic; +using System.Linq; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - /// Represents the collection configuration - a customizable description of performance counters, metrics, and full telemetry documents to be collected by the SDK. - internal partial class CollectionConfigurationInfo + /// Represents the collection configuration - a customizable description of performance counters, metrics, and full telemetry documents to be collected by the client SDK. + public partial class CollectionConfigurationInfo { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . - internal CollectionConfigurationInfo() + /// An encoded string that indicates whether the collection configuration is changed. + /// An array of metric configuration info. + /// An array of document stream configuration info. + /// , or is null. + internal CollectionConfigurationInfo(string eTag, IEnumerable metrics, IEnumerable documentStreams) { - Metrics = new ChangeTrackingList(); - DocumentStreams = new ChangeTrackingList(); + Argument.AssertNotNull(eTag, nameof(eTag)); + Argument.AssertNotNull(metrics, nameof(metrics)); + Argument.AssertNotNull(documentStreams, nameof(documentStreams)); + + ETag = eTag; + Metrics = metrics.ToList(); + DocumentStreams = documentStreams.ToList(); } /// Initializes a new instance of . - /// An encoded string that indicates whether the collection configuration is changed. + /// An encoded string that indicates whether the collection configuration is changed. /// An array of metric configuration info. /// An array of document stream configuration info. - /// Control document quotas for QuickPulse. - internal CollectionConfigurationInfo(string etag, IReadOnlyList metrics, IReadOnlyList documentStreams, QuotaConfigurationInfo quotaInfo) + /// Controls document quotas to be sent to Live Metrics. + /// Keeps track of any properties unknown to the library. + internal CollectionConfigurationInfo(string eTag, IReadOnlyList metrics, IReadOnlyList documentStreams, QuotaConfigurationInfo quotaInfo, IDictionary serializedAdditionalRawData) { - Etag = etag; + ETag = eTag; Metrics = metrics; DocumentStreams = documentStreams; QuotaInfo = quotaInfo; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal CollectionConfigurationInfo() + { } /// An encoded string that indicates whether the collection configuration is changed. - public string Etag { get; } + public string ETag { get; } /// An array of metric configuration info. public IReadOnlyList Metrics { get; } /// An array of document stream configuration info. public IReadOnlyList DocumentStreams { get; } - /// Control document quotas for QuickPulse. + /// Controls document quotas to be sent to Live Metrics. public QuotaConfigurationInfo QuotaInfo { get; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DerivedMetricInfo.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DerivedMetricInfo.Serialization.cs index 6c3560ede4d8..f4ff0c154a76 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DerivedMetricInfo.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DerivedMetricInfo.Serialization.cs @@ -5,15 +5,78 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class DerivedMetricInfo + public partial class DerivedMetricInfo : IUtf8JsonSerializable, IJsonModel { - internal static DerivedMetricInfo DeserializeDerivedMetricInfo(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(DerivedMetricInfo)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("Id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("TelemetryType"u8); + writer.WriteStringValue(TelemetryType); + writer.WritePropertyName("FilterGroups"u8); + writer.WriteStartArray(); + foreach (var item in FilterGroups) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + writer.WritePropertyName("Projection"u8); + writer.WriteStringValue(Projection); + writer.WritePropertyName("Aggregation"u8); + writer.WriteStringValue(Aggregation.ToString()); + writer.WritePropertyName("BackEndAggregation"u8); + writer.WriteStringValue(BackEndAggregation.ToString()); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + DerivedMetricInfo IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(DerivedMetricInfo)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeDerivedMetricInfo(document.RootElement, options); + } + + internal static DerivedMetricInfo DeserializeDerivedMetricInfo(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -22,7 +85,10 @@ internal static DerivedMetricInfo DeserializeDerivedMetricInfo(JsonElement eleme string telemetryType = default; IReadOnlyList filterGroups = default; string projection = default; - DerivedMetricInfoAggregation? aggregation = default; + AggregationType aggregation = default; + AggregationType backEndAggregation = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("Id"u8)) @@ -37,14 +103,10 @@ internal static DerivedMetricInfo DeserializeDerivedMetricInfo(JsonElement eleme } if (property.NameEquals("FilterGroups"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(FilterConjunctionGroupInfo.DeserializeFilterConjunctionGroupInfo(item)); + array.Add(FilterConjunctionGroupInfo.DeserializeFilterConjunctionGroupInfo(item, options)); } filterGroups = array; continue; @@ -56,15 +118,75 @@ internal static DerivedMetricInfo DeserializeDerivedMetricInfo(JsonElement eleme } if (property.NameEquals("Aggregation"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - aggregation = new DerivedMetricInfoAggregation(property.Value.GetString()); + aggregation = new AggregationType(property.Value.GetString()); continue; } + if (property.NameEquals("BackEndAggregation"u8)) + { + backEndAggregation = new AggregationType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new DerivedMetricInfo( + id, + telemetryType, + filterGroups, + projection, + aggregation, + backEndAggregation, + serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(DerivedMetricInfo)} does not support writing '{options.Format}' format."); + } + } + + DerivedMetricInfo IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeDerivedMetricInfo(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(DerivedMetricInfo)} does not support reading '{options.Format}' format."); } - return new DerivedMetricInfo(id, telemetryType, filterGroups ?? new ChangeTrackingList(), projection, aggregation); + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static DerivedMetricInfo FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeDerivedMetricInfo(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DerivedMetricInfo.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DerivedMetricInfo.cs index 76cb88f524b7..eab7928db601 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DerivedMetricInfo.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DerivedMetricInfo.cs @@ -5,17 +5,68 @@ #nullable disable +using System; using System.Collections.Generic; +using System.Linq; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { /// A metric configuration set by UX to scope the metrics it's interested in. - internal partial class DerivedMetricInfo + public partial class DerivedMetricInfo { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . - internal DerivedMetricInfo() + /// metric configuration identifier. + /// Telemetry type. + /// A collection of filters to scope metrics that UX needs. + /// Telemetry's metric dimension whose value is to be aggregated. Example values: Duration, Count(),... + /// Aggregation type. This is the aggregation done from everything within a single server. + /// Aggregation type. This Aggregation is done across the values for all the servers taken together. + /// , , or is null. + internal DerivedMetricInfo(string id, string telemetryType, IEnumerable filterGroups, string projection, AggregationType aggregation, AggregationType backEndAggregation) { - FilterGroups = new ChangeTrackingList(); + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(telemetryType, nameof(telemetryType)); + Argument.AssertNotNull(filterGroups, nameof(filterGroups)); + Argument.AssertNotNull(projection, nameof(projection)); + + Id = id; + TelemetryType = telemetryType; + FilterGroups = filterGroups.ToList(); + Projection = projection; + Aggregation = aggregation; + BackEndAggregation = backEndAggregation; } /// Initializes a new instance of . @@ -23,14 +74,23 @@ internal DerivedMetricInfo() /// Telemetry type. /// A collection of filters to scope metrics that UX needs. /// Telemetry's metric dimension whose value is to be aggregated. Example values: Duration, Count(),... - /// Aggregation type. - internal DerivedMetricInfo(string id, string telemetryType, IReadOnlyList filterGroups, string projection, DerivedMetricInfoAggregation? aggregation) + /// Aggregation type. This is the aggregation done from everything within a single server. + /// Aggregation type. This Aggregation is done across the values for all the servers taken together. + /// Keeps track of any properties unknown to the library. + internal DerivedMetricInfo(string id, string telemetryType, IReadOnlyList filterGroups, string projection, AggregationType aggregation, AggregationType backEndAggregation, IDictionary serializedAdditionalRawData) { Id = id; TelemetryType = telemetryType; FilterGroups = filterGroups; Projection = projection; Aggregation = aggregation; + BackEndAggregation = backEndAggregation; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal DerivedMetricInfo() + { } /// metric configuration identifier. @@ -41,7 +101,9 @@ internal DerivedMetricInfo(string id, string telemetryType, IReadOnlyList FilterGroups { get; } /// Telemetry's metric dimension whose value is to be aggregated. Example values: Duration, Count(),... public string Projection { get; } - /// Aggregation type. - public DerivedMetricInfoAggregation? Aggregation { get; } + /// Aggregation type. This is the aggregation done from everything within a single server. + public AggregationType Aggregation { get; } + /// Aggregation type. This Aggregation is done across the values for all the servers taken together. + public AggregationType BackEndAggregation { get; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DerivedMetricInfoAggregation.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DerivedMetricInfoAggregation.cs deleted file mode 100644 index 92713bca6f49..000000000000 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DerivedMetricInfoAggregation.cs +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ComponentModel; - -namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models -{ - /// Aggregation type. - public readonly partial struct DerivedMetricInfoAggregation : IEquatable - { - private readonly string _value; - - /// Initializes a new instance of . - /// is null. - public DerivedMetricInfoAggregation(string value) - { - _value = value ?? throw new ArgumentNullException(nameof(value)); - } - - private const string AvgValue = "Avg"; - private const string SumValue = "Sum"; - private const string MinValue = "Min"; - private const string MaxValue = "Max"; - - /// Avg. - public static DerivedMetricInfoAggregation Avg { get; } = new DerivedMetricInfoAggregation(AvgValue); - /// Sum. - public static DerivedMetricInfoAggregation Sum { get; } = new DerivedMetricInfoAggregation(SumValue); - /// Min. - public static DerivedMetricInfoAggregation Min { get; } = new DerivedMetricInfoAggregation(MinValue); - /// Max. - public static DerivedMetricInfoAggregation Max { get; } = new DerivedMetricInfoAggregation(MaxValue); - /// Determines if two values are the same. - public static bool operator ==(DerivedMetricInfoAggregation left, DerivedMetricInfoAggregation right) => left.Equals(right); - /// Determines if two values are not the same. - public static bool operator !=(DerivedMetricInfoAggregation left, DerivedMetricInfoAggregation right) => !left.Equals(right); - /// Converts a string to a . - public static implicit operator DerivedMetricInfoAggregation(string value) => new DerivedMetricInfoAggregation(value); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => obj is DerivedMetricInfoAggregation other && Equals(other); - /// - public bool Equals(DerivedMetricInfoAggregation other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => _value?.GetHashCode() ?? 0; - /// - public override string ToString() => _value; - } -} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentFilterConjunctionGroupInfo.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentFilterConjunctionGroupInfo.Serialization.cs index 7faa44f8bb27..6648026de4b8 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentFilterConjunctionGroupInfo.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentFilterConjunctionGroupInfo.Serialization.cs @@ -5,42 +5,139 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class DocumentFilterConjunctionGroupInfo + public partial class DocumentFilterConjunctionGroupInfo : IUtf8JsonSerializable, IJsonModel { - internal static DocumentFilterConjunctionGroupInfo DeserializeDocumentFilterConjunctionGroupInfo(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(DocumentFilterConjunctionGroupInfo)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("TelemetryType"u8); + writer.WriteStringValue(TelemetryType.ToString()); + writer.WritePropertyName("Filters"u8); + writer.WriteObjectValue(Filters, options); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + DocumentFilterConjunctionGroupInfo IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(DocumentFilterConjunctionGroupInfo)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeDocumentFilterConjunctionGroupInfo(document.RootElement, options); + } + + internal static DocumentFilterConjunctionGroupInfo DeserializeDocumentFilterConjunctionGroupInfo(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } - DocumentFilterConjunctionGroupInfoTelemetryType? telemetryType = default; + TelemetryType telemetryType = default; FilterConjunctionGroupInfo filters = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("TelemetryType"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - telemetryType = new DocumentFilterConjunctionGroupInfoTelemetryType(property.Value.GetString()); + telemetryType = new TelemetryType(property.Value.GetString()); continue; } if (property.NameEquals("Filters"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - filters = FilterConjunctionGroupInfo.DeserializeFilterConjunctionGroupInfo(property.Value); + filters = FilterConjunctionGroupInfo.DeserializeFilterConjunctionGroupInfo(property.Value, options); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new DocumentFilterConjunctionGroupInfo(telemetryType, filters, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(DocumentFilterConjunctionGroupInfo)} does not support writing '{options.Format}' format."); } - return new DocumentFilterConjunctionGroupInfo(telemetryType, filters); + } + + DocumentFilterConjunctionGroupInfo IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeDocumentFilterConjunctionGroupInfo(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(DocumentFilterConjunctionGroupInfo)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static DocumentFilterConjunctionGroupInfo FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeDocumentFilterConjunctionGroupInfo(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentFilterConjunctionGroupInfo.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentFilterConjunctionGroupInfo.cs index 55bd2bfcc40b..1325a51f1d92 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentFilterConjunctionGroupInfo.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentFilterConjunctionGroupInfo.cs @@ -5,28 +5,77 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - /// A collection of filters for a specificy telemetry type. - internal partial class DocumentFilterConjunctionGroupInfo + /// A collection of filters for a specific telemetry type. + public partial class DocumentFilterConjunctionGroupInfo { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . - internal DocumentFilterConjunctionGroupInfo() + /// Telemetry type. + /// An array of filter groups. + /// is null. + internal DocumentFilterConjunctionGroupInfo(TelemetryType telemetryType, FilterConjunctionGroupInfo filters) { + Argument.AssertNotNull(filters, nameof(filters)); + + TelemetryType = telemetryType; + Filters = filters; } /// Initializes a new instance of . /// Telemetry type. - /// An AND-connected group of FilterInfo objects. - internal DocumentFilterConjunctionGroupInfo(DocumentFilterConjunctionGroupInfoTelemetryType? telemetryType, FilterConjunctionGroupInfo filters) + /// An array of filter groups. + /// Keeps track of any properties unknown to the library. + internal DocumentFilterConjunctionGroupInfo(TelemetryType telemetryType, FilterConjunctionGroupInfo filters, IDictionary serializedAdditionalRawData) { TelemetryType = telemetryType; Filters = filters; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal DocumentFilterConjunctionGroupInfo() + { } /// Telemetry type. - public DocumentFilterConjunctionGroupInfoTelemetryType? TelemetryType { get; } - /// An AND-connected group of FilterInfo objects. + public TelemetryType TelemetryType { get; } + /// An array of filter groups. public FilterConjunctionGroupInfo Filters { get; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentFilterConjunctionGroupInfoTelemetryType.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentFilterConjunctionGroupInfoTelemetryType.cs deleted file mode 100644 index f63ac090c40a..000000000000 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentFilterConjunctionGroupInfoTelemetryType.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ComponentModel; - -namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models -{ - /// Telemetry type. - public readonly partial struct DocumentFilterConjunctionGroupInfoTelemetryType : IEquatable - { - private readonly string _value; - - /// Initializes a new instance of . - /// is null. - public DocumentFilterConjunctionGroupInfoTelemetryType(string value) - { - _value = value ?? throw new ArgumentNullException(nameof(value)); - } - - private const string RequestValue = "Request"; - private const string DependencyValue = "Dependency"; - private const string ExceptionValue = "Exception"; - private const string EventValue = "Event"; - private const string MetricValue = "Metric"; - private const string PerformanceCounterValue = "PerformanceCounter"; - private const string TraceValue = "Trace"; - - /// Request. - public static DocumentFilterConjunctionGroupInfoTelemetryType Request { get; } = new DocumentFilterConjunctionGroupInfoTelemetryType(RequestValue); - /// Dependency. - public static DocumentFilterConjunctionGroupInfoTelemetryType Dependency { get; } = new DocumentFilterConjunctionGroupInfoTelemetryType(DependencyValue); - /// Exception. - public static DocumentFilterConjunctionGroupInfoTelemetryType Exception { get; } = new DocumentFilterConjunctionGroupInfoTelemetryType(ExceptionValue); - /// Event. - public static DocumentFilterConjunctionGroupInfoTelemetryType Event { get; } = new DocumentFilterConjunctionGroupInfoTelemetryType(EventValue); - /// Metric. - public static DocumentFilterConjunctionGroupInfoTelemetryType Metric { get; } = new DocumentFilterConjunctionGroupInfoTelemetryType(MetricValue); - /// PerformanceCounter. - public static DocumentFilterConjunctionGroupInfoTelemetryType PerformanceCounter { get; } = new DocumentFilterConjunctionGroupInfoTelemetryType(PerformanceCounterValue); - /// Trace. - public static DocumentFilterConjunctionGroupInfoTelemetryType Trace { get; } = new DocumentFilterConjunctionGroupInfoTelemetryType(TraceValue); - /// Determines if two values are the same. - public static bool operator ==(DocumentFilterConjunctionGroupInfoTelemetryType left, DocumentFilterConjunctionGroupInfoTelemetryType right) => left.Equals(right); - /// Determines if two values are not the same. - public static bool operator !=(DocumentFilterConjunctionGroupInfoTelemetryType left, DocumentFilterConjunctionGroupInfoTelemetryType right) => !left.Equals(right); - /// Converts a string to a . - public static implicit operator DocumentFilterConjunctionGroupInfoTelemetryType(string value) => new DocumentFilterConjunctionGroupInfoTelemetryType(value); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => obj is DocumentFilterConjunctionGroupInfoTelemetryType other && Equals(other); - /// - public bool Equals(DocumentFilterConjunctionGroupInfoTelemetryType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => _value?.GetHashCode() ?? 0; - /// - public override string ToString() => _value; - } -} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentIngress.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentIngress.Serialization.cs index cc77ddd9915a..8d2d0a79bbf4 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentIngress.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentIngress.Serialization.cs @@ -5,15 +5,26 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class DocumentIngress : IUtf8JsonSerializable + [PersistableModelProxy(typeof(UnknownDocumentIngress))] + internal partial class DocumentIngress : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(DocumentIngress)} does not support writing '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("DocumentType"u8); writer.WriteStringValue(DocumentType.ToString()); @@ -33,11 +44,107 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStartArray(); foreach (var item in Properties) { - writer.WriteObjectValue(item); + writer.WriteObjectValue(item, options); } writer.WriteEndArray(); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + + DocumentIngress IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(DocumentIngress)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeDocumentIngress(document.RootElement, options); + } + + internal static DocumentIngress DeserializeDocumentIngress(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("DocumentType", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "Event": return Event.DeserializeEvent(element, options); + case "Exception": return Exception.DeserializeException(element, options); + case "RemoteDependency": return RemoteDependency.DeserializeRemoteDependency(element, options); + case "Request": return Request.DeserializeRequest(element, options); + case "Trace": return Trace.DeserializeTrace(element, options); + } + } + return UnknownDocumentIngress.DeserializeUnknownDocumentIngress(element, options); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(DocumentIngress)} does not support writing '{options.Format}' format."); + } + } + + DocumentIngress IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeDocumentIngress(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(DocumentIngress)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static DocumentIngress FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeDocumentIngress(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; + } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentIngress.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentIngress.cs index e7f2f875b4e8..847603c1adba 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentIngress.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentIngress.cs @@ -5,6 +5,7 @@ #nullable disable +using System; using System.Collections.Generic; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models @@ -16,29 +17,63 @@ namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models /// internal abstract partial class DocumentIngress { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . protected DocumentIngress() { DocumentStreamIds = new ChangeTrackingList(); - Properties = new ChangeTrackingList(); + Properties = new ChangeTrackingList(); } /// Initializes a new instance of . /// Telemetry type. Types not defined in enum will get replaced with a 'Unknown' type. /// An array of document streaming ids. Each id identifies a flow of documents customized by UX customers. /// Collection of custom properties. - internal DocumentIngress(DocumentIngressDocumentType documentType, IList documentStreamIds, IList properties) + /// Keeps track of any properties unknown to the library. + internal DocumentIngress(DocumentType documentType, IList documentStreamIds, IList properties, IDictionary serializedAdditionalRawData) { DocumentType = documentType; DocumentStreamIds = documentStreamIds; Properties = properties; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// Telemetry type. Types not defined in enum will get replaced with a 'Unknown' type. - internal DocumentIngressDocumentType DocumentType { get; set; } + internal DocumentType DocumentType { get; set; } /// An array of document streaming ids. Each id identifies a flow of documents customized by UX customers. public IList DocumentStreamIds { get; } /// Collection of custom properties. - public IList Properties { get; } + public IList Properties { get; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentIngressDocumentType.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentIngressDocumentType.cs deleted file mode 100644 index 04c6c0fc1b05..000000000000 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentIngressDocumentType.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ComponentModel; - -namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models -{ - /// Telemetry type. Types not defined in enum will get replaced with a 'Unknown' type. - public readonly partial struct DocumentIngressDocumentType : IEquatable - { - private readonly string _value; - - /// Initializes a new instance of . - /// is null. - public DocumentIngressDocumentType(string value) - { - _value = value ?? throw new ArgumentNullException(nameof(value)); - } - - private const string RequestValue = "Request"; - private const string RemoteDependencyValue = "RemoteDependency"; - private const string ExceptionValue = "Exception"; - private const string EventValue = "Event"; - private const string TraceValue = "Trace"; - - /// Request. - public static DocumentIngressDocumentType Request { get; } = new DocumentIngressDocumentType(RequestValue); - /// RemoteDependency. - public static DocumentIngressDocumentType RemoteDependency { get; } = new DocumentIngressDocumentType(RemoteDependencyValue); - /// Exception. - public static DocumentIngressDocumentType Exception { get; } = new DocumentIngressDocumentType(ExceptionValue); - /// Event. - public static DocumentIngressDocumentType Event { get; } = new DocumentIngressDocumentType(EventValue); - /// Trace. - public static DocumentIngressDocumentType Trace { get; } = new DocumentIngressDocumentType(TraceValue); - /// Determines if two values are the same. - public static bool operator ==(DocumentIngressDocumentType left, DocumentIngressDocumentType right) => left.Equals(right); - /// Determines if two values are not the same. - public static bool operator !=(DocumentIngressDocumentType left, DocumentIngressDocumentType right) => !left.Equals(right); - /// Converts a string to a . - public static implicit operator DocumentIngressDocumentType(string value) => new DocumentIngressDocumentType(value); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => obj is DocumentIngressDocumentType other && Equals(other); - /// - public bool Equals(DocumentIngressDocumentType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => _value?.GetHashCode() ?? 0; - /// - public override string ToString() => _value; - } -} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentStreamInfo.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentStreamInfo.Serialization.cs index 7c9b97e9ef82..70633fb599c5 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentStreamInfo.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentStreamInfo.Serialization.cs @@ -5,21 +5,78 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class DocumentStreamInfo + public partial class DocumentStreamInfo : IUtf8JsonSerializable, IJsonModel { - internal static DocumentStreamInfo DeserializeDocumentStreamInfo(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(DocumentStreamInfo)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("Id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("DocumentFilterGroups"u8); + writer.WriteStartArray(); + foreach (var item in DocumentFilterGroups) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + DocumentStreamInfo IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(DocumentStreamInfo)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeDocumentStreamInfo(document.RootElement, options); + } + + internal static DocumentStreamInfo DeserializeDocumentStreamInfo(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string id = default; IReadOnlyList documentFilterGroups = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("Id"u8)) @@ -29,20 +86,68 @@ internal static DocumentStreamInfo DeserializeDocumentStreamInfo(JsonElement ele } if (property.NameEquals("DocumentFilterGroups"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(DocumentFilterConjunctionGroupInfo.DeserializeDocumentFilterConjunctionGroupInfo(item)); + array.Add(DocumentFilterConjunctionGroupInfo.DeserializeDocumentFilterConjunctionGroupInfo(item, options)); } documentFilterGroups = array; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new DocumentStreamInfo(id, documentFilterGroups, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(DocumentStreamInfo)} does not support writing '{options.Format}' format."); } - return new DocumentStreamInfo(id, documentFilterGroups ?? new ChangeTrackingList()); + } + + DocumentStreamInfo IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeDocumentStreamInfo(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(DocumentStreamInfo)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static DocumentStreamInfo FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeDocumentStreamInfo(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentStreamInfo.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentStreamInfo.cs index d88e4fe32190..c7b3bfce5d61 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentStreamInfo.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentStreamInfo.cs @@ -5,26 +5,74 @@ #nullable disable +using System; using System.Collections.Generic; +using System.Linq; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { /// Configurations/filters set by UX to scope the document/telemetry it's interested in. - internal partial class DocumentStreamInfo + public partial class DocumentStreamInfo { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . - internal DocumentStreamInfo() + /// Identifier of the document stream initiated by a UX. + /// Gets or sets an OR-connected collection of filter groups. + /// or is null. + internal DocumentStreamInfo(string id, IEnumerable documentFilterGroups) { - DocumentFilterGroups = new ChangeTrackingList(); + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(documentFilterGroups, nameof(documentFilterGroups)); + + Id = id; + DocumentFilterGroups = documentFilterGroups.ToList(); } /// Initializes a new instance of . /// Identifier of the document stream initiated by a UX. /// Gets or sets an OR-connected collection of filter groups. - internal DocumentStreamInfo(string id, IReadOnlyList documentFilterGroups) + /// Keeps track of any properties unknown to the library. + internal DocumentStreamInfo(string id, IReadOnlyList documentFilterGroups, IDictionary serializedAdditionalRawData) { Id = id; DocumentFilterGroups = documentFilterGroups; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal DocumentStreamInfo() + { } /// Identifier of the document stream initiated by a UX. diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentType.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentType.cs new file mode 100644 index 000000000000..f70f29029080 --- /dev/null +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/DocumentType.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models +{ + /// Document type. + internal readonly partial struct DocumentType : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public DocumentType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string RequestValue = "Request"; + private const string RemoteDependencyValue = "RemoteDependency"; + private const string ExceptionValue = "Exception"; + private const string EventValue = "Event"; + private const string TraceValue = "Trace"; + private const string UnknownValue = "Unknown"; + + /// Represents a request telemetry type. + public static DocumentType Request { get; } = new DocumentType(RequestValue); + /// Represents a remote dependency telemetry type. + public static DocumentType RemoteDependency { get; } = new DocumentType(RemoteDependencyValue); + /// Represents an exception telemetry type. + public static DocumentType Exception { get; } = new DocumentType(ExceptionValue); + /// Represents an event telemetry type. + public static DocumentType Event { get; } = new DocumentType(EventValue); + /// Represents a trace telemetry type. + public static DocumentType Trace { get; } = new DocumentType(TraceValue); + /// Represents an unknown telemetry type. + public static DocumentType Unknown { get; } = new DocumentType(UnknownValue); + /// Determines if two values are the same. + public static bool operator ==(DocumentType left, DocumentType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(DocumentType left, DocumentType right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator DocumentType(string value) => new DocumentType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is DocumentType other && Equals(other); + /// + public bool Equals(DocumentType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Event.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Event.Serialization.cs index 8b5d60229296..0ad5ad1c6fd4 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Event.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Event.Serialization.cs @@ -5,15 +5,26 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class Event : IUtf8JsonSerializable + internal partial class Event : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Event)} does not support writing '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(Name)) { @@ -38,11 +49,148 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStartArray(); foreach (var item in Properties) { - writer.WriteObjectValue(item); + writer.WriteObjectValue(item, options); } writer.WriteEndArray(); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + + Event IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Event)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeEvent(document.RootElement, options); + } + + internal static Event DeserializeEvent(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + DocumentType documentType = default; + IList documentStreamIds = default; + IList properties = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("Name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("DocumentType"u8)) + { + documentType = new DocumentType(property.Value.GetString()); + continue; + } + if (property.NameEquals("DocumentStreamIds"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + documentStreamIds = array; + continue; + } + if (property.NameEquals("Properties"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(KeyValuePairStringString.DeserializeKeyValuePairStringString(item, options)); + } + properties = array; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new Event(documentType, documentStreamIds ?? new ChangeTrackingList(), properties ?? new ChangeTrackingList(), serializedAdditionalRawData, name); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(Event)} does not support writing '{options.Format}' format."); + } + } + + Event IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeEvent(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(Event)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new Event FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeEvent(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; + } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Event.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Event.cs index b1805687f938..0bd5c03e286b 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Event.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Event.cs @@ -5,28 +5,29 @@ #nullable disable +using System; using System.Collections.Generic; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - /// Event type document. + /// Event document type. internal partial class Event : DocumentIngress { /// Initializes a new instance of . public Event() { - DocumentType = DocumentIngressDocumentType.Event; + DocumentType = DocumentType.Event; } /// Initializes a new instance of . /// Telemetry type. Types not defined in enum will get replaced with a 'Unknown' type. /// An array of document streaming ids. Each id identifies a flow of documents customized by UX customers. /// Collection of custom properties. + /// Keeps track of any properties unknown to the library. /// Event name. - internal Event(DocumentIngressDocumentType documentType, IList documentStreamIds, IList properties, string name) : base(documentType, documentStreamIds, properties) + internal Event(DocumentType documentType, IList documentStreamIds, IList properties, IDictionary serializedAdditionalRawData, string name) : base(documentType, documentStreamIds, properties, serializedAdditionalRawData) { Name = name; - DocumentType = documentType; } /// Event name. diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Exception.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Exception.Serialization.cs index 388cf5cf5472..93780837bbdc 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Exception.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Exception.Serialization.cs @@ -5,15 +5,26 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class Exception : IUtf8JsonSerializable + internal partial class Exception : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Exception)} does not support writing '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(ExceptionType)) { @@ -43,11 +54,160 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStartArray(); foreach (var item in Properties) { - writer.WriteObjectValue(item); + writer.WriteObjectValue(item, options); } writer.WriteEndArray(); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + + Exception IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Exception)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeException(document.RootElement, options); + } + + internal static Exception DeserializeException(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string exceptionType = default; + string exceptionMessage = default; + DocumentType documentType = default; + IList documentStreamIds = default; + IList properties = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("ExceptionType"u8)) + { + exceptionType = property.Value.GetString(); + continue; + } + if (property.NameEquals("ExceptionMessage"u8)) + { + exceptionMessage = property.Value.GetString(); + continue; + } + if (property.NameEquals("DocumentType"u8)) + { + documentType = new DocumentType(property.Value.GetString()); + continue; + } + if (property.NameEquals("DocumentStreamIds"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + documentStreamIds = array; + continue; + } + if (property.NameEquals("Properties"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(KeyValuePairStringString.DeserializeKeyValuePairStringString(item, options)); + } + properties = array; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new Exception( + documentType, + documentStreamIds ?? new ChangeTrackingList(), + properties ?? new ChangeTrackingList(), + serializedAdditionalRawData, + exceptionType, + exceptionMessage); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(Exception)} does not support writing '{options.Format}' format."); + } + } + + Exception IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeException(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(Exception)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new Exception FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeException(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; + } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Exception.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Exception.cs index 191ad4a00012..97807c3276d9 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Exception.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Exception.cs @@ -5,30 +5,31 @@ #nullable disable +using System; using System.Collections.Generic; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - /// Exception type document. + /// Exception document type. internal partial class Exception : DocumentIngress { /// Initializes a new instance of . public Exception() { - DocumentType = DocumentIngressDocumentType.Exception; + DocumentType = DocumentType.Exception; } /// Initializes a new instance of . /// Telemetry type. Types not defined in enum will get replaced with a 'Unknown' type. /// An array of document streaming ids. Each id identifies a flow of documents customized by UX customers. /// Collection of custom properties. + /// Keeps track of any properties unknown to the library. /// Exception type name. /// Exception message. - internal Exception(DocumentIngressDocumentType documentType, IList documentStreamIds, IList properties, string exceptionType, string exceptionMessage) : base(documentType, documentStreamIds, properties) + internal Exception(DocumentType documentType, IList documentStreamIds, IList properties, IDictionary serializedAdditionalRawData, string exceptionType, string exceptionMessage) : base(documentType, documentStreamIds, properties, serializedAdditionalRawData) { ExceptionType = exceptionType; ExceptionMessage = exceptionMessage; - DocumentType = documentType; } /// Exception type name. diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterConjunctionGroupInfo.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterConjunctionGroupInfo.Serialization.cs index f4994ea610d3..f3ad5df804eb 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterConjunctionGroupInfo.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterConjunctionGroupInfo.Serialization.cs @@ -5,38 +5,141 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class FilterConjunctionGroupInfo + public partial class FilterConjunctionGroupInfo : IUtf8JsonSerializable, IJsonModel { - internal static FilterConjunctionGroupInfo DeserializeFilterConjunctionGroupInfo(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FilterConjunctionGroupInfo)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("Filters"u8); + writer.WriteStartArray(); + foreach (var item in Filters) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + FilterConjunctionGroupInfo IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FilterConjunctionGroupInfo)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeFilterConjunctionGroupInfo(document.RootElement, options); + } + + internal static FilterConjunctionGroupInfo DeserializeFilterConjunctionGroupInfo(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } IReadOnlyList filters = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("Filters"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(FilterInfo.DeserializeFilterInfo(item)); + array.Add(FilterInfo.DeserializeFilterInfo(item, options)); } filters = array; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new FilterConjunctionGroupInfo(filters, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(FilterConjunctionGroupInfo)} does not support writing '{options.Format}' format."); } - return new FilterConjunctionGroupInfo(filters ?? new ChangeTrackingList()); + } + + FilterConjunctionGroupInfo IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeFilterConjunctionGroupInfo(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(FilterConjunctionGroupInfo)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static FilterConjunctionGroupInfo FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeFilterConjunctionGroupInfo(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterConjunctionGroupInfo.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterConjunctionGroupInfo.cs index 080cf0aa8622..89d39c574416 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterConjunctionGroupInfo.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterConjunctionGroupInfo.cs @@ -5,27 +5,72 @@ #nullable disable +using System; using System.Collections.Generic; +using System.Linq; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { /// An AND-connected group of FilterInfo objects. - internal partial class FilterConjunctionGroupInfo + public partial class FilterConjunctionGroupInfo { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . - internal FilterConjunctionGroupInfo() + /// An array of filters. + /// is null. + internal FilterConjunctionGroupInfo(IEnumerable filters) { - Filters = new ChangeTrackingList(); + Argument.AssertNotNull(filters, nameof(filters)); + + Filters = filters.ToList(); } /// Initializes a new instance of . - /// - internal FilterConjunctionGroupInfo(IReadOnlyList filters) + /// An array of filters. + /// Keeps track of any properties unknown to the library. + internal FilterConjunctionGroupInfo(IReadOnlyList filters, IDictionary serializedAdditionalRawData) { Filters = filters; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal FilterConjunctionGroupInfo() + { } - /// Gets the filters. + /// An array of filters. public IReadOnlyList Filters { get; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterInfo.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterInfo.Serialization.cs index 6f135bd4a8de..43640b3a696e 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterInfo.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterInfo.Serialization.cs @@ -5,21 +5,76 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class FilterInfo + internal partial class FilterInfo : IUtf8JsonSerializable, IJsonModel { - internal static FilterInfo DeserializeFilterInfo(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FilterInfo)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("FieldName"u8); + writer.WriteStringValue(FieldName); + writer.WritePropertyName("Predicate"u8); + writer.WriteStringValue(Predicate.ToString()); + writer.WritePropertyName("Comparand"u8); + writer.WriteStringValue(Comparand); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + FilterInfo IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FilterInfo)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeFilterInfo(document.RootElement, options); + } + + internal static FilterInfo DeserializeFilterInfo(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string fieldName = default; - FilterInfoPredicate? predicate = default; + PredicateType predicate = default; string comparand = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("FieldName"u8)) @@ -29,11 +84,7 @@ internal static FilterInfo DeserializeFilterInfo(JsonElement element) } if (property.NameEquals("Predicate"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - predicate = new FilterInfoPredicate(property.Value.GetString()); + predicate = new PredicateType(property.Value.GetString()); continue; } if (property.NameEquals("Comparand"u8)) @@ -41,8 +92,60 @@ internal static FilterInfo DeserializeFilterInfo(JsonElement element) comparand = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new FilterInfo(fieldName, predicate, comparand, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(FilterInfo)} does not support writing '{options.Format}' format."); + } + } + + FilterInfo IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeFilterInfo(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(FilterInfo)} does not support reading '{options.Format}' format."); } - return new FilterInfo(fieldName, predicate, comparand); + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static FilterInfo FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeFilterInfo(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterInfo.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterInfo.cs index 995fb4d5cf55..877bc4542b04 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterInfo.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterInfo.cs @@ -5,32 +5,84 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { /// A filter set on UX. internal partial class FilterInfo { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . - internal FilterInfo() + /// dimension name of the filter. + /// Operator of the filter. + /// Comparand of the filter. + /// or is null. + internal FilterInfo(string fieldName, PredicateType predicate, string comparand) { + Argument.AssertNotNull(fieldName, nameof(fieldName)); + Argument.AssertNotNull(comparand, nameof(comparand)); + + FieldName = fieldName; + Predicate = predicate; + Comparand = comparand; } /// Initializes a new instance of . /// dimension name of the filter. /// Operator of the filter. - /// - internal FilterInfo(string fieldName, FilterInfoPredicate? predicate, string comparand) + /// Comparand of the filter. + /// Keeps track of any properties unknown to the library. + internal FilterInfo(string fieldName, PredicateType predicate, string comparand, IDictionary serializedAdditionalRawData) { FieldName = fieldName; Predicate = predicate; Comparand = comparand; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal FilterInfo() + { } /// dimension name of the filter. public string FieldName { get; } /// Operator of the filter. - public FilterInfoPredicate? Predicate { get; } - /// Gets the comparand. + public PredicateType Predicate { get; } + /// Comparand of the filter. public string Comparand { get; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterInfoPredicate.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterInfoPredicate.cs deleted file mode 100644 index ee08e533204a..000000000000 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/FilterInfoPredicate.cs +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ComponentModel; - -namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models -{ - /// Operator of the filter. - public readonly partial struct FilterInfoPredicate : IEquatable - { - private readonly string _value; - - /// Initializes a new instance of . - /// is null. - public FilterInfoPredicate(string value) - { - _value = value ?? throw new ArgumentNullException(nameof(value)); - } - - private const string EqualValue = "Equal"; - private const string NotEqualValue = "NotEqual"; - private const string LessThanValue = "LessThan"; - private const string GreaterThanValue = "GreaterThan"; - private const string LessThanOrEqualValue = "LessThanOrEqual"; - private const string GreaterThanOrEqualValue = "GreaterThanOrEqual"; - private const string ContainsValue = "Contains"; - private const string DoesNotContainValue = "DoesNotContain"; - - /// Equal. - public static FilterInfoPredicate Equal { get; } = new FilterInfoPredicate(EqualValue); - /// NotEqual. - public static FilterInfoPredicate NotEqual { get; } = new FilterInfoPredicate(NotEqualValue); - /// LessThan. - public static FilterInfoPredicate LessThan { get; } = new FilterInfoPredicate(LessThanValue); - /// GreaterThan. - public static FilterInfoPredicate GreaterThan { get; } = new FilterInfoPredicate(GreaterThanValue); - /// LessThanOrEqual. - public static FilterInfoPredicate LessThanOrEqual { get; } = new FilterInfoPredicate(LessThanOrEqualValue); - /// GreaterThanOrEqual. - public static FilterInfoPredicate GreaterThanOrEqual { get; } = new FilterInfoPredicate(GreaterThanOrEqualValue); - /// Contains. - public static FilterInfoPredicate Contains { get; } = new FilterInfoPredicate(ContainsValue); - /// DoesNotContain. - public static FilterInfoPredicate DoesNotContain { get; } = new FilterInfoPredicate(DoesNotContainValue); - /// Determines if two values are the same. - public static bool operator ==(FilterInfoPredicate left, FilterInfoPredicate right) => left.Equals(right); - /// Determines if two values are not the same. - public static bool operator !=(FilterInfoPredicate left, FilterInfoPredicate right) => !left.Equals(right); - /// Converts a string to a . - public static implicit operator FilterInfoPredicate(string value) => new FilterInfoPredicate(value); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => obj is FilterInfoPredicate other && Equals(other); - /// - public bool Equals(FilterInfoPredicate other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => _value?.GetHashCode() ?? 0; - /// - public override string ToString() => _value; - } -} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/KeyValuePairString.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/KeyValuePairString.Serialization.cs deleted file mode 100644 index e1177642fbf1..000000000000 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/KeyValuePairString.Serialization.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System.Text.Json; -using Azure.Core; - -namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models -{ - internal partial class KeyValuePairString : IUtf8JsonSerializable - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) - { - writer.WriteStartObject(); - if (Optional.IsDefined(Key)) - { - writer.WritePropertyName("key"u8); - writer.WriteStringValue(Key); - } - if (Optional.IsDefined(Value)) - { - writer.WritePropertyName("value"u8); - writer.WriteStringValue(Value); - } - writer.WriteEndObject(); - } - } -} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/KeyValuePairString.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/KeyValuePairString.cs deleted file mode 100644 index 2420ee9e4725..000000000000 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/KeyValuePairString.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models -{ - /// The KeyValuePairString. - internal partial class KeyValuePairString - { - /// Initializes a new instance of . - public KeyValuePairString() - { - } - - /// Initializes a new instance of . - /// - /// - internal KeyValuePairString(string key, string value) - { - Key = key; - Value = value; - } - - /// Gets or sets the key. - public string Key { get; set; } - /// Gets or sets the value. - public string Value { get; set; } - } -} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/KeyValuePairStringString.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/KeyValuePairStringString.Serialization.cs new file mode 100644 index 000000000000..3c1fbb1db5e8 --- /dev/null +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/KeyValuePairStringString.Serialization.cs @@ -0,0 +1,143 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models +{ + internal partial class KeyValuePairStringString : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(KeyValuePairStringString)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("key"u8); + writer.WriteStringValue(Key); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(Value); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + KeyValuePairStringString IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(KeyValuePairStringString)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeKeyValuePairStringString(document.RootElement, options); + } + + internal static KeyValuePairStringString DeserializeKeyValuePairStringString(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string key = default; + string value = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("key"u8)) + { + key = property.Value.GetString(); + continue; + } + if (property.NameEquals("value"u8)) + { + value = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new KeyValuePairStringString(key, value, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(KeyValuePairStringString)} does not support writing '{options.Format}' format."); + } + } + + KeyValuePairStringString IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeKeyValuePairStringString(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(KeyValuePairStringString)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static KeyValuePairStringString FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeKeyValuePairStringString(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; + } + } +} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/KeyValuePairStringString.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/KeyValuePairStringString.cs new file mode 100644 index 000000000000..3b4d55994e4a --- /dev/null +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/KeyValuePairStringString.cs @@ -0,0 +1,82 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models +{ + /// Key-value pair of string and string. + internal partial class KeyValuePairStringString + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// Key of the key-value pair. + /// Value of the key-value pair. + /// or is null. + public KeyValuePairStringString(string key, string value) + { + Argument.AssertNotNull(key, nameof(key)); + Argument.AssertNotNull(value, nameof(value)); + + Key = key; + Value = value; + } + + /// Initializes a new instance of . + /// Key of the key-value pair. + /// Value of the key-value pair. + /// Keeps track of any properties unknown to the library. + internal KeyValuePairStringString(string key, string value, IDictionary serializedAdditionalRawData) + { + Key = key; + Value = value; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal KeyValuePairStringString() + { + } + + /// Key of the key-value pair. + public string Key { get; } + /// Value of the key-value pair. + public string Value { get; } + } +} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/MetricPoint.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/MetricPoint.Serialization.cs index d1c257968f8d..fcaf06f00414 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/MetricPoint.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/MetricPoint.Serialization.cs @@ -5,32 +5,147 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class MetricPoint : IUtf8JsonSerializable + public partial class MetricPoint : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MetricPoint)} does not support writing '{format}' format."); + } + writer.WriteStartObject(); - if (Optional.IsDefined(Name)) + writer.WritePropertyName("Name"u8); + writer.WriteStringValue(Name); + writer.WritePropertyName("Value"u8); + writer.WriteNumberValue(Value); + writer.WritePropertyName("Weight"u8); + writer.WriteNumberValue(Weight); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + MetricPoint IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") { - writer.WritePropertyName("Name"u8); - writer.WriteStringValue(Name); + throw new FormatException($"The model {nameof(MetricPoint)} does not support reading '{format}' format."); } - if (Optional.IsDefined(Value)) + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMetricPoint(document.RootElement, options); + } + + internal static MetricPoint DeserializeMetricPoint(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) { - writer.WritePropertyName("Value"u8); - writer.WriteNumberValue(Value.Value); + return null; } - if (Optional.IsDefined(Weight)) + string name = default; + double value = default; + int weight = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) { - writer.WritePropertyName("Weight"u8); - writer.WriteNumberValue(Weight.Value); + if (property.NameEquals("Name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("Value"u8)) + { + value = property.Value.GetDouble(); + continue; + } + if (property.NameEquals("Weight"u8)) + { + weight = property.Value.GetInt32(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - writer.WriteEndObject(); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new MetricPoint(name, value, weight, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(MetricPoint)} does not support writing '{options.Format}' format."); + } + } + + MetricPoint IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeMetricPoint(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MetricPoint)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static MetricPoint FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeMetricPoint(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/MetricPoint.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/MetricPoint.cs index 524aab1d81e1..1bc925352d27 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/MetricPoint.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/MetricPoint.cs @@ -5,32 +5,83 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { /// Metric data point. - internal partial class MetricPoint + public partial class MetricPoint { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . - public MetricPoint() + /// Metric name. + /// Metric value. + /// Metric weight. + /// is null. + public MetricPoint(string name, double value, int weight) { + Argument.AssertNotNull(name, nameof(name)); + + Name = name; + Value = value; + Weight = weight; } /// Initializes a new instance of . /// Metric name. /// Metric value. /// Metric weight. - internal MetricPoint(string name, float? value, int? weight) + /// Keeps track of any properties unknown to the library. + internal MetricPoint(string name, double value, int weight, IDictionary serializedAdditionalRawData) { Name = name; Value = value; Weight = weight; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal MetricPoint() + { } /// Metric name. - public string Name { get; set; } + public string Name { get; } /// Metric value. - public float? Value { get; set; } + public double Value { get; } /// Metric weight. - public int? Weight { get; set; } + public int Weight { get; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/MonitoringDataPoint.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/MonitoringDataPoint.Serialization.cs index 1291d30eb97a..e20f15ddaddf 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/MonitoringDataPoint.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/MonitoringDataPoint.Serialization.cs @@ -5,46 +5,39 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class MonitoringDataPoint : IUtf8JsonSerializable + public partial class MonitoringDataPoint : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - writer.WriteStartObject(); - if (Optional.IsDefined(Version)) - { - writer.WritePropertyName("Version"u8); - writer.WriteStringValue(Version); - } - if (Optional.IsDefined(InvariantVersion)) - { - writer.WritePropertyName("InvariantVersion"u8); - writer.WriteNumberValue(InvariantVersion.Value); - } - if (Optional.IsDefined(Instance)) - { - writer.WritePropertyName("Instance"u8); - writer.WriteStringValue(Instance); - } - if (Optional.IsDefined(RoleName)) - { - writer.WritePropertyName("RoleName"u8); - writer.WriteStringValue(RoleName); - } - if (Optional.IsDefined(MachineName)) - { - writer.WritePropertyName("MachineName"u8); - writer.WriteStringValue(MachineName); - } - if (Optional.IsDefined(StreamId)) + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") { - writer.WritePropertyName("StreamId"u8); - writer.WriteStringValue(StreamId); + throw new FormatException($"The model {nameof(MonitoringDataPoint)} does not support writing '{format}' format."); } + + writer.WriteStartObject(); + writer.WritePropertyName("Version"u8); + writer.WriteStringValue(Version); + writer.WritePropertyName("InvariantVersion"u8); + writer.WriteNumberValue(InvariantVersion); + writer.WritePropertyName("Instance"u8); + writer.WriteStringValue(Instance); + writer.WritePropertyName("RoleName"u8); + writer.WriteStringValue(RoleName); + writer.WritePropertyName("MachineName"u8); + writer.WriteStringValue(MachineName); + writer.WritePropertyName("StreamId"u8); + writer.WriteStringValue(StreamId); if (Optional.IsDefined(Timestamp)) { writer.WritePropertyName("Timestamp"u8); @@ -55,23 +48,17 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("TransmissionTime"u8); writer.WriteStringValue(TransmissionTime.Value, "O"); } - if (Optional.IsDefined(IsWebApp)) - { - writer.WritePropertyName("IsWebApp"u8); - writer.WriteBooleanValue(IsWebApp.Value); - } - if (Optional.IsDefined(PerformanceCollectionSupported)) - { - writer.WritePropertyName("PerformanceCollectionSupported"u8); - writer.WriteBooleanValue(PerformanceCollectionSupported.Value); - } + writer.WritePropertyName("IsWebApp"u8); + writer.WriteBooleanValue(IsWebApp); + writer.WritePropertyName("PerformanceCollectionSupported"u8); + writer.WriteBooleanValue(PerformanceCollectionSupported); if (Optional.IsCollectionDefined(Metrics)) { writer.WritePropertyName("Metrics"u8); writer.WriteStartArray(); foreach (var item in Metrics) { - writer.WriteObjectValue(item); + writer.WriteObjectValue(item, options); } writer.WriteEndArray(); } @@ -81,7 +68,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStartArray(); foreach (var item in Documents) { - writer.WriteObjectValue(item); + writer.WriteObjectValue(item, options); } writer.WriteEndArray(); } @@ -91,7 +78,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStartArray(); foreach (var item in TopCpuProcesses) { - writer.WriteObjectValue(item); + writer.WriteObjectValue(item, options); } writer.WriteEndArray(); } @@ -101,11 +88,249 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStartArray(); foreach (var item in CollectionConfigurationErrors) { - writer.WriteObjectValue(item); + writer.WriteObjectValue(item, options); } writer.WriteEndArray(); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + + MonitoringDataPoint IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MonitoringDataPoint)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMonitoringDataPoint(document.RootElement, options); + } + + internal static MonitoringDataPoint DeserializeMonitoringDataPoint(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string version = default; + int invariantVersion = default; + string instance = default; + string roleName = default; + string machineName = default; + string streamId = default; + DateTimeOffset? timestamp = default; + DateTimeOffset? transmissionTime = default; + bool isWebApp = default; + bool performanceCollectionSupported = default; + IList metrics = default; + IList documents = default; + IList topCpuProcesses = default; + IList collectionConfigurationErrors = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("Version"u8)) + { + version = property.Value.GetString(); + continue; + } + if (property.NameEquals("InvariantVersion"u8)) + { + invariantVersion = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("Instance"u8)) + { + instance = property.Value.GetString(); + continue; + } + if (property.NameEquals("RoleName"u8)) + { + roleName = property.Value.GetString(); + continue; + } + if (property.NameEquals("MachineName"u8)) + { + machineName = property.Value.GetString(); + continue; + } + if (property.NameEquals("StreamId"u8)) + { + streamId = property.Value.GetString(); + continue; + } + if (property.NameEquals("Timestamp"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + timestamp = property.Value.GetDateTimeOffset("O"); + continue; + } + if (property.NameEquals("TransmissionTime"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + transmissionTime = property.Value.GetDateTimeOffset("O"); + continue; + } + if (property.NameEquals("IsWebApp"u8)) + { + isWebApp = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("PerformanceCollectionSupported"u8)) + { + performanceCollectionSupported = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("Metrics"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(MetricPoint.DeserializeMetricPoint(item, options)); + } + metrics = array; + continue; + } + if (property.NameEquals("Documents"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(DocumentIngress.DeserializeDocumentIngress(item, options)); + } + documents = array; + continue; + } + if (property.NameEquals("TopCpuProcesses"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ProcessCpuData.DeserializeProcessCpuData(item, options)); + } + topCpuProcesses = array; + continue; + } + if (property.NameEquals("CollectionConfigurationErrors"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(CollectionConfigurationError.DeserializeCollectionConfigurationError(item, options)); + } + collectionConfigurationErrors = array; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new MonitoringDataPoint( + version, + invariantVersion, + instance, + roleName, + machineName, + streamId, + timestamp, + transmissionTime, + isWebApp, + performanceCollectionSupported, + metrics ?? new ChangeTrackingList(), + documents ?? new ChangeTrackingList(), + topCpuProcesses ?? new ChangeTrackingList(), + collectionConfigurationErrors ?? new ChangeTrackingList(), + serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(MonitoringDataPoint)} does not support writing '{options.Format}' format."); + } + } + + MonitoringDataPoint IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeMonitoringDataPoint(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MonitoringDataPoint)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static MonitoringDataPoint FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeMonitoringDataPoint(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; + } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/MonitoringDataPoint.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/MonitoringDataPoint.cs index 7c038e264740..0b49c2cdfbfe 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/MonitoringDataPoint.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/MonitoringDataPoint.cs @@ -10,12 +10,67 @@ namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - /// Monitoring data point coming from SDK, which includes metrics, documents and other metadata info. - internal partial class MonitoringDataPoint + /// Monitoring data point coming from the client, which includes metrics, documents and other metadata info. + public partial class MonitoringDataPoint { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . - public MonitoringDataPoint() + /// Application Insights SDK version. + /// Version/generation of the data contract (MonitoringDataPoint) between SDK and Live Metrics. + /// Service instance name where Application Insights SDK lives. + /// Service role name. + /// Computer name where Application Insights SDK lives. + /// Identifies an Application Insights SDK as a trusted agent to report metrics and documents. + /// True if the current application is an Azure Web App. + /// True if performance counters collection is supported. + /// , , , or is null. + public MonitoringDataPoint(string version, int invariantVersion, string instance, string roleName, string machineName, string streamId, bool isWebApp, bool performanceCollectionSupported) { + Argument.AssertNotNull(version, nameof(version)); + Argument.AssertNotNull(instance, nameof(instance)); + Argument.AssertNotNull(roleName, nameof(roleName)); + Argument.AssertNotNull(machineName, nameof(machineName)); + Argument.AssertNotNull(streamId, nameof(streamId)); + + Version = version; + InvariantVersion = invariantVersion; + Instance = instance; + RoleName = roleName; + MachineName = machineName; + StreamId = streamId; + IsWebApp = isWebApp; + PerformanceCollectionSupported = performanceCollectionSupported; Metrics = new ChangeTrackingList(); Documents = new ChangeTrackingList(); TopCpuProcesses = new ChangeTrackingList(); @@ -23,25 +78,26 @@ public MonitoringDataPoint() } /// Initializes a new instance of . - /// AI SDK version. - /// Version/generation of the data contract (MonitoringDataPoint) between SDK and QuickPulse. - /// Service instance name where AI SDK lives. + /// Application Insights SDK version. + /// Version/generation of the data contract (MonitoringDataPoint) between SDK and Live Metrics. + /// Service instance name where Application Insights SDK lives. /// Service role name. - /// Computer name where AI SDK lives. - /// Identifies an AI SDK as a trusted agent to report metrics and documents. + /// Computer name where Application Insights SDK lives. + /// Identifies an Application Insights SDK as a trusted agent to report metrics and documents. /// Data point generation timestamp. - /// Timestamp when SDK transmits the metrics and documents to QuickPulse. A 8-byte long type of ticks. + /// Timestamp when the client transmits the metrics and documents to Live Metrics. /// True if the current application is an Azure Web App. /// True if performance counters collection is supported. - /// An array of meric data points. + /// An array of metric data points. /// /// An array of documents of a specific type {Request}, {RemoteDependency}, {Exception}, {Event}, or {Trace} /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. /// The available derived classes include , , , and . /// /// An array of top cpu consumption data point. - /// An array of error while parsing and applying . - internal MonitoringDataPoint(string version, int? invariantVersion, string instance, string roleName, string machineName, string streamId, DateTimeOffset? timestamp, DateTimeOffset? transmissionTime, bool? isWebApp, bool? performanceCollectionSupported, IList metrics, IList documents, IList topCpuProcesses, IList collectionConfigurationErrors) + /// An array of error while SDK parses and applies the {CollectionConfigurationInfo} provided by Live Metrics. + /// Keeps track of any properties unknown to the library. + internal MonitoringDataPoint(string version, int invariantVersion, string instance, string roleName, string machineName, string streamId, DateTimeOffset? timestamp, DateTimeOffset? transmissionTime, bool isWebApp, bool performanceCollectionSupported, IList metrics, IList documents, IList topCpuProcesses, IList collectionConfigurationErrors, IDictionary serializedAdditionalRawData) { Version = version; InvariantVersion = invariantVersion; @@ -57,29 +113,35 @@ internal MonitoringDataPoint(string version, int? invariantVersion, string insta Documents = documents; TopCpuProcesses = topCpuProcesses; CollectionConfigurationErrors = collectionConfigurationErrors; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal MonitoringDataPoint() + { } - /// AI SDK version. - public string Version { get; set; } - /// Version/generation of the data contract (MonitoringDataPoint) between SDK and QuickPulse. - public int? InvariantVersion { get; set; } - /// Service instance name where AI SDK lives. - public string Instance { get; set; } + /// Application Insights SDK version. + public string Version { get; } + /// Version/generation of the data contract (MonitoringDataPoint) between SDK and Live Metrics. + public int InvariantVersion { get; } + /// Service instance name where Application Insights SDK lives. + public string Instance { get; } /// Service role name. - public string RoleName { get; set; } - /// Computer name where AI SDK lives. - public string MachineName { get; set; } - /// Identifies an AI SDK as a trusted agent to report metrics and documents. - public string StreamId { get; set; } + public string RoleName { get; } + /// Computer name where Application Insights SDK lives. + public string MachineName { get; } + /// Identifies an Application Insights SDK as a trusted agent to report metrics and documents. + public string StreamId { get; } /// Data point generation timestamp. public DateTimeOffset? Timestamp { get; set; } - /// Timestamp when SDK transmits the metrics and documents to QuickPulse. A 8-byte long type of ticks. + /// Timestamp when the client transmits the metrics and documents to Live Metrics. public DateTimeOffset? TransmissionTime { get; set; } /// True if the current application is an Azure Web App. - public bool? IsWebApp { get; set; } + public bool IsWebApp { get; } /// True if performance counters collection is supported. - public bool? PerformanceCollectionSupported { get; set; } - /// An array of meric data points. + public bool PerformanceCollectionSupported { get; } + /// An array of metric data points. public IList Metrics { get; } /// /// An array of documents of a specific type {Request}, {RemoteDependency}, {Exception}, {Event}, or {Trace} @@ -89,7 +151,7 @@ internal MonitoringDataPoint(string version, int? invariantVersion, string insta public IList Documents { get; } /// An array of top cpu consumption data point. public IList TopCpuProcesses { get; } - /// An array of error while parsing and applying . + /// An array of error while SDK parses and applies the {CollectionConfigurationInfo} provided by Live Metrics. public IList CollectionConfigurationErrors { get; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/PredicateType.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/PredicateType.cs new file mode 100644 index 000000000000..f4dea5beed58 --- /dev/null +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/PredicateType.cs @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models +{ + /// Enum representing the different types of predicates. + internal readonly partial struct PredicateType : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public PredicateType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string EqualValue = "Equal"; + private const string NotEqualValue = "NotEqual"; + private const string LessThanValue = "LessThan"; + private const string GreaterThanValue = "GreaterThan"; + private const string LessThanOrEqualValue = "LessThanOrEqual"; + private const string GreaterThanOrEqualValue = "GreaterThanOrEqual"; + private const string ContainsValue = "Contains"; + private const string DoesNotContainValue = "DoesNotContain"; + + /// Represents an equality predicate. + public static PredicateType Equal { get; } = new PredicateType(EqualValue); + /// Represents a not-equal predicate. + public static PredicateType NotEqual { get; } = new PredicateType(NotEqualValue); + /// Represents a less-than predicate. + public static PredicateType LessThan { get; } = new PredicateType(LessThanValue); + /// Represents a greater-than predicate. + public static PredicateType GreaterThan { get; } = new PredicateType(GreaterThanValue); + /// Represents a less-than-or-equal predicate. + public static PredicateType LessThanOrEqual { get; } = new PredicateType(LessThanOrEqualValue); + /// Represents a greater-than-or-equal predicate. + public static PredicateType GreaterThanOrEqual { get; } = new PredicateType(GreaterThanOrEqualValue); + /// Represents a contains predicate. + public static PredicateType Contains { get; } = new PredicateType(ContainsValue); + /// Represents a does-not-contain predicate. + public static PredicateType DoesNotContain { get; } = new PredicateType(DoesNotContainValue); + /// Determines if two values are the same. + public static bool operator ==(PredicateType left, PredicateType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(PredicateType left, PredicateType right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator PredicateType(string value) => new PredicateType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is PredicateType other && Equals(other); + /// + public bool Equals(PredicateType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/ProcessCpuData.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/ProcessCpuData.Serialization.cs index bb6729913131..4988488a35c9 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/ProcessCpuData.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/ProcessCpuData.Serialization.cs @@ -5,27 +5,139 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class ProcessCpuData : IUtf8JsonSerializable + public partial class ProcessCpuData : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - writer.WriteStartObject(); - if (Optional.IsDefined(ProcessName)) + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") { - writer.WritePropertyName("ProcessName"u8); - writer.WriteStringValue(ProcessName); + throw new FormatException($"The model {nameof(ProcessCpuData)} does not support writing '{format}' format."); } - if (Optional.IsDefined(CpuPercentage)) + + writer.WriteStartObject(); + writer.WritePropertyName("ProcessName"u8); + writer.WriteStringValue(ProcessName); + writer.WritePropertyName("CpuPercentage"u8); + writer.WriteNumberValue(CpuPercentage); + if (options.Format != "W" && _serializedAdditionalRawData != null) { - writer.WritePropertyName("CpuPercentage"u8); - writer.WriteNumberValue(CpuPercentage.Value); + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } } writer.WriteEndObject(); } + + ProcessCpuData IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ProcessCpuData)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeProcessCpuData(document.RootElement, options); + } + + internal static ProcessCpuData DeserializeProcessCpuData(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string processName = default; + int cpuPercentage = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("ProcessName"u8)) + { + processName = property.Value.GetString(); + continue; + } + if (property.NameEquals("CpuPercentage"u8)) + { + cpuPercentage = property.Value.GetInt32(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ProcessCpuData(processName, cpuPercentage, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ProcessCpuData)} does not support writing '{options.Format}' format."); + } + } + + ProcessCpuData IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeProcessCpuData(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ProcessCpuData)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ProcessCpuData FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeProcessCpuData(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; + } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/ProcessCpuData.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/ProcessCpuData.cs index c2308b132789..06a1038813d8 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/ProcessCpuData.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/ProcessCpuData.cs @@ -5,28 +5,77 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { /// CPU consumption datapoint. - internal partial class ProcessCpuData + public partial class ProcessCpuData { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . - public ProcessCpuData() + /// Process name. + /// CPU consumption percentage. + /// is null. + public ProcessCpuData(string processName, int cpuPercentage) { + Argument.AssertNotNull(processName, nameof(processName)); + + ProcessName = processName; + CpuPercentage = cpuPercentage; } /// Initializes a new instance of . /// Process name. /// CPU consumption percentage. - internal ProcessCpuData(string processName, int? cpuPercentage) + /// Keeps track of any properties unknown to the library. + internal ProcessCpuData(string processName, int cpuPercentage, IDictionary serializedAdditionalRawData) { ProcessName = processName; CpuPercentage = cpuPercentage; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ProcessCpuData() + { } /// Process name. - public string ProcessName { get; set; } + public string ProcessName { get; } /// CPU consumption percentage. - public int? CpuPercentage { get; set; } + public int CpuPercentage { get; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/QuotaConfigurationInfo.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/QuotaConfigurationInfo.Serialization.cs index 421517a3fe75..83f01ecb8c93 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/QuotaConfigurationInfo.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/QuotaConfigurationInfo.Serialization.cs @@ -5,14 +5,70 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class QuotaConfigurationInfo + public partial class QuotaConfigurationInfo : IUtf8JsonSerializable, IJsonModel { - internal static QuotaConfigurationInfo DeserializeQuotaConfigurationInfo(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(QuotaConfigurationInfo)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (Optional.IsDefined(InitialQuota)) + { + writer.WritePropertyName("InitialQuota"u8); + writer.WriteNumberValue(InitialQuota.Value); + } + writer.WritePropertyName("MaxQuota"u8); + writer.WriteNumberValue(MaxQuota); + writer.WritePropertyName("QuotaAccrualRatePerSec"u8); + writer.WriteNumberValue(QuotaAccrualRatePerSec); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + QuotaConfigurationInfo IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(QuotaConfigurationInfo)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeQuotaConfigurationInfo(document.RootElement, options); + } + + internal static QuotaConfigurationInfo DeserializeQuotaConfigurationInfo(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -20,6 +76,8 @@ internal static QuotaConfigurationInfo DeserializeQuotaConfigurationInfo(JsonEle float? initialQuota = default; float maxQuota = default; float quotaAccrualRatePerSec = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("InitialQuota"u8)) @@ -41,8 +99,60 @@ internal static QuotaConfigurationInfo DeserializeQuotaConfigurationInfo(JsonEle quotaAccrualRatePerSec = property.Value.GetSingle(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new QuotaConfigurationInfo(initialQuota, maxQuota, quotaAccrualRatePerSec, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(QuotaConfigurationInfo)} does not support writing '{options.Format}' format."); + } + } + + QuotaConfigurationInfo IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeQuotaConfigurationInfo(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(QuotaConfigurationInfo)} does not support reading '{options.Format}' format."); } - return new QuotaConfigurationInfo(initialQuota, maxQuota, quotaAccrualRatePerSec); + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static QuotaConfigurationInfo FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeQuotaConfigurationInfo(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/QuotaConfigurationInfo.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/QuotaConfigurationInfo.cs index 369c7e0f3d9c..e463707185bc 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/QuotaConfigurationInfo.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/QuotaConfigurationInfo.cs @@ -5,11 +5,46 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - /// Control document quotas for QuickPulse. - internal partial class QuotaConfigurationInfo + /// Controls document quotas to be sent to Live Metrics. + public partial class QuotaConfigurationInfo { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// Max quota. /// Quota accrual rate per second. @@ -23,11 +58,18 @@ internal QuotaConfigurationInfo(float maxQuota, float quotaAccrualRatePerSec) /// Initial quota. /// Max quota. /// Quota accrual rate per second. - internal QuotaConfigurationInfo(float? initialQuota, float maxQuota, float quotaAccrualRatePerSec) + /// Keeps track of any properties unknown to the library. + internal QuotaConfigurationInfo(float? initialQuota, float maxQuota, float quotaAccrualRatePerSec, IDictionary serializedAdditionalRawData) { InitialQuota = initialQuota; MaxQuota = maxQuota; QuotaAccrualRatePerSec = quotaAccrualRatePerSec; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal QuotaConfigurationInfo() + { } /// Initial quota. diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/RemoteDependency.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/RemoteDependency.Serialization.cs index 24dd3f790845..01ead0138e83 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/RemoteDependency.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/RemoteDependency.Serialization.cs @@ -5,15 +5,26 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class RemoteDependency : IUtf8JsonSerializable + internal partial class RemoteDependency : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RemoteDependency)} does not support writing '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(Name)) { @@ -53,11 +64,174 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStartArray(); foreach (var item in Properties) { - writer.WriteObjectValue(item); + writer.WriteObjectValue(item, options); } writer.WriteEndArray(); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + + RemoteDependency IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RemoteDependency)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRemoteDependency(document.RootElement, options); + } + + internal static RemoteDependency DeserializeRemoteDependency(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + string commandName = default; + string resultCode = default; + string duration = default; + DocumentType documentType = default; + IList documentStreamIds = default; + IList properties = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("Name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("CommandName"u8)) + { + commandName = property.Value.GetString(); + continue; + } + if (property.NameEquals("ResultCode"u8)) + { + resultCode = property.Value.GetString(); + continue; + } + if (property.NameEquals("Duration"u8)) + { + duration = property.Value.GetString(); + continue; + } + if (property.NameEquals("DocumentType"u8)) + { + documentType = new DocumentType(property.Value.GetString()); + continue; + } + if (property.NameEquals("DocumentStreamIds"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + documentStreamIds = array; + continue; + } + if (property.NameEquals("Properties"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(KeyValuePairStringString.DeserializeKeyValuePairStringString(item, options)); + } + properties = array; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new RemoteDependency( + documentType, + documentStreamIds ?? new ChangeTrackingList(), + properties ?? new ChangeTrackingList(), + serializedAdditionalRawData, + name, + commandName, + resultCode, + duration); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RemoteDependency)} does not support writing '{options.Format}' format."); + } + } + + RemoteDependency IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeRemoteDependency(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RemoteDependency)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new RemoteDependency FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeRemoteDependency(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; + } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/RemoteDependency.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/RemoteDependency.cs index 83d35e0403a3..14168c3a1be9 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/RemoteDependency.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/RemoteDependency.cs @@ -5,34 +5,35 @@ #nullable disable +using System; using System.Collections.Generic; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - /// Dependency type document. + /// RemoteDependency document type. internal partial class RemoteDependency : DocumentIngress { /// Initializes a new instance of . public RemoteDependency() { - DocumentType = DocumentIngressDocumentType.RemoteDependency; + DocumentType = DocumentType.RemoteDependency; } /// Initializes a new instance of . /// Telemetry type. Types not defined in enum will get replaced with a 'Unknown' type. /// An array of document streaming ids. Each id identifies a flow of documents customized by UX customers. /// Collection of custom properties. + /// Keeps track of any properties unknown to the library. /// Name of the command initiated with this dependency call, e.g., GET /username. /// URL of the dependency call to the target, with all query string parameters. /// Result code of a dependency call. Examples are SQL error code and HTTP status code. /// Request duration in ISO 8601 duration format, i.e., P[n]Y[n]M[n]DT[n]H[n]M[n]S or P[n]W. - internal RemoteDependency(DocumentIngressDocumentType documentType, IList documentStreamIds, IList properties, string name, string commandName, string resultCode, string duration) : base(documentType, documentStreamIds, properties) + internal RemoteDependency(DocumentType documentType, IList documentStreamIds, IList properties, IDictionary serializedAdditionalRawData, string name, string commandName, string resultCode, string duration) : base(documentType, documentStreamIds, properties, serializedAdditionalRawData) { Name = name; CommandName = commandName; ResultCode = resultCode; Duration = duration; - DocumentType = documentType; } /// Name of the command initiated with this dependency call, e.g., GET /username. diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Request.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Request.Serialization.cs index 4b1462061483..f600387af834 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Request.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Request.Serialization.cs @@ -5,15 +5,26 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class Request : IUtf8JsonSerializable + internal partial class Request : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Request)} does not support writing '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(Name)) { @@ -23,7 +34,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) if (Optional.IsDefined(Url)) { writer.WritePropertyName("Url"u8); - writer.WriteStringValue(Url); + writer.WriteStringValue(Url.AbsoluteUri); } if (Optional.IsDefined(ResponseCode)) { @@ -53,11 +64,178 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStartArray(); foreach (var item in Properties) { - writer.WriteObjectValue(item); + writer.WriteObjectValue(item, options); } writer.WriteEndArray(); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + + Request IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Request)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRequest(document.RootElement, options); + } + + internal static Request DeserializeRequest(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + Uri url = default; + string responseCode = default; + string duration = default; + DocumentType documentType = default; + IList documentStreamIds = default; + IList properties = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("Name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("Url"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + url = new Uri(property.Value.GetString()); + continue; + } + if (property.NameEquals("ResponseCode"u8)) + { + responseCode = property.Value.GetString(); + continue; + } + if (property.NameEquals("Duration"u8)) + { + duration = property.Value.GetString(); + continue; + } + if (property.NameEquals("DocumentType"u8)) + { + documentType = new DocumentType(property.Value.GetString()); + continue; + } + if (property.NameEquals("DocumentStreamIds"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + documentStreamIds = array; + continue; + } + if (property.NameEquals("Properties"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(KeyValuePairStringString.DeserializeKeyValuePairStringString(item, options)); + } + properties = array; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new Request( + documentType, + documentStreamIds ?? new ChangeTrackingList(), + properties ?? new ChangeTrackingList(), + serializedAdditionalRawData, + name, + url, + responseCode, + duration); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(Request)} does not support writing '{options.Format}' format."); + } + } + + Request IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(Request)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new Request FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeRequest(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; + } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Request.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Request.cs index 06492f7ba20a..2be9c6ce0bd8 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Request.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Request.cs @@ -5,41 +5,42 @@ #nullable disable +using System; using System.Collections.Generic; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - /// Request type document. + /// Request document type. internal partial class Request : DocumentIngress { /// Initializes a new instance of . public Request() { - DocumentType = DocumentIngressDocumentType.Request; + DocumentType = DocumentType.Request; } /// Initializes a new instance of . /// Telemetry type. Types not defined in enum will get replaced with a 'Unknown' type. /// An array of document streaming ids. Each id identifies a flow of documents customized by UX customers. /// Collection of custom properties. + /// Keeps track of any properties unknown to the library. /// Name of the request, e.g., 'GET /values/{id}'. /// Request URL with all query string parameters. - /// Result of a request execution. For http requestss, it could be some HTTP status code. + /// Result of a request execution. For http requests, it could be some HTTP status code. /// Request duration in ISO 8601 duration format, i.e., P[n]Y[n]M[n]DT[n]H[n]M[n]S or P[n]W. - internal Request(DocumentIngressDocumentType documentType, IList documentStreamIds, IList properties, string name, string url, string responseCode, string duration) : base(documentType, documentStreamIds, properties) + internal Request(DocumentType documentType, IList documentStreamIds, IList properties, IDictionary serializedAdditionalRawData, string name, Uri url, string responseCode, string duration) : base(documentType, documentStreamIds, properties, serializedAdditionalRawData) { Name = name; Url = url; ResponseCode = responseCode; Duration = duration; - DocumentType = documentType; } /// Name of the request, e.g., 'GET /values/{id}'. public string Name { get; set; } /// Request URL with all query string parameters. - public string Url { get; set; } - /// Result of a request execution. For http requestss, it could be some HTTP status code. + public Uri Url { get; set; } + /// Result of a request execution. For http requests, it could be some HTTP status code. public string ResponseCode { get; set; } /// Request duration in ISO 8601 duration format, i.e., P[n]Y[n]M[n]DT[n]H[n]M[n]S or P[n]W. public string Duration { get; set; } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/ServiceError.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/ServiceError.Serialization.cs index 8243046f2a58..a39f7b21a8f0 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/ServiceError.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/ServiceError.Serialization.cs @@ -6,23 +6,81 @@ #nullable disable using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class ServiceError + internal partial class ServiceError : IUtf8JsonSerializable, IJsonModel { - internal static ServiceError DeserializeServiceError(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ServiceError)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("RequestId"u8); + writer.WriteStringValue(RequestId); + writer.WritePropertyName("ResponseDateTime"u8); + writer.WriteStringValue(ResponseDateTime); + writer.WritePropertyName("Code"u8); + writer.WriteStringValue(Code); + writer.WritePropertyName("Message"u8); + writer.WriteStringValue(Message); + writer.WritePropertyName("Exception"u8); + writer.WriteStringValue(Exception); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ServiceError IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ServiceError)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeServiceError(document.RootElement, options); + } + + internal static ServiceError DeserializeServiceError(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string requestId = default; - DateTimeOffset? responseDateTime = default; + string responseDateTime = default; string code = default; string message = default; string exception = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("RequestId"u8)) @@ -32,11 +90,7 @@ internal static ServiceError DeserializeServiceError(JsonElement element) } if (property.NameEquals("ResponseDateTime"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - responseDateTime = property.Value.GetDateTimeOffset("O"); + responseDateTime = property.Value.GetString(); continue; } if (property.NameEquals("Code"u8)) @@ -54,8 +108,66 @@ internal static ServiceError DeserializeServiceError(JsonElement element) exception = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ServiceError( + requestId, + responseDateTime, + code, + message, + exception, + serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ServiceError)} does not support writing '{options.Format}' format."); + } + } + + ServiceError IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeServiceError(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ServiceError)} does not support reading '{options.Format}' format."); } - return new ServiceError(requestId, responseDateTime, code, message, exception); + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ServiceError FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeServiceError(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/ServiceError.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/ServiceError.cs index f14f65af6ebb..af2ee2bee4fe 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/ServiceError.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/ServiceError.cs @@ -6,36 +6,93 @@ #nullable disable using System; +using System.Collections.Generic; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - /// Optional http response body, whose existance carries additional error descriptions. + /// Optional http response body, whose existence carries additional error descriptions. internal partial class ServiceError { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . - internal ServiceError() + /// A globally unique identifier to identify the diagnostic context. It defaults to the empty GUID. + /// Service error response date time. + /// Error code. + /// Error message. + /// Message of the exception that triggers the error response. + /// , , , or is null. + internal ServiceError(string requestId, string responseDateTime, string code, string message, string exception) { + Argument.AssertNotNull(requestId, nameof(requestId)); + Argument.AssertNotNull(responseDateTime, nameof(responseDateTime)); + Argument.AssertNotNull(code, nameof(code)); + Argument.AssertNotNull(message, nameof(message)); + Argument.AssertNotNull(exception, nameof(exception)); + + RequestId = requestId; + ResponseDateTime = responseDateTime; + Code = code; + Message = message; + Exception = exception; } /// Initializes a new instance of . - /// A guid of the request that triggers the service error. + /// A globally unique identifier to identify the diagnostic context. It defaults to the empty GUID. /// Service error response date time. /// Error code. /// Error message. /// Message of the exception that triggers the error response. - internal ServiceError(string requestId, DateTimeOffset? responseDateTime, string code, string message, string exception) + /// Keeps track of any properties unknown to the library. + internal ServiceError(string requestId, string responseDateTime, string code, string message, string exception, IDictionary serializedAdditionalRawData) { RequestId = requestId; ResponseDateTime = responseDateTime; Code = code; Message = message; Exception = exception; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ServiceError() + { } - /// A guid of the request that triggers the service error. + /// A globally unique identifier to identify the diagnostic context. It defaults to the empty GUID. public string RequestId { get; } /// Service error response date time. - public DateTimeOffset? ResponseDateTime { get; } + public string ResponseDateTime { get; } /// Error code. public string Code { get; } /// Error message. diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/TelemetryType.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/TelemetryType.cs new file mode 100644 index 000000000000..4673602da0be --- /dev/null +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/TelemetryType.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models +{ + /// Telemetry type. + public readonly partial struct TelemetryType : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public TelemetryType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string RequestValue = "Request"; + private const string DependencyValue = "Dependency"; + private const string ExceptionValue = "Exception"; + private const string EventValue = "Event"; + private const string MetricValue = "Metric"; + private const string PerformanceCounterValue = "PerformanceCounter"; + private const string TraceValue = "Trace"; + + /// Represents a request telemetry type. + public static TelemetryType Request { get; } = new TelemetryType(RequestValue); + /// Represents a dependency telemetry type. + public static TelemetryType Dependency { get; } = new TelemetryType(DependencyValue); + /// Represents an exception telemetry type. + public static TelemetryType Exception { get; } = new TelemetryType(ExceptionValue); + /// Represents an event telemetry type. + public static TelemetryType Event { get; } = new TelemetryType(EventValue); + /// Represents a metric telemetry type. + public static TelemetryType Metric { get; } = new TelemetryType(MetricValue); + /// Represents a performance counter telemetry type. + public static TelemetryType PerformanceCounter { get; } = new TelemetryType(PerformanceCounterValue); + /// Represents a trace telemetry type. + public static TelemetryType Trace { get; } = new TelemetryType(TraceValue); + /// Determines if two values are the same. + public static bool operator ==(TelemetryType left, TelemetryType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(TelemetryType left, TelemetryType right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator TelemetryType(string value) => new TelemetryType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is TelemetryType other && Equals(other); + /// + public bool Equals(TelemetryType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Trace.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Trace.Serialization.cs index 0b73c46cbebd..34e96300d76e 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Trace.Serialization.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Trace.Serialization.cs @@ -5,15 +5,26 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure.Core; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - internal partial class Trace : IUtf8JsonSerializable + internal partial class Trace : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Trace)} does not support writing '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(Message)) { @@ -38,11 +49,148 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStartArray(); foreach (var item in Properties) { - writer.WriteObjectValue(item); + writer.WriteObjectValue(item, options); } writer.WriteEndArray(); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + + Trace IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Trace)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeTrace(document.RootElement, options); + } + + internal static Trace DeserializeTrace(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string message = default; + DocumentType documentType = default; + IList documentStreamIds = default; + IList properties = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("Message"u8)) + { + message = property.Value.GetString(); + continue; + } + if (property.NameEquals("DocumentType"u8)) + { + documentType = new DocumentType(property.Value.GetString()); + continue; + } + if (property.NameEquals("DocumentStreamIds"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + documentStreamIds = array; + continue; + } + if (property.NameEquals("Properties"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(KeyValuePairStringString.DeserializeKeyValuePairStringString(item, options)); + } + properties = array; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new Trace(documentType, documentStreamIds ?? new ChangeTrackingList(), properties ?? new ChangeTrackingList(), serializedAdditionalRawData, message); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(Trace)} does not support writing '{options.Format}' format."); + } + } + + Trace IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeTrace(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(Trace)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new Trace FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeTrace(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; + } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Trace.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Trace.cs index 045a3401809f..a874c1b04efe 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Trace.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/Trace.cs @@ -5,28 +5,29 @@ #nullable disable +using System; using System.Collections.Generic; namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models { - /// Trace type name. + /// Trace document type. internal partial class Trace : DocumentIngress { /// Initializes a new instance of . public Trace() { - DocumentType = DocumentIngressDocumentType.Trace; + DocumentType = DocumentType.Trace; } /// Initializes a new instance of . /// Telemetry type. Types not defined in enum will get replaced with a 'Unknown' type. /// An array of document streaming ids. Each id identifies a flow of documents customized by UX customers. /// Collection of custom properties. + /// Keeps track of any properties unknown to the library. /// Trace message. - internal Trace(DocumentIngressDocumentType documentType, IList documentStreamIds, IList properties, string message) : base(documentType, documentStreamIds, properties) + internal Trace(DocumentType documentType, IList documentStreamIds, IList properties, IDictionary serializedAdditionalRawData, string message) : base(documentType, documentStreamIds, properties, serializedAdditionalRawData) { Message = message; - DocumentType = documentType; } /// Trace message. diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/UnknownDocumentIngress.Serialization.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/UnknownDocumentIngress.Serialization.cs new file mode 100644 index 000000000000..b3a34a746b9d --- /dev/null +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/UnknownDocumentIngress.Serialization.cs @@ -0,0 +1,185 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models +{ + internal partial class UnknownDocumentIngress : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(DocumentIngress)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("DocumentType"u8); + writer.WriteStringValue(DocumentType.ToString()); + if (Optional.IsCollectionDefined(DocumentStreamIds)) + { + writer.WritePropertyName("DocumentStreamIds"u8); + writer.WriteStartArray(); + foreach (var item in DocumentStreamIds) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(Properties)) + { + writer.WritePropertyName("Properties"u8); + writer.WriteStartArray(); + foreach (var item in Properties) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + DocumentIngress IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(DocumentIngress)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeDocumentIngress(document.RootElement, options); + } + + internal static UnknownDocumentIngress DeserializeUnknownDocumentIngress(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + DocumentType documentType = "AutoRest.CSharp.Output.Models.Types.EnumTypeValue"; + IList documentStreamIds = default; + IList properties = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("DocumentType"u8)) + { + documentType = new DocumentType(property.Value.GetString()); + continue; + } + if (property.NameEquals("DocumentStreamIds"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + documentStreamIds = array; + continue; + } + if (property.NameEquals("Properties"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(KeyValuePairStringString.DeserializeKeyValuePairStringString(item, options)); + } + properties = array; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownDocumentIngress(documentType, documentStreamIds ?? new ChangeTrackingList(), properties ?? new ChangeTrackingList(), serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(DocumentIngress)} does not support writing '{options.Format}' format."); + } + } + + DocumentIngress IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeDocumentIngress(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(DocumentIngress)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownDocumentIngress FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownDocumentIngress(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, new ModelReaderWriterOptions("W")); + return content; + } + } +} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/UnknownDocumentIngress.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/UnknownDocumentIngress.cs new file mode 100644 index 000000000000..aee517bc3906 --- /dev/null +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/Models/UnknownDocumentIngress.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models +{ + /// Unknown version of DocumentIngress. + internal partial class UnknownDocumentIngress : DocumentIngress + { + /// Initializes a new instance of . + /// Telemetry type. Types not defined in enum will get replaced with a 'Unknown' type. + /// An array of document streaming ids. Each id identifies a flow of documents customized by UX customers. + /// Collection of custom properties. + /// Keeps track of any properties unknown to the library. + internal UnknownDocumentIngress(DocumentType documentType, IList documentStreamIds, IList properties, IDictionary serializedAdditionalRawData) : base(documentType, documentStreamIds, properties, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownDocumentIngress() + { + } + } +} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/MonitorOpenTelemetryLiveMetricsClientBuilderExtensions.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/MonitorOpenTelemetryLiveMetricsClientBuilderExtensions.cs new file mode 100644 index 000000000000..a1fc036d39e3 --- /dev/null +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/MonitorOpenTelemetryLiveMetricsClientBuilderExtensions.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core.Extensions; +using Azure.Monitor.OpenTelemetry.LiveMetrics; + +namespace Microsoft.Extensions.Azure +{ + /// Extension methods to add to client builder. + public static partial class MonitorOpenTelemetryLiveMetricsClientBuilderExtensions + { + /// Registers a instance. + /// The builder to register with. + /// The endpoint of the Live Metrics service. + public static IAzureClientBuilder AddLiveMetricsClient(this TBuilder builder, Uri endpoint) + where TBuilder : IAzureClientFactoryBuilderWithCredential + { + return builder.RegisterClientFactory((options, cred) => new LiveMetricsClient(endpoint, cred, options)); + } + + /// Registers a instance. + /// The builder to register with. + /// The configuration values. + public static IAzureClientBuilder AddLiveMetricsClient(this TBuilder builder, TConfiguration configuration) + where TBuilder : IAzureClientFactoryBuilderWithConfiguration + { + return builder.RegisterClientFactory(configuration); + } + } +} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/MonitorOpenTelemetryLiveMetricsModelFactory.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/MonitorOpenTelemetryLiveMetricsModelFactory.cs new file mode 100644 index 000000000000..7b97adf13c05 --- /dev/null +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/MonitorOpenTelemetryLiveMetricsModelFactory.cs @@ -0,0 +1,82 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Linq; + +namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Models +{ + /// Model factory for models. + public static partial class MonitorOpenTelemetryLiveMetricsModelFactory + { + /// Initializes a new instance of . + /// An encoded string that indicates whether the collection configuration is changed. + /// An array of metric configuration info. + /// An array of document stream configuration info. + /// Controls document quotas to be sent to Live Metrics. + /// A new instance for mocking. + public static CollectionConfigurationInfo CollectionConfigurationInfo(string eTag = null, IEnumerable metrics = null, IEnumerable documentStreams = null, QuotaConfigurationInfo quotaInfo = null) + { + metrics ??= new List(); + documentStreams ??= new List(); + + return new CollectionConfigurationInfo(eTag, metrics?.ToList(), documentStreams?.ToList(), quotaInfo, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// metric configuration identifier. + /// Telemetry type. + /// A collection of filters to scope metrics that UX needs. + /// Telemetry's metric dimension whose value is to be aggregated. Example values: Duration, Count(),... + /// Aggregation type. This is the aggregation done from everything within a single server. + /// Aggregation type. This Aggregation is done across the values for all the servers taken together. + /// A new instance for mocking. + public static DerivedMetricInfo DerivedMetricInfo(string id = null, string telemetryType = null, IEnumerable filterGroups = null, string projection = null, AggregationType aggregation = default, AggregationType backEndAggregation = default) + { + filterGroups ??= new List(); + + return new DerivedMetricInfo( + id, + telemetryType, + filterGroups?.ToList(), + projection, + aggregation, + backEndAggregation, + serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// Identifier of the document stream initiated by a UX. + /// Gets or sets an OR-connected collection of filter groups. + /// A new instance for mocking. + public static DocumentStreamInfo DocumentStreamInfo(string id = null, IEnumerable documentFilterGroups = null) + { + documentFilterGroups ??= new List(); + + return new DocumentStreamInfo(id, documentFilterGroups?.ToList(), serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// Telemetry type. + /// An array of filter groups. + /// A new instance for mocking. + public static DocumentFilterConjunctionGroupInfo DocumentFilterConjunctionGroupInfo(TelemetryType telemetryType = default, FilterConjunctionGroupInfo filters = null) + { + return new DocumentFilterConjunctionGroupInfo(telemetryType, filters, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// Initial quota. + /// Max quota. + /// Quota accrual rate per second. + /// A new instance for mocking. + public static QuotaConfigurationInfo QuotaConfigurationInfo(float? initialQuota = null, float maxQuota = default, float quotaAccrualRatePerSec = default) + { + return new QuotaConfigurationInfo(initialQuota, maxQuota, quotaAccrualRatePerSec, serializedAdditionalRawData: null); + } + } +} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/QuickPulseSDKClientAPIsPingHeaders.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/QuickPulseSDKClientAPIsPingHeaders.cs deleted file mode 100644 index 8931e3fb4264..000000000000 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/QuickPulseSDKClientAPIsPingHeaders.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using Azure.Core; - -namespace Azure.Monitor.OpenTelemetry.LiveMetrics -{ - internal partial class QuickPulseSDKClientAPIsPingHeaders - { - private readonly Response _response; - public QuickPulseSDKClientAPIsPingHeaders(Response response) - { - _response = response; - } - /// A boolean flag indicating whether there are active user sessions 'watching' the SDK's ikey. If true, SDK must start collecting data and post'ing it to QuickPulse. Otherwise, SDK must keep ping'ing. - public string XMsQpsSubscribed => _response.Headers.TryGetValue("x-ms-qps-subscribed", out string value) ? value : null; - /// An encoded string that indicates whether the collection configuration is changed. - public string XMsQpsConfigurationEtag => _response.Headers.TryGetValue("x-ms-qps-configuration-etag", out string value) ? value : null; - /// Recommended time (in milliseconds) before an SDK should ping the service again. This header exists only when ikey is not watched by UX. - public int? XMsQpsServicePollingIntervalHint => _response.Headers.TryGetValue("x-ms-qps-service-polling-interval-hint", out int? value) ? value : null; - /// Contains a URI of the service endpoint that an SDK must permanently use for the particular resource. This header exists only when SDK is talking to QuickPulse's global endpoint. - public string XMsQpsServiceEndpointRedirectV2 => _response.Headers.TryGetValue("x-ms-qps-service-endpoint-redirect-v2", out string value) ? value : null; - } -} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/QuickPulseSDKClientAPIsPostHeaders.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/QuickPulseSDKClientAPIsPostHeaders.cs deleted file mode 100644 index a77db18f6432..000000000000 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/QuickPulseSDKClientAPIsPostHeaders.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using Azure.Core; - -namespace Azure.Monitor.OpenTelemetry.LiveMetrics -{ - internal partial class QuickPulseSDKClientAPIsPostHeaders - { - private readonly Response _response; - public QuickPulseSDKClientAPIsPostHeaders(Response response) - { - _response = response; - } - /// Tells SDK whether the input ikey is subscribed to by UX. - public string XMsQpsSubscribed => _response.Headers.TryGetValue("x-ms-qps-subscribed", out string value) ? value : null; - /// An encoded string that indicates whether the collection configuration is changed. - public string XMsQpsConfigurationEtag => _response.Headers.TryGetValue("x-ms-qps-configuration-etag", out string value) ? value : null; - /// A 8-byte long type of milliseconds QuickPulse suggests SDK polling period. - public int? XMsQpsServicePollingIntervalHint => _response.Headers.TryGetValue("x-ms-qps-service-polling-interval-hint", out int? value) ? value : null; - /// All official SDKs now uses v2 header. Use v2 instead. - public string XMsQpsServiceEndpointRedirect => _response.Headers.TryGetValue("x-ms-qps-service-endpoint-redirect", out string value) ? value : null; - /// URI of the service endpoint that an SDK must permanently use for the particular resource. - public string XMsQpsServiceEndpointRedirectV2 => _response.Headers.TryGetValue("x-ms-qps-service-endpoint-redirect-v2", out string value) ? value : null; - } -} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/QuickPulseSDKClientAPIsRestClient.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/QuickPulseSDKClientAPIsRestClient.cs deleted file mode 100644 index bebc10cf21c9..000000000000 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/Generated/QuickPulseSDKClientAPIsRestClient.cs +++ /dev/null @@ -1,316 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; -using System.Text.Json; -using System.Threading; -using System.Threading.Tasks; -using Azure.Core; -using Azure.Core.Pipeline; -using Azure.Monitor.OpenTelemetry.LiveMetrics.Models; - -namespace Azure.Monitor.OpenTelemetry.LiveMetrics -{ - internal partial class QuickPulseSDKClientAPIsRestClient - { - private readonly HttpPipeline _pipeline; - private readonly string _host; - - /// The ClientDiagnostics is used to provide tracing support for the client library. - internal ClientDiagnostics ClientDiagnostics { get; } - - /// Initializes a new instance of QuickPulseSDKClientAPIsRestClient. - /// The handler for diagnostic messaging in the client. - /// The HTTP pipeline for sending and receiving REST requests and responses. - /// QuickPulse endpoint: https://rt.services.visualstudio.com. The default value is "https://rt.services.visualstudio.com". - /// , or is null. - public QuickPulseSDKClientAPIsRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host) - { - ClientDiagnostics = clientDiagnostics ?? throw new ArgumentNullException(nameof(clientDiagnostics)); - _pipeline = pipeline ?? throw new ArgumentNullException(nameof(pipeline)); - _host = host ?? throw new ArgumentNullException(nameof(host)); - } - - internal HttpMessage CreatePingRequest(string ikey, string apikey, int? xMsQpsTransmissionTime, string xMsQpsMachineName, string xMsQpsInstanceName, string xMsQpsStreamId, string xMsQpsRoleName, string xMsQpsInvariantVersion, string xMsQpsConfigurationEtag, MonitoringDataPoint monitoringDataPoint) - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_host, false); - uri.AppendPath("/QuickPulseService.svc/ping", false); - uri.AppendQuery("ikey", ikey, true); - if (apikey != null) - { - uri.AppendQuery("apikey", apikey, true); - } - request.Uri = uri; - if (xMsQpsTransmissionTime != null) - { - request.Headers.Add("x-ms-qps-transmission-time", xMsQpsTransmissionTime.Value); - } - if (xMsQpsMachineName != null) - { - request.Headers.Add("x-ms-qps-machine-name", xMsQpsMachineName); - } - if (xMsQpsInstanceName != null) - { - request.Headers.Add("x-ms-qps-instance-name", xMsQpsInstanceName); - } - if (xMsQpsStreamId != null) - { - request.Headers.Add("x-ms-qps-stream-id", xMsQpsStreamId); - } - if (xMsQpsRoleName != null) - { - request.Headers.Add("x-ms-qps-role-name", xMsQpsRoleName); - } - if (xMsQpsInvariantVersion != null) - { - request.Headers.Add("x-ms-qps-invariant-version", xMsQpsInvariantVersion); - } - if (xMsQpsConfigurationEtag != null) - { - request.Headers.Add("x-ms-qps-configuration-etag", xMsQpsConfigurationEtag); - } - request.Headers.Add("Accept", "application/json"); - if (monitoringDataPoint != null) - { - request.Headers.Add("Content-Type", "application/json"); - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(monitoringDataPoint); - request.Content = content; - } - return message; - } - - /// SDK ping. - /// The ikey of the target Application Insights component that displays server info sent by /QuickPulseService.svc/ping. - /// Deprecated. An alternative way to pass api key. Use AAD auth instead. - /// Timestamp when SDK transmits the metrics and documents to QuickPulse. A 8-byte long type of ticks. - /// Computer name where AI SDK lives. QuickPulse uses machine name with instance name as a backup. - /// Service instance name where AI SDK lives. QuickPulse uses machine name with instance name as a backup. - /// Identifies an AI SDK as trusted agent to report metrics and documents. - /// Cloud role name for which SDK reports metrics and documents. - /// Version/generation of the data contract (MonitoringDataPoint) between SDK and QuickPulse. - /// An encoded string that indicates whether the collection configuration is changed. - /// Data contract between SDK and QuickPulse. /QuickPulseService.svc/ping uses this as a backup source of machine name, instance name and invariant version. - /// The cancellation token to use. - /// is null. - public async Task> PingAsync(string ikey, string apikey = null, int? xMsQpsTransmissionTime = null, string xMsQpsMachineName = null, string xMsQpsInstanceName = null, string xMsQpsStreamId = null, string xMsQpsRoleName = null, string xMsQpsInvariantVersion = null, string xMsQpsConfigurationEtag = null, MonitoringDataPoint monitoringDataPoint = null, CancellationToken cancellationToken = default) - { - if (ikey == null) - { - throw new ArgumentNullException(nameof(ikey)); - } - - using var message = CreatePingRequest(ikey, apikey, xMsQpsTransmissionTime, xMsQpsMachineName, xMsQpsInstanceName, xMsQpsStreamId, xMsQpsRoleName, xMsQpsInvariantVersion, xMsQpsConfigurationEtag, monitoringDataPoint); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - var headers = new QuickPulseSDKClientAPIsPingHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - CollectionConfigurationInfo value = default; - using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - value = CollectionConfigurationInfo.DeserializeCollectionConfigurationInfo(document.RootElement); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - case 400: - case 401: - case 403: - case 404: - case 500: - case 503: - { - ServiceError value = default; - using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - value = ServiceError.DeserializeServiceError(document.RootElement); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - default: - throw new RequestFailedException(message.Response); - } - } - - /// SDK ping. - /// The ikey of the target Application Insights component that displays server info sent by /QuickPulseService.svc/ping. - /// Deprecated. An alternative way to pass api key. Use AAD auth instead. - /// Timestamp when SDK transmits the metrics and documents to QuickPulse. A 8-byte long type of ticks. - /// Computer name where AI SDK lives. QuickPulse uses machine name with instance name as a backup. - /// Service instance name where AI SDK lives. QuickPulse uses machine name with instance name as a backup. - /// Identifies an AI SDK as trusted agent to report metrics and documents. - /// Cloud role name for which SDK reports metrics and documents. - /// Version/generation of the data contract (MonitoringDataPoint) between SDK and QuickPulse. - /// An encoded string that indicates whether the collection configuration is changed. - /// Data contract between SDK and QuickPulse. /QuickPulseService.svc/ping uses this as a backup source of machine name, instance name and invariant version. - /// The cancellation token to use. - /// is null. - public ResponseWithHeaders Ping(string ikey, string apikey = null, int? xMsQpsTransmissionTime = null, string xMsQpsMachineName = null, string xMsQpsInstanceName = null, string xMsQpsStreamId = null, string xMsQpsRoleName = null, string xMsQpsInvariantVersion = null, string xMsQpsConfigurationEtag = null, MonitoringDataPoint monitoringDataPoint = null, CancellationToken cancellationToken = default) - { - if (ikey == null) - { - throw new ArgumentNullException(nameof(ikey)); - } - - using var message = CreatePingRequest(ikey, apikey, xMsQpsTransmissionTime, xMsQpsMachineName, xMsQpsInstanceName, xMsQpsStreamId, xMsQpsRoleName, xMsQpsInvariantVersion, xMsQpsConfigurationEtag, monitoringDataPoint); - _pipeline.Send(message, cancellationToken); - var headers = new QuickPulseSDKClientAPIsPingHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - CollectionConfigurationInfo value = default; - using var document = JsonDocument.Parse(message.Response.ContentStream); - value = CollectionConfigurationInfo.DeserializeCollectionConfigurationInfo(document.RootElement); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - case 400: - case 401: - case 403: - case 404: - case 500: - case 503: - { - ServiceError value = default; - using var document = JsonDocument.Parse(message.Response.ContentStream); - value = ServiceError.DeserializeServiceError(document.RootElement); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - default: - throw new RequestFailedException(message.Response); - } - } - - internal HttpMessage CreatePostRequest(string ikey, string apikey, string xMsQpsConfigurationEtag, int? xMsQpsTransmissionTime, IEnumerable monitoringDataPoints) - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_host, false); - uri.AppendPath("/QuickPulseService.svc/post", false); - uri.AppendQuery("ikey", ikey, true); - if (apikey != null) - { - uri.AppendQuery("apikey", apikey, true); - } - request.Uri = uri; - if (xMsQpsConfigurationEtag != null) - { - request.Headers.Add("x-ms-qps-configuration-etag", xMsQpsConfigurationEtag); - } - if (xMsQpsTransmissionTime != null) - { - request.Headers.Add("x-ms-qps-transmission-time", xMsQpsTransmissionTime.Value); - } - request.Headers.Add("Accept", "application/json"); - if (monitoringDataPoints != null) - { - request.Headers.Add("Content-Type", "application/json"); - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteStartArray(); - foreach (var item in monitoringDataPoints) - { - content.JsonWriter.WriteObjectValue(item); - } - content.JsonWriter.WriteEndArray(); - request.Content = content; - } - return message; - } - - /// SDK post. - /// The ikey of the target Application Insights component that displays metrics and documents sent by /QuickPulseService.svc/post. - /// An alternative way to pass api key. Deprecated. Use AAD authentication instead. - /// An encoded string that indicates whether the collection configuration is changed. - /// Timestamp when SDK transmits the metrics and documents to QuickPulse. A 8-byte long type of ticks. - /// Data contract between SDK and QuickPulse. /QuickPulseService.svc/post uses this to publish metrics and documents to the backend QuickPulse server. - /// The cancellation token to use. - /// is null. - public async Task> PostAsync(string ikey, string apikey = null, string xMsQpsConfigurationEtag = null, int? xMsQpsTransmissionTime = null, IEnumerable monitoringDataPoints = null, CancellationToken cancellationToken = default) - { - if (ikey == null) - { - throw new ArgumentNullException(nameof(ikey)); - } - - using var message = CreatePostRequest(ikey, apikey, xMsQpsConfigurationEtag, xMsQpsTransmissionTime, monitoringDataPoints); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - var headers = new QuickPulseSDKClientAPIsPostHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - CollectionConfigurationInfo value = default; - using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - value = CollectionConfigurationInfo.DeserializeCollectionConfigurationInfo(document.RootElement); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - case 400: - case 401: - case 403: - case 404: - case 500: - case 503: - { - ServiceError value = default; - using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - value = ServiceError.DeserializeServiceError(document.RootElement); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - default: - throw new RequestFailedException(message.Response); - } - } - - /// SDK post. - /// The ikey of the target Application Insights component that displays metrics and documents sent by /QuickPulseService.svc/post. - /// An alternative way to pass api key. Deprecated. Use AAD authentication instead. - /// An encoded string that indicates whether the collection configuration is changed. - /// Timestamp when SDK transmits the metrics and documents to QuickPulse. A 8-byte long type of ticks. - /// Data contract between SDK and QuickPulse. /QuickPulseService.svc/post uses this to publish metrics and documents to the backend QuickPulse server. - /// The cancellation token to use. - /// is null. - public ResponseWithHeaders Post(string ikey, string apikey = null, string xMsQpsConfigurationEtag = null, int? xMsQpsTransmissionTime = null, IEnumerable monitoringDataPoints = null, CancellationToken cancellationToken = default) - { - if (ikey == null) - { - throw new ArgumentNullException(nameof(ikey)); - } - - using var message = CreatePostRequest(ikey, apikey, xMsQpsConfigurationEtag, xMsQpsTransmissionTime, monitoringDataPoints); - _pipeline.Send(message, cancellationToken); - var headers = new QuickPulseSDKClientAPIsPostHeaders(message.Response); - switch (message.Response.Status) - { - case 200: - { - CollectionConfigurationInfo value = default; - using var document = JsonDocument.Parse(message.Response.ContentStream); - value = CollectionConfigurationInfo.DeserializeCollectionConfigurationInfo(document.RootElement); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - case 400: - case 401: - case 403: - case 404: - case 500: - case 503: - { - ServiceError value = default; - using var document = JsonDocument.Parse(message.Response.ContentStream); - value = ServiceError.DeserializeServiceError(document.RootElement); - return ResponseWithHeaders.FromValue(value, headers, message.Response); - } - default: - throw new RequestFailedException(message.Response); - } - } - } -} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/autorest.md b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/autorest.md deleted file mode 100644 index c999fae32e5f..000000000000 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/src/autorest.md +++ /dev/null @@ -1,17 +0,0 @@ -# Generated code configuration - -Run `dotnet build /t:GenerateCode` to generate code. - -``` yaml -input-file: - - https://quickpulsespecs.blob.core.windows.net/specs/swagger-v2-for%20sdk%20only.json. -generation1-convenience-client: true -``` - -``` yaml -directive: -- from: swagger-document - where: $.definitions.* - transform: > - $["x-accessibility"]="internal" -``` diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/tests/Generated/Samples/Samples_LiveMetricsClient.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/tests/Generated/Samples/Samples_LiveMetricsClient.cs new file mode 100644 index 000000000000..8b4fe17e53aa --- /dev/null +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/tests/Generated/Samples/Samples_LiveMetricsClient.cs @@ -0,0 +1,710 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using Azure.Monitor.OpenTelemetry.LiveMetrics.Models; +using NUnit.Framework; + +namespace Azure.Monitor.OpenTelemetry.LiveMetrics.Samples +{ + public partial class Samples_LiveMetricsClient + { + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_LiveMetrics_IsSubscribed_ShortVersion() + { + TokenCredential credential = new DefaultAzureCredential(); + LiveMetricsClient client = new LiveMetricsClient(credential); + + using RequestContent content = null; + Response response = client.IsSubscribed("", content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("ETag").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Id").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("TelemetryType").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("FieldName").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Predicate").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Comparand").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Projection").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Aggregation").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("BackEndAggregation").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("Id").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("TelemetryType").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("FieldName").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Predicate").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Comparand").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_LiveMetrics_IsSubscribed_ShortVersion_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + LiveMetricsClient client = new LiveMetricsClient(credential); + + using RequestContent content = null; + Response response = await client.IsSubscribedAsync("", content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("ETag").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Id").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("TelemetryType").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("FieldName").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Predicate").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Comparand").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Projection").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Aggregation").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("BackEndAggregation").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("Id").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("TelemetryType").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("FieldName").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Predicate").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Comparand").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_LiveMetrics_IsSubscribed_ShortVersion_Convenience() + { + TokenCredential credential = new DefaultAzureCredential(); + LiveMetricsClient client = new LiveMetricsClient(credential); + + Response response = client.IsSubscribed(""); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_LiveMetrics_IsSubscribed_ShortVersion_Convenience_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + LiveMetricsClient client = new LiveMetricsClient(credential); + + Response response = await client.IsSubscribedAsync(""); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_LiveMetrics_IsSubscribed_AllParameters() + { + TokenCredential credential = new DefaultAzureCredential(); + LiveMetricsClient client = new LiveMetricsClient(credential); + + using RequestContent content = RequestContent.Create(new + { + Version = "", + InvariantVersion = 1234, + Instance = "", + RoleName = "", + MachineName = "", + StreamId = "", + Timestamp = "2022-05-10T14:57:31.2311892-04:00", + TransmissionTime = "2022-05-10T14:57:31.2311892-04:00", + IsWebApp = true, + PerformanceCollectionSupported = true, + Metrics = new object[] + { +new +{ +Name = "", +Value = 123.45, +Weight = 1234, +} + }, + Documents = new object[] + { +new +{ +Name = "", +Url = "http://localhost:3000", +ResponseCode = "", +Duration = "", +DocumentType = "Request", +DocumentStreamIds = new object[] +{ +"" +}, +Properties = new object[] +{ +new +{ +key = "", +value = "", +} +}, +} + }, + TopCpuProcesses = new object[] + { +new +{ +ProcessName = "", +CpuPercentage = 1234, +} + }, + CollectionConfigurationErrors = new object[] + { +new +{ +CollectionConfigurationErrorType = "Unknown", +Message = "", +FullException = "", +Data = new object[] +{ +null +}, +} + }, + }); + Response response = client.IsSubscribed("", content, transmissionTime: 1234L, machineName: "", instanceName: "", streamId: "", roleName: "", invariantVersion: "", configurationEtag: ""); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("ETag").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Id").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("TelemetryType").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("FieldName").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Predicate").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Comparand").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Projection").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Aggregation").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("BackEndAggregation").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("Id").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("TelemetryType").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("FieldName").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Predicate").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Comparand").ToString()); + Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("InitialQuota").ToString()); + Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("MaxQuota").ToString()); + Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("QuotaAccrualRatePerSec").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_LiveMetrics_IsSubscribed_AllParameters_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + LiveMetricsClient client = new LiveMetricsClient(credential); + + using RequestContent content = RequestContent.Create(new + { + Version = "", + InvariantVersion = 1234, + Instance = "", + RoleName = "", + MachineName = "", + StreamId = "", + Timestamp = "2022-05-10T14:57:31.2311892-04:00", + TransmissionTime = "2022-05-10T14:57:31.2311892-04:00", + IsWebApp = true, + PerformanceCollectionSupported = true, + Metrics = new object[] + { +new +{ +Name = "", +Value = 123.45, +Weight = 1234, +} + }, + Documents = new object[] + { +new +{ +Name = "", +Url = "http://localhost:3000", +ResponseCode = "", +Duration = "", +DocumentType = "Request", +DocumentStreamIds = new object[] +{ +"" +}, +Properties = new object[] +{ +new +{ +key = "", +value = "", +} +}, +} + }, + TopCpuProcesses = new object[] + { +new +{ +ProcessName = "", +CpuPercentage = 1234, +} + }, + CollectionConfigurationErrors = new object[] + { +new +{ +CollectionConfigurationErrorType = "Unknown", +Message = "", +FullException = "", +Data = new object[] +{ +null +}, +} + }, + }); + Response response = await client.IsSubscribedAsync("", content, transmissionTime: 1234L, machineName: "", instanceName: "", streamId: "", roleName: "", invariantVersion: "", configurationEtag: ""); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("ETag").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Id").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("TelemetryType").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("FieldName").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Predicate").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Comparand").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Projection").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Aggregation").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("BackEndAggregation").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("Id").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("TelemetryType").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("FieldName").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Predicate").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Comparand").ToString()); + Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("InitialQuota").ToString()); + Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("MaxQuota").ToString()); + Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("QuotaAccrualRatePerSec").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_LiveMetrics_IsSubscribed_AllParameters_Convenience() + { + TokenCredential credential = new DefaultAzureCredential(); + LiveMetricsClient client = new LiveMetricsClient(credential); + + MonitoringDataPoint monitoringDataPoint = new MonitoringDataPoint( + "", + 1234, + "", + "", + "", + "", + true, + true) + { + Timestamp = DateTimeOffset.Parse("2022-05-10T14:57:31.2311892-04:00"), + TransmissionTime = DateTimeOffset.Parse("2022-05-10T14:57:31.2311892-04:00"), + Metrics = { new MetricPoint("", 123.45, 1234) }, + Documents = {new Models.Request +{ +Name = "", +Url = new Uri("http://localhost:3000"), +ResponseCode = "", +Duration = "", +DocumentStreamIds = {""}, +Properties = {new KeyValuePairStringString("", "")}, +}}, + TopCpuProcesses = { new ProcessCpuData("", 1234) }, + CollectionConfigurationErrors = {new CollectionConfigurationError(CollectionConfigurationErrorType.Unknown, "", "", new KeyValuePairStringString[] +{ +default +})}, + }; + Response response = client.IsSubscribed("", monitoringDataPoint: monitoringDataPoint, transmissionTime: 1234L, machineName: "", instanceName: "", streamId: "", roleName: "", invariantVersion: "", configurationEtag: ""); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_LiveMetrics_IsSubscribed_AllParameters_Convenience_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + LiveMetricsClient client = new LiveMetricsClient(credential); + + MonitoringDataPoint monitoringDataPoint = new MonitoringDataPoint( + "", + 1234, + "", + "", + "", + "", + true, + true) + { + Timestamp = DateTimeOffset.Parse("2022-05-10T14:57:31.2311892-04:00"), + TransmissionTime = DateTimeOffset.Parse("2022-05-10T14:57:31.2311892-04:00"), + Metrics = { new MetricPoint("", 123.45, 1234) }, + Documents = {new Models.Request +{ +Name = "", +Url = new Uri("http://localhost:3000"), +ResponseCode = "", +Duration = "", +DocumentStreamIds = {""}, +Properties = {new KeyValuePairStringString("", "")}, +}}, + TopCpuProcesses = { new ProcessCpuData("", 1234) }, + CollectionConfigurationErrors = {new CollectionConfigurationError(CollectionConfigurationErrorType.Unknown, "", "", new KeyValuePairStringString[] +{ +default +})}, + }; + Response response = await client.IsSubscribedAsync("", monitoringDataPoint: monitoringDataPoint, transmissionTime: 1234L, machineName: "", instanceName: "", streamId: "", roleName: "", invariantVersion: "", configurationEtag: ""); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_LiveMetrics_Publish_ShortVersion() + { + TokenCredential credential = new DefaultAzureCredential(); + LiveMetricsClient client = new LiveMetricsClient(credential); + + using RequestContent content = null; + Response response = client.Publish("", content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("ETag").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Id").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("TelemetryType").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("FieldName").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Predicate").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Comparand").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Projection").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Aggregation").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("BackEndAggregation").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("Id").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("TelemetryType").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("FieldName").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Predicate").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Comparand").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_LiveMetrics_Publish_ShortVersion_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + LiveMetricsClient client = new LiveMetricsClient(credential); + + using RequestContent content = null; + Response response = await client.PublishAsync("", content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("ETag").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Id").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("TelemetryType").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("FieldName").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Predicate").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Comparand").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Projection").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Aggregation").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("BackEndAggregation").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("Id").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("TelemetryType").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("FieldName").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Predicate").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Comparand").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_LiveMetrics_Publish_ShortVersion_Convenience() + { + TokenCredential credential = new DefaultAzureCredential(); + LiveMetricsClient client = new LiveMetricsClient(credential); + + Response response = client.Publish(""); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_LiveMetrics_Publish_ShortVersion_Convenience_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + LiveMetricsClient client = new LiveMetricsClient(credential); + + Response response = await client.PublishAsync(""); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_LiveMetrics_Publish_AllParameters() + { + TokenCredential credential = new DefaultAzureCredential(); + LiveMetricsClient client = new LiveMetricsClient(credential); + + using RequestContent content = RequestContent.Create(new object[] + { +new +{ +Version = "", +InvariantVersion = 1234, +Instance = "", +RoleName = "", +MachineName = "", +StreamId = "", +Timestamp = "2022-05-10T14:57:31.2311892-04:00", +TransmissionTime = "2022-05-10T14:57:31.2311892-04:00", +IsWebApp = true, +PerformanceCollectionSupported = true, +Metrics = new object[] +{ +new +{ +Name = "", +Value = 123.45, +Weight = 1234, +} +}, +Documents = new object[] +{ +new +{ +Name = "", +Url = "http://localhost:3000", +ResponseCode = "", +Duration = "", +DocumentType = "Request", +DocumentStreamIds = new object[] +{ +"" +}, +Properties = new object[] +{ +new +{ +key = "", +value = "", +} +}, +} +}, +TopCpuProcesses = new object[] +{ +new +{ +ProcessName = "", +CpuPercentage = 1234, +} +}, +CollectionConfigurationErrors = new object[] +{ +new +{ +CollectionConfigurationErrorType = "Unknown", +Message = "", +FullException = "", +Data = new object[] +{ +null +}, +} +}, +} + }); + Response response = client.Publish("", content, configurationEtag: "", transmissionTime: 1234L); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("ETag").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Id").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("TelemetryType").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("FieldName").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Predicate").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Comparand").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Projection").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Aggregation").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("BackEndAggregation").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("Id").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("TelemetryType").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("FieldName").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Predicate").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Comparand").ToString()); + Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("InitialQuota").ToString()); + Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("MaxQuota").ToString()); + Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("QuotaAccrualRatePerSec").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_LiveMetrics_Publish_AllParameters_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + LiveMetricsClient client = new LiveMetricsClient(credential); + + using RequestContent content = RequestContent.Create(new object[] + { +new +{ +Version = "", +InvariantVersion = 1234, +Instance = "", +RoleName = "", +MachineName = "", +StreamId = "", +Timestamp = "2022-05-10T14:57:31.2311892-04:00", +TransmissionTime = "2022-05-10T14:57:31.2311892-04:00", +IsWebApp = true, +PerformanceCollectionSupported = true, +Metrics = new object[] +{ +new +{ +Name = "", +Value = 123.45, +Weight = 1234, +} +}, +Documents = new object[] +{ +new +{ +Name = "", +Url = "http://localhost:3000", +ResponseCode = "", +Duration = "", +DocumentType = "Request", +DocumentStreamIds = new object[] +{ +"" +}, +Properties = new object[] +{ +new +{ +key = "", +value = "", +} +}, +} +}, +TopCpuProcesses = new object[] +{ +new +{ +ProcessName = "", +CpuPercentage = 1234, +} +}, +CollectionConfigurationErrors = new object[] +{ +new +{ +CollectionConfigurationErrorType = "Unknown", +Message = "", +FullException = "", +Data = new object[] +{ +null +}, +} +}, +} + }); + Response response = await client.PublishAsync("", content, configurationEtag: "", transmissionTime: 1234L); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("ETag").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Id").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("TelemetryType").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("FieldName").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Predicate").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("FilterGroups")[0].GetProperty("Filters")[0].GetProperty("Comparand").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Projection").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("Aggregation").ToString()); + Console.WriteLine(result.GetProperty("Metrics")[0].GetProperty("BackEndAggregation").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("Id").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("TelemetryType").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("FieldName").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Predicate").ToString()); + Console.WriteLine(result.GetProperty("DocumentStreams")[0].GetProperty("DocumentFilterGroups")[0].GetProperty("Filters").GetProperty("Filters")[0].GetProperty("Comparand").ToString()); + Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("InitialQuota").ToString()); + Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("MaxQuota").ToString()); + Console.WriteLine(result.GetProperty("QuotaInfo").GetProperty("QuotaAccrualRatePerSec").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_LiveMetrics_Publish_AllParameters_Convenience() + { + TokenCredential credential = new DefaultAzureCredential(); + LiveMetricsClient client = new LiveMetricsClient(credential); + + Response response = client.Publish("", monitoringDataPoints: new MonitoringDataPoint[] + { +new MonitoringDataPoint( + "", + 1234, + "", + "", + "", + "", + true, + true) +{ +Timestamp = DateTimeOffset.Parse("2022-05-10T14:57:31.2311892-04:00"), +TransmissionTime = DateTimeOffset.Parse("2022-05-10T14:57:31.2311892-04:00"), +Metrics = {new MetricPoint("", 123.45, 1234)}, +Documents = {new Models.Request +{ +Name = "", +Url = new Uri("http://localhost:3000"), +ResponseCode = "", +Duration = "", +DocumentStreamIds = {""}, +Properties = {new KeyValuePairStringString("", "")}, +}}, +TopCpuProcesses = {new ProcessCpuData("", 1234)}, +CollectionConfigurationErrors = {new CollectionConfigurationError(CollectionConfigurationErrorType.Unknown, "", "", new KeyValuePairStringString[] +{ +default +})}, +} + }, configurationEtag: "", transmissionTime: 1234L); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_LiveMetrics_Publish_AllParameters_Convenience_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + LiveMetricsClient client = new LiveMetricsClient(credential); + + Response response = await client.PublishAsync("", monitoringDataPoints: new MonitoringDataPoint[] + { +new MonitoringDataPoint( + "", + 1234, + "", + "", + "", + "", + true, + true) +{ +Timestamp = DateTimeOffset.Parse("2022-05-10T14:57:31.2311892-04:00"), +TransmissionTime = DateTimeOffset.Parse("2022-05-10T14:57:31.2311892-04:00"), +Metrics = {new MetricPoint("", 123.45, 1234)}, +Documents = {new Models.Request +{ +Name = "", +Url = new Uri("http://localhost:3000"), +ResponseCode = "", +Duration = "", +DocumentStreamIds = {""}, +Properties = {new KeyValuePairStringString("", "")}, +}}, +TopCpuProcesses = {new ProcessCpuData("", 1234)}, +CollectionConfigurationErrors = {new CollectionConfigurationError(CollectionConfigurationErrorType.Unknown, "", "", new KeyValuePairStringString[] +{ +default +})}, +} + }, configurationEtag: "", transmissionTime: 1234L); + } + } +} diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/tsp-location.yaml b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/tsp-location.yaml new file mode 100644 index 000000000000..f219eb397428 --- /dev/null +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.LiveMetrics/tsp-location.yaml @@ -0,0 +1,6 @@ +# https://github.com/Azure/azure-sdk-tools/blob/main/doc/common/TypeSpec-Project-Scripts.md#per-project-setup +# https://github.com/Azure/azure-sdk-for-net/blob/main/doc/DataPlaneCodeGeneration/AzureSDKCodeGeneration_DataPlane_Quickstart.md +# +directory: specification/applicationinsights/ApplicationInsights.LiveMetrics +commit: 5dfe00a5d363a30d7434fba9bb99d962e22dcb86 +repo: Azure/azure-rest-api-specs