Skip to content

Commit 13cfbe3

Browse files
committed
Setup mdox
Signed-off-by: Saswata Mukherjee <[email protected]>
1 parent 0821ada commit 13cfbe3

File tree

14 files changed

+1035
-73
lines changed

14 files changed

+1035
-73
lines changed

.github/workflows/ci.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ jobs:
2222
with:
2323
go-version: ${{ env.golang-version }}
2424
- run: make --always-make generate validate && git diff --exit-code
25+
check-docs:
26+
runs-on: ubuntu-latest
27+
name: Check Documentation formatting and links
28+
steps:
29+
- uses: actions/checkout@v2
30+
with:
31+
persist-credentials: false
32+
- uses: actions/setup-go@v2
33+
with:
34+
go-version: ${{ env.golang-version }}
35+
- run: make check-docs
2536
lint:
2637
runs-on: ubuntu-latest
2738
name: Jsonnet linter

.mdox.validate.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: 1
2+
3+
validators:
4+
# Ignore localhost links.
5+
- regex: 'localhost'
6+
type: "ignore"
7+
# Ignore release links.
8+
- regex: 'https:\/\/github\.com\/prometheus-operator\/kube-prometheus\/releases'
9+
type: "ignore"

Makefile

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,39 @@ SHELL=/bin/bash -o pipefail
22

33
BIN_DIR?=$(shell pwd)/tmp/bin
44

5-
EMBEDMD_BIN=$(BIN_DIR)/embedmd
5+
MDOX_BIN=$(BIN_DIR)/mdox
66
JB_BIN=$(BIN_DIR)/jb
77
GOJSONTOYAML_BIN=$(BIN_DIR)/gojsontoyaml
88
JSONNET_BIN=$(BIN_DIR)/jsonnet
99
JSONNETLINT_BIN=$(BIN_DIR)/jsonnet-lint
1010
JSONNETFMT_BIN=$(BIN_DIR)/jsonnetfmt
1111
KUBECONFORM_BIN=$(BIN_DIR)/kubeconform
12-
TOOLING=$(EMBEDMD_BIN) $(JB_BIN) $(GOJSONTOYAML_BIN) $(JSONNET_BIN) $(JSONNETLINT_BIN) $(JSONNETFMT_BIN) $(KUBECONFORM_BIN)
12+
TOOLING=$(JB_BIN) $(GOJSONTOYAML_BIN) $(JSONNET_BIN) $(JSONNETLINT_BIN) $(JSONNETFMT_BIN) $(KUBECONFORM_BIN) $(MDOX_BIN)
1313

1414
JSONNETFMT_ARGS=-n 2 --max-blank-lines 2 --string-style s --comment-style s
1515

16-
all: generate fmt test
16+
MDOX_VALIDATE_CONFIG?=.mdox.validate.yaml
17+
MD_FILES_TO_FORMAT=$(shell find docs developer-workspace examples experimental jsonnet manifests -name "*.md") $(shell ls *.md)
18+
19+
all: generate fmt test docs
1720

1821
.PHONY: clean
1922
clean:
2023
# Remove all files and directories ignored by git.
2124
git clean -Xfd .
2225

23-
.PHONY: generate
24-
generate: manifests **.md
26+
.PHONY: docs
27+
docs: $(MDOX_BIN) $(shell find examples) build.sh example.jsonnet
28+
@echo ">> formatting and local/remote links"
29+
$(MDOX_BIN) fmt --soft-wraps -l --links.localize.address-regex="https://prometheus-operator.dev/.*" --links.validate.config-file=$(MDOX_VALIDATE_CONFIG) $(MD_FILES_TO_FORMAT)
2530

26-
**.md: $(EMBEDMD_BIN) $(shell find examples) build.sh example.jsonnet
27-
$(EMBEDMD_BIN) -w `find . -name "*.md" | grep -v vendor`
31+
.PHONY: check-docs
32+
check-docs: $(MDOX_BIN) $(shell find examples) build.sh example.jsonnet
33+
@echo ">> checking formatting and local/remote links"
34+
$(MDOX_BIN) fmt --soft-wraps --check -l --links.localize.address-regex="https://prometheus-operator.dev/.*" --links.validate.config-file=$(MDOX_VALIDATE_CONFIG) $(MD_FILES_TO_FORMAT)
35+
36+
.PHONY: generate
37+
generate: manifests
2838

2939
manifests: examples/kustomize.jsonnet $(GOJSONTOYAML_BIN) vendor
3040
./build.sh $<

README.md

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Then access via [http://localhost:9093](http://localhost:9093)
173173
## Customizing Kube-Prometheus
174174

175175
This section:
176-
* describes how to customize the kube-prometheus library via compiling the kube-prometheus manifests yourself (as an alternative to the [Quickstart section](#Quickstart)).
176+
* describes how to customize the kube-prometheus library via compiling the kube-prometheus manifests yourself (as an alternative to the [Quickstart section](#quickstart)).
177177
* still doesn't require you to make a copy of this entire repository, but rather only a copy of a few select files.
178178

179179
### Installing
@@ -210,8 +210,7 @@ Here's [example.jsonnet](example.jsonnet):
210210

211211
> Note: some of the following components must be configured beforehand. See [configuration](#configuration) and [customization-examples](#customization-examples).
212212
213-
[embedmd]:# (example.jsonnet)
214-
```jsonnet
213+
```jsonnet mdox-exec="cat example.jsonnet"
215214
local kp =
216215
(import 'kube-prometheus/main.libsonnet') +
217216
// Uncomment the following imports to enable its patches
@@ -250,8 +249,7 @@ local kp =
250249

251250
And here's the [build.sh](build.sh) script (which uses `vendor/` to render all manifests in a json structure of `{filename: manifest-content}`):
252251

253-
[embedmd]:# (build.sh)
254-
```sh
252+
```sh mdox-exec="cat build.sh"
255253
#!/usr/bin/env bash
256254

257255
# This script uses arg $1 (name of *.jsonnet file to use) to generate the manifests/*.yaml files.
@@ -343,7 +341,7 @@ Configuration is mainly done in the `values` map. You can see this being used in
343341
},
344342
```
345343

346-
The grafana definition is located in a different project (https://github.com/brancz/kubernetes-grafana), but needed configuration can be customized from the same top level `values` field. For example to allow anonymous access to grafana, add the following `values` section:
344+
The grafana definition is located in a different project (https://github.com/brancz/kubernetes-grafana ), but needed configuration can be customized from the same top level `values` field. For example to allow anonymous access to grafana, add the following `values` section:
347345
```
348346
grafana+:: {
349347
config: { // http://docs.grafana.org/installation/configuration/
@@ -373,8 +371,7 @@ A common example is that not all Kubernetes clusters are created exactly the sam
373371

374372
These mixins are selectable via the `platform` field of kubePrometheus:
375373

376-
[embedmd]:# (examples/jsonnet-snippets/platform.jsonnet)
377-
```jsonnet
374+
```jsonnet mdox-exec="cat examples/jsonnet-snippets/platform.jsonnet"
378375
(import 'kube-prometheus/main.libsonnet') +
379376
{
380377
values+:: {
@@ -406,8 +403,7 @@ The output of this command can be piped to a shell to be executed by appending `
406403

407404
Then to generate manifests with `internal-registry.com/organization`, use the `withImageRepository` mixin:
408405

409-
[embedmd]:# (examples/internal-registry.jsonnet)
410-
```jsonnet
406+
```jsonnet mdox-exec="cat examples/internal-registry.jsonnet"
411407
local mixin = import 'kube-prometheus/addons/config-mixins.libsonnet';
412408
local kp = (import 'kube-prometheus/main.libsonnet') + {
413409
values+:: {
@@ -430,8 +426,7 @@ local kp = (import 'kube-prometheus/main.libsonnet') + {
430426

431427
Another mixin that may be useful for exploring the stack is to expose the UIs of Prometheus, Alertmanager and Grafana on NodePorts:
432428

433-
[embedmd]:# (examples/jsonnet-snippets/node-ports.jsonnet)
434-
```jsonnet
429+
```jsonnet mdox-exec="cat examples/jsonnet-snippets/node-ports.jsonnet"
435430
(import 'kube-prometheus/main.libsonnet') +
436431
(import 'kube-prometheus/addons/node-ports.libsonnet')
437432
```
@@ -440,8 +435,7 @@ Another mixin that may be useful for exploring the stack is to expose the UIs of
440435

441436
To give another customization example, the name of the `Prometheus` object provided by this library can be overridden:
442437

443-
[embedmd]:# (examples/prometheus-name-override.jsonnet)
444-
```jsonnet
438+
```jsonnet mdox-exec="cat examples/prometheus-name-override.jsonnet"
445439
((import 'kube-prometheus/main.libsonnet') + {
446440
prometheus+: {
447441
prometheus+: {
@@ -457,8 +451,7 @@ To give another customization example, the name of the `Prometheus` object provi
457451

458452
Standard Kubernetes manifests are all written using [ksonnet-lib](https://github.com/ksonnet/ksonnet-lib/), so they can be modified with the mixins supplied by ksonnet-lib. For example to override the namespace of the node-exporter DaemonSet:
459453

460-
[embedmd]:# (examples/ksonnet-example.jsonnet)
461-
```jsonnet
454+
```jsonnet mdox-exec="cat examples/ksonnet-example.jsonnet"
462455
((import 'kube-prometheus/main.libsonnet') + {
463456
nodeExporter+: {
464457
daemonset+: {
@@ -474,8 +467,7 @@ Standard Kubernetes manifests are all written using [ksonnet-lib](https://github
474467

475468
The Alertmanager configuration is located in the `values.alertmanager.config` configuration field. In order to set a custom Alertmanager configuration simply set this field.
476469

477-
[embedmd]:# (examples/alertmanager-config.jsonnet)
478-
```jsonnet
470+
```jsonnet mdox-exec="cat examples/alertmanager-config.jsonnet"
479471
((import 'kube-prometheus/main.libsonnet') + {
480472
values+:: {
481473
alertmanager+: {
@@ -502,8 +494,7 @@ The Alertmanager configuration is located in the `values.alertmanager.config` co
502494

503495
In the above example the configuration has been inlined, but can just as well be an external file imported in jsonnet via the `importstr` function.
504496

505-
[embedmd]:# (examples/alertmanager-config-external.jsonnet)
506-
```jsonnet
497+
```jsonnet mdox-exec="cat examples/alertmanager-config-external.jsonnet"
507498
((import 'kube-prometheus/main.libsonnet') + {
508499
values+:: {
509500
alertmanager+: {
@@ -517,8 +508,7 @@ In the above example the configuration has been inlined, but can just as well be
517508

518509
In order to monitor additional namespaces, the Prometheus server requires the appropriate `Role` and `RoleBinding` to be able to discover targets from that namespace. By default the Prometheus server is limited to the three namespaces it requires: default, kube-system and the namespace you configure the stack to run in via `$.values.namespace`. This is specified in `$.values.prometheus.namespaces`, to add new namespaces to monitor, simply append the additional namespaces:
519510

520-
[embedmd]:# (examples/additional-namespaces.jsonnet)
521-
```jsonnet
511+
```jsonnet mdox-exec="cat examples/additional-namespaces.jsonnet"
522512
local kp = (import 'kube-prometheus/main.libsonnet') + {
523513
values+:: {
524514
common+: {
@@ -548,8 +538,7 @@ In order to Prometheus be able to discovery and scrape services inside the addit
548538
549539
You can define ServiceMonitor resources in your `jsonnet` spec. See the snippet bellow:
550540

551-
[embedmd]:# (examples/additional-namespaces-servicemonitor.jsonnet)
552-
```jsonnet
541+
```jsonnet mdox-exec="cat examples/additional-namespaces-servicemonitor.jsonnet"
553542
local kp = (import 'kube-prometheus/main.libsonnet') + {
554543
values+:: {
555544
common+: {
@@ -601,8 +590,7 @@ local kp = (import 'kube-prometheus/main.libsonnet') + {
601590

602591
In case you want to monitor all namespaces in a cluster, you can add the following mixin. Also, make sure to empty the namespaces defined in prometheus so that roleBindings are not created against them.
603592

604-
[embedmd]:# (examples/all-namespaces.jsonnet)
605-
```jsonnet
593+
```jsonnet mdox-exec="cat examples/all-namespaces.jsonnet"
606594
local kp = (import 'kube-prometheus/main.libsonnet') +
607595
(import 'kube-prometheus/addons/all-namespaces.libsonnet') + {
608596
values+:: {
@@ -630,7 +618,7 @@ Proceed with [creating ServiceMonitors for the services in the namespaces](#defi
630618

631619
### Static etcd configuration
632620

633-
In order to configure a static etcd cluster to scrape there is a simple [kube-prometheus-static-etcd.libsonnet](jsonnet/kube-prometheus/kube-prometheus-static-etcd.libsonnet) mixin prepared - see [etcd.jsonnet](examples/etcd.jsonnet) for an example of how to use that mixin, and [Monitoring external etcd](docs/monitoring-external-etcd.md) for more information.
621+
In order to configure a static etcd cluster to scrape there is a simple [static-etcd.libsonnet](jsonnet/kube-prometheus/addons/static-etcd.libsonnet) mixin prepared - see [etcd.jsonnet](examples/etcd.jsonnet) for an example of how to use that mixin, and [Monitoring external etcd](docs/monitoring-external-etcd.md) for more information.
634622

635623
> Note that monitoring etcd in minikube is currently not possible because of how etcd is setup. (minikube's etcd binds to 127.0.0.1:2379 only, and within host networking namespace.)
636624
@@ -639,8 +627,7 @@ In order to configure a static etcd cluster to scrape there is a simple [kube-pr
639627
To prevent `Prometheus` and `Alertmanager` instances from being deployed onto the same node when
640628
possible, one can include the [kube-prometheus-anti-affinity.libsonnet](jsonnet/kube-prometheus/addons/anti-affinity.libsonnet) mixin:
641629

642-
[embedmd]:# (examples/anti-affinity.jsonnet)
643-
```jsonnet
630+
```jsonnet mdox-exec="cat examples/anti-affinity.jsonnet"
644631
local kp = (import 'kube-prometheus/main.libsonnet') +
645632
(import 'kube-prometheus/addons/anti-affinity.libsonnet') + {
646633
values+:: {
@@ -664,8 +651,7 @@ local kp = (import 'kube-prometheus/main.libsonnet') +
664651
Sometimes in small clusters, the CPU/memory limits can get high enough for alerts to be fired continuously. To prevent this, one can strip off the predefined limits.
665652
To do that, one can import the following mixin
666653

667-
[embedmd]:# (examples/strip-limits.jsonnet)
668-
```jsonnet
654+
```jsonnet mdox-exec="cat examples/strip-limits.jsonnet"
669655
local kp = (import 'kube-prometheus/main.libsonnet') +
670656
(import 'kube-prometheus/addons/strip-limits.libsonnet') + {
671657
values+:: {
@@ -759,7 +745,7 @@ resources. One driver for more resource needs, is a high number of
759745
namespaces. There may be others.
760746

761747
kube-state-metrics resource allocation is managed by
762-
[addon-resizer](https://github.com/kubernetes/autoscaler/tree/main/addon-resizer/nanny)
748+
[addon-resizer](https://github.com/kubernetes/autoscaler/tree/master/addon-resizer/nanny)
763749
You can control it's parameters by setting variables in the
764750
config. They default to:
765751

developer-workspace/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ If you are working on new features/bug fixes, you can regenerate kube-prometheus
2626

2727
Gitpod is already available to everyone to use for free. It can also run commands that we speficy in the `.gitpod.yml` file located in the root directory of the git repository, so even the cluster creation can be fully automated.
2828

29-
You can use the same workflow as mentioned in the [Codespaces](#Codespaces) section, however Gitpod doesn't have native support for any kubernetes distribution. The workaround is to create a full QEMU Virtual Machine and deploy [k3s](https://github.com/k3s-io/k3s) inside this VM. Don't worry, this whole process is already fully automated, but due to the workaround the whole workspace may be very slow.
29+
You can use the same workflow as mentioned in the [Codespaces](#codespaces) section, however Gitpod doesn't have native support for any kubernetes distribution. The workaround is to create a full QEMU Virtual Machine and deploy [k3s](https://github.com/k3s-io/k3s) inside this VM. Don't worry, this whole process is already fully automated, but due to the workaround the whole workspace may be very slow.
3030

3131
To open up a workspace with Gitpod, you can install the [Google Chrome extension](https://www.gitpod.io/docs/browser-extension/) to add a new button to Github UI and use it on PRs or from the main page. Or by directly typing in the browser `http://gitpod.io/#https://github.com/prometheus-operator/kube-prometheus/pull/<Pull Request Number>` or just `http://gitpod.io/#https://github.com/prometheus-operator/kube-prometheus`
3232

docs/EKS-cni-support.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ AWS EKS uses [CNI](https://github.com/aws/amazon-vpc-cni-k8s) networking plugin
55
One fatal issue that can occur is that you run out of IP addresses in your eks cluster. (Generally happens due to error configs where pods keep scheduling).
66

77
You can monitor the `awscni` using kube-promethus with :
8-
[embedmd]:# (../examples/eks-cni-example.jsonnet)
9-
```jsonnet
8+
9+
```jsonnet mdox-exec="cat examples/eks-cni-example.jsonnet"
1010
local kp = (import 'kube-prometheus/main.libsonnet') + {
1111
values+:: {
1212
common+: {

docs/developing-prometheus-rules-and-grafana-dashboards.md

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ For both the Prometheus rules and the Grafana dashboards Kubernetes `ConfigMap`s
2020

2121
As a basis, all examples in this guide are based on the base example of the kube-prometheus [readme](../README.md):
2222

23-
[embedmd]:# (../example.jsonnet)
24-
```jsonnet
23+
```jsonnet mdox-exec="cat example.jsonnet"
2524
local kp =
2625
(import 'kube-prometheus/main.libsonnet') +
2726
// Uncomment the following imports to enable its patches
@@ -68,8 +67,7 @@ The format is exactly the Prometheus format, so there should be no changes neces
6867

6968
> Note that alerts can just as well be included into this file, using the jsonnet `import` function. In this example it is just inlined in order to demonstrate their use in a single file.
7069
71-
[embedmd]:# (../examples/prometheus-additional-alert-rule-example.jsonnet)
72-
```jsonnet
70+
```jsonnet mdox-exec="cat examples/prometheus-additional-alert-rule-example.jsonnet"
7371
local kp = (import 'kube-prometheus/main.libsonnet') + {
7472
values+:: {
7573
common+: {
@@ -124,8 +122,7 @@ In order to add a recording rule, simply do the same with the `prometheusRules`
124122

125123
> Note that rules can just as well be included into this file, using the jsonnet `import` function. In this example it is just inlined in order to demonstrate their use in a single file.
126124
127-
[embedmd]:# (../examples/prometheus-additional-recording-rule-example.jsonnet)
128-
```jsonnet
125+
```jsonnet mdox-exec="cat examples/prometheus-additional-recording-rule-example.jsonnet"
129126
local kp = (import 'kube-prometheus/main.libsonnet') + {
130127
values+:: {
131128
common+: {
@@ -184,8 +181,7 @@ cat existingrule.yaml | gojsontoyaml -yamltojson > existingrule.json
184181

185182
Then import it in jsonnet:
186183

187-
[embedmd]:# (../examples/prometheus-additional-rendered-rule-example.jsonnet)
188-
```jsonnet
184+
```jsonnet mdox-exec="cat examples/prometheus-additional-rendered-rule-example.jsonnet"
189185
local kp = (import 'kube-prometheus/main.libsonnet') + {
190186
values+:: {
191187
common+: {
@@ -337,8 +333,7 @@ We recommend using the [grafonnet](https://github.com/grafana/grafonnet-lib/) li
337333

338334
> Note that dashboards can just as well be included into this file, using the jsonnet `import` function. In this example it is just inlined in order to demonstrate their use in a single file.
339335
340-
[embedmd]:# (../examples/grafana-additional-jsonnet-dashboard-example.jsonnet)
341-
```jsonnet
336+
```jsonnet mdox-exec="cat examples/grafana-additional-jsonnet-dashboard-example.jsonnet"
342337
local grafana = import 'grafonnet/grafana.libsonnet';
343338
local dashboard = grafana.dashboard;
344339
local row = grafana.row;
@@ -394,8 +389,7 @@ local kp = (import 'kube-prometheus/main.libsonnet') + {
394389

395390
As jsonnet is a superset of json, the jsonnet `import` function can be used to include Grafana dashboard json blobs. In this example we are importing a [provided example dashboard](../examples/example-grafana-dashboard.json).
396391

397-
[embedmd]:# (../examples/grafana-additional-rendered-dashboard-example.jsonnet)
398-
```jsonnet
392+
```jsonnet mdox-exec="cat examples/grafana-additional-rendered-dashboard-example.jsonnet"
399393
local kp = (import 'kube-prometheus/main.libsonnet') + {
400394
values+:: {
401395
common+:: {
@@ -419,8 +413,8 @@ local kp = (import 'kube-prometheus/main.libsonnet') + {
419413
```
420414

421415
In case you have lots of json dashboard exported out from grafana UI the above approach is going to take lots of time to improve performance we can use `rawDashboards` field and provide it's value as json string by using `importstr`
422-
[embedmd]:# (../examples/grafana-additional-rendered-dashboard-example-2.jsonnet)
423-
```jsonnet
416+
417+
```jsonnet mdox-exec="cat examples/grafana-additional-rendered-dashboard-example-2.jsonnet"
424418
local kp = (import 'kube-prometheus/main.libsonnet') + {
425419
values+:: {
426420
common+:: {
@@ -523,8 +517,7 @@ values+:: {
523517

524518
Full example of including etcd mixin using method described above:
525519

526-
[embedmd]:# (../examples/mixin-inclusion.jsonnet)
527-
```jsonnet
520+
```jsonnet mdox-exec="cat examples/mixin-inclusion.jsonnet"
528521
local addMixin = (import 'kube-prometheus/lib/mixin.libsonnet');
529522
local etcdMixin = addMixin({
530523
name: 'etcd',

docs/exposing-prometheus-alertmanager-grafana-ingress.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ k.core.v1.list.new([
104104

105105
In order to expose Alertmanager and Grafana, simply create additional fields containing an ingress object, but simply pointing at the `alertmanager` or `grafana` instead of the `prometheus-k8s` Service. Make sure to also use the correct port respectively, for Alertmanager it is also `web`, for Grafana it is `http`. Be sure to also specify the appropriate external URL. Note that the external URL for grafana is set in a different way than the external URL for Prometheus or Alertmanager. See [ingress.jsonnet](../examples/ingress.jsonnet) for how to set the Grafana external URL.
106106

107-
In order to render the ingress objects similar to the other objects use as demonstrated in the [main readme](../README.md#usage):
107+
In order to render the ingress objects similar to the other objects use as demonstrated in the [main readme](../README.md):
108108

109109
```
110110
{ ['00namespace-' + name]: kp.kubePrometheus[name] for name in std.objectFields(kp.kubePrometheus) } +

0 commit comments

Comments
 (0)