From 50afa6854544bae09b9c91e665dac246687bb0de Mon Sep 17 00:00:00 2001 From: Oluwole Fadeyi <16049411+tfadeyi@users.noreply.github.com> Date: Thu, 13 Apr 2023 21:54:12 +0100 Subject: [PATCH] Add example prometheus configuration (#41) Signed-off-by: Oluwole Fadeyi <16049411+tfadeyi@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- .github/workflows/release.yml | 4 +- Makefile | 11 +++++- README.md | 68 +++++++++++++++++++++++++-------- cmd/options/exporter/options.go | 4 +- dev/devshell.toml | 2 +- examples/prometheus.yaml | 17 +++++++++ 7 files changed, 85 insertions(+), 23 deletions(-) create mode 100644 examples/prometheus.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2ee229..6cfab68 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: go-version: '1.19' - uses: actions/checkout@v3 - name: Install tools - run: make install-tools + run: make install-ci-tools - name: Go Fmt run: diff -u <(echo -n) <(gofmt -d ./) shell: bash diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 86bc548..69572d6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,7 +41,7 @@ jobs: run: git fetch --prune --unshallow - name: Install tools - run: make install-tools + run: make install-ci-tools - name: Install cosign uses: sigstore/cosign-installer@v3.0.2 @@ -97,7 +97,7 @@ jobs: fetch-depth: 0 - name: Install tools - run: make install-tools + run: make install-ci-tools - name: Install Go uses: actions/setup-go@v4 diff --git a/Makefile b/Makefile index d3dc79a..06ab65b 100644 --- a/Makefile +++ b/Makefile @@ -13,14 +13,18 @@ export KO_DOCKER_REPO=$KO_DOCKER_REPO # include files with the `// +build mock` annotation TEST_TAGS:=-tags mock -coverprofile cover.out -.PHONY: build generate docs test build-all-platforms clean install-tools licenses docker-build +.PHONY: build generate docs test build-all-platforms clean install-tools licenses lint -install-tools: +install-ci-tools: go install github.com/swaggo/swag/cmd/swag@v1.8.7 go install github.com/matryer/moq@v0.2.7 go install github.com/google/go-licenses@c781b427440f8ea100841eefdd308e660d26d121 go install github.com/norwoodj/helm-docs/cmd/helm-docs@v1.11.0 +install-local-tools: install-ci-tools + go install https://github.com/goreleaser/goreleaser@v1.17.0 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2 + build: cd $(ROOT_DIR) && $(GO_BUILD) -o builds/$(BIN_NAME) . @@ -53,6 +57,9 @@ clean: rm -rf ./builds && \ rm -rf kodata +lint: + golangci-lint run + # generates the licenses used by the tool licenses: rm -rf kodata diff --git a/README.md b/README.md index aeeb79d..6acf536 100644 --- a/README.md +++ b/README.md @@ -30,25 +30,39 @@ This Prometheus exporter aims to simplify this, making it easier to expose tenan * *(Optional)* Auth0 tenant management API [static token](https://auth0.com/docs/secure/tokens/access-tokens/management-api-access-tokens). ## TL;DR -Run exporter's container with TLS disabled. + +The quickest way to install the exporter is through Helm, make sure you have your Auth0 credentials at hand. ```shell export TOKEN="< auth0 management API static static token >" export DOMAIN="< auth0 tenant domain >" - -curl -LJO https://github.com/tfadeyi/auth0-simple-exporter/releases/download/v0.0.1/auth0-simple-exporter-linux-amd64.tar.gz && \ -tar -xzvf auth0-simple-exporter-linux-amd64.tar.gz && \ -cd auth0-simple-exporter-linux-amd64 - -./auth0-simple-exporter export --tls.disabled ``` +```shell + # Installing by passing in secret directly + helm repo add auth0-exporter https://tfadeyi.github.io/auth0-simple-exporter + helm upgrade --install --create-namespace -n auth0-exporter auth0-exporter/auth0-exporter \ + --set auth0.domain="$DOMAIN" --set auth0.token="$TOKEN" \ + --set exporter.tls.disabled=true +``` +This will install the exporter running with TLS disabled. ## Installation -* ### Download Binaries +* ### Download Pre-built Binaries Binaries can be downloaded from [Releases](https://github.com/tfadeyi/auth0-simple-exporter/releases) page. + * Download and run exporter's binary with TLS disabled. + + ```shell + export TOKEN="< auth0 management API static static token >" + export DOMAIN="< auth0 tenant domain >" + + curl -LJO https://github.com/tfadeyi/auth0-simple-exporter/releases/download/v0.0.2/auth0-simple-exporter-linux-amd64.tar.gz && \ + tar -xzvf auth0-simple-exporter-linux-amd64.tar.gz && \ + cd auth0-simple-exporter-linux-amd64 + ./auth0-simple-exporter export --tls.disabled + ``` * ### Docker The recommended way to get the Docker Image is to pull the prebuilt image from the project's Github Container Registry. ```shell @@ -75,6 +89,13 @@ cd auth0-simple-exporter-linux-amd64 More info on the helm deployment can be found [here](deploy/charts/auth0-exporter/README.md). +* ### Build from source + From the repository root directory run: + ```shell + make build + # or for multiple systems + make build-all-platforms + ``` ## Usage ``` @@ -149,13 +170,30 @@ Monitor the number current logged-in users for a client application in Auth0 ten ## Known Issues -### API Rate Limits -When the Prometheus scraping job interval is too frequent the exporter might encounter api-rate limit from Auth0. -To mitigate this try increasing the scraping interval for the job. - -### Not all logs/events are available -Currently, not all logs/events from Auth0 are exposed, if a metric is not exposed, feel free to open a feature request. - +* ### API Rate Limits + When the Prometheus scraping job interval is too frequent the exporter might encounter api-rate limit from Auth0. + To mitigate this try increasing the scraping interval for the job. + +* ### Not all logs/events are available + Currently, not all logs/events from Auth0 are exposed, if a metric is not exposed, feel free to open a feature request. + +## Prometheus + +Example Prometheus configuration for the exporter. Replace `AUTH0-EXPORTER-HOSTNAME` with your instance's hostname. +```yaml +scrape_configs: + - job_name: auth0_exporter + metrics_path: /metrics + static_configs: + - targets: ['<>:9301'] + relabel_configs: + - source_labels: [ __address__ ] + target_label: __param_target + - source_labels: [ __param_target ] + target_label: instance + - target_label: __address__ + replacement: <>:9301 +``` ## Development diff --git a/cmd/options/exporter/options.go b/cmd/options/exporter/options.go index cfc4626..d1044b5 100644 --- a/cmd/options/exporter/options.go +++ b/cmd/options/exporter/options.go @@ -185,7 +185,7 @@ func (o *Options) addAppFlags(fs *pflag.FlagSet) { fs.IntVar( &o.HostPort, "web.listen-address", - 8080, + 9301, "Port where the exporter webserver will listen on.", ) fs.StringVar( @@ -198,7 +198,7 @@ func (o *Options) addAppFlags(fs *pflag.FlagSet) { fs.IntVar( &o.ProbePort, "probe.listen-address", - 8081, + 9302, "Port where the probe webserver will listen on.", ) fs.StringVar( diff --git a/dev/devshell.toml b/dev/devshell.toml index e6972ce..d1aaf50 100644 --- a/dev/devshell.toml +++ b/dev/devshell.toml @@ -26,7 +26,7 @@ startup.kill.text = "alias done='pkill -f tmux'" startup.sessions.text = "alias sessions='tmux list-session'" # Profiling & Testing startup.heap.text = "alias heap='go tool pprof'" -startup.testing.text = "alias test='make test && golangci-lint run && KO_DOCKER_REPO=ghcr.io/tfadeyi/auth0-exporter goreleaser check'" +startup.testing.text = "alias test='make test && make lint && KO_DOCKER_REPO=ghcr.io/tfadeyi/auth0-exporter goreleaser check'" # Exporter startup.exporter.text = "tmux new -s exporter -d 'air -c $ROOT_DIR/dev/.air-exporter.toml'" diff --git a/examples/prometheus.yaml b/examples/prometheus.yaml new file mode 100644 index 0000000..80c07cb --- /dev/null +++ b/examples/prometheus.yaml @@ -0,0 +1,17 @@ +# my global config +global: + scrape_interval: 5s # Set the scrape interval to every 5 seconds. Default is every 1 minute. + evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. + +scrape_configs: + - job_name: auth0_exporter + metrics_path: /metrics + static_configs: + - targets: ['localhost:9301'] + relabel_configs: + - source_labels: [ __address__ ] + target_label: __param_target + - source_labels: [ __param_target ] + target_label: instance + - target_label: __address__ + replacement: localhost:9301