diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 7d7f86f..e46f14e 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -2,9 +2,9 @@ name: Docker Image CI on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + branches: ["main"] jobs: build: diff --git a/README.md b/README.md index 2e943c3..c191325 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Furthermore, a cron job is executed every n seconds which collects the current s Thus, the following metrics are collected: -| Metric | type | description | +| Metric | Type | Description | | ------------------------- | --------- | ------------------------------------------------------- | | bullmq_processed_duration | histogram | Processing time for completed jobs | | bullmq_completed_duration | histogram | Completion time for jobs | @@ -46,23 +46,56 @@ Each metric also has the attribute `queue` which indicated which queue the metri ## How to use +### Variables + +These environment variables may be set to overwrite the values in the config file. +Note that not all values are supported. + +| Name | Description | +| -------------- | ----------------------------------- | +| REDIS_HOST | Redis host, e. g. "localhost:6379/" | +| REDIS_USERNAME | Redis username | +| REDIS_PASSWORD | Redis password | +| REDIS_SSL | Wether to use ssl | + +### Local + 1. Install the dependencies -``` +```bash npm install ``` 2. Default environment is `local`. This can be set using the `NODE_ENV` variable. -``` +```bash export NODE_ENV=production ``` 3. Make sure that the required config file is present: `./configs/config-${NODE_ENV}.json` (see [local](./configs/config-local.json)). 4. Start the server -``` +```bash npm run dev ``` 5. Access the resources `http://localhost:8080/bullmq/ui/login` or `http://localhost:8080/prometheus/metrics` + +### Docker + +The Dockerimage is published using the [local](./configs/config-local.json) configuration. In most cases that will not be sufficient and should be overwritten. +This can be done using environment variables (see [here](#variables)) or by mounting a separate file. + +```bash +# This needs a config file under ./configs/config-dev.json +docker run \ + -it \ + --mount type=bind,source=$(pwd)/configs,target=/app/configs \ + --env=NODE_ENV=dev \ + --env=REDIS_HOST=some-host:6379/ \ + rgummich/bullmq-exporter +``` + +### Kubernetes + +In Kubernetes this may be done using [Secrets](https://kubernetes.io/docs/concepts/configuration/secret/). diff --git a/src/config.ts b/src/config.ts index f977c34..a391c49 100644 --- a/src/config.ts +++ b/src/config.ts @@ -12,8 +12,18 @@ export interface Config { users?: Array; } +function setFromEnv(key: string, def: any) { + const val = process.env[key.toUpperCase()]; + return val === undefined ? def : val; +} + const prefix = process.env.NODE_ENV?.toLowerCase() || "local"; const jsonRaw = readFileSync(`./configs/config-${prefix}.json`); -const config = JSON.parse(jsonRaw.toString()); +const config = JSON.parse(jsonRaw.toString()) as Config; + +config.redis.host = setFromEnv("REDIS_HOST", config.redis.host); +config.redis.username = setFromEnv("REDIS_USERNAME", config.redis.username); +config.redis.password = setFromEnv("REDIS_PASSWORD", config.redis.password); +config.redis.ssl = setFromEnv("REDIS_SSL", config.redis.ssl); -export default config as Config; +export default config;