Skip to content

Commit a8c39b6

Browse files
committed
Initial setup
1 parent de827d1 commit a8c39b6

File tree

10 files changed

+305
-0
lines changed

10 files changed

+305
-0
lines changed

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
[![tests](https://github.com/ddev/ddev-grafana/actions/workflows/tests.yml/badge.svg)](https://github.com/ddev/ddev-grafana/actions/workflows/tests.yml) ![project is maintained](https://img.shields.io/maintenance/yes/2024.svg)
2+
3+
# ddev-grafana <!-- omit in toc -->
4+
5+
* [What is ddev-grafana?](#what-is-ddev-grafana)
6+
* [Components of the repository](#components-of-the-repository)
7+
* [Getting started](#getting-started)
8+
9+
## What is ddev-grafana?
10+
11+
This repository is a template for providing [DDEV](https://ddev.readthedocs.io) add-ons and services.
12+
13+
In DDEV addons can be installed from the command line using the `ddev get` command, for example, `ddev get ddev/ddev-grafana` or `ddev get ddev/ddev-drupal9-solr`.
14+
15+
A repository like this one is the way to get started. You can create a new repo from this one by clicking the template button in the top right corner of the page.
16+
17+
![template button](images/template-button.png)
18+
19+
## Components of the repository
20+
21+
* The fundamental contents of the add-on service or other component. For example, in this template there is a [docker-compose.grafana.yaml](docker-compose.grafana.yaml) file.
22+
* An [install.yaml](install.yaml) file that describes how to install the service or other component.
23+
* A test suite in [test.bats](tests/test.bats) that makes sure the service continues to work as expected.
24+
* [Github actions setup](.github/workflows/tests.yml) so that the tests run automatically when you push to the repository.
25+
26+
## Getting started
27+
28+
1. Choose a good descriptive name for your add-on. It should probably start with "ddev-" and include the basic service or functionality. If it's particular to a specific CMS, perhaps `ddev-<CMS>-servicename`.
29+
2. Create the new template repository by using the template button.
30+
3. Globally replace "grafana" with the name of your add-on.
31+
4. Add the files that need to be added to a ddev project to the repository. For example, you might remove `docker-compose.grafana.yaml` with the `docker-compose.*.yaml` for your recipe.
32+
5. Update the install.yaml to give the necessary instructions for installing the add-on.
33+
34+
* The fundamental line is the `project_files` directive, a list of files to be copied from this repo into the project `.ddev` directory.
35+
* You can optionally add files to the `global_files` directive as well, which will cause files to be placed in the global `.ddev` directory, `~/.ddev`.
36+
* Finally, `pre_install_commands` and `post_install_commands` are supported. These can use the host-side environment variables documented [in ddev docs](https://ddev.readthedocs.io/en/stable/users/extend/custom-commands/#environment-variables-provided).
37+
38+
6. Update `tests/test.bats` to provide a reasonable test for the repository. You can run it manually with `bats tests` and it will be run on push and nightly as well. Please make sure to attend to test failures when they happen. Others will be depending on you. `bats` is a simple testing framework that just uses `bash`. You can install it with `brew install bats-core` or [see other techniques](https://bats-core.readthedocs.io/en/stable/installation.html). See [bats tutorial](https://bats-core.readthedocs.io/en/stable/).
39+
7. When everything is working, including the tests, you can push the repository to GitHub.
40+
8. Create a release on GitHub.
41+
9. Test manually with `ddev get <owner/repo>`.
42+
10. You can test PRs with `ddev get https://github.com/<user>/<repo>/tarball/<branch>`
43+
11. Update the README.md to describe the add-on, how to use it, and how to contribute. If there are any manual actions that have to be taken, please explain them. If it requires special configuration of the using project, please explain how to do those. Examples in [ddev/ddev-drupal9-solr](https://github.com/ddev/ddev-drupal9-solr), [ddev/ddev-memcached](github.com/ddev/ddev-memcached), and [ddev/ddev-beanstalkd](https://github.com/ddev/ddev-beanstalkd).
44+
12. Add a good short description to your repo, and add the label "ddev-get". It will immediately be added to the list provided by `ddev get --list --all`.
45+
13. When it has matured you will hopefully want to have it become an "official" maintained add-on. Open an issue in the [ddev queue](https://github.com/ddev/ddev/issues) for that.
46+
47+
Note that more advanced techniques are discussed in [DDEV docs](https://ddev.readthedocs.io/en/latest/users/extend/additional-services/#additional-service-configurations-and-add-ons-for-ddev).
48+
49+
**Contributed and maintained by [@CONTRIBUTOR](https://github.com/CONTRIBUTOR) based on the original [ddev-contrib recipe](https://github.com/ddev/ddev-contrib/tree/master/docker-compose-services/RECIPE) by [@CONTRIBUTOR](https://github.com/CONTRIBUTOR)**
50+
51+
**Originally Contributed by [somebody](https://github.com/somebody) in <https://github.com/ddev/ddev-contrib/>

docker-compose.grafana.yaml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
version: '3.6'
2+
3+
services:
4+
grafana:
5+
container_name: "ddev-${DDEV_SITENAME}-grafana"
6+
image: grafana/grafana:latest
7+
entrypoint:
8+
- /usr/share/grafana/bin/grafana-server
9+
- --homepath=/usr/share/grafana
10+
- --config=/etc/grafana-config/grafana.ini
11+
labels:
12+
com.ddev.site-name: ${DDEV_SITENAME}
13+
com.ddev.approot: $DDEV_APPROOT
14+
volumes:
15+
- ./grafana/grafana/config:/etc/grafana-config
16+
- ./grafana/grafana/datasources:/etc/grafana/provisioning/datasources
17+
- ./grafana/grafana/dashboards-provisioning:/etc/grafana/provisioning/dashboards
18+
- ./grafana/grafana/dashboards:/var/lib/grafana/dashboards
19+
networks: [default, ddev_default]
20+
expose:
21+
- 3000
22+
environment:
23+
- VIRTUAL_HOST=$DDEV_HOSTNAME
24+
- HTTP_EXPOSE=3000:3000
25+
- HTTPS_EXPOSE=3001:3000
26+
27+
prometheus:
28+
container_name: "ddev-${DDEV_SITENAME}-prometheus"
29+
image: prom/prometheus:latest
30+
command:
31+
- '--config.file=/etc/prometheus/prometheus.yaml'
32+
- '--storage.tsdb.path=/prometheus'
33+
- '--web.console.libraries=/etc/prometheus/console_libraries'
34+
- '--web.console.templates=/etc/prometheus/consoles'
35+
- '--web.enable-lifecycle'
36+
networks: [default, ddev_default]
37+
expose:
38+
- 9090
39+
volumes:
40+
- ./grafana/prometheus/prometheus.yaml:/etc/prometheus/prometheus.yaml
41+
- prometheus-data:/prometheus
42+
43+
loki:
44+
image: grafana/loki:latest
45+
expose:
46+
- 3100
47+
volumes:
48+
- ./grafana/loki/loki.yaml:/etc/loki/local-config.yaml
49+
- loki-data:/loki
50+
51+
tempo:
52+
container_name: "ddev-${DDEV_SITENAME}-tempo"
53+
image: grafana/tempo:latest
54+
volumes:
55+
- ./grafana/tempo/tempo.yaml:/etc/tempo.yaml
56+
- tempo-data:/data
57+
command:
58+
- "-config.file=/etc/tempo.yaml"
59+
networks: [default, ddev_default]
60+
expose:
61+
- 3200
62+
- 4317
63+
- 4318
64+
65+
volumes:
66+
tempo-data:
67+
name: "ddev-${DDEV_SITENAME}_tempo"
68+
prometheus-data:
69+
name: "ddev-${DDEV_SITENAME}_prometheus"
70+
loki-data:
71+
name: "ddev-${DDEV_SITENAME}_loki"

grafana/grafana/config/grafana.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[auth.anonymous]
2+
enabled = true
3+
org_role = Admin
4+
5+
[security]
6+
admin_user = admin
7+
admin_password = tvh
8+
9+
[feature_toggles]
10+
enable = tempoSearch tempoBackendSearch
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apiVersion: 1
2+
3+
datasources:
4+
- name: Loki
5+
type: loki
6+
access: proxy
7+
orgId: 1
8+
url: http://loki:3100
9+
basicAuth: false
10+
isDefault: true
11+
version: 1
12+
editable: false
13+
apiVersion: 1
14+
uid: loki
15+
16+
- name: Prometheus
17+
type: prometheus
18+
access: proxy
19+
orgId: 1
20+
url: http://prometheus:9090
21+
basicAuth: false
22+
isDefault: false
23+
version: 1
24+
editable: false
25+
apiVersion: 1
26+
uid: prometheus
27+
28+
- name: Tempo
29+
type: tempo
30+
access: proxy
31+
orgId: 1
32+
url: http://tempo:3200
33+
basicAuth: false
34+
isDefault: false
35+
version: 1
36+
editable: false
37+
apiVersion: 1
38+
uid: tempo

grafana/loki/loki.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
auth_enabled: false
2+
3+
server:
4+
http_listen_port: 3100
5+
grpc_listen_port: 9096
6+
7+
common:
8+
instance_addr: 127.0.0.1
9+
path_prefix: /tmp/loki
10+
storage:
11+
filesystem:
12+
chunks_directory: /tmp/loki/chunks
13+
rules_directory: /tmp/loki/rules
14+
replication_factor: 1
15+
ring:
16+
kvstore:
17+
store: inmemory
18+
19+
query_range:
20+
results_cache:
21+
cache:
22+
embedded_cache:
23+
enabled: true
24+
max_size_mb: 100
25+
26+
schema_config:
27+
configs:
28+
- from: 2020-10-24
29+
store: boltdb-shipper
30+
object_store: filesystem
31+
schema: v11
32+
index:
33+
prefix: index_
34+
period: 24h
35+
36+
ruler:
37+
alertmanager_url: http://localhost:9093
38+
# By default, Loki will send anonymous, but uniquely-identifiable usage and configuration
39+
# analytics to Grafana Labs. These statistics are sent to https://stats.grafana.org/
40+
#
41+
# Statistics help us better understand how Loki is used, and they show us performance
42+
# levels for most users. This helps us prioritize features and documentation.
43+
# For more information on what's sent, look at
44+
# https://github.com/grafana/loki/blob/main/pkg/usagestats/stats.go
45+
# Refer to the buildReport method to see what goes into a report.
46+
#
47+
# If you would like to disable reporting, uncomment the following lines:
48+
#analytics:
49+
# reporting_enabled: false

grafana/prometheus/prometheus.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
global:
2+
scrape_interval: 15s
3+
evaluation_interval: 15s
4+
5+
scrape_configs:
6+
- job_name: "prometheus"
7+
static_configs:
8+
- targets:
9+
- "localhost:9090"
10+
- job_name: "tempo"
11+
static_configs:
12+
- targets:
13+
- "tempo:3200"

grafana/tempo/tempo.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
server:
2+
http_listen_port: 3200
3+
# log_level: debug
4+
5+
distributor:
6+
receivers: # this configuration will listen on all ports and protocols that tempo is capable of.
7+
jaeger: # the receives all come from the OpenTelemetry collector. more configuration information can
8+
protocols: # be found there: https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver
9+
thrift_http: #
10+
grpc: # for a production deployment you should only enable the receivers you need!
11+
thrift_binary:
12+
thrift_compact:
13+
zipkin:
14+
otlp:
15+
protocols:
16+
http: # port 4318
17+
grpc: # port 4317
18+
opencensus:
19+
20+
storage:
21+
trace:
22+
backend: local # backend configuration to use
23+
wal:
24+
path: /data/tempo/wal # where to store the the wal locally
25+
local:
26+
path: /data/tempo/blocks

install.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: grafana
2+
3+
pre_install_actions:
4+
5+
project_files:
6+
- docker-compose.grafana.yaml
7+
- grafana/

tests/test.bats

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
setup() {
2+
set -eu -o pipefail
3+
export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.."
4+
export TESTDIR=~/tmp/test-grafana
5+
mkdir -p $TESTDIR
6+
export PROJNAME=test-grafana
7+
export DDEV_NON_INTERACTIVE=true
8+
ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true
9+
cd "${TESTDIR}"
10+
ddev config --project-name=${PROJNAME}
11+
ddev start -y >/dev/null
12+
}
13+
14+
teardown() {
15+
set -eu -o pipefail
16+
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
17+
ddev delete -Oy ${PROJNAME} >/dev/null 2>&1
18+
[ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR}
19+
}
20+
21+
@test "install from directory" {
22+
set -eu -o pipefail
23+
cd ${TESTDIR}
24+
echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
25+
ddev get ${DIR}
26+
ddev restart
27+
# Do something here to verify functioning extra service
28+
# For extra credit, use a real CMS with actual config.
29+
# ddev exec "curl -s elasticsearch:9200" | grep "${PROJNAME}-elasticsearch"
30+
}
31+
32+
@test "install from release" {
33+
set -eu -o pipefail
34+
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
35+
echo "# ddev get ddev/ddev-grafana with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
36+
ddev get ddev/ddev-grafana
37+
ddev restart >/dev/null
38+
# Do something useful here that verifies the add-on
39+
# ddev exec "curl -s elasticsearch:9200" | grep "${PROJNAME}-elasticsearch"
40+
}

tests/testdata/.gitmanaged

Whitespace-only changes.

0 commit comments

Comments
 (0)