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

Documentation Rewrite #982

Merged
merged 72 commits into from
Sep 25, 2019
Merged
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
a2de08c
docs: create structure of docs overhaul
rfratto Sep 6, 2019
45bab6f
docs: add design docs back in
rfratto Sep 6, 2019
00619ef
docs: add community documentation
rfratto Sep 6, 2019
645762a
docs: add LogQL docs
rfratto Sep 6, 2019
7690e1d
docs: port existing operations documentation
rfratto Sep 9, 2019
d8ae8e8
docs: add new placeholder file for promtail configuration docs
rfratto Sep 9, 2019
0b3dff8
docs: add TOC for operations/storage
rfratto Sep 9, 2019
29c1df3
docs: add Loki API documentation
rfratto Sep 9, 2019
3a04846
docs: port troubleshooting document
rfratto Sep 9, 2019
ae76437
docs: add docker-driver documentation
rfratto Sep 10, 2019
3a3bebe
docs: link to configuration from main docker-driver document
rfratto Sep 10, 2019
dd4f217
docs: update API for new paths
rfratto Sep 10, 2019
67f104b
docs: fix broken links in api.md and remove json marker from examples
rfratto Sep 10, 2019
7720827
docs: incorporate api changes from #1009
rfratto Sep 11, 2019
3e76241
docs: port promtail documentation
rfratto Sep 12, 2019
01c4b72
docs: add TOC to promtail configuration reference
rfratto Sep 12, 2019
0e5a408
docs: fix promtail spelling errors
rfratto Sep 12, 2019
dfa8b6b
docs: add loki configuration reference
rfratto Sep 12, 2019
8b8d7cc
docs: add TOC to configuration
rfratto Sep 12, 2019
f0c9cf1
docs: add loki configuration example
rfratto Sep 13, 2019
938a679
docs: add Loki overview with brief explanation about each component
rfratto Sep 13, 2019
2a08cfa
docs: add comparisons document
rfratto Sep 13, 2019
0e0f526
docs: add info on table manager and update storage/README.md
rfratto Sep 13, 2019
564dcbd
docs: add getting started
rfratto Sep 16, 2019
0821f38
docs: incorporate config yaml changes from #755
rfratto Sep 16, 2019
398f4e1
docs: fix typo in releases url for promtail
rfratto Sep 17, 2019
d4f2e98
docs: add installation instructions
rfratto Sep 17, 2019
dd979d6
docs: add more configuration examples
rfratto Sep 17, 2019
de50e45
docs: add information on fluentd client
rfratto Sep 17, 2019
9cf01a4
docs: PR review feedback
rfratto Sep 17, 2019
7291b2c
docs: add architecture document
rfratto Sep 18, 2019
276bdae
docs: add missing information from old docs
rfratto Sep 18, 2019
f23fd99
`localy` typo
rfratto Sep 18, 2019
c12c929
docs: s/ran/run/g
rfratto Sep 18, 2019
0e6f789
Typo
pstibrany Sep 19, 2019
fe09d98
Typo
pstibrany Sep 19, 2019
e0015b1
Tyop
pstibrany Sep 19, 2019
6961bd9
Typo
pstibrany Sep 19, 2019
1c2d1c3
docs: fixed typo
pstibrany Sep 19, 2019
133796a
docs: PR feedback
rfratto Sep 19, 2019
c7b6b76
docs: @cyriltovena PR feedback
rfratto Sep 19, 2019
00357fe
docs: add more details to promtail url config option
rfratto Sep 20, 2019
b9c45bd
docs: expand promtail's pipelines document with extra detail
rfratto Sep 20, 2019
3fe341f
docs: fixed some spelling
pstibrany Sep 20, 2019
7a447f9
docs: remove reference to Stage interface in pipelines.md
rfratto Sep 20, 2019
012dc06
docs: clarify promtail configuration and scraping
rfratto Sep 20, 2019
5b9226f
docs: attempt #2 at explaining promtail's usage of machine hostname
rfratto Sep 20, 2019
5c0f523
docs: spelling fixes
pstibrany Sep 20, 2019
4034a3e
docs: add reference to promtail custom metrics and fix silly typo
rfratto Sep 20, 2019
bd4b360
docs: cognizant -> aware
rfratto Sep 20, 2019
dc893fa
docs: typo
pstibrany Sep 20, 2019
3bbaf35
docs: typos
pstibrany Sep 20, 2019
9d76dc1
docs: add which components expose which API endpoints in microservice…
rfratto Sep 20, 2019
e946c19
docs: change ksonnet installation to tanka
rfratto Sep 20, 2019
84d97dd
docs: address most @pracucci feedback
rfratto Sep 23, 2019
d3384bb
docs: fix all spelling errors so reviewers don't have to keep finding…
rfratto Sep 23, 2019
d0026d5
docs: incorporate changes to API endpoints made in #1022
rfratto Sep 23, 2019
48f75ef
docs: add missing loki metrics
rfratto Sep 23, 2019
87139c2
docs: add missing promtail metrics
rfratto Sep 23, 2019
fce9154
docs: @pstribrany feedback
rfratto Sep 24, 2019
a733358
docs: more @pracucci feedback
rfratto Sep 24, 2019
723dfde
docs: move metrics into a table
rfratto Sep 24, 2019
43168b9
docs: update push path references to /loki/api/v1/push
rfratto Sep 24, 2019
bb0eb6e
docs: add detail to further explain limitations of monolithic mode
rfratto Sep 24, 2019
b00c91d
docs: add alternative names to modes_of_operation diagram
rfratto Sep 24, 2019
7cc7bfd
docs: add log ordering requirement
rfratto Sep 24, 2019
d00243d
docs: add procedure for updating docs with latest version
rfratto Sep 24, 2019
65254ac
docs: separate out stages documentation into one document per stage
rfratto Sep 24, 2019
5852035
docs: list supported stores in storage documentation
rfratto Sep 25, 2019
13086c5
docs: add info on duplicate log lines in pipelines
rfratto Sep 25, 2019
5cc963e
docs: add line_format as key feature to fluentd
rfratto Sep 25, 2019
9c432f3
docs: hopefully final commit :)
rfratto Sep 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: add LogQL docs
  • Loading branch information
rfratto committed Sep 25, 2019
commit 645762a5befb7332dc08bf5ff7ed9621610075d2
160 changes: 159 additions & 1 deletion docs/logql.md
Original file line number Diff line number Diff line change
@@ -1 +1,159 @@
# Querying Loi
# LogQL: Log Query Language

Loki comes with its very own language for querying logs called *LogQL*. LogQL
can be considered a distributed `grep` with labels for extra querying control.
rfratto marked this conversation as resolved.
Show resolved Hide resolved

A basic LogQL query consists of two parts: the **log stream selector** and a
**filter expression**. Because of how Loki is designed, a set of log streams
must be selected using a [Prometheus](https://prometheus.io)-style log stream
rfratto marked this conversation as resolved.
Show resolved Hide resolved
selector.

The log stream selector will reduce the number of log streams to a manageable
volume. Depending how many labels you use to filter down the log streams will
affect the relative performance of the query's execution. The filter expression
is then used to do a distributed `grep` over the retrieved log streams.

### Log Stream Selector

The log stream selector determines which log streams should be included in your
query. The stream selector is comprised of one or more key-value pairs, where
each key is a **log label** and the value is that label's value.

The log stream selector is written by wrapping the key-value pairs in a
pair of curly braces:

```
{app="mysql",name="mysql-backup"}
```

In this example, log streams that have a label of `app` and `name` with exact
rfratto marked this conversation as resolved.
Show resolved Hide resolved
values of `mysql` and `mysql-backup` will be included in the query results.

The `=` operator after the label name is a **label matching operator**. The
following label matching operators are supported:

- `=`: exactly equal.
- `!=`: not equal.
- `=~`: regex matches.
- `!~`: regex does not match.

Examples:

- `{name=~"mysql.+"}`
- `{name!~"mysql.+"}`

The same rules that apply for [Prometheus Label
Selectors](https://prometheus.io/docs/prometheus/latest/querying/basics/#instant-vector-selectors)
apply for Loki log stream selectors.

### Filter Expression

After writing the log stream selector, the resulting set of logs can be filtered
further with a search expression. The search expression can be just text or
regex:

- `{job="mysql"} |= "error"`
- `{name="kafka"} |~ "tsdb-ops.*io:2003"`
- `{instance=~"kafka-[23]",name="kafka"} != kafka.server:type=ReplicaManager`

In the previous examples, `|=`, `|~`, and `!=` act as **filter operators** and
the following filter operators are supported:

- `|=`: Log line contains string.
- `!=`: Log line does not contain string.
- `|~`: Log line matches regular expression.
- `!~`: Log line does not match regular expression.

Filter operators can be chained and will sequentially filter down the
expression - resulting log lines must satisfy _every_ filter:

`{job="mysql"} |= "error" != "timeout"`

When using `|~` and `!~`,
[RE2 syntax](https://github.com/google/re2/wiki/Syntax) regex may be used. The
rfratto marked this conversation as resolved.
Show resolved Hide resolved
matching is case-sensitive by default and can be switched to case-insensitive
prefixing the regex with `(?i)`.

### Future Query Language Extensions
rfratto marked this conversation as resolved.
Show resolved Hide resolved

The query language is still under development to support more features, for
example:

- `AND` / `NOT` operators
- JSON accessors for filtering of JSON-structured logs
- Context (like `grep -C n`)

## Counting logs

LogQL also supports functions that wrap a query and allow for counting entries
per stream.

### Range Vector aggregation

LogQL shares the same [range vector](https://prometheus.io/docs/prometheus/latest/querying/basics/#range-vector-selectors)
concept from Prometheus, except the selected range of samples include a value of
1 for each log entry. An aggregation can be applied over the selected range to
transform it into an instance vector.

`rate` calculates the number of entries per second while `count_over_time`
rfratto marked this conversation as resolved.
Show resolved Hide resolved
counts the entries for each log stream within the range.

> `count_over_time({job="mysql"}[5m])`

This example counts all the log lines within the last five minutes for the
MySQL job.

> `rate( ( {job="mysql"} |= "error" != "timeout)[10s] ) )`

This example demonstrates that a fully LogQL query can be wrapped in the
aggregation syntax, including filter expressions. This example gets the
per-second rate of all non-timeout errors within the last ten seconds for the
MySQL job.

### Aggregation operators

Like [PromQL](https://prometheus.io/docs/prometheus/latest/querying/operators/#aggregation-operators),
LogQL supports a subset of built-in aggregation operators that can be used to
aggregate the element of a single vector, resulting in a new vector of fewer
elements but with aggregated values:

- `sum`: Calculate sum over labels
- `min`: Select minimum over labels
- `max`: Select maximum over labels
- `avg`: Calculate the average over labels
- `stddev`: Calculate the population standard deviation over labels
- `stdvar`: Calculate the population standard variance over labels
- `count`: Count number of elements in the vector
- `bottomk`: Select smallest k elements by sample value
- `topk`: Select largest k elements by sample value

The aggregation operators can either be used to aggregate over all label
values or a set of distinct label values by including a _without_ or a
rfratto marked this conversation as resolved.
Show resolved Hide resolved
_by_ clause:

> `<aggr-op>([parameter,] <vector expression>) [without|by (<label list>)]`

`parameter` is only required when using `topk` and `bottomk`. `topk` and
`bottomk` are different from other aggregators in that a subset of the input
samples, including the original labels, are returned in the result vector. `by`
and `without` are only used to group the input vector.

The `without` cause removes the listed labels from the resulting vector, keeping
all others. The `by` clause does the opposite, dropping labels that are not
listed in the clause, even if their label values are identical between all
elements of the vector.

#### Examples

> `topk(10,sum(rate({region="us-east1"}[5m]) by (name))`

Gets the top 10 applicaitons by the highest log throughput.

> `sum(count_over_time({job="mysql"}[5m])) by (level)`

Gets the count of logs during the last five minutes, grouping
by level.

> `avg(rate(({job="nginx"} |= "GET")[10s])) by (region)`

Gets the rate of HTTP GET requests from nginx logs.