Search code examples
oracle-cloud-infrastructureoci-java-sdk

Exception in thread "main" com.oracle.bmc.model.BmcException: (400, InvalidParameter, false) token recognition error at: ':'


SummarizeMetricsData

final String compartment = "ocid1.compartment.oc1..aaaaaaaao6rwmdqqv5264k2hfnlvzlridxj2mhtz3mzycq526bybtxuiyygq";
final String namespace = "oci_computeagent";
final String query = "NetworksBytesOut[1m]{resourceId:ocid1.instance.oc1.eu-frankfurt-1.abtheljtx3jpe4ifo3bxwhfngxfcgu3clrivse3zpuzumasauvveu74xxh4q}.sum()";
final String profile = CONFIG_PROFILE_DEFAULT;

  final SummarizeMetricsDataRequest request =
                SummarizeMetricsDataRequest.builder()
                        .compartmentId(compartment)
                        .summarizeMetricsDataDetails(
                                SummarizeMetricsDataDetails.builder()
                                        .namespace(namespace)
                                        .query(query)
                                        .startTime(START)
                                        .endTime(UNTIL)
                                        .build())
                        .build();

I am using Java SDK for fetching the datapoints for a metric.

But getting the below exception.

Exception in thread "main" com.oracle.bmc.model.BmcException: (400, InvalidParameter, false) token recognition error at: ':'
NetworksBytesOut[1m]{resourceId:ocid1.instance.oc1.eu-frankfurt-1.abtheljtx3jpe4ifo3bxwhfngxfcgu3clrivse3zpuzumasauvveu74xxh4q}.sum()
(opc-request-id: FD8B823E39BA4C6787ADAA8C88C4831B/A3A7C538D3C290E4982C5875B700C788/C1A4F87CFA3E44B83585B3372579D324)
at com.oracle.bmc.http.internal.ResponseHelper.throwIfNotSuccessful(ResponseHelper.java:120)
at com.oracle.bmc.http.internal.ResponseConversionFunctionFactory$ValidatingParseResponseFunction.apply(ResponseConversionFunctionFactory.java:86)
at com.oracle.bmc.http.internal.ResponseConversionFunctionFactory$ValidatingParseResponseFunction.apply(ResponseConversionFunctionFactory.java:82)

Any inputs? My thoughts are that the 'query' string is incorrect. But the documentation tells to frame the query like below.

{
"namespace": "oci_computeagent",
"query": "CpuUtilization[1m]{resourceId:<instance_OCID>}.max()",
"startTime": "2019-03-10T22:19:26.789Z",
"endTime": "2019-03-10T22:28:26.789Z"
}

Solution

  • Use = instead of :. Like this: metric[interval]{dimensionname="dimensionvalue"}.groupingfunction.statistic, see reference here.