-
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
Improve documentation based on what I learned when I did loki setup. #461
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b23c6ff
Improve documentation based on what I learned when I did loki setup.
garo 375ec5e
Fix typos
garo 15a3723
Fix underscores with Markdown rendering in Promtail examples
garo 9f5194f
Fix underscores with Markdown rendering in Promtail examples
garo 55b5be3
Clarify that Promtail can also be used outside kubernetes
garo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
## Promtail and scrape_configs | ||
|
||
Promtail is an agent which reads log files and sends streams of log data to | ||
the centralised Loki instances along with a set of labels. For example if you are running Promtail in Kubernetes | ||
then each container in a single pod will usually yield a single log stream with a set of labels | ||
based on that particular pod Kubernetes labels. You can also run Promtail outside Kubernetes, but you would | ||
then need to customise the scrape_configs for your particular use case. | ||
|
||
The way how Promtail finds out the log locations and extracts the set of labels is by using the *scrape_configs* | ||
section in the Promtail yaml configuration. The syntax is the same what Prometheus uses. | ||
|
||
The scrape_configs contains one or more *entries* which are all executed for each container in each new pod running | ||
in the instance. If more than one entry matches your logs you will get duplicates as the logs are sent in more than | ||
one stream, likely with a slightly different labels. Everything is based on different labels. | ||
The term "label" here is used in more than one different way and they can be easily confused. | ||
|
||
* Labels starting with __ (two underscores) are internal labels. They are not stored to the loki index and are | ||
invisible after Promtail. They "magically" appear from different sources. | ||
* Labels starting with \_\_meta_kubernetes_pod_label_* are "meta labels" which are generated based on your kubernetes | ||
pod labels. Example: If your kubernetes pod has a label "name" set to "foobar" then the scrape_configs section | ||
will have a label \_\_meta_kubernetes_pod_label_name with value set to "foobar". | ||
* There are other \_\_meta_kubernetes_* labels based on the Kubernetes metadadata, such as the namespace the pod is | ||
running (\_\_meta_kubernetes_namespace) or the name of the container inside the pod (\_\_meta_kubernetes_pod_container_name) | ||
* The label \_\_path\_\_ is a special label which Promtail will read to find out where the log files are to be read in. | ||
|
||
The most important part of each entry is the *relabel_configs* which are a list of operations which creates, | ||
renames, modifies or alters labels. A single scrape_config can also reject logs by doing an "action: drop" if | ||
a label value matches a specified regex, which means that this particular scrape_config will not forward logs | ||
from a particular log source, but another scrape_config might. | ||
|
||
Many of the scrape_configs read labels from \_\_meta_kubernetes_* meta-labels, assign them to intermediate labels | ||
such as \_\_service\_\_ based on a few different logic, possibly drop the processing if the \_\_service\_\_ was empty | ||
and finally set visible labels (such as "job") based on the \_\_service\_\_ label. | ||
|
||
In general, all of the default Promtail scrape_configs do the following: | ||
* They read pod logs from under /var/log/pods/$1/*.log. | ||
* They set "namespace" label directly from the \_\_meta_kubernetes_namespace. | ||
* They expect to see your pod name in the "name" label | ||
* They set a "job" label which is roughly "your namespace/your job name" | ||
|
||
### Idioms and examples on different relabel_configs: | ||
|
||
* Drop the processing if a label is empty: | ||
```yaml | ||
- action: drop | ||
regex: ^$ | ||
source_labels: | ||
- __service__ | ||
``` | ||
* Drop the processing if any of these labels contains a value: | ||
```yaml | ||
- action: drop | ||
regex: .+ | ||
separator: '' | ||
source_labels: | ||
- __meta_kubernetes_pod_label_name | ||
- __meta_kubernetes_pod_label_app | ||
``` | ||
* Rename a metadata label into anothe so that it will be visible in the final log stream: | ||
```yaml | ||
- action: replace | ||
source_labels: | ||
- __meta_kubernetes_namespace | ||
target_label: namespace | ||
``` | ||
* Convert all of the Kubernetes pod labels into visible labels: | ||
```yaml | ||
- action: labelmap | ||
regex: __meta_kubernetes_pod_label_(.+) | ||
``` | ||
|
||
|
||
Additional reading: | ||
* https://www.slideshare.net/roidelapluie/taking-advantage-of-prometheus-relabeling-109483749 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those part is a little duplicate with https://github.com/grafana/loki/blob/master/docs/troubleshooting.md#connecting-to-a-promtail-pod-to-troubleshoot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first (cannot find the location of your log files) reason was added based on the discussion on the slack where one user had this problem.
I added the second bullet based how I was personally hit with the fact that not all my streams were visible because I wasn't using compatible labels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "Connecting to a promtail pod to troubleshoot" is a good chapter with further explanation how to debug the subject. I feel that mentioning these two cases specifically adds valuable information.