Skip to content

Commit 85f9678

Browse files
authored
Merge pull request #24 from authzed/add-datadog-example
Add datadog example to examples repo
2 parents 7eae47e + b032ea8 commit 85f9678

File tree

9 files changed

+977
-0
lines changed

9 files changed

+977
-0
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
repos:
3+
- repo: "https://github.com/adrienverge/yamllint"
4+
rev: "v1.35.1"
5+
hooks:
6+
- id: "yamllint"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Spicedb Observability with the Datadog Agent
2+
3+
## Overview
4+
This is a repository that demonstrates a configuration of SpiceDB and the Datadog Agent
5+
that supports sending metrics and traces to Datadog. This is not the only valid configuration
6+
and should be adapted to your use case.
7+
8+
The metrics produced in this configuration are submitted as custom metrics. We're actively working
9+
on an official SpiceDB integration that would make the metrics into standard metrics and simplify
10+
setup and configuration.
11+
12+
### Running in Production
13+
A "real" deployment would use a container runtime of some sort. One approach would be to
14+
run the datadog agent as a sidecar; another would be to run a set of agents using
15+
the [Datadog Operator](https://docs.datadoghq.com/getting_started/containers/datadog_operator/)
16+
and then point them at your SpiceDB instances using [annotations](https://docs.datadoghq.com/containers/kubernetes/integrations).
17+
This repository is only intended to communicate the agent check configuration
18+
and the required SpiceDB configuration.
19+
20+
## Running this repo
21+
```
22+
mv placeholder.env .env
23+
```
24+
25+
Define your `DD_API_KEY` in the env file.
26+
27+
Run `docker compose up`.
28+
29+
### Thumper
30+
This is an internal load-testing tool that we built a while back. We use it in this project to
31+
exercise gRPC endpoints so that there are traces and metrics to look at.
32+
33+
## The Dashboard
34+
This is a preview of the dashboard that will be bundled with the SpiceDB Community integration.
35+
It shows throughput, latency, and some basic node CPU and memory metrics. Note that the CPU and memory
36+
metrics may be missing context from the container runtime environment, such as limits provided by kubernetes.
37+
38+
Also note that the dashboard uses the metrics exported by SpiceDB as histogram metrics, which Datadog then internally
39+
converts to its distribution-style metrics. There's likely some loss in resolution as a result; if this is a concern,
40+
and 100% of traces are being collected, it may make more sense to make the latency graphs reference the trace
41+
distribution supplied by Datadog.
42+
43+
To use the dashboard, grab `spicedb-dashboard.json` and import it into Datadog.
44+
45+
## Tracing
46+
SpiceDB supports OTLP export of traces. This is configured in the environment variables in `docker-compose.yml` on
47+
the `datadog` and `spicedb` services. Traces are pushed by SpiceDB to the Datadog agent via its OTLP endpoint,
48+
and then the agent forwards them to Datadog.
49+
50+
## Metrics
51+
SpiceDB exposes a Prometheus metrics endpoint on port 9090 by default. This can be scraped by the Datadog Agent
52+
using its Openmetrics integration, which is compatible with the Prometheus metrics format. The configuration is
53+
visible in `conf.d/openmetrics.d/conf.yaml`.
54+
55+
## Logs
56+
SpiceDB writes structured JSON logs to stdout, which can be collected through your normal log collection mechanisms.
57+
58+
### All Available Metrics
59+
The configuration in `conf.d/openmetrics.d/conf.yaml` currently only includes those metrics required to drive the dashboard.
60+
If additional metrics are desired, their names and descriptions can be found in `all_metrics.txt`.

observability/simple-datadog/all_metrics.txt

Lines changed: 788 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
init_config:
3+
service: "spicedb"
4+
5+
instances:
6+
- openmetrics_endpoint: "http://spicedb:9090/metrics"
7+
# Prefixes all of the metrics scraped by DD with `spicedb.`
8+
namespace: "spicedb"
9+
metrics:
10+
- grpc_server_handling_seconds:
11+
name: "grpc.server.handling"
12+
type: "histogram"
13+
- grpc_server_handled:
14+
name: "grpc.server.handled"
15+
type: "counter"
16+
# NOTE: for counter metrics that are suffixed by _total, you need to
17+
# remove the suffix for Datadog to pick it up correctly.
18+
- process_cpu_seconds:
19+
name: "process.cpu.seconds"
20+
type: "counter"
21+
- process_virtual_memory_bytes:
22+
name: "process.virtual_memory_bytes"
23+
type: "gauge"
24+
histogram_buckets_as_distributions: true
25+
min_collection_interval: 5
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
# We also don't care about logs
3+
process_config:
4+
container_collection:
5+
enabled: false
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
name: "metrics-adventure"
3+
4+
services:
5+
datadog:
6+
image: "datadog/agent"
7+
environment:
8+
DD_API_KEY: "${DD_API_KEY}"
9+
DD_HOSTNAME: "yetibox"
10+
11+
# NOTE: you can't set this via the config; it needs to come from environment variables.
12+
# These are the environment variables that enable collection via OTLP.
13+
DD_OTLP_CONFIG_RECEIVER_PROTOCOLS_GRPC_ENDPOINT: "0.0.0.0:4317"
14+
# Tells Datadog that we want to send along traces.
15+
# Additional variables would be needed for OTLP logging and metrics
16+
# if desired.
17+
DD_OTLP_CONFIG_TRACES_ENABLED: true
18+
volumes:
19+
- "./conf.d:/conf.d"
20+
- "./datadog.yaml:/datadog.yaml"
21+
22+
spicedb:
23+
image: "authzed/spicedb:v1.38.1"
24+
command: "serve"
25+
restart: "on-failure"
26+
environment:
27+
SPICEDB_GRPC_PRESHARED_KEY: "thisisnotasecret"
28+
SPICEDB_DATASTORE_ENGINE: &datastore_engine "postgres"
29+
SPICEDB_DATASTORE_CONN_URI: &datastore_conn_uri "postgres://postgres:secret@database:5432/spicedb?sslmode=disable"
30+
31+
# OTLP flags; this is how traces are sent to the Datadog agent.
32+
# This matches the receiver endpoint configured on the agent.
33+
SPICEDB_OTEL_ENDPOINT: "datadog:4317"
34+
# Whether to use HTTP or HTTPS
35+
SPICEDB_OTEL_INSECURE: true
36+
# Use gRPC for submission, since the DD agent supports it. `otlphttp`
37+
# is a valid option as well.
38+
SPICEDB_OTEL_PROVIDER: "otlpgrpc"
39+
# Send all traces. This defaults to 0.01 and should be tuned for your system.
40+
SPICEDB_OTEL_SAMPLE_RATIO: 1.0
41+
# The default is w3c, which datadog doesn't support. In order to get trace
42+
# propagation from a datadog-instrumented application, you'll need to
43+
# ensure that the APM is configured to attach b3 trace propagation header.
44+
SPICEDB_OTEL_TRACE_PROPAGATOR: "b3"
45+
ports:
46+
- "9090:9090"
47+
depends_on:
48+
- "spicedb-migrate"
49+
50+
spicedb-migrate:
51+
image: "authzed/spicedb:v1.38.1"
52+
command: "migrate head"
53+
restart: "on-failure"
54+
environment:
55+
SPICEDB_DATASTORE_ENGINE: *datastore_engine
56+
SPICEDB_DATASTORE_CONN_URI: *datastore_conn_uri
57+
depends_on:
58+
- "database"
59+
60+
# Load generation tooling. This is to ensure that there are metrics
61+
# and traces to look at.
62+
thumper:
63+
image: "authzed/thumper"
64+
command: "run --endpoint spicedb:50051 --token thisisnotasecret /scripts/example.yaml"
65+
depends_on:
66+
- "spicedb"
67+
- "thumper-init"
68+
# This runs the schema write for the subsequent load generation.
69+
thumper-init:
70+
image: "authzed/thumper"
71+
command: "migrate --endpoint spicedb:50051 --token thisisnotasecret /scripts/schema.yaml"
72+
# Restarting on failure should mean that the init reattempts until it succeeds
73+
restart: "on-failure"
74+
depends_on:
75+
spicedb:
76+
condition: "service_started"
77+
78+
database:
79+
image: "postgres:16"
80+
ports:
81+
- "5432:5432"
82+
environment:
83+
- "POSTGRES_PASSWORD=secret"
84+
- "POSTGRES_DB=spicedb"
85+
# This keeps postgres's data around when you bring the system down and back up
86+
volumes:
87+
- "pgdata:/var/lib/postgresql/data"
88+
89+
volumes:
90+
pgdata:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DD_API_KEY=

observability/simple-datadog/spicedb-dashboard.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)