OpenTSDB / opentsdb

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

Can't query data point which timestamp is small #1132

Open ZhongChaoqiang opened 6 years ago

ZhongChaoqiang commented 6 years ago

Insert a data point with timestamp 100001: curl -i -X POST -d '{"metric":"test1", "timestamp":100001, "value":2, "tags":{"tagk1":"tagv1"}}' http://X.X.X.X:4242/api/put?sync&sync_timeout=1000

And we query with timestamp range of 100000 to 100005. The result is empty. curl -i -X POST -d '{"start": 100000,"end": 100005,"queries": [{"aggregator": "none","metric": "test1"}]}' http://X.X.X.X:4242/api/query

The root cause mybe as bellow: In TsdbQuery#getScanStartTimeSeconds() function, the start Time that returned by getStartTime() must be milliseconds, so we don't need to check whether start Time is seconds or milliseconds.

  private long getScanStartTimeSeconds() {
    // Begin with the raw query start time.
    long start = getStartTime();              // start=100000000

    // Convert to seconds if we have a query in ms.
    if ((start & Const.SECOND_MASK) != 0L) {          //  return false, don't convert to second. the start time is wrong.
      start /= 1000L;
    }

Can Anyone check this issue and fix it ?

ZhongChaoqiang commented 6 years ago

When TsdbQuery#setStartTime() is called by CliQuery#parseCommandLineQuery and GraphHandler#doGraph, the start time has been converted to seconds, but TsdbQuery#configureFromQuery don't. Should TsdbQuery#configureFromQuery convert start time to seconds before calling TsdbQuery#setStartTime()?

manolama commented 5 years ago

Yes this is a bug in TSDB that we'll address in 3.0 with timestamps. Unless someone wants to patch 2.x to handle this edge case.