-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Promtail: syslog job over UDP is not working #6772
Comments
@xtavras How have you installed loki and promtail? |
@jsalatiel Promtail is just official binary deployed with this ansible playbook https://github.com/patrickjahns/ansible-role-promtail which just use github releases, I've tried to build binary from "main" and have same problem. I can see that Promtail is listeing on udp port using
|
Can you check if the kubernetes service has been created with TCP or UDP? |
@jsalatiel what service do you mean? Isn't Promtail communicate with Loki just with HTTP calls, so they are always TCP? |
AFAIK when you enable syslog on promtail it creates a service so that external services can send syslog messages to promtail. |
Sorry if I was not clear, promtail is running on VM just as binary, so no Docker or Kubernetes, only Loki itself is running on Kubernetes. And I see that port is |
If there's nothing listening on UDP thats the reason you can not send udp messages to promtail =) |
But it is listening on UDP, I already posted my netstat ouput. Promtail send data to Loki always using HTTP/HTTPS so not sure why UDP is expected on Loki side, correct me if I'm wrong. |
@xtavras did you check syslog config , if there is udp / or tcp destination ? |
@saibug yes, our switches (Huawei) only support UDP on port 514, like I've said I see it in tcpdump in cleartext on promtail machine. |
Here is tcpdump example, as you see protocol is UDP: first is test script, second is real log from switch
|
Same thing for me. I have Unifi EdgeSwitch which supports only UDP. Promtail configuration: scrape_configs:
# ...
- job_name: syslog
relabel_configs:
- source_labels:
- __syslog_message_hostname
target_label: host
syslog:
idle_timeout: 60s
label_structured_data: true
labels:
cluster: lab
job: syslog
listen_address: 0.0.0.0:514
listen_protocol: udp Started via systemd (on NixOS) on 514/udp. |
In my case packets are handled by nontransparent parser. I've made a minimal server to debug this https://gist.github.com/corpix/d76a90678d24e412eb5f9347dc1b58c1
UDP is not connection oriented, so there is no |
Sorry. |
I've been testing UDP using
With this configuration Promtail receives the logs and pushed them to Loki. Unfortunately I don't have a hardware device where I could test it. I've also tested your Python script, and by adding a newline character at the end of the log message, it worked: #!/usr/bin/env python3
import socket
import logging
from random import random
from time import sleep
from rfc5424logging import Rfc5424SysLogHandler, transport
logger = logging.getLogger("promtail")
logger.setLevel(logging.DEBUG)
rfc5424Handler = Rfc5424SysLogHandler(address=("localhost", 514), hostname="localhost", appname="promtailudp.py")
rfc5424Handler.setLevel(logging.DEBUG)
logger.addHandler(rfc5424Handler)
for x in range(100):
logger.warning("this is a UDP test\n", extra={"msgid":1})
sleep(random()) Seems like this is required as delimiter. |
@chaudum thank you for looking into it, I can confirm that your script works indeed, removing newline breaks it. Unfortunately our switches do not add new line at the end (and looking at comments looks like some other vendors don't do it too). What do you think, would it be possible as workaround append newline to such log messages in promtail? |
@grafana/loki-team What do you think?
Tbh, I have no idea why it works over TCP but not over UDP, since we use the same code path for parsing messages. I would need to investigate the syslog parser library we use. That would take a lot of time I guess. |
I noted similar behaviour with promtail:2.8.2. |
I dug a little deeper and found that the reader we send to the parser is coded to read until it sees the expected delimiter. github.com/leodido/ragel-machinery/parser. In promtail's case it is looking for a Line Feed so the reader will hang looking for it on any message not ending in a line feed. |
Same here. On Synology NAS you can choose whether to send syslogs in TCP or UDP format. |
Put in a PR to fix this here and in grafana agent - very simple workaround of making a bytes reader from the datagram so the parser gets the EOF |
Hi, (first interaction on Github so apologises for any missing information I may provide) I think I may be experiencing this exact issue in our network. We have a few hundreds switches and routers which syslog back to two central archive logging servers using UDP 514, Debian bare-metal based running syslog-ng. After forwarding all syslog to Promtail via UDP, nothing is caught. Promtail does work via scraping the local logs sorted via syslog but this is not ideal for labelling. We run a Grafana instance on one of these boxes and I would love to get Loki logs working with Promtail. I will be keeping a close eye on this issue as I'm eager to find a solution, and reluctant to move our boxes to rsyslog. |
@joshuapare was your grafana agent PR merged? if so we can likely merge a similar fix here, we're just trying to avoid too much divergence since the agent team forked the promtail code and soon all logs collection work will be done within that repo. |
Yep it was, and the matching PR for this repo is here as well: #10708 |
@cstyan : Referring to your comment of Promtail being in a "feature complete" status now (#10256 (comment)), is there any chance for this be fixed as well? It seems that there have been multiple almost PRs for Promtail and for the Grafana Agent, but receiving syslog events via UDP is still not working. A lot of (hardware and software) appliances are still unable to use UDP as a transport protocol for syslog, fixing this would be greatly appreciated by a lot of people (including me and my colleagues)! |
Describe the bug
Promtail will not deliver "Syslog UDP" logs to Loki, but "Syslog TCP" logs works fine.
To Reproduce
Steps to reproduce the behavior:
Try to send some logs using UDP, I've used this example or real hardware switches which only support UDP syslog
https://gist.github.com/xtavras/4a01f7d1f94237a4abcdfb02074453c1
I can see in tcpdump that logs are coming to promtail machine, but nothing in Loki. I've tried to run promtail with debug option but don't see any additional errors.
2. Enable "tcp" as "listen_protocol" (it's default), e.g.
Send logs using tcp, I've used this example
https://gist.github.com/xtavras/be13760713e2a9ee1a8bdae2ed6d2565
Logs are visible in tcpdump and are coming and visible in Loki.
Expected behavior
Logs sent to UDP syslogs should be delivered to Loki same way as TCP syslogs
Environment:
Screenshots, Promtail config, or terminal output
Promtail config
The text was updated successfully, but these errors were encountered: