Skip to content

Commit eedf513

Browse files
committed
Exporter refactor. Remove all of crunchy-postgres-exporter from this repo. Refactor postgres-operator to hold the setup.sql and queries.yml files used by the postgres_exporter. Add logic to postgres-operator to replace the functionality that was in the start.sh script that will be removed from the exporter image. Adjust testing accordingly.
1 parent f7bec84 commit eedf513

File tree

22 files changed

+449
-718
lines changed

22 files changed

+449
-718
lines changed

.github/workflows/test.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
branches:
99
- master
1010

11+
env:
12+
QUERIES_CONFIG_DIR: "${{ github.workspace }}/hack/tools/queries"
13+
1114
jobs:
1215
go-test:
1316
runs-on: ubuntu-20.04

Makefile

Lines changed: 12 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,9 @@ PGO_IMAGE_DESCRIPTION ?= $(PGO_IMAGE_SUMMARY)
55
PGO_IMAGE_URL ?= https://www.crunchydata.com/products/crunchy-postgresql-for-kubernetes
66
PGO_IMAGE_PREFIX ?= localhost
77

8-
CRUNCHY_POSTGRES_EXPORTER_IMAGE_NAME ?= crunchy-postgres-exporter
9-
CRUNCHY_POSTGRES_EXPORTER_MAINTAINER ?= $(PGO_IMAGE_MAINTAINER)
10-
CRUNCHY_POSTGRES_EXPORTER_SUMMARY ?= Metrics exporter for PostgreSQL
11-
CRUNCHY_POSTGRES_EXPORTER_DESCRIPTION ?= \
12-
When run with the crunchy-postgres family of containers, crunchy-postgres-exporter reads the PostgreSQL data directory \
13-
and has a SQL interface to a database to allow for metrics collection.
14-
CRUNCHY_POSTGRES_EXPORTER_URL ?= https://www.crunchydata.com/products/crunchy-postgresql-for-kubernetes
15-
CRUNCHY_POSTGRES_EXPORTER_IMAGE_PREFIX ?= $(PGO_IMAGE_PREFIX)
16-
CRUNCHY_POSTGRES_EXPORTER_PG_VERSION ?= 15
17-
CRUNCHY_POSTGRES_EXPORTER_PG_FULL_VERSION ?= 15.3
18-
198
PGMONITOR_DIR ?= hack/tools/pgmonitor
209
PGMONITOR_VERSION ?= v4.8.1
21-
POSTGRES_EXPORTER_VERSION ?= 0.12.1
22-
POSTGRES_EXPORTER_ARCHITECTURE ?= amd64
23-
POSTGRES_EXPORTER_URL ?= https://github.com/prometheus-community/postgres_exporter/releases/download/v${POSTGRES_EXPORTER_VERSION}/postgres_exporter-${POSTGRES_EXPORTER_VERSION}.linux-${POSTGRES_EXPORTER_ARCHITECTURE}.tar.gz
10+
QUERIES_CONFIG_DIR ?= hack/tools/queries
2411

2512
# Buildah's "build" used to be "bud". Use the alias to be compatible for a while.
2613
BUILDAH_BUILD ?= buildah bud
@@ -58,23 +45,19 @@ help: ## Display this help.
5845
.PHONY: all
5946
all: ## Build all images
6047
all: build-postgres-operator-image
61-
all: build-crunchy-postgres-exporter-image
6248

6349
.PHONY: setup
6450
setup: ## Run Setup needed to build images
6551
setup: get-pgmonitor
66-
setup: get-postgres-exporter
6752

6853
.PHONY: get-pgmonitor
6954
get-pgmonitor:
7055
git -C '$(dir $(PGMONITOR_DIR))' clone https://github.com/CrunchyData/pgmonitor.git || git -C '$(PGMONITOR_DIR)' fetch origin
7156
@git -C '$(PGMONITOR_DIR)' checkout '$(PGMONITOR_VERSION)'
7257
@git -C '$(PGMONITOR_DIR)' config pull.ff only
73-
74-
.PHONY: get-postgres-exporter
75-
get-postgres-exporter:
76-
[ ! -e hack/tools/postgres_exporter.tar.gz ] || (rm hack/tools/postgres_exporter.tar.gz && echo "Deleting old exporter")
77-
wget -O hack/tools/postgres_exporter.tar.gz '$(POSTGRES_EXPORTER_URL)'
58+
[ -d '${QUERIES_CONFIG_DIR}' ] || mkdir -p '${QUERIES_CONFIG_DIR}'
59+
cp -r '$(PGMONITOR_DIR)/postgres_exporter/common/.' '${QUERIES_CONFIG_DIR}'
60+
cp '$(PGMONITOR_DIR)/postgres_exporter/linux/queries_backrest.yml' '${QUERIES_CONFIG_DIR}'
7861

7962
.PHONY: clean
8063
clean: ## Clean resources
@@ -105,6 +88,10 @@ clean-deprecated: ## Clean deprecated resources
10588
@# keys used to be generated before install
10689
[ ! -d conf/pgo-backrest-repo ] || rm -r conf/pgo-backrest-repo
10790
[ ! -d conf/postgres-operator ] || rm -r conf/postgres-operator
91+
@# crunchy-postgres-exporter used to live in this repo
92+
[ ! -d bin/crunchy-postgres-exporter ] || rm -r bin/crunchy-postgres-exporter
93+
[ ! -d build/crunchy-postgres-exporter ] || rm -r build/crunchy-postgres-exporter
94+
10895

10996
##@ Deployment
11097
.PHONY: createnamespaces
@@ -134,11 +121,13 @@ undeploy: ## Undeploy the PostgreSQL Operator
134121
.PHONY: deploy-dev
135122
deploy-dev: ## Deploy the PostgreSQL Operator locally
136123
deploy-dev: PGO_FEATURE_GATES ?= "TablespaceVolumes=true"
124+
deploy-dev: get-pgmonitor
137125
deploy-dev: build-postgres-operator
138126
deploy-dev: createnamespaces
139127
kubectl apply --server-side -k ./config/dev
140128
hack/create-kubeconfig.sh postgres-operator pgo
141129
env \
130+
QUERIES_CONFIG_DIR="${QUERIES_CONFIG_DIR}" \
142131
CRUNCHY_DEBUG=true \
143132
PGO_FEATURE_GATES="${PGO_FEATURE_GATES}" \
144133
CHECK_FOR_UPGRADES='$(if $(CHECK_FOR_UPGRADES),$(CHECK_FOR_UPGRADES),false)' \
@@ -158,45 +147,6 @@ build-postgres-operator: ## Build the postgres-operator binary
158147
-o bin/postgres-operator ./cmd/postgres-operator
159148

160149
##@ Build - Images
161-
.PHONY: build-crunchy-postgres-exporter-image
162-
build-crunchy-postgres-exporter-image: ## Build the crunchy-postgres-exporter image
163-
build-crunchy-postgres-exporter-image: CRUNCHY_POSTGRES_EXPORTER_IMAGE_REVISION := $(shell git rev-parse HEAD)
164-
build-crunchy-postgres-exporter-image: CRUNCHY_POSTGRES_EXPORTER_IMAGE_TIMESTAMP := $(shell date -u +%FT%TZ)
165-
build-crunchy-postgres-exporter-image: build/crunchy-postgres-exporter/Dockerfile
166-
$(if $(shell (echo 'buildah version 1.24'; $(word 1,$(BUILDAH_BUILD)) --version) | sort -Vc 2>&1), \
167-
$(warning WARNING: old buildah does not invalidate its cache for changed labels: \
168-
https://github.com/containers/buildah/issues/3517))
169-
$(if $(IMAGE_TAG),, $(error missing IMAGE_TAG))
170-
$(strip $(BUILDAH_BUILD)) \
171-
--tag $(BUILDAH_TRANSPORT)$(CRUNCHY_POSTGRES_EXPORTER_IMAGE_PREFIX)/$(CRUNCHY_POSTGRES_EXPORTER_IMAGE_NAME):$(IMAGE_TAG) \
172-
--build-arg PGVERSION=$(CRUNCHY_POSTGRES_EXPORTER_PG_VERSION) \
173-
--label name='$(CRUNCHY_POSTGRES_EXPORTER_IMAGE_NAME)' \
174-
--label build-date='$(CRUNCHY_POSTGRES_EXPORTER_IMAGE_TIMESTAMP)' \
175-
--label description='$(CRUNCHY_POSTGRES_EXPORTER_DESCRIPTION)' \
176-
--label maintainer='$(CRUNCHY_POSTGRES_EXPORTER_MAINTAINER)' \
177-
--label summary='$(CRUNCHY_POSTGRES_EXPORTER_SUMMARY)' \
178-
--label url='$(CRUNCHY_POSTGRES_EXPORTER_URL)' \
179-
--label vcs-ref='$(CRUNCHY_POSTGRES_EXPORTER_IMAGE_REVISION)' \
180-
--label vendor='$(CRUNCHY_POSTGRES_EXPORTER_MAINTAINER)' \
181-
--label postgres.version.major='$(CRUNCHY_POSTGRES_EXPORTER_PG_VERSION)' \
182-
--label postgres.version='$(CRUNCHY_POSTGRES_EXPORTER_PG_FULL_VERSION)' \
183-
--label io.k8s.display-name='$(CRUNCHY_POSTGRES_EXPORTER_IMAGE_NAME)' \
184-
--label io.k8s.description='$(CRUNCHY_POSTGRES_EXPORTER_DESCRIPTION)' \
185-
--label io.openshift.tags="postgresql,postgres,monitoring,database,crunchy" \
186-
--annotation org.opencontainers.image.authors='$(CRUNCHY_POSTGRES_EXPORTER_MAINTAINER)' \
187-
--annotation org.opencontainers.image.vendor='$(CRUNCHY_POSTGRES_EXPORTER_MAINTAINER)' \
188-
--annotation org.opencontainers.image.created='$(CRUNCHY_POSTGRES_EXPORTER_IMAGE_TIMESTAMP)' \
189-
--annotation org.opencontainers.image.description='$(CRUNCHY_POSTGRES_EXPORTER_DESCRIPTION)' \
190-
--annotation org.opencontainers.image.revision='$(CRUNCHY_POSTGRES_EXPORTER_IMAGE_REVISION)' \
191-
--annotation org.opencontainers.image.title='$(CRUNCHY_POSTGRES_EXPORTER_SUMMARY)' \
192-
--annotation org.opencontainers.image.url='$(CRUNCHY_POSTGRES_EXPORTER_URL)' \
193-
$(if $(PGO_VERSION),$(strip \
194-
--label release='$(PGO_VERSION)' \
195-
--label version='$(PGO_VERSION)' \
196-
--annotation org.opencontainers.image.version='$(PGO_VERSION)' \
197-
)) \
198-
--file $< --format docker --layers .
199-
200150
.PHONY: build-postgres-operator-image
201151
build-postgres-operator-image: ## Build the postgres-operator image
202152
build-postgres-operator-image: PGO_IMAGE_REVISION := $(shell git rev-parse HEAD)
@@ -245,7 +195,7 @@ check: ## Run basic go tests with coverage output
245195
check-envtest: ## Run check using envtest and a mock kube api
246196
check-envtest: ENVTEST_USE = hack/tools/setup-envtest --bin-dir=$(CURDIR)/hack/tools/envtest use $(ENVTEST_K8S_VERSION)
247197
check-envtest: SHELL = bash
248-
check-envtest:
198+
check-envtest: get-pgmonitor
249199
GOBIN='$(CURDIR)/hack/tools' $(GO) install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
250200
@$(ENVTEST_USE) --print=overview && echo
251201
source <($(ENVTEST_USE) --print=env) && PGO_NAMESPACE="postgres-operator" $(GO_TEST) -count=1 -cover -tags=envtest ./...
@@ -256,6 +206,7 @@ check-envtest:
256206
# make check-envtest-existing PGO_TEST_TIMEOUT_SCALE=1.2
257207
.PHONY: check-envtest-existing
258208
check-envtest-existing: ## Run check using envtest and an existing kube api
209+
check-envtest-existing: get-pgmonitor
259210
check-envtest-existing: createnamespaces
260211
kubectl apply --server-side -k ./config/dev
261212
USE_EXISTING_CLUSTER=true PGO_NAMESPACE="postgres-operator" $(GO_TEST) -count=1 -cover -p=1 -tags=envtest ./...
@@ -366,14 +317,3 @@ release-postgres-operator-image-labels:
366317
$(if $(PGO_IMAGE_NAME),, $(error missing PGO_IMAGE_NAME))
367318
$(if $(PGO_IMAGE_SUMMARY),, $(error missing PGO_IMAGE_SUMMARY))
368319
$(if $(PGO_VERSION),, $(error missing PGO_VERSION))
369-
370-
.PHONY: release-crunchy-postgres-exporter-image release-crunchy-postgres-exporter-image-labels
371-
release-crunchy-postgres-exporter-image: ## Build the postgres-operator image and all its prerequisites
372-
release-crunchy-postgres-exporter-image: release-crunchy-postgres-exporter-image-labels
373-
release-crunchy-postgres-exporter-image: build-crunchy-postgres-exporter-image
374-
release-crunchy-postgres-exporter-image-labels:
375-
$(if $(CRUNCHY_POSTGRES_EXPORTER_DESCRIPTION),, $(error missing CRUNCHY_POSTGRES_EXPORTER_DESCRIPTION))
376-
$(if $(CRUNCHY_POSTGRES_EXPORTER_MAINTAINER),, $(error missing CRUNCHY_POSTGRES_EXPORTER_MAINTAINER))
377-
$(if $(CRUNCHY_POSTGRES_EXPORTER_IMAGE_NAME),, $(error missing CRUNCHY_POSTGRES_EXPORTER_IMAGE_NAME))
378-
$(if $(CRUNCHY_POSTGRES_EXPORTER_SUMMARY),, $(error missing CRUNCHY_POSTGRES_EXPORTER_SUMMARY))
379-
$(if $(PGO_VERSION),, $(error missing PGO_VERSION))

bin/crunchy-postgres-exporter/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

bin/crunchy-postgres-exporter/common_lib.sh

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)