GithubHelp home page GithubHelp logo

`/api/v1/query` API not working? about qryn HOT 7 CLOSED

metrico avatar metrico commented on May 9, 2024
`/api/v1/query` API not working?

from qryn.

Comments (7)

navinpai avatar navinpai commented on May 9, 2024 1

You should insert to the line column instead as clients do.

Ah yes... that seems to have fixed it.

More importantly everything works as intended when using Loki clients and Grafana which is our intended usecase.

The usecase I'm playing with cloki for is quite similar but I'm a suckler for testing APIs directly to know what's flowing in and out! πŸ˜„. I also confirmed via grafana that the data being pushed manually via is being returned there! Would be nice to have some simple examples to have people up and running, but can close this out for now! πŸ‘

Thanks again @lmangani !

from qryn.

lmangani avatar lmangani commented on May 9, 2024

Hello @navinpai

Thanks for your report! There are indeed "leftovers" of the Loki 1.0 API here and there, and documentation for manual actions might need refresh. We'll make sure the examples for the query API are rectified in the coming days.

Now, query is used for doing queries against a single point in time, while most of the focus is on the Grafana integration at this time where query_range is the core function:

Here's a working example:

curl -G -s localhost:3100/loki/api/v1/query_range --data-urlencode 'query={type="clickhouse"}'

EDIT: Wiki has been updated!

from qryn.

lmangani avatar lmangani commented on May 9, 2024

Patches for /query endpoint being worked in #65

from qryn.

navinpai avatar navinpai commented on May 9, 2024

Thanks for the quick reply @lmangani

Unfortunately, looks like query_range is not working for me either.

How to Reproduce

node v.17.0.1
cloki (current master: f3b32b5)
clickhouse v 21.12.1.8808

# Run Cloki to create initial tables in empty test db
DEBUG="true" CLICKHOUSE_SERVER="127.0.0.1" CLICKHOUSE_AUTH="default:" CLICKHOUSE_DB="test" node ./cloki.js

# Push log
$ curl -i -XPOST -H "Content-Type: application/json" http://localhost:3100/loki/api/v1/push --data '{"streams":[{"labels":"{\"__name__\":\"metric\"}","entries":[{"timestamp":"2021-11-21T16:00:06.944Z","value":"100"}]}]}'
HTTP/1.1 200 OK

# Ensure label is present
$ curl localhost:3100/loki/api/v1/label/__name__/values
{"status":"success","data":["metric"]}

# Query for data
curl -G -s localhost:3100/loki/api/v1/query_range --data-urlencode 'query={__name__="metric"}'
{"status":"success", "data":{ "resultType":"streams", "result": []}}

Debug logs show:

GET /loki/api/v1/query_range
QUERY:  [Object: null prototype] { query: '{__name__="metric"}' }
Scanning Fingerprints...
Scanning Fingerprints...

and I also see the data in clickhouse in time_series table and the samples_read table:

β”Œβ”€β”€β”€β”€β”€β”€β”€date─┬─fingerprint─┬─labels────────────────┬─name─┐
β”‚ 2021-11-21 β”‚  1417368218 β”‚ {"__name__":"metric"} β”‚      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€fingerprint─┬──timestamp_ms─┬─value─┬─string─┐
β”‚  1417368218 β”‚ 1637510406944 β”‚   100 β”‚        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Any idea what I may be missing here?

from qryn.

lmangani avatar lmangani commented on May 9, 2024

Thanks for the details, I see the issue now - the example is a bit misleading and it seems you're inserting metrics rather than strings/logs. This is a special feature for timeseries. You should insert to the line column instead as clients do.

curl -i -XPOST -H "Content-Type: application/json" http://localhost:3100/loki/api/v1/push --data '{"streams":[{"labels":"{\"__name__\":\"up\"}","entries":[{"timestamp":"2020-11-21T21:00:09.999Z","line":"zzz"}]}]}'

Things should work if you push lines (please confirm)

More importantly everything works as intended when using Loki clients and Grafana which is our intended usecase.

from qryn.

lmangani avatar lmangani commented on May 9, 2024

Unrelated note: only node 14.x and 16.x are officially supported & tested, other version might fail.

from qryn.

lmangani avatar lmangani commented on May 9, 2024

We'll extend the documentation with better examples. Thanks for taking the time to confirm & welcome to our users family!

from qryn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.