Skip to content

Commit

Permalink
Download prometheus using make instead of Go (#11)
Browse files Browse the repository at this point in the history
* Download prometheus using make instead of Go
* Simplify run command

Co-authored-by: Sebastian Widmer <[email protected]>
  • Loading branch information
ccremer and bastjan authored Jan 18, 2022
1 parent 960c976 commit 1d3bfe4
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 207 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ build-docker: build-bin ## Build docker image
$(DOCKER_CMD) build -t $(CONTAINER_IMG) .

.PHONY: ensure-prometheus
ensure-prometheus:
go run ./util/ensure_prometheus
ensure-prometheus: .cache/prometheus ## Ensures that Prometheus is installed in the project dir. Downloads it if necessary.

.PHONY: test
test: export ACR_DB_URL = postgres://test-migrations:test-migrations@localhost:65432/test-migrations?sslmode=disable
Expand Down Expand Up @@ -66,3 +65,10 @@ generate: ## Generate additional code and artifacts
.PHONY: clean
clean: ## Cleans local build artifacts
rm -rf docs/node_modules $(docs_out_dir) dist .cache

.cache/prometheus:
mkdir -p .cache
curl -fsSLo .cache/prometheus.tar.gz $(PROMETHEUS_DOWNLOAD_LINK)
tar -xzf .cache/prometheus.tar.gz -C .cache
mv .cache/prometheus-$(PROMETHEUS_VERSION).$(PROMETHEUS_DIST)-$(PROMETHEUS_ARCH) .cache/prometheus
rm -rf .cache/*.tar.gz
5 changes: 5 additions & 0 deletions Makefile.vars.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ DOCKER_CMD ?= docker
IMG_TAG ?= latest
# Image URL to use all building/pushing image targets
CONTAINER_IMG ?= local.dev/$(PROJECT_OWNER)/$(PROJECT_NAME):$(IMG_TAG)

PROMETHEUS_VERSION ?= 2.32.1
PROMETHEUS_DIST ?= $(shell go env GOOS)
PROMETHEUS_ARCH ?= $(shell go env GOARCH)
PROMETHEUS_DOWNLOAD_LINK ?= https://github.com/prometheus/prometheus/releases/download/v$(PROMETHEUS_VERSION)/prometheus-$(PROMETHEUS_VERSION).$(PROMETHEUS_DIST)-$(PROMETHEUS_ARCH).tar.gz
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ kubectl --as=cluster-admin -n appuio-thanos port-forward svc/thanos-query 9090 &
DB_USER=$(kubectl -n appuio-reporting get secret/reporting-db-superuser -o jsonpath='{.data.user}' | base64 --decode)
DB_PASSWORD=$(kubectl -n appuio-reporting get secret/reporting-db-superuser -o jsonpath='{.data.password}' | base64 --decode)
export ACR_DB_URL="postgres://${DB_USER}:${DB_PASSWORD}@localhost/reporting?sslmode=disable"
go run github.com/appuio/appuio-cloud-reporting migrate --show-pending
go run . migrate --show-pending

# Run a query
go run github.com/appuio/appuio-cloud-reporting report --query-name ping --begin "2022-01-17T09:00:00Z"
go run . report --query-name ping --begin "2022-01-17T09:00:00Z"

# Connect to the database's interactive terminal
DB_USER=$(kubectl -n appuio-reporting get secret/reporting-db-superuser -o jsonpath='{.data.user}' | base64 --decode)
Expand Down Expand Up @@ -58,7 +58,7 @@ DB_USER=$(kubectl -n appuio-reporting get secret/reporting-db-superuser -o jsonp
DB_PASSWORD=$(kubectl -n appuio-reporting get secret/reporting-db-superuser -o jsonpath='{.data.password}' | base64 --decode)
export ACR_DB_URL="postgres://${DB_USER}:${DB_PASSWORD}@localhost/reporting?sslmode=disable"

go run github.com/appuio/appuio-cloud-reporting report --query-name ping --begin "2022-01-17T09:00:00Z"
go run . report --query-name ping --begin "2022-01-17T09:00:00Z"
```

### Migrate to Most Recent Schema
Expand All @@ -70,9 +70,9 @@ DB_USER=$(kubectl -n appuio-reporting get secret/reporting-db-superuser -o jsonp
DB_PASSWORD=$(kubectl -n appuio-reporting get secret/reporting-db-superuser -o jsonpath='{.data.password}' | base64 --decode)
export ACR_DB_URL="postgres://${DB_USER}:${DB_PASSWORD}@localhost/reporting?sslmode=disable"

go run github.com/appuio/appuio-cloud-reporting migrate --show-pending
go run . migrate --show-pending

go run github.com/appuio/appuio-cloud-reporting migrate
go run . migrate
```

### Connect to the Database
Expand All @@ -94,8 +94,8 @@ Local development assumes a locally installed PostgreSQL database.
createdb appuio-cloud-reporting-test
export ACR_DB_URL="postgres://localhost/appuio-cloud-reporting-test?sslmode=disable"

go run github.com/appuio/appuio-cloud-reporting migrate
go run github.com/appuio/appuio-cloud-reporting migrate --seed
go run . migrate
go run . migrate --seed
go test ./...
```

Expand Down
32 changes: 0 additions & 32 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/go-logr/logr v1.2.2
github.com/go-logr/zapr v1.2.2
github.com/google/uuid v1.3.0
github.com/hashicorp/go-getter v1.5.11
github.com/jackc/pgconn v1.10.1
github.com/jackc/pgtype v1.9.1
github.com/jackc/pgx/v4 v4.14.1
Expand All @@ -20,55 +19,24 @@ require (
)

require (
cloud.google.com/go v0.65.0 // indirect
cloud.google.com/go/storage v1.10.0 // indirect
github.com/aws/aws-sdk-go v1.15.78 // indirect
github.com/benbjohnson/clock v1.1.0 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.1.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.2.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/klauspost/compress v1.11.2 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/mitchellh/go-homedir v1.0.0 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
go.opencensus.io v0.22.4 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.5 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/api v0.30.0 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 // indirect
google.golang.org/grpc v1.31.0 // indirect
google.golang.org/protobuf v1.26.0-rc.1 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

replace github.com/codahale/hdrhistogram => github.com/HdrHistogram/hdrhistogram-go v1.1.2
Loading

0 comments on commit 1d3bfe4

Please sign in to comment.