OpenTSDB / opentsdb

A scalable, distributed Time Series Database.
http://opentsdb.net
GNU Lesser General Public License v2.1
4.99k stars 1.25k forks source link

Some TestQueryRpc unit tests, despite passing, hit QueryRpc: Exception thrown during exception handling #2194

Open twegener-embertec opened 2 years ago

twegener-embertec commented 2 years ago

When running make check-local the following unit tests give the error QueryRpc: Exception thrown during exception handling even though they otherwise pass. This is annoying and confusing since it makes it hard to tell whether these are real problems with exception reporting.

2021-10-13 17:09:05,099 WARN  [main] HttpQuery: [fake channel] Bad Request on /api/query: No such name for 'foo': 'metrics'
2021-10-13 17:09:05,109 ERROR [main] QueryRpc: Exception thrown during exception handling
java.lang.NullPointerException: null
        at net.opentsdb.tsd.AbstractHttpQuery.sendBuffer(AbstractHttpQuery.java:457) ~[na:na]
        at net.opentsdb.tsd.HttpQuery.sendBuffer(HttpQuery.java:702) ~[na:na]
        at net.opentsdb.tsd.HttpQuery.sendReply(HttpQuery.java:577) ~[na:na]
        at net.opentsdb.tsd.HttpQuery.badRequest(HttpQuery.java:423) ~[na:na]
        at net.opentsdb.tsd.QueryRpc$1ErrorCB.call(QueryRpc.java:216) [na:na]
        at net.opentsdb.tsd.QueryRpc$1ErrorCB.call(QueryRpc.java:180) [na:na]
        at com.stumbleupon.async.Deferred.doCall(Deferred.java:1278) [na:na]
        at com.stumbleupon.async.Deferred.addCallbacks(Deferred.java:688) [na:na]
        at com.stumbleupon.async.Deferred.addErrback(Deferred.java:756) [na:na]
        at net.opentsdb.tsd.QueryRpc.handleQuery(QueryRpc.java:320) [na:na]
        at net.opentsdb.tsd.QueryRpc.execute(QueryRpc.java:117) [na:na]
        at net.opentsdb.tsd.TestQueryRpc.postQueryNoMetricBadRequest(TestQueryRpc.java:517) [na:na]
...
2021-10-13 17:09:05,459 WARN  [main] HttpQuery: [fake channel] Bad Request on /api/query?start=1h-ago&m=sum:sys.cpu.user: No such name for 'foo': 'metri
cs'
2021-10-13 17:09:05,464 ERROR [main] QueryRpc: Exception thrown during exception handling
java.lang.NullPointerException: null
        at net.opentsdb.tsd.AbstractHttpQuery.sendBuffer(AbstractHttpQuery.java:457) ~[na:na]
        at net.opentsdb.tsd.HttpQuery.sendBuffer(HttpQuery.java:702) ~[na:na]
        at net.opentsdb.tsd.HttpQuery.sendReply(HttpQuery.java:577) ~[na:na]
        at net.opentsdb.tsd.HttpQuery.badRequest(HttpQuery.java:423) ~[na:na]
        at net.opentsdb.tsd.QueryRpc$1ErrorCB.call(QueryRpc.java:216) [na:na]
        at net.opentsdb.tsd.QueryRpc$1ErrorCB.call(QueryRpc.java:180) [na:na]
        at com.stumbleupon.async.Deferred.doCall(Deferred.java:1278) [na:na]
        at com.stumbleupon.async.Deferred.addCallbacks(Deferred.java:688) [na:na]
        at com.stumbleupon.async.Deferred.addErrback(Deferred.java:756) [na:na]
        at net.opentsdb.tsd.QueryRpc.handleQuery(QueryRpc.java:320) [na:na]
        at net.opentsdb.tsd.QueryRpc.execute(QueryRpc.java:117) [na:na]
        at net.opentsdb.tsd.TestQueryRpc.executeNSU(TestQueryRpc.java:578) [na:na]
...
2021-10-13 17:09:05,866 WARN  [main] HttpQuery: [fake channel] Bad Request on /api/query/gexp?start=1h-ago&exp=scale(sum:sys.cpu.user,notanumber): Unpar
seable scale factor value: 0.0
2021-10-13 17:09:05,873 ERROR [main] QueryRpc: Exception thrown during exception handling
java.lang.NullPointerException: null
        at net.opentsdb.tsd.AbstractHttpQuery.sendBuffer(AbstractHttpQuery.java:457) ~[na:na]
        at net.opentsdb.tsd.HttpQuery.sendBuffer(HttpQuery.java:702) ~[na:na]
        at net.opentsdb.tsd.HttpQuery.sendReply(HttpQuery.java:577) ~[na:na]
        at net.opentsdb.tsd.HttpQuery.badRequest(HttpQuery.java:423) ~[na:na]
        at net.opentsdb.tsd.QueryRpc$1ErrorCB.call(QueryRpc.java:220) [na:na]
        at net.opentsdb.tsd.QueryRpc$1ErrorCB.call(QueryRpc.java:180) [na:na]
        at com.stumbleupon.async.Deferred.doCall(Deferred.java:1278) [na:na]
        at com.stumbleupon.async.Deferred.addCallbacks(Deferred.java:688) [na:na]
        at com.stumbleupon.async.Deferred.addErrback(Deferred.java:756) [na:na]
        at net.opentsdb.tsd.QueryRpc.handleQuery(QueryRpc.java:320) [na:na]
        at net.opentsdb.tsd.QueryRpc.execute(QueryRpc.java:112) [na:na]
        at net.opentsdb.tsd.TestQueryRpc.gexpBadExpression(TestQueryRpc.java:676) [na:na]

This issue may have been around for ages, but it seems like it would be worth fixing, or if unavoidable, then at least having a comment in the test code saying so and why.

twegener-embertec commented 2 years ago

The following patch for the test makes the Exception thrown during exception handling errors go away, but I don't know whether this is an appropriate change. I just followed the pattern seen in some other tests in that file, but I also noticed some other tests that don't have the NettyMocks.mockChannelFuture(query); call and yet don't run into this problem.

diff --git a/test/tsd/TestQueryRpc.java b/test/tsd/TestQueryRpc.java
index f9f855a3..b8241580 100644
--- a/test/tsd/TestQueryRpc.java
+++ b/test/tsd/TestQueryRpc.java
@@ -514,6 +514,7 @@ public final class TestQueryRpc {
         "{\"start\":1425440315306,\"queries\":" +
           "[{\"metric\":\"nonexistent\",\"aggregator\":\"sum\",\"rate\":true," +
           "\"rateOptions\":{\"counter\":false}}]}");
+    NettyMocks.mockChannelFuture(query);
     rpc.execute(tsdb, query);
     assertEquals(HttpResponseStatus.BAD_REQUEST, query.response().getStatus());
     final String json =
@@ -575,6 +576,7 @@ public final class TestQueryRpc {

     final HttpQuery query = NettyMocks.getQuery(tsdb,
         "/api/query?start=1h-ago&m=sum:sys.cpu.user");
+    NettyMocks.mockChannelFuture(query);
     rpc.execute(tsdb, query);
     assertEquals(HttpResponseStatus.BAD_REQUEST, query.response().getStatus());
     final String json =
@@ -673,6 +675,7 @@ public final class TestQueryRpc {

     final HttpQuery query = NettyMocks.getQuery(tsdb,
         "/api/query/gexp?start=1h-ago&exp=scale(sum:sys.cpu.user,notanumber)");
+    NettyMocks.mockChannelFuture(query);
     rpc.execute(tsdb, query);
     assertEquals(query.response().getStatus(), HttpResponseStatus.BAD_REQUEST);
     final String json =