Skip to content
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
57 changes: 53 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,68 @@
GO := go

DOCKER_IMAGE_NAME ?= prometheus-bigquery-exporter
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))

COLOR_BLUE := \033[0;34m
COLOR_RED := \033[0;31m
COLOR_GREEN := \033[0;32m
COLOR_YELLOW := \033[0;33m
COLOR_RESET := \033[0m


all: vet build
.PHONY: all build docker needs-query needs-project needs-gcloud-config needs-gcloud-sa-key run-query

vet:
@echo ">> vetting code"
@echo "$(COLOR_BLUE)>> Vetting code$(COLOR_RESET)"
@$(GO) vet $(pkgs)

build:
@$(GO) get -t .

docker:
@echo ">> building docker image"
@docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
@echo "$(COLOR_BLUE)>> Building docker image$(COLOR_RESET)"
@docker build -t "$(DOCKER_IMAGE_NAME) -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .

needs-query:
@echo "$(COLOR_BLUE)>> Checking query file$(COLOR_RESET)"
@if [ -z "$(query)" ]; then \
echo "$(COLOR_RED)ERROR: Please provide a query file with query=<file>.sql$(COLOR_RESET)"; \
exit 1; \
fi
@if [ ! -f "$(PWD)/ahoy/prometheus-bigquery-exporter/queries/$(query)" ]; then \
echo "$(COLOR_RED)ERROR: Query file $(PWD)/ahoy/prometheus-bigquery-exporter/queries/$(query) does not exist$(COLOR_RESET)"; \
exit 1; \
fi

needs-project:
@echo "$(COLOR_BLUE)>> Checking project ID$(COLOR_RESET)"
@if [ -z "$(project)" ]; then \
echo "$(COLOR_RED)ERROR: Please provide the Google project ID (numeric) with project=XXXXX$(COLOR_RESET)"; \
exit 1; \
fi

needs-gcloud-config:
@echo "$(COLOR_BLUE)>> Checking gcloud config directory exists$(COLOR_RESET)"
@if [ ! -d "$(HOME)/.config/gcloud" ]; then \
echo "$(COLOR_RED)ERROR: Please run gcloud auth login and gcloud config set project PROJECT_ID$(COLOR_RESET)"; \
exit 1; \
fi

needs-gcloud-sa-key:
@echo "$(COLOR_BLUE)>> Checking service account key file exists$(COLOR_RESET)"
@if [ ! -f "$(PWD)/key.json" ]; then \
echo "$(COLOR_RED)ERROR: Please ensure service account key exists at $(PWD)/key.json$(COLOR_RESET)"; \
exit 1; \
fi

.PHONY: all build docker
run-query: needs-gcloud-config needs-gcloud-sa-key needs-project needs-query
@echo "$(COLOR_BLUE)>> Running query from $(COLOR_YELLOW)$(query)$(COLOR_RESET)"
@echo "$(COLOR_BLUE)>> Using project ID $(COLOR_YELLOW)$(project)$(COLOR_RESET)"
@echo "$(COLOR_BLUE)>> Review generated metrics at: $(COLOR_YELLOW)http://localhost:9348/metrics$(COLOR_RESET)"
docker run -p 9348:9348 --rm \
-v $(HOME)/.config/gcloud:/root/.config/gcloud \
-v $(PWD)/key.json:/key.json \
-v $(PWD)/ahoy/prometheus-bigquery-exporter/queries:/queries -it "$(DOCKER_IMAGE_NAME)" \
-project=$(project) \
-gauge-query=/queries/$(query)
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ Use the following steps:
1. Build the docker image.

```sh
docker build -t bqx-local -f Dockerfile .
docker build -t prometheus-bigquery-exporter -f Dockerfile .
```

or use the make target:

```sh
make docker
```

2. Authenticate using your Google account. Both steps are necessary, the
Expand All @@ -135,7 +141,17 @@ Use the following steps:
```sh
docker run -p 9348:9348 --rm \
-v $HOME/.config/gcloud:/root/.config/gcloud \
-v $PWD:/queries -it bqx-local \
-v $PWD:/queries -it prometheus-bigquery-exporter \
-project=$GCLOUD_PROJECT \
-gauge-query=/queries/example/config/bq_example.sql
```

or use the make target:

```sh
make run-query query=<file>.sql project=<google project id>
```

4. Access the metrics

Review the generated metrics at [http://localhost:9348/metrics](http://localhost:9348/metrics).