Azure Monitor Java SDK -MismatchedInputException: Missing required creator property 'timespan'

yating-9727 0 Reputation points
2024-06-07T19:50:56.8166667+00:00

I'm using the Azure Monitor Metrics SDK in my Java application to query metrics for redis resource. However, I'm encountering a com.fasterxml.jackson.databind.exc.MismatchedInputException with the error message "Missing required creator property 'timespan' (index 0)". How could I fix this?

This is my code snippet:

			<dependency>
				<groupId>com.azure.resourcemanager</groupId>
				<artifactId>azure-resourcemanager-redis</artifactId>
				<version>2.39.0</version>
			</dependency>
			<dependency>
				<groupId>com.azure</groupId>
				<artifactId>azure-identity</artifactId>
				<version>1.12.1</version>
			</dependency>
			<dependency>
				<groupId>com.azure</groupId>
				<artifactId>azure-monitor-query</artifactId>
				<version>1.3.2</version>
			</dependency>

final MetricsQueryClient metricsQueryClient = new MetricsQueryClientBuilder() .credential(clientSecretCredential) .buildClient()
final MetricsQueryResult metricsQueryResult = metricsQueryClient.queryResource(instanceId,Arrays.asList("usedmemory"));

The full stacktrace is :

Exception in thread "main" com.azure.core.exception.HttpResponseException: Deserialization Failed.
	at com.azure.core.implementation.serializer.HttpResponseBodyDecoder.decodeByteArray(HttpResponseBodyDecoder.java:99)
	at com.azure.core.implementation.serializer.HttpResponseDecoder$HttpDecodedResponse.getDecodedBody(HttpResponseDecoder.java:93)
	at com.azure.core.implementation.http.rest.SyncRestProxy.handleBodyReturnType(SyncRestProxy.java:192)
	at com.azure.core.implementation.http.rest.SyncRestProxy.handleRestResponseReturnType(SyncRestProxy.java:148)
	at com.azure.core.implementation.http.rest.SyncRestProxy.handleRestReturnType(SyncRestProxy.java:220)
	at com.azure.core.implementation.http.rest.SyncRestProxy.invoke(SyncRestProxy.java:86)
	at com.azure.core.implementation.http.rest.RestProxyBase.invoke(RestProxyBase.java:125)
	at com.azure.core.http.rest.RestProxy.invoke(RestProxy.java:97)
	at com.sun.proxy.$Proxy3.listSync(Unknown Source)
	at com.azure.monitor.query.implementation.metrics.MetricsImpl.listWithResponse(MetricsImpl.java:1038)
	at com.azure.monitor.query.MetricsQueryClient.queryResourceWithResponse(MetricsQueryClient.java:158)
	at com.azure.monitor.query.MetricsQueryClient.queryResource(MetricsQueryClient.java:122)
	at com.test.global.service.azure.AzureRedisService.queryMetrics(AzureRedisService.java:137)
	at com.test.global.service.azure.AzureRedisService.main(AzureRedisService.java:52)
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Missing required creator property 'timespan' (index 0)
 at [Source: (byte[])"{"value":[]}"; line: 1, column: 12] (through reference chain: com.azure.monitor.query.implementation.metrics.models.MetricsResponse["timespan"])
	at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
	at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1755)
	at com.fasterxml.jackson.databind.deser.impl.PropertyValueBuffer._findMissing(PropertyValueBuffer.java:192)
	at com.fasterxml.jackson.databind.deser.impl.PropertyValueBuffer.getParameters(PropertyValueBuffer.java:158)
	at com.fasterxml.jackson.databind.deser.ValueInstantiator.createFromObjectWith(ValueInstantiator.java:288)
	at com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator.build(PropertyBasedCreator.java:202)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:518)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1405)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:351)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:184)
	at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:322)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4674)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3723)
	at com.azure.core.implementation.jackson.ObjectMapperShim.readValue(ObjectMapperShim.java:240)
	at com.azure.core.util.serializer.JacksonAdapter.lambda$deserialize$9(JacksonAdapter.java:359)
	at com.azure.core.util.serializer.JacksonAdapter.useAccessHelper(JacksonAdapter.java:491)
	at com.azure.core.util.serializer.JacksonAdapter.deserialize(JacksonAdapter.java:347)
	at com.azure.core.implementation.serializer.HttpResponseBodyDecoder.deserialize(HttpResponseBodyDecoder.java:176)
	at com.azure.core.implementation.serializer.HttpResponseBodyDecoder.deserializeBody(HttpResponseBodyDecoder.java:150)
	at com.azure.core.implementation.serializer.HttpResponseBodyDecoder.decodeByteArray(HttpResponseBodyDecoder.java:93)
	... 13 more

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,306 questions
Azure Cache for Redis
Azure Cache for Redis
An Azure service that provides access to a secure, dedicated Redis cache, managed by Microsoft.
258 questions
{count} votes

1 answer

Sort by: Most helpful
  1. yating-9727 0 Reputation points
    2024-06-11T08:28:38.6733333+00:00

    After adding these permissions to my azure app, this problem gone:

    Microsoft.Insights/Metrics/read, Microsoft.Insights/MetricDefinitions/read

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.