Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hack scripts to test urls, update add-runbook #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
public/
resources/
.hugo_build.lock
hack/kps/
hack/run.log
32 changes: 27 additions & 5 deletions content/docs/add-runbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ menu:
2. Open a PR with new file placed in correct component subdirectory. You can use
[links below to open a PR directly](#pr-links)
3. Name the new file the same as the alert it describes
4. Fill in the new file following [a template below](#template).
5. Remember to put alert name at the top of the file
4. Ensure the file has `.md` extension
5. Fill in the new file following [a template below](#template).
6. Remember to put alert name at the top of the file

### Finding correct component

Expand All @@ -37,7 +38,7 @@ For example `KubeStateMetricsListErrors` suggest it is a kube-state-metrics aler

Runbook example based on a NodeFilesystemSpaceFillingUp (thanks to @beorn7):

```
```text
# NodeFilesystemSpaceFillingUp

## Meaning
Expand Down Expand Up @@ -69,8 +70,16 @@ Is this some irregular condition, e.g. a process fails to clean up behind itself

<Insert site specific measures, for example to grow a persistent volume.>

Cross referencing other document:

See [Node RAID Degraded]({ {< ref "../runbooks/node/NodeRAIDDegraded.md" >} })
(remove spaces between curly braces, this was added here to avoid auto-parsing)


[1]: https://github.github.com/gfm/#html-block

(Notice urls are not auto processed yet in Hugo.)

```

### Guidelines
Expand All @@ -83,6 +92,19 @@ The primary target for these runbooks are folks who are novices and don't have m

To test your changes locally:

1. Install [Hugo](https://gohugo.io/getting-started/installing/)
1. Install [Hugo](https://gohugo.io/getting-started/installing/),
notice `Extended` version
2. Run `git submodule init` and `git submodule update` to clone the Hugo theme
3. Run `hugo server` and navigate to http://localhost:1313/ in your browser
3. Run `hugo server` for example as container
from the root of the git repo:

```shell
docker run --rm -it -v $(pwd):/src -p 1313:1313 klakegg/hugo:ext-alpine server
```

and navigate to [localhost:1313](http://localhost:1313/) in your browser.

4. extra scripts in `hack/` to check links (linux specific):

- `check_urls.sh`: git + grep + wget
- `spider.sh`: [linkcheck](https://github.com/tennox/linkcheck)
27 changes: 27 additions & 0 deletions hack/check_urls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# check urls via trying to connect to hugo server on localhost:1313

rm -rf kps
git clone --depth 1 https://github.com/prometheus-community/helm-charts/ kps

URL_PATHS=$(grep -R "runbook_url:" kps/charts/kube-prometheus-stack | grep .yaml | awk '{print $5}' | tr -d "}" | sort | uniq)

ENDPOINT=${ENDPOINT:-"http://localhost:1313/runbooks"}

exit_code=0
echo "Checking runbook urls... please wait"

for runbook in $URL_PATHS; do
if ! curl --output /dev/null --silent --head --fail "${ENDPOINT}${runbook}"; then
rule_file=$(grep -n -R "$runbook" kps/charts/kube-prometheus-stack | awk '{print $1}')
echo -e "Missing ${runbook} \n\t $EDITOR $rule_file"
exit_code=1
fi
done

if [ $exit_code == 0 ]; then
echo "Great Success, no issues found!"
else
echo "Oh no, errors!"
fi
exit $exit_code
Comment on lines +1 to +27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using mdox for this in kube-prometheus and prometheus-operator. I don't see any reason we shouldn't be using it here too.

7 changes: 7 additions & 0 deletions hack/spider.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/sur/bin/env bash
#
# crawl over all urls
ENDPOINT=${ENDPOINT:-"http://localhost:1313/"}

echo "Checking all urls... please wait"
docker run --network=host --rm tennox/linkcheck http://localhost:1313