Skip to content

Commit

Permalink
Add Grafana Loki example (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vunovati authored Sep 8, 2023
1 parent 1b0a333 commit 7652365
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ Observe the logs
Note that not all log entries will immediately be written to the `otlp-logs.log` file. The collector will flush to the disk eventually. The flush will be forced if the collector receives a kill signal.

## Examples
[HTTP Server with trace context propagation](./examples/trace-context)
* [HTTP Server with trace context propagation](./examples/trace-context)
* [Sending logs to Grafana Loki](./examples/grafana-loki)

## Options

Expand Down
34 changes: 34 additions & 0 deletions examples/grafana-loki/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Sending logs to Grafana Loki

```mermaid
graph LR;
pino["Pino Opentelemetry Transport"]
otel["OTEL Collector"]
loki["Loki"]
grafana["Grafana"]
pino-->otel;
otel-->loki;
loki-->grafana;
```

## Running the example

### Local infrastructure

Run the required infra locally with
`docker compose up`

It will boot [Grafana](https://grafana.com/docs/grafana/latest/), [Loki](https://grafana.com/docs/loki/latest/) and an [Opentelemetry Collector](https://opentelemetry.io/docs/collector/).

Loki ingester readiness can be checked at
[http://localhost:3100/ready](http://localhost:3100/ready).

The logs can be inspected in Grafana UI at
[http://localhost:3000/explore](http://localhost:3000/explore).

[This article](https://grafana.com/docs/opentelemetry/visualization/loki-data/) explains how to inspect OTLP data in the Grafana UI.

### Generating logs
Run the [trace-context](../trace-context) example, but skip the `docker compose up` part


58 changes: 58 additions & 0 deletions examples/grafana-loki/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: "3"

networks:
loki:

services:
loki:
image: grafana/loki:2.9.0
ports:
- "3100:3100"
command: -config.file=/etc/loki/local-config.yaml
networks:
- loki

grafana:
environment:
- GF_PATHS_PROVISIONING=/etc/grafana/provisioning
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
entrypoint:
- sh
- -euc
- |
mkdir -p /etc/grafana/provisioning/datasources
cat <<EOF > /etc/grafana/provisioning/datasources/ds.yaml
apiVersion: 1
datasources:
- name: Loki
type: loki
access: proxy
orgId: 1
url: http://loki:3100
basicAuth: false
isDefault: true
version: 1
editable: false
EOF
/run.sh
image: grafana/grafana:latest
ports:
- "3000:3000"
networks:
- loki
depends_on:
- loki

otel-collector:
image: otel/opentelemetry-collector-contrib:latest
command: ["--config=/etc/otel-collector-config.yaml"]
volumes:
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
- /tmp/test-logs:/etc/test-logs
ports:
- "4317:4317" # OTLP gRPC receiver
networks:
- loki
depends_on:
- loki
19 changes: 19 additions & 0 deletions examples/grafana-loki/otel-collector-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
receivers:
otlp:
protocols:
grpc:

exporters:
loki:
endpoint: http://loki:3100/loki/api/v1/push

processors:
batch:

service:
pipelines:
logs:
receivers: [otlp]
processors: []
exporters: [loki]

0 comments on commit 7652365

Please sign in to comment.