Skip to content

Commit 883e238

Browse files
committed
move mimir test setup to examples
This moves the mimir test setup to the examples directory, removing the Makefile targets and describing the required steps in the examples README.
1 parent ec18294 commit 883e238

File tree

6 files changed

+112
-63
lines changed

6 files changed

+112
-63
lines changed

Makefile

-31
Original file line numberDiff line numberDiff line change
@@ -100,34 +100,3 @@ examples/openshift/manifests: examples/openshift/main.jsonnet jsonnet/controller
100100
jsonnet -m examples/openshift/manifests examples/openshift/main.jsonnet | xargs -I{} sh -c 'cat {} | gojsontoyaml > {}.yaml' -- {}
101101
find examples/openshift/manifests -type f ! -name '*.yaml' -delete
102102

103-
KIND_CONFIG_FILE := testdata/kind-cluster.yaml
104-
105-
kind:
106-
ifeq (, $(shell which kind))
107-
go install sigs.k8s.io/[email protected]
108-
KIND=$(GOBIN)/kind
109-
else
110-
CONTROLLER_GEN=$(shell which kind)
111-
endif
112-
113-
helm-repo-add:
114-
helm repo add grafana https://grafana.github.io/helm-charts || true
115-
116-
helm-repo-update: helm-repo-add
117-
helm repo update grafana
118-
119-
ensure-kind-cluster: kind
120-
@if ! kind get clusters | grep -q "^mimir$$"; then \
121-
kind create cluster --config $(KIND_CONFIG_FILE); \
122-
else \
123-
echo "Cluster is already configured"; \
124-
fi
125-
126-
setup-mimir-test-cluster: ensure-kind-cluster helm-repo-update
127-
helm upgrade -i mimir grafana/mimir-distributed --version=5.4.0 -f ./testdata/mimir-values.yaml --wait
128-
@echo "\n"
129-
@echo "Mimir will be available at http://localhost:30950"
130-
@echo "e.g. curl localhost:30950/prometheus/config/v1/rules/namespace"
131-
132-
delete-mimir-test-cluster: kind
133-
kind delete cluster --name mimir

examples/mimir/README.md

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Mimir Example
2+
3+
The following explains how to deploy a simple Mimir setup that can be used to test Pyrra.
4+
5+
## Pre-Requisites
6+
7+
- [Helm](https://helm.sh/)
8+
- Kubernetes Cluster (e.g. via [kind](https://kind.sigs.k8s.io/))
9+
10+
## Setup
11+
12+
Ensure the Pyrra CRDs are installed in your cluster:
13+
14+
```sh
15+
kubectl apply -f ./examples/kubernetes/manifests/setup/pyrra-slo-CustomResourceDefinition.yaml
16+
```
17+
18+
To setup a mimir test cluster for local development you can run:
19+
20+
```sh
21+
helm upgrade -i mimir grafana/mimir-distributed --version=5.4.0 -n mimir --create-namespace -f ./examples/mimir/mimir-values.yaml --wait
22+
```
23+
24+
This will install the [Mimir Helm Chart](https://github.com/grafana/mimir/tree/main/operations/helm/charts/mimir-distributed) in a minimal configuration.
25+
26+
To access the mimir API we have to port-forrward the mimir-gateway service to our local machine:
27+
28+
```sh
29+
kubectl port-forward -n mimir svc/mimir-gateway 8080:8080
30+
```
31+
32+
In another terminal session we can verify that everything is working by running:
33+
34+
```sh
35+
curl localhost:8080
36+
```
37+
38+
which should return `OK`.
39+
40+
## Running Pyrra
41+
42+
To run the Pyrra Operator against Mimir we can use the following command:
43+
44+
```sh
45+
./pyrra kubernetes --mimir-url=http://localhost:8080
46+
```
47+
48+
Additionally, we can run the Pyrra API and connect it against Mimir and the Pyrra Operator:
49+
50+
```sh
51+
./pyrra api --prometheus-url=http://localhost:8080/prometheus --api-url=http://localhost:9444
52+
```
53+
54+
We can then access the Pyrra UI at `http://localhost:9099`.
55+
56+
## Deploying a SLO
57+
58+
Lets deploy a simple SLO to test the setup:
59+
60+
```sh
61+
kubectl apply -f examples/mimir/example-slo.yaml
62+
```
63+
64+
The Mimir Operator logs should now indicate that the related Mimir rules have been created.
65+
66+
## Using Mimirtool
67+
68+
We can use the `mimirtool` to interact with the Mimir API.
69+
70+
For setup instructions, you can refer to: <https://grafana.com/docs/mimir/latest/manage/tools/mimirtool/#installation>
71+
72+
We can then configure the `mimirtool` to use the Mimir API:
73+
74+
```sh
75+
export MIMIR_ADDRESS=http://localhost:8080
76+
export MIMIR_TENANT_ID=anonymous
77+
```
78+
79+
Now we can list the rules created by Pyrra:
80+
81+
```sh
82+
mimirtool rules list
83+
```
84+
85+
Which should return the following:
86+
87+
```
88+
Namespace | Rule Group
89+
apiserver-read-cluster-latency | apiserver-read-cluster-latency
90+
```
91+
92+
## Teardown
93+
94+
You can run `helm uninstall mimir -n mimir` to remove the mimir deployment.

examples/mimir/example-slo.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: pyrra.dev/v1alpha1
2+
kind: ServiceLevelObjective
3+
metadata:
4+
labels:
5+
prometheus: k8s
6+
role: alert-rules
7+
name: apiserver-read-cluster-latency
8+
namespace: default
9+
spec:
10+
description: ""
11+
indicator:
12+
latency:
13+
success:
14+
metric: apiserver_request_sli_duration_seconds_bucket{component="apiserver",scope=~"cluster|",verb=~"LIST|GET",le="5"}
15+
total:
16+
metric: apiserver_request_sli_duration_seconds_count{component="apiserver",scope=~"cluster|",verb=~"LIST|GET"}
17+
target: "99"
18+
window: 2w

testdata/mimir-values.yaml renamed to examples/mimir/mimir-values.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,3 @@ nginx:
5454
gateway:
5555
enabledNonEnterprise: true
5656
replicas: 1
57-
service:
58-
type: "NodePort"
59-
nodePort: 30950

testdata/README.md

-21
This file was deleted.

testdata/kind-cluster.yaml

-8
This file was deleted.

0 commit comments

Comments
 (0)