Skip to content

Commit c562389

Browse files
authored
Bot instance metric labels (#87)
* Label all metrics with guild id and instance name * Improve local scripts and docs * Bump chart version
1 parent 784577e commit c562389

File tree

11 files changed

+24
-24
lines changed

11 files changed

+24
-24
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
1. Run `yarn` to install dependencies for your IDE
4040
2. Install docker and [kind](https://kind.sigs.k8s.io/docs/user/quick-start).
4141
3. Install helm by following https://helm.sh/docs/intro/install/
42-
5. Start a local kubernetes cluster by running `kind create cluster --name tim-local`
42+
4. Start a local kubernetes cluster by running `kind create cluster --name <cluster-name-here>` where `<cluster-name-here>` is any string (e.g. `local`)
4343

4444
### Running tests
4545

@@ -56,4 +56,4 @@ Script | Description
5656
`./local-build.sh` | Builds the bot using docker
5757
`./local-start.sh` | Installs the bot's helm chart
5858
`./local-stop.sh` | Uninstalls the bot's helm chart
59-
`./local-tail.sh` | Tails the bot's pod's logs
59+
`./local-tail.sh` | View the bot's logs

helm/citsbot/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
apiVersion: v2
22
description: UWA CSDS Discord Bot
33
name: citsbot
4-
version: 1.17.1
4+
version: 1.18.0

helm/citsbot/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ spec:
1919
- name: citsbot
2020
image: "{{ $.Values.image }}:{{ $.Chart.Version }}"
2121
env:
22+
- name: INSTANCE_NAME
23+
value: "{{ $instance.name }}"
2224
- name: PUSHGATEWAY_URL
2325
value: "{{ $.Values.pushgatewayUrl }}"
2426
- name: DISCORD_TOKEN

local-build.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
#!/bin/bash
22

3-
sh ./local-set-context.sh
3+
./local-set-context.sh
44

55
VERSION=$(cat ./helm/citsbot/Chart.yaml | grep version | awk '{ print $2 }')
66
docker build -t citsbot:${VERSION} .
77

8-
if [[ "$LOCAL_KUBE_CONTEXT" = "minikube" ]]; then
9-
# minikube uses a separate daemon to the host, so images built on the host need to be transferred to it
10-
docker save citsbot:${VERSION} | (eval $(minikube docker-env) && docker load)
11-
elif [[ ! -z "$LOCAL_KUBE_CONTEXT" ]]; then
12-
# kind uses a separate daemon to the host, so images built on the host need to be transferred to it
13-
kind load docker-image citsbot:${VERSION} --name $LOCAL_KUBE_CONTEXT
14-
fi
8+
# kind uses a separate daemon to the host, so images built on the host need to be transferred to it
9+
LOCAL_KUBE_CONTEXT=$(kubectl config get-contexts | grep kind | sed -e 's/^[ |*]*//' | sed -e 's/\(^[^ ]*\).*$/\1/')
10+
kind load docker-image citsbot:${VERSION} --name "$LOCAL_KUBE_CONTEXT"

local-reset.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22

3-
sh ./local-set-context.sh
3+
./local-set-context.sh
44

5-
sh ./local-stop.sh && ./local-build.sh && ./local-start.sh && ./local-tail.sh
5+
./local-stop.sh && ./local-build.sh && ./local-start.sh && ./local-tail.sh

local-set-context.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash
22

33
LOCAL_KUBE_CONTEXT=$(kubectl config get-contexts | grep kind | sed -e 's/^[ |*]*//' | sed -e 's/\(^[^ ]*\).*$/\1/')
4-
54
kubectl config use-context $LOCAL_KUBE_CONTEXT

local-start.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
22

3-
sh ./local-set-context.sh
3+
./local-set-context.sh
44

5-
. .env
5+
source .env
66
if [ -z "$DISCORD_TOKEN" ]; then
77
echo "DISCORD_TOKEN is not set in .env"
88
exit 1

local-stop.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22

3-
sh ./local-set-context.sh
3+
./local-set-context.sh
44

55
sudo helm uninstall -n citsbot citsbot || true

local-tail.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
sh ./local-set-context.sh
3+
./local-set-context.sh
44

55
function is_pod_running() {
66
POD_NAME=$(kubectl get pods -n citsbot -o jsonpath="{.items[0].metadata.name}")

src/metrics/process.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { Pushgateway } from 'prom-client';
1+
import client, { Pushgateway } from 'prom-client';
22

3-
export const initPushgateway = (url: string | undefined) => {
3+
export const initPushgateway = (url: string | undefined, instance: string, guild: string) => {
44
if (!url) {
55
console.log(`No pushgateway URL provided. No metrics will be pushed.`);
6-
return setInterval(() => undefined, 5000);
6+
return setInterval(() => undefined, 5_000);
77
}
8-
const pushgateway = new Pushgateway(url);
9-
return setInterval(() => pushgateway.pushAdd({ jobName: `citsbot` }), 5000);
8+
client.register.setDefaultLabels({ instance, guild });
9+
const pushgateway = new Pushgateway(url, undefined, client.register);
10+
return setInterval(() => pushgateway.pushAdd({ jobName: `citsbot` }), 5_000);
1011
};

0 commit comments

Comments
 (0)