Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MetricsPortal query API throws an uninformative 500 if you POST without Content-type: application/json #332

Open
orborde opened this issue Feb 25, 2020 · 0 comments

Comments

@orborde
Copy link
Contributor

orborde commented Feb 25, 2020

$ curl http://[redacted]:8080/api/v1/datapoints/query --header 'Host: [redacted]' -vvv  -d'{
   "start_absolute":1581292800000,
   "end_absolute":1581379200000,
   "metrics":[
     {
       "name":"redacted/metric_name",

     }
   ]
 }'
*   Trying [redacted]...
* Connected to [redacted] ([redacted]) port 8080 (#0)
> POST /api/v1/datapoints/query HTTP/1.1
> Host: [redacted]
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Length: 139
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 139 out of 139 bytes
< HTTP/1.1 500 Internal Server Error
< Date: Tue, 25 Feb 2020 21:08:34 GMT
< Content-Length: 0
< 
* Connection #0 to host [redacted] left intact

There's a stack in the MetricsPortal log:

  "exception": {
    "type": "java.lang.NullPointerException",
    "message": null,
    "backtrace": [
      "at com.fasterxml.jackson.databind.ObjectMapper.treeToValue(ObjectMapper.java:2746)",
      "at controllers.KairosDbProxyController.queryMetrics(KairosDbProxyController.java:155)",
      "at portal.Routes$$anonfun$routes$1$$anonfun$applyOrElse$27$$anonfun$apply$27.apply(Routes.scala:767)",
      "at portal.Routes$$anonfun$routes$1$$anonfun$applyOrElse$27$$anonfun$apply$27.apply(Routes.scala:767)",
      "at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:146)",
      "at play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$8$$anon$2$$anon$1.invocation(HandlerInvoker.scala:115)",
      "at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:111)",
      "at com.arpnetworking.play.metrics.MetricsActionWrapper.call(MetricsActionWrapper.java:60)",
      "at play.core.j.JavaAction$$anonfun$9.apply(JavaAction.scala:170)",
      "at play.core.j.JavaAction$$anonfun$9.apply(JavaAction.scala:170)",
      "at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)",
      "at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)",
      "at play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:64)",
      "at play.api.libs.streams.Execution$trampoline$.execute(Execution.scala:71)",
      "at play.core.j.HttpExecutionContext.execute(HttpExecutionContext.scala:56)",
      "at scala.concurrent.impl.Future$.apply(Future.scala:31)",
      "at scala.concurrent.Future$.apply(Future.scala:494)",
      "at play.core.j.JavaAction.apply(JavaAction.scala:170)",
      "at play.api.mvc.Action$$anonfun$apply$2.apply(Action.scala:97)",
      "at play.api.mvc.Action$$anonfun$apply$2.apply(Action.scala:90)",
      "at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:253)",
      "at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:251)",
      "at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:36)",
      "at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)",
      "at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run$1.apply$mcV$sp(BatchingExecutor.scala:91)",
      "at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run$1.apply(BatchingExecutor.scala:91)",
      "at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run$1.apply(BatchingExecutor.scala:91)",
      "at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:72)",
      "at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:90)",
      "at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40)",
      "at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:44)",
      "at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)",
      "at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)",
      "at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)",
      "at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)"
    ],

If you add --header 'Content-type: application/json', the above curl invocation works.

The expected behavior here is either:
(A) MetricsPortal parses the JSON even if the Content-type header is not present, or
(B) Returns a 400 Bad Request with an error page requesting the Content-type header to be set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant