Closed SeaLife closed 1 month ago
Hello, I would like to report a situation where the code is not working properly in my environment. loki version 2.8.11 promtail version 2.8.11
Test code
lib.logger(-1, 'LogTest', 'Test 123', 'test123:test123', 'rpname:Lena Meier', 'job:police')
postBody {"streams":[{"stream":{"server":"[QBCore Framework] QBServer","resource":"pg_test","event":"LogTest"},"values":[["1716564324000000000","Test 123",{"job":"police","test123":"test123","rpname":"Lena Meier"}]]}]}
PerformHttpRequest callback function [400,null,[],"HTTP 400: loghttp.PushRequest.Streams: []*loghttp.Stream: unmarshalerDecoder: Value is string, but can't find closing '\"' symbol, error found in #10 byte of ...|Meier\"}]]}]}|..., bigger context ...|ice\",\"test123\":\"test123\",\"rpname\":\"Lena Meier\"}]]}]}|...\n"]
Code to print data
local postBody = json.encode({streams = tempBuffer})
print(postBody)
PerformHttpRequest(endpoint, function(...)
print(json.encode({...}))
end, 'POST', postBody, headers)
Hello, I would like to report a situation where the code is not working properly in my environment. loki version 2.8.11 promtail version 2.8.11
Test code
lib.logger(-1, 'LogTest', 'Test 123', 'test123:test123', 'rpname:Lena Meier', 'job:police')
postBody {"streams":[{"stream":{"server":"[QBCore Framework] QBServer","resource":"pg_test","event":"LogTest"},"values":[["1716564324000000000","Test 123",{"job":"police","test123":"test123","rpname":"Lena Meier"}]]}]}
PerformHttpRequest callback function [400,null,[],"HTTP 400: loghttp.PushRequest.Streams: []*loghttp.Stream: unmarshalerDecoder: Value is string, but can't find closing '"' symbol, error found in #10 byte of ...|Meier"}]]}]}|..., bigger context ...|ice","test123":"test123","rpname":"Lena Meier"}]]}]}|...\n"]
Code to print data
local postBody = json.encode({streams = tempBuffer}) print(postBody) PerformHttpRequest(endpoint, function(...) print(json.encode({...})) end, 'POST', postBody, headers)
The generated JSON works by posting it via HTTPie directly to loki. I think this is not related to this?
Im using Loki 3.0.0, maybe there is a difference in the API?
Just investigated a bit around the API and it seems that they added posting meta variables in the values
-Part in 3.0.0 and therefore this fails on 2.8.x
https://grafana.com/docs/loki/v2.8.x/api/#push-log-entries-to-loki https://grafana.com/docs/loki/latest/reference/loki-http-api/#ingest-logs
If possible, can you upgrade to Loki 3.0.0 ?
Can you check if the error persist on ox_lib v3.21.0 ?
@Cata-a1138
Just tested in loki 3.0.0 and ox_lib v3.21.0, get the same results as you, thank you for your reply.
And I found the reason why you get "table":0x7fe593f2ca50".
That is, { rpname = "Lena Meier", job = "police" }
in string.tostringall(...)
is then converted to a string, so json.encode
doesn't work as expected.
I have opened a pull request to solve this problem. #588
Hey!
i dont know if this is expected behaviour and the loki provider probably needs more rework but i played around with it a bit and currently its submitting the data in a wrong format. The code i used to submit logs (test):
(before)
(after my changes)
![image](https://github.com/overextended/ox_lib/assets/6567620/52e6b7c4-560b-4274-82a2-9c52314b48ba)
I tried the following:
Which ended up in this:![image](https://github.com/overextended/ox_lib/assets/6567620/1a75feb2-d91d-4c3e-a723-95c050c6df7d)
Probably this need some more rework, i think submitting the meta data in this format
key:value
is inconvenient. But this is out-of-scope for this "fix" 🗡️