Skip to content

Commit

Permalink
big refactoring, following consistent format
Browse files Browse the repository at this point in the history
Signed-off-by: Juraci Paixão Kröhling <[email protected]>
  • Loading branch information
jpkrohling committed May 28, 2024
1 parent 201cf85 commit e4e5695
Show file tree
Hide file tree
Showing 73 changed files with 490 additions and 380 deletions.
12 changes: 9 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Contributing your recipes
# 🍚 Contributing your recipes

Do you have a cool recipe to contribute? That's great! Just open a PR with your
configuration YAML, along with a description on the readme file.
Do you have a cool recipe to contribute? That's great! Here's what I look for when reviewing a contribution:

- Keep a narrow focus and demonstrate one concept or integration
- The recipe has to be reproducible for everyone
- Specify the versions of the software you used for testing the recipe
- It should be self-contained. It might reference other recipes, but everything needed to succeed is included in the recipe itself
- Unless you are demonstrating a specific exporter, export the telemetry to Grafana Cloud for consistency with the other recipes
- Recipes featuring other commercial vendors are OK as long as they can be reproduced by everyone with a free account. If the main purpose of the recipe is to show how to export data to this vendor, propose one that is similar to [`grafana-cloud`](./grafana-cloud/)
40 changes: 22 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
# OpenTelemetry Collector Recipes by jpkrohling
# 🧑🏼‍🍳🍲 OpenTelemetry Collector Cookbook

This repository has a personal collection of OpenTelemetry Collector recipes curated by [@jpkrohling](https://github.com/jpkrohling).

**Note** that only the recipes referenced in the README files were tested. The others are provided as-is, and may not work.
## 📔 Recipes

## Recipes
Each directory in this repository is a recipe and has an appropriate readme file with instructions.

The recipes are organized in the following categories:
This repository grew organically based on tests that I needed to perform in order to verify a bug report, create an example configuration for a Grafana Labs customer, or prepare for a presentation. As such, quite a few recipes lack good descriptions and running instructions. Those recipes are found under ["ratatouille"](./ratatouille/).

* [Simple](recipes/simple/README.md#simple-recipes): simple recipes that can be used as a starting point for more complex scenarios
* [Grafana](recipes/grafana/): recipes to use with Grafana products and projects, including Loki, Tempo, Mimir, and Grafana Cloud
* [Kubernetes](recipes/kubernetes/): recipes to use on Kubernetes, including the Operator
* [Load balancing](recipes/load-balancing/): recipes to use with the load balancing exporter
* [OTTL](recipes/ottl/): recipes that use components featuring OpenTelemetry Transformation Language (OTTL)
* [Routing](recipes/routing/): recipes to use with the routing processor
* [Tail-sampling](recipes/tail-sampling/): recipes to use with the tail-sampling processor
# 🥢 Tools used

# Pre-requisites
- [`telemetrygen`](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/cmd/telemetrygen#installing) is used a lot in this repository to send telemetry data to our Collector instance
- [`otelcol-contrib`](https://github.com/open-telemetry/opentelemetry-collector-releases/releases) is used as well, both in binary format for local examples, and as container image in examples using Kubernetes
- [`k3d`](https://k3d.io) is used in the Kubernetes recipes, in order to create a local Kubernetes cluster
- [OpenTelemetry Operator](https://github.com/open-telemetry/opentelemetry-operator) is used in most Kubernetes recipes. See the setup instructions below
- `kubens` from the [`kubectx`](https://github.com/ahmetb/kubectx) project

Most of the recipes send data to the Collector using the [`telemetrygen`](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/cmd/telemetrygen#installing) command-line tool.
## 🍴 OpenTelemetry Operator

Unless otherwise specified, the recipes will work with the contrib distribution of the collector, which can be started like this:
To get a working instance of the OpenTelemetry Operator, [follow the official instructions](https://github.com/open-telemetry/opentelemetry-operator?tab=readme-ov-file#getting-started) from the project, but here's a quick summary of what's needed for our purposes:

```commandline
otelcol-contrib --config recipes/simple/simplest.yaml
```terminal
k3d cluster create
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/latest/download/cert-manager.yaml
kubectl wait --for=condition=Available deployments/cert-manager -n cert-manager
kubectl apply -f https://github.com/open-telemetry/opentelemetry-operator/releases/latest/download/opentelemetry-operator.yaml
kubectl wait --for=condition=Available deployments/opentelemetry-operator-controller-manager -n opentelemetry-operator-system
```

# Bugs
# 🪳 Bugs

Did you find a bug? Is a recipe confusing, or not working at all? Please [open an issue](https://github.com/jpkrohling/otelcol-configs/issues/new). Make sure to include:
Did you find a bug? Is a recipe confusing, or not working at all? Please [open an issue](https://github.com/jpkrohling/otelcol-cookbook/issues/new). Make sure to include:

- the recipe name
- the command you used to run the recipe
Expand Down
54 changes: 54 additions & 0 deletions grafana-cloud-from-kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 🍜 Recipe: Grafana Cloud from Kubernetes

This recipe shows how to send telemetry data to Grafana Cloud with the OpenTelemetry Collector running on a Kubernetes Cluster. This is very similar to the ["grafana-cloud"](../grafana-cloud/) recipe, with extra steps to make it run on Kubernetes. You are encouraged to try that one first if you are not familiar with the Collector or sending data to Grafana Cloud via OTLP.

One interesting aspect of this recipe is that it keeps the credentials on a secret, mounting them as environment variables. This way, the secrets aren't exposed in plain-text.

## 🧄 Ingredients

- OpenTelemetry Operator, see the main [`README.md`](../README.md) for instructions
- The `telemetrygen` tool, or any other application that is able to send OTLP data to our collector
- The `otelcol-cr.yaml` file from this directory
- A `GRAFANA_CLOUD_USER` environment variable, also known as Grafana Cloud instance ID, found under the instructions for "OpenTelemetry" on your Grafana Cloud stack.
- A `GRAFANA_CLOUD_TOKEN` environment variable, which can be generated under the instructions for "OpenTelemetry" on your Grafana Cloud stack.
- The endpoint for your stack

## 🥣 Preparation

1. Create and switch to a namespace for our recipe
```terminal
kubectl create ns grafana-cloud-from-kubernetes
kubens grafana-cloud-from-kubernetes
```

2. Create a secret with the credentials:
```terminal
kubectl create secret generic grafana-cloud-credentials --from-literal=GRAFANA_CLOUD_USER="..." --from-literal=GRAFANA_CLOUD_TOKEN="..."
```

3. Change the `endpoint` parameter for the `otlphttp` exporter to point to your stack's endpoint

4. Install the OTel Collector custom resource
```terminal
kubectl apply -f grafana-cloud-from-kubernetes/otelcol-cr.yaml
```

5. Open a port-forward to the Collector:
```terminal
kubectl port-forward svc/grafana-cloud-from-kubernetes-collector 4317
```

6. Send some telemetry to your Collector
```terminal
telemetrygen traces --traces 2 --otlp-insecure --otlp-attributes='recipe="grafana-cloud-from-kubernetes"'
```

7. Open your Grafana instance, go to Explore, and select the appropriate datasource, such as "...-traces". If used the command above, click "Search" and you should see two traces listed, each with two spans.

## 😋 Executed last time with these versions

The most recent execution of this recipe was done with these versions:

- OpenTelemetry Operator v0.100.1
- OpenTelemetry Collector Contrib v0.101.0
- `telemetrygen` v0.101.0
42 changes: 42 additions & 0 deletions grafana-cloud-from-kubernetes/otelcol-cr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
name: grafana-cloud-from-kubernetes
spec:
image: ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-contrib:0.101.0
envFrom:
- secretRef:
name: grafana-cloud-credentials
config:
extensions:
basicauth:
client_auth:
username: "${env:GRAFANA_CLOUD_USER}"
password: "${env:GRAFANA_CLOUD_TOKEN}"

receivers:
otlp:
protocols:
grpc: {}

exporters:
otlphttp:
endpoint: https://otlp-gateway-prod-eu-west-2.grafana.net/otlp
auth:
authenticator: basicauth

service:
extensions: [ basicauth ]
pipelines:
traces:
receivers: [ otlp ]
processors: [ ]
exporters: [ otlphttp ]
logs:
receivers: [ otlp ]
processors: [ ]
exporters: [ otlphttp ]
metrics:
receivers: [ otlp ]
processors: [ ]
exporters: [ otlphttp ]
36 changes: 36 additions & 0 deletions grafana-cloud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 🍜 Recipe: Grafana Cloud

This recipe shows how to send telemetry data to Grafana Cloud with the OpenTelemetry Collector. The recommended way to send data for most use-cases is via the OTLP endpoint, given that the Collector already has an internal representation on that format. It's also better to send OTLP Logs via the OTLP endpoint to Grafana Cloud Logs, as it would appropriately place some values, such as the trace ID and span ID, on its new metadata storage, which isn't part of the message body or index.

## 🧄 Ingredients

- The `telemetrygen` tool, or any other application that is able to send OTLP data to our collector
- The `otelcol.yaml` file from this directory
- A `GRAFANA_CLOUD_USER` environment variable, also known as Grafana Cloud instance ID, found under the instructions for "OpenTelemetry" on your Grafana Cloud stack.
- A `GRAFANA_CLOUD_TOKEN` environment variable, which can be generated under the instructions for "OpenTelemetry" on your Grafana Cloud stack.
- The endpoint for your stack

## 🥣 Preparation

1. Change the `endpoint` parameter for the `otlphttp` exporter to point to your stack's endpoint

2. Export the environment variables `GRAFANA_CLOUD_USER` and `GRAFANA_CLOUD_TOKEN`

3. Run a Collector distribution with the provided configuration file
```terminal
otelcol-contrib --config otelcol.yaml
```

4. Send some telemetry to your Collector
```terminal
telemetrygen traces --traces 2 --otlp-insecure --otlp-attributes='recipe="grafana-cloud"'
```

5. Open your Grafana instance, go to Explore, and select the appropriate datasource, such as "...-traces". If used the command above, click "Search" and you should see two traces listed, each with two spans.

## 😋 Executed last time with these versions

The most recent execution of this recipe was done with these versions:

- OpenTelemetry Collector Contrib v0.101.0
- `telemetrygen` v0.101.0
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ extensions:
username: "${env:GRAFANA_CLOUD_USER}"
password: "${env:GRAFANA_CLOUD_TOKEN}"

processors:
batch:

receivers:
otlp:
protocols:
grpc:

exporters:
otlphttp:
endpoint: https://otlp-gateway-prod-us-central-0.grafana.net/otlp
endpoint: https://otlp-gateway-prod-eu-west-2.grafana.net/otlp
auth:
authenticator: basicauth

Expand All @@ -25,3 +22,11 @@ service:
receivers: [ otlp ]
processors: [ ]
exporters: [ otlphttp ]
logs:
receivers: [ otlp ]
processors: [ ]
exporters: [ otlphttp ]
metrics:
receivers: [ otlp ]
processors: [ ]
exporters: [ otlphttp ]
72 changes: 72 additions & 0 deletions kafka-on-kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 🍜 Recipe: Kafka on Kubernetes

This recipe uses a Kafka cluster between two layers of Collectors, showing how to scale a collection pipeline that is able to absorb spikes in traffic without putting extra pressure on the backend. The idea is that the first layer might scale according to the demand, sending data to Kafka, which is consumed by a static set of Collectors. This architecture is suitable for scaling Collectors when the backend can eventually catch-up with the traffic, as is usually the case with sudden spikes.

Note that we've used the `transform` processor to add the current timestamp to all spans at both layers (`published_at` and `consumed_at`), so that we know when we sent something to the queue, and when we've consumed it from the queue.

## 🧄 Ingredients

- OpenTelemetry Operator, see the main [`README.md`](../README.md) for instructions
- A Kafka Cluster and one topic for each telemetry data type (metric, logs, traces)
- The `telemetrygen` tool, or any other application that is able to send OTLP data to our collector
- The `otelcol-cr.yaml` file from this directory
- A `GRAFANA_CLOUD_USER` environment variable, also known as Grafana Cloud instance ID, found under the instructions for "OpenTelemetry" on your Grafana Cloud stack.
- A `GRAFANA_CLOUD_TOKEN` environment variable, which can be generated under the instructions for "OpenTelemetry" on your Grafana Cloud stack.
- The endpoint for your stack

## 🥣 Preparation

1. Install [Strimzi](https://strimzi.io), a Kubernetes Operator for Kafka
```terminal
kubectl create ns kafka
kubens kafka
kubectl create -f 'https://strimzi.io/install/latest?namespace=kafka'
kubectl wait --for=condition=Available deployments/strimzi-cluster-operator --timeout=300s
```
2. Install the Kafka cluster and topics for our recipe
```terminal
kubectl apply -f kafka-for-otelcol.yaml
kubectl wait kafka/kafka-for-otelcol --for=condition=Ready --timeout=300s
```
3. Create and switch to a namespace for our recipe
```terminal
kubectl create ns kafka-on-kubernetes
kubens kafka-on-kubernetes
```
4. Create a secret with the credentials:
```terminal
kubectl create secret generic grafana-cloud-credentials --from-literal=GRAFANA_CLOUD_USER="..." --from-literal=GRAFANA_CLOUD_TOKEN="..."
```

5. Create the OTel Collector custom resources that publishes to and consumes from the Kafka topic
```terminal
kubectl apply -f otelcol-pub.yaml
kubectl apply -f otelcol-sub.yaml
kubectl wait --for=condition=Available deployments/otelcol-pub-collector
kubectl wait --for=condition=Available deployments/otelcol-sub-collector
```
6. Open a port-forward to the Collector that is publishing to Kafka:
```terminal
kubectl port-forward svc/otelcol-pub-collector 4317
```

7. Send some telemetry to your Collector
```terminal
telemetrygen traces --traces 2 --otlp-insecure --otlp-attributes='recipe="kafka-on-kubernetes"'
```

8. Open your Grafana instance, go to Explore, and select the appropriate datasource, such as "...-traces". If used the command above, click "Search" and you should see two traces listed, each with two spans.

## 😋 Executed last time with these versions

The most recent execution of this recipe was done with these versions:

- Strimzi v0.41.0
- OpenTelemetry Operator v0.100.1
- OpenTelemetry Collector Contrib v0.101.0
- `telemetrygen` v0.101.0
63 changes: 63 additions & 0 deletions kafka-on-kubernetes/kafka-for-otelcol.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaNodePool
metadata:
name: dual-role
labels:
strimzi.io/cluster: kafka-for-otelcol
spec:
replicas: 1
roles:
- controller
- broker
storage:
type: jbod
volumes:
- id: 0
type: persistent-claim
size: 100Gi
deleteClaim: false
kraftMetadata: shared
---
apiVersion: kafka.strimzi.io/v1beta2
kind: Kafka
metadata:
name: kafka-for-otelcol
annotations:
strimzi.io/node-pools: enabled
strimzi.io/kraft: enabled
spec:
kafka:
version: 3.7.0
metadataVersion: 3.7-IV4
config:
offsets.topic.replication.factor: 1
transaction.state.log.replication.factor: 1
transaction.state.log.min.isr: 1
default.replication.factor: 1
min.insync.replicas: 1
listeners:
- name: plain
port: 9092
type: internal
tls: false
---
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaTopic
metadata:
name: otlp-spans
labels:
strimzi.io/cluster: kafka-for-otelcol
---
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaTopic
metadata:
name: otlp-metrics
labels:
strimzi.io/cluster: kafka-for-otelcol
---
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaTopic
metadata:
name: otlp-logs
labels:
strimzi.io/cluster: kafka-for-otelcol
Loading

0 comments on commit e4e5695

Please sign in to comment.