Skip to content

Commit

Permalink
clean up the docker compose example environment (grafana#1456)
Browse files Browse the repository at this point in the history
The various docker-compose.*.yaml files have been replaced with a single
docker-compose.yaml file.

By default, this file will spawn and expose ports for Loki, Grafana,
Tempo, and Cortex so telemetry data can be stored and visualized. This
allows developers to bring up dependencies needed for testing a local
Grafana Agent process, useful for validating code changes.

Version 3 of Docker Compose is used for profile support, allowing
docker-compose.yaml to optionally run extra services:

* The `agent` profile will also run a Grafana Agent that collects
  metrics from itself and sends them to Cortex.

* The `integrations` profile will run example services that integrations
  can target, such as MySQL and Consul. Each of these `integrations`
  services can also be enabled independently by using the profile name
  matching the relevant integration name (i.e., the `mysqld_exporter`
  profile enables the MySQL service). All integration services will
  expose their ports for a local agent to connect to.
  • Loading branch information
rfratto committed Mar 3, 2022
1 parent cb43f6b commit 5fa5831
Show file tree
Hide file tree
Showing 17 changed files with 351 additions and 825 deletions.
2 changes: 0 additions & 2 deletions docs/user/scraping-service/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ metrics:

Note that there are no instance configs present in this example; instance
configs must be passed to the API for the Agent to start scraping metrics.
See [the docker-compose Scraping Service Example](https://github.com/grafana/agent/blob/main/example/docker-compose/docker-compose.scraping-service.yaml)
for how to run a Scraping Service Agent cluster locally.

## agentctl

Expand Down
90 changes: 36 additions & 54 deletions example/docker-compose/README.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,56 @@
# Example

This directory contains an example deployment of the Grafana Agent with
the following components:
This directory contains a Docker Compose 3 environment that can be used to test
Grafana Agent.

1. Cortex to store metrics
2. Grafana Agent to collect metrics
3. Grafana to visualize metrics
4. Avalanche to load test the Agent.
By default, the following services are exposed:

This example is used for seeing how a single instance of the Agent performs
under moderate load; the Docker Compose configuration as present in this
directory will generate roughly 90,000 metrics.
1. Cortex for storing metrics (localhost:9009)
2. Grafana for visualizing telemetry (localhost:3000)
3. Loki for storing logs (localhost:3100)
4. Tempo for storing traces (localhost:3200)
5. Avalanche for a sample /metrics endpoint to scrape (localhost:9001).

To get started, run the following from this directory:
Run the following to bring up the environment:

```
docker-compose up -d
```

This will create Cortex storage in `/tmp/cortex` and the agent WAL in
`/tmp/agent`; you may want to delete those directories after you are done
testing.
By default, the Docker Compose environment doesn't include a Grafana Agent
container. This lets you test the agent externally, especially useful when
validating code changes. You can enable the included Grafana Agent by passing
`agent` to the profiles list: `docker compose --profile=agent up -d`. When
running, the Agent exposes its HTTP endpoint at localhost:12345.

Once the containers are running, a Grafana instance will be exposed at
`http://localhost:3000` with Cortex as the only datasource. You should shortly
see metrics in Cortex that are sent from the agent. Agent operational dashboards
are included in the deployment.
The Docker Compose environment heavily relies on profiles to enable optional
features. You can pass multiple profiles by separating them by comma:
`docker compose --profile=agent,integrations up -d`.

The Agent is exposed on the host at `http://localhost:12345`.
## Running Integrations

## Hacking on the Example
The Docker Compose environment includes example services to point integrations
at (e.g., mysql, redis, consul, etc.). You can run all integrations using the
`integrations` profile, or run individual services with a profile name matching
the integration (i.e., enabling the `dnsmasq_exporter` profile to specifically
enable the dnsmasq service).

The reduced memory requirements is a critical feature of the Agent, and
the example provides a good launching point to end-to-end test and validate
the usage.
Enabling specific integration profiles is useful when you only want to test a
single integration, as the `integrations` profile can be resource intensive.

To build the image locally, run `make agent-image` at the root of this
repository.
## Visualizing

To get a memory profile, you can use `pprof` against the Agent:
Grafana is exposed at `http://localhost:3000`, and includes some useful
dashboards:

```
go tool pprof -http=:6060 http://localhost:12345/debug/pprof/heap?debug=1
```

Useful one-off queries to run once everything is up:

1. `agent_wal_storage_active_series`: How many series are active in the WAL
2. `cortex_ingester_memory_series`: How many series are active in Cortex.
Should be equal to the previous metric.
3. `go_memstats_heap_inuse_bytes{container="agent"} / 1e6`: Current memory
usage of agent in megabytes.
4. `max by (container,instance,job)
(avg_over_time(go_memstats_heap_inuse_bytes[10m])) / 1e6`: Current memory
usage of the agent and Cortex averaged out from the last 10 minutes.
* The `Agent` dashboard gives a very high-level overview of running agents.

## Scraping Service

A [Scraping Service](https://grafana.com/docs/agent/latest/scraping-service/) cluster example is also
present in this directory. To start it, run:

```
docker-compose -f docker-compose.scraping-service.yaml up -d
```
* The `Agent Prometheus Remote Write` dashboard visualizes the current state of
writing metrics to Cortex.

The Scraping Service cluster will start with an empty KV store for instance
configurations. A set of instance configuration files is provided in
[`agent/instance-configs`](./agent/instance-configs) that will work with the
Docker Compose example.
* The `Agent Tracing Pipeline` dashbaord visualizes the current state of the
tracing pipeline (if spans are being processed).

The `agentctl` tool provided by this repository can automatically deploy
those configs for you; run `agentctl config-sync -a http://localhost:12345 ./agent/instance-configs`
from this directory to do so.
* The `Agent Operational` dashboard shows resource consumption of Grafana
Agent. Not all panels will have data here, as they rely on metrics from other
sources (i.e., cAdvisor).
23 changes: 0 additions & 23 deletions example/docker-compose/agent/config/agent-integrations-next.yaml

This file was deleted.

94 changes: 0 additions & 94 deletions example/docker-compose/agent/config/agent-local.yaml

This file was deleted.

62 changes: 0 additions & 62 deletions example/docker-compose/agent/config/agent-scraping-service.yaml

This file was deleted.

Loading

0 comments on commit 5fa5831

Please sign in to comment.