ytyou / ticktock

TickTockDB is an OpenTSDB-like time series database, with much better performance.
GNU General Public License v3.0
72 stars 8 forks source link

reading values via http only works in curl and Grafana, but not in other clients like browsers #33

Closed Soren-klars closed 1 year ago

Soren-klars commented 1 year ago

version: 0.10.2 on Debian Hi there, I'm trying to do a simply query from Python to get some data: http://localhost:6182/api/query?start=1674172800&m=avg:1m-avg:energy.kitchen\{direction=consumed,type=kwh-last-10-min} It works in curl and Grafana, but not in any browser, Postman or any python client I tried. I analyzed the request in Wireshark to find any header parameters etc. that are different, but I could not find anything to explain that behavior. Please see the screenshots for the difference: The requests are the same, but in curl the response has values, and in Postman (or any other client I tried) the response is simply empty: [ ]

request-Postman response-Postman response-curl request-curl

I tried to add all kinds of headers like 'accept' and 'host' and different 'User-Agent' values, no difference. There are only differences in the TCP part to establish a the HTTP request. But the DB should behave either the same or throw an error...

ylin30 commented 1 year ago

@Soren-klars hm. We never tested in Postmon. We did test with python but unfortunately only writes (https://github.com/ytyou/ticktock/wiki/Usage-Examples#3-python-examples). I will try python reads to see.

The only difference I can see is the escape chars in two URLs, postman with \{direction=consumer...\} while curl does not have the \. I am not sure if it will make difference. It does when using curl if not specify --binary-data. Let us repro it first.

image

ylin30 commented 1 year ago

I tried python reads and actually adding the escape char \ will result in empty values. It works correctly if not with the \.

First, I run the python write (/api-examples/python/http_plain_writer.py) to insert a data point. Then I tested in python shell:

>>>
>>> url = "http://localhost:6182/api/query?start=1633412100&m=avg:1m-avg:http.cpu.usr\{host=foo\}"
>>>
>>> res = requests.get(url)
>>> print(res.text)
[]
>>> url = "http://localhost:6182/api/query?start=1633412100&m=avg:1m-avg:http.cpu.usr{host=foo}"
>>> res = requests.get(url)
>>> print(res.text)
[{"metric":"http.cpu.usr","tags":{"cpu":"1","host":"foo"},"aggregateTags":[],"dps":{"1633412160":20.0}}]
>>> 
Soren-klars commented 1 year ago

I confirm that it works without the back-slashes... strange phenomenon... solved. But please update the documentation about this.

ylin30 commented 1 year ago

I will update the doc. Thanks for reporting.