Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit 67e78c2

Browse files
authored
Improve annotations based scraping for helm (#529)
* Improve annotations based scraping for helm * typo
1 parent f125450 commit 67e78c2

File tree

9 files changed

+1899
-54
lines changed

9 files changed

+1899
-54
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ deploy-monitoring: $(BIN)/tk $(BIN)/kind tools/monitoring/environments/default/s
334334
.PHONY: tools/monitoring/environments/default/spec.json # This is a phony target for now as the cluster might be not already created.
335335
tools/monitoring/environments/default/spec.json: $(BIN)/tk $(BIN)/kind
336336
$(BIN)/kind export kubeconfig --name $(KIND_CLUSTER) || $(BIN)/kind create cluster --name $(KIND_CLUSTER)
337-
pushd tools/monitoring/ && rm -Rf vendor/ lib/ environments/default/spec.json && PATH=$(BIN) $(BIN)/tk init -f
337+
pushd tools/monitoring/ && rm -Rf vendor/ lib/ environments/default/spec.json && PATH=$(BIN):$(PATH) $(BIN)/tk init -f
338338
echo "import 'monitoring.libsonnet'" > tools/monitoring/environments/default/main.jsonnet
339339
$(BIN)/tk env set tools/monitoring/environments/default --server=$(shell $(BIN)/kind get kubeconfig --name phlare-dev | grep server: | sed 's/server://g' | xargs) --namespace=monitoring
340340

docs/sources/operators-guide/deploy-kubernetes/_index.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ Use a custom namespace so that you do not have to overwrite the default namespac
119119
--set-string 'podAnnotations.phlare\.grafana\.com/scrape=true' \
120120
--set-string 'podAnnotations.phlare\.grafana\.com/port=6060'
121121
```
122+
122123
For details, see [Deploy Grafana on Kubernetes](/docs/grafana/latest/setup-grafana/installation/kubernetes/).
123124

124125
1. Port-forward Grafana to `localhost`, by using the `kubectl` command:
@@ -134,7 +135,7 @@ Use a custom namespace so that you do not have to overwrite the default namespac
134135
| Field | Value |
135136
| ----- | ------------------------------------------------------------ |
136137
| Name | Phlare |
137-
| URL | http://phlare-querier.phlare-test.svc.cluster.local.:4100/ |
138+
| URL | `http://phlare-querier.phlare-test.svc.cluster.local.:4100/` |
138139

139140
To add a data source, see [Add a data source](/docs/grafana/latest/datasources/add-a-data-source/).
140141

@@ -143,7 +144,7 @@ Use a custom namespace so that you do not have to overwrite the default namespac
143144
You should be able to query profiles in [Grafana Explore](/docs/grafana/latest/explore/),
144145
as well as create dashboard panels by using your newly configured Phlare data source.
145146

146-
## Optional: Persistently add data source:
147+
## Optional: Persistently add data source
147148

148149
The deployment of Grafana has no persistent database, so it will not retain settings like the data source configuration across restarts.
149150

@@ -177,8 +178,41 @@ In order to get Phlare to scrape pods, you must add the following annotations to
177178
```yaml
178179
metadata:
179180
annotations:
180-
phlare.grafana.com/scrape: "true"
181-
phlare.grafana.com/port: "8080"
181+
profiles.grafana.com/memory.scrape: "true"
182+
profiles.grafana.com/memory.port: "8080"
183+
profiles.grafana.com/cpu.scrape: "true"
184+
profiles.grafana.com/cpu.port: "8080"
185+
profiles.grafana.com/goroutine.scrape: "true"
186+
profiles.grafana.com/goroutine.port: "8080"
187+
```
188+
189+
The above example will scrape the `memory`, `cpu` and `goroutine` profiles from the `8080` port of the pod.
190+
191+
Each profile type has a set of corresponding annotations which allows customization of scraping per profile type.
192+
193+
```yaml
194+
metadata:
195+
annotations:
196+
profiles.grafana.com/<profile-type>.scrape: "true"
197+
profiles.grafana.com/<profile-type>.port: "<port>"
198+
profiles.grafana.com/<profile-type>.port_name: "<port-name>"
199+
profiles.grafana.com/<profile-type>.scheme: "<scheme>"
200+
profiles.grafana.com/<profile-type>.path: "<profile_path>"
182201
```
183202

184-
`phlare.grafana.com/port` should be set to the port that your pod serves the `/debug/pprof/` endpoints from. Note that the values for `phlare.grafana.io/scrape` and `phlare.grafana.io/port` must be enclosed in double quotes to ensure it is represented as a string.
203+
The full list of profile types supported by annotations is `cpu`, `memory`, `goroutine`, `block` and `mutex`.
204+
205+
The following table describes the annotations:
206+
207+
| Annotation | Description | Default |
208+
| ---------- | ----------- | ------- |
209+
| `profiles.grafana.com/<profile-type>.scrape` | Whether to scrape the profile type. | `false` |
210+
| `profiles.grafana.com/<profile-type>.port` | The port to scrape the profile type from. | `` |
211+
| `profiles.grafana.com/<profile-type>.port_name` | The port name to scrape the profile type from. | `` |
212+
| `profiles.grafana.com/<profile-type>.scheme` | The scheme to scrape the profile type from. | `http` |
213+
| `profiles.grafana.com/<profile-type>.path` | The path to scrape the profile type from. | default golang path |
214+
215+
By default, the port will be discovered using named port `http2` or ending with `-metrics` or `-profiles`.
216+
This means that if you don't have a named port the scraping target will be dropped.
217+
218+
If you don't want to use the port name then you can use the `profiles.grafana.com/<profile-type>.port` annotation to statically specify the port number.

operations/phlare/helm/phlare/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
| phlare.persistence.annotations | object | `{}` | |
3838
| phlare.persistence.enabled | bool | `false` | |
3939
| phlare.persistence.size | string | `"10Gi"` | |
40-
| phlare.podAnnotations."phlare.grafana.com/port" | string | `"4100"` | |
41-
| phlare.podAnnotations."phlare.grafana.com/scrape" | string | `"true"` | |
40+
| phlare.podAnnotations."profiles.grafana.com/cpu.scrape" | string | `"true"` | |
41+
| phlare.podAnnotations."profiles.grafana.com/goroutine.scrape" | string | `"true"` | |
42+
| phlare.podAnnotations."profiles.grafana.com/memory.scrape" | string | `"true"` | |
4243
| phlare.podSecurityContext.fsGroup | int | `10001` | |
4344
| phlare.podSecurityContext.runAsNonRoot | bool | `true` | |
4445
| phlare.podSecurityContext.runAsUser | int | `10001` | |

0 commit comments

Comments
 (0)