Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse sent data with raw http request error #12914

Closed
chesha1 opened this issue May 8, 2024 · 2 comments
Closed

Parse sent data with raw http request error #12914

chesha1 opened this issue May 8, 2024 · 2 comments
Assignees

Comments

@chesha1
Copy link

chesha1 commented May 8, 2024

Describe the bug
When sending logs with direct http request to loki in grafana cloud, it seems that loki didn't parse data correctly.

To Reproduce
The endpoint looks like https://123:glc_eyJ@logs-prod-020.grafana.net/loki/api/v1/push

The http header Content-Type is set application/json

The request body is below, it is directly copied from official documents

{
	"streams": [
		{
			"stream": {
				"label": "value"
			},
			"values": [
				[
					"2024-05-08T18:52:26.164724+08:00",
					"{\"level\":\"info\",\"message\":\"Hello world!\"}"
				],
				[
					"2024-05-08T18:52:26.164724+08:00",
					"{\"level\":\"info\",\"message\":\"Hello world!\"}"
				]
			]
		}
	]
}

There is a curl version:

curl --request POST \
  --url https://787766:glc_ey@logs-prod-020.grafana.net/loki/api/v1/push \
  --header 'Content-Type: application/json' \
  --data '{
	"streams": [
		{
			"stream": {
				"label": "value"
			},
			"values": [
				[
					"2024-05-08T18:52:26.164724+08:00",
					"{\"level\":\"info\",\"message\":\"Hello world!\"}"
				],
				[
					"2024-05-08T18:52:26.164724+08:00",
					"{\"level\":\"info\",\"message\":\"Hello world!\"}"
				]
			]
		}
	]
}'

The response is:

loghttp.PushRequest.Streams: []loghttp.LogProtoStream: unmarshalerDecoder: Value looks like Number/Boolean/None, but can't find its end: ',' or '}' symbol, error found in #10 byte of ...|]
			]
		}
	]
}|..., bigger context ...|fo\",\"message\":\"Hello world!\"}"
				]
			]
		}
	]
}|...
@paul1r
Copy link
Collaborator

paul1r commented May 10, 2024

Hello!

The timestamp, as mentioned in the document you referenced, needs to be in nanoseconds, so something along the lines of 1715165546164724000 for 2024-05-08T18:52:26.164724+08:00.

As such, I was able to issue your command using my local install after making this adjustment:

curl --request POST \
  --url http://localhost:3100/loki/api/v1/push \
  --header 'Content-Type: application/json' \
  --data '{
	"streams": [
		{
			"stream": {
				"label": "value"
			},
			"values": [
				[
					"1715313600000000000",
					"{\"level\":\"info\",\"message\":\"Hello world2!\"}"
				],
				[
					"1715313600000000000",
					"{\"level\":\"info\",\"message\":\"Hello world!\"}"
				]
			]
		}
	]
}'

@chesha1
Copy link
Author

chesha1 commented May 10, 2024

Hello!

The timestamp, as mentioned in the document you referenced, needs to be in nanoseconds, so something along the lines of 1715165546164724000 for 2024-05-08T18:52:26.164724+08:00.

As such, I was able to issue your command using my local install after making this adjustment:

curl --request POST \
  --url http://localhost:3100/loki/api/v1/push \
  --header 'Content-Type: application/json' \
  --data '{
	"streams": [
		{
			"stream": {
				"label": "value"
			},
			"values": [
				[
					"1715313600000000000",
					"{\"level\":\"info\",\"message\":\"Hello world2!\"}"
				],
				[
					"1715313600000000000",
					"{\"level\":\"info\",\"message\":\"Hello world!\"}"
				]
			]
		}
	]
}'

Thank you very much for reply, it now works.

But I have another problem, no logs can be found in grafana cloud, could you check this? #12935

@paul1r paul1r self-assigned this May 10, 2024
@paul1r paul1r closed this as completed May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants