Skip to content

LogToMetricAction criteria field definition doesn't match wire payload #5326

Closed

Description

Ported from Azure/azure-sdk-for-go#4121

In https://github.com/Azure/azure-rest-api-specs/blob/master/specification/monitor/resource-manager/Microsoft.Insights/stable/2018-04-16/scheduledQueryRule_API.json#L730 criteria is defined as a singular object however the server expects an array of Criteria objects. See the following server response.

{
	"error": {
		"code": "Failed to deserialize payload : Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.List`1[Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.Criteria]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.",
		"message": {
			"lang": "en-US",
			"value": "Failed to deserialize payload : Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.List`1[Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.Criteria]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.\r\nPath 'criteria.metricName'."
		},
		"innererror": {
			"stacktrace": "System.ArgumentException: Failed to deserialize payload : Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.List`1[Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.Criteria]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.\r\nPath 'criteria.metricName'. ---> Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.List`1[Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.Criteria]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.\r\nPath 'criteria.metricName'.\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)\r\n   at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)\r\n   at Newtonsoft.Json.Linq.JToken.ToObject[T](JsonSerializer jsonSerializer)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)\r\n   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)\r\n   at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)\r\n   at Newtonsoft.Json.Linq.JToken.ToObject[T](JsonSerializer jsonSerializer)\r\n   at Microsoft.AppInsights.Nexus.ResourceProvider.Csm.CsmResourceProvider`1.PutResourceAsync[T](String subscriptionId, String resourceGroupName, String resourceName, JObject resourceEnv, String eTag, RpRequestOptions options, String operationId) in X:\\bt\\988380\\repo\\src\\SQR-CDS\\Nexus\\ResourceProvider\\Csm\\CsmResourceProvider.cs:line 226\r\n   --- End of inner exception stack trace ---\r\n   at Microsoft.AppInsights.Nexus.ResourceProvider.Csm.CsmResourceProvider`1.PutResourceAsync[T](String subscriptionId, String resourceGroupName, String resourceName, JObject resourceEnv, String eTag, RpRequestOptions options, String operationId) in X:\\bt\\988380\\repo\\src\\SQR-CDS\\Nexus\\ResourceProvider\\Csm\\CsmResourceProvider.cs:line 230\r\n   at Microsoft.ManagementServices.Rules.Endpoint.Controllers.Nexus.CsmResourcesNxControllerBase`1.<>c__DisplayClass13_0.<<PutResourceAsync>b__0>d.MoveNext() in X:\\bt\\988380\\repo\\src\\SQR-CDS\\Service\\Endpoint\\Controllers\\Nexus\\CsmResourcesNxControllerBase.cs:line 208\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.ManagementServices.Rules.Endpoint.Controllers.Nexus.NexusControllerBase.<PerformActionAsync>d__17.MoveNext() in X:\\bt\\988380\\repo\\src\\SQR-CDS\\Service\\Endpoint\\Controllers\\Nexus\\NexusControllerBase.cs:line 97"
		}
	}
}

You should also remove the full stack trace being returned in the error object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions