Closed lyudmilalala closed 1 year ago
I am trying to collect logs from a python flask function, and hope I can retain them as log files on disk, which will rotate once a day. During this process, I find that:
Hi, it sounds like you could solve your problem by:
kubectl logs
- rotation is automatic, and you can specify a "since" valueFunction Pods (replicas) come and go often, you shouldn't be writing anything to disk and expecting it to still be there at a future date.
Alex
/set title: Support question on log aggregation
/add label: support
I am trying to collect logs from a python flask function, and hope I can retain them as log files on disk, which will rotate once a day. During this process, I find that:
Hi, it sounds like you could solve your problem by:
- Using
kubectl logs
- rotation is automatic, and you can specify a "since" value- A log aggregation solution like logz.io or Grafana Loki
Function Pods (replicas) come and go often, you shouldn't be writing anything to disk and expecting it to still be there at a future date.
Alex
Thanks for quick response, @alexellis .
I am not going to save logs on the specific worker node running the pod. I am just thinking about collecting logs to a NFS system or something similar, as I am not familiar with ES or Grafana.
Any idea on the reason why I cannot see logs by kubectl logs
or faas-cli logs
?
You'll usually see logs for pods which still exist, so long as they haven't been deleted.
For long term aggregation, I'd suggest using whatever your cloud provider makes available, or Loki or perhaps logz.io
In a default installation - faas-cli logs maps to kubectl logs.
So the current problem now is that my faas-cli logs
and kubectl logs
do not show logs.
Could you please take a look at the current behavior section and the steps to reproduce section of the issue to see what I did wrong?
My actions before raising this issue
This is more a question rather than an issue.
I am trying to collect logs from a python flask function, and hope I can retain them as log files on disk, which will rotate once a day. During this process, I find that:
faas-cli logs <func_name>
, I can only see logs bydocker logs <container_name>
.How someone could tell me how to implement the log collection correctly.
A further question is that, if collecting logs to a file system is unrealistic, do I need to make sure my logs can be shown by
faas-cli logs <func_name>
before trying to collect it by Elastic Search or Grafana Loki? I am not familiar with these two things.Expected Behaviour
Some logs show when running
faas-cli logs flask-faas
orkubectl logs XXX
Current Behaviour
Run
faas-cli logs flask-faas
shows nothingRun
kubectl logs flask-faas-57f6449bbd-z5cld -n openfaas-fn
shows an error. I am not sure if it is related with openfaas or not.Only when using
docker logs
the logger and stdout/stderr works (2ef3e197a8b1 is the id of the function container).If I add
PYTHONUNBUFFERED=1
as mentioned in this post, the docker log includes print and stdout information as shown below, but thefaas-cli logs
andkubectl logs
are still the same, giving no useful logs.Steps to Reproduce (for bugs)
Create a function by template. I am using the flask template with of-watchdog:0.9.10.
Overwrite the
handler.py
in theflask-faas
folder.Overwrite the
flask-faas.yml
192.168.1.124
is my local IP.Start the function.
Call the function with
curl
.Your Environment
FaaS-CLI version ( Full output from:
faas-cli version
): 0.14.2Docker version
docker version
(e.g. Docker 17.0.05 ): docker version 20.10.11Are you using Docker Swarm or Kubernetes (FaaS-netes)? FaaS-netes with tag 0.16.4, k8s version v1.22.4
Operating System and version (e.g. Linux, Windows, MacOS): Windows 10 64-bit, Docker Desktop 4.3.0 with kind
Code example or link to GitHub repo or gist to reproduce problem:
Other diagnostic information / logs from troubleshooting guide
Docs and posts about logging I have gone through
I did not find much about customized log provider. Also, because I am considering to move some of my business from python to c++ for performance improvement, I want to know more about logging for customized docker image with of-watchdog. (In my case, I use a pistachio server behind of-watchdog, and don't whether I should use a log library or just stdout logs.) I hope to see more documentations about them.
Next steps
You may join Slack for community support.