Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit df8041a

Browse files
JamesGuthriejgpruitt
authored andcommitted
Run tests against corresponding extension docker container
The main goal of this change (which is probably too large) is to ensure that we can build the promscale connector against a version of the promscale extension which contains all of the necessary bits. This change is motivated by the fact that there is now a hard dependency on the extension, and we need to be able to test in-progress changes across repositories. The basic mechanism is that for each open PR in the promscale_extension repo, there will be a docker image built and pushed to the registry at: `ghcr.io/timescale/dev_promscale_extension:<special-tag-here>`. `<special-tag-here>` is constructed from the branch name from which the PR originated. When a PR is opened in the promscale repository, we look to see if there is already a docker image corresponding to the branch name. If not, we fall back to the most recent docker image which was built on the `develop` branch in the extension repository. `<special-tag-here>` has the basic form of: `<extension-version>-<timescale-major>-<pg-version>` Some examples are: - `jg-ha-dockerfile-ts2-pg14` - `develop-ts2-pg14` - `0.5.0-ts2-pg14` Local development is supported through two mechanisms: 1. When running e.g. `make docker-image-14` in the promscale_extension repo, the docker image is tagged as: `local/dev_promscale_extension` with the `<extension-version>` component of the tag set to `head`. 2. When running `make test` in the promscale repo, it first looks to see if a local image is available matching the `local/` prefix, then checks for a docker image derived from the current branch name, and then for built from the `develop` branch. A number of things have changed tangentially as well: - end_to_end tests now take the docker image which they should run against as an argument instead of using some magic to derive it - `make test` was split into two components: `make unit` and `make e2e` - multinode tests are being skipped because we broke them in the develop branch of the promscale extension
1 parent 58da7b2 commit df8041a

16 files changed

+199
-154
lines changed

.github/workflows/go-scheduled.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ jobs:
112112
TSDB: ${{ matrix.test-setups.tsdb }}
113113
MULTI: ${{ matrix.test-setups.multi }}
114114
NIGHTLY: ${{ matrix.test-setups.nightly }}
115-
run: go test ./pkg/tests/end_to_end_tests/ -use-timescaledb=$TSDB -use-multinode=$MULTI -use-timescaledb-nightly=$NIGHTLY -postgres-version-major=$PG
115+
DOCKER_IMAGE: ghcr.io/timescale/dev_promscale_extension:develop-ts2-pg${{ matrix.test-setups.pg }}
116+
run: go test ./pkg/tests/end_to_end_tests/ -use-timescaledb=$TSDB -use-multinode=$MULTI -use-timescaledb-nightly=$NIGHTLY -timescale-docker-image=$DOCKER_IMAGE
116117

117118
test-helm-chart:
118119
name: Test helm-chart template generation

.github/workflows/go.yml

+22-5
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
${{ runner.os }}-go-
6767
6868
- name: Test
69-
run: make test > complete-test-run.log 2>&1
69+
run: make unit > complete-test-run.log 2>&1
7070

7171
- name: 'Print failure logs'
7272
if: ${{ failure() }}
@@ -95,8 +95,8 @@ jobs:
9595
- {name: "Singlenode (13)", shortname: "singlenode-13", tsdb: true, multi: false, pg: 13}
9696
- {name: "Singlenode", shortname: "singlenode-14", tsdb: true, multi: false, pg: 14}
9797
- {name: "Without TimescaleDB", shortname: "no-timescaledb", tsdb: false, multi: false, pg: 14}
98-
- {name: "Multinode", shortname: "multinode", tsdb: true, multi: true, pg: 14}
99-
98+
# TODO (james): Skipping multinode because tests are broken for now
99+
# - {name: "Multinode", shortname: "multinode", tsdb: true, multi: true, pg: 14}
100100
steps:
101101
- name: Check out code into the Go module directory
102102
uses: actions/checkout@v3
@@ -118,13 +118,30 @@ jobs:
118118
restore-keys: |
119119
${{ runner.os }}-go-
120120
121+
- name: Login to GitHub Container Registry
122+
uses: docker/login-action@v1
123+
with:
124+
registry: ghcr.io
125+
username: ${{ github.actor }}
126+
password: ${{ secrets.GITHUB_TOKEN }}
127+
128+
- name: Prepare metadata
129+
id: metadata
130+
run: |
131+
branch_name=$(echo ${{github.head_ref || github.ref_name}} | sed 's#/#-#')
132+
possible_branch_tag=$(echo ${branch_name}-ts2-pg${{matrix.test-setups.pg}})
133+
develop_branch_tag=$(echo develop-ts2-pg${{matrix.test-setups.pg}})
134+
image_base="ghcr.io/timescale/dev_promscale_extension"
135+
docker_image=$(./scripts/fallback-docker.sh ${image_base}:${possible_branch_tag} ${image_base}:${develop_branch_tag})
136+
echo "::set-output name=docker_image::${docker_image}"
137+
121138
- name: Test ${{ matrix.test-setups.name }}
122139
env:
123-
PG: ${{ matrix.test-setups.pg }}
140+
DOCKER_IMAGE: ${{steps.metadata.outputs.docker_image}}
124141
TSDB: ${{ matrix.test-setups.tsdb }}
125142
MULTI: ${{ matrix.test-setups.multi }}
126143
SHORTNAME: ${{ matrix.test-setups.shortname }}
127-
run: go test -race -timeout=30m ./pkg/tests/end_to_end_tests/ -use-timescaledb=$TSDB -use-multinode=$MULTI -postgres-version-major=$PG | tee $SHORTNAME-test-run.log 2>&1
144+
run: go test -race -timeout=30m ./pkg/tests/end_to_end_tests/ -use-timescaledb=$TSDB -use-multinode=$MULTI -timescale-docker-image=$DOCKER_IMAGE | tee $SHORTNAME-test-run.log 2>&1
128145

129146
- name: 'Upload Log Artifact'
130147
if: ${{ always() }}

.github/workflows/integration.yml

+16-8
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ jobs:
1818
runs-on: ubuntu-latest
1919
strategy:
2020
matrix:
21-
test-setups:
22-
- {name: "TimescaleDB 2.x without Promscale extension (pg13)", image: "timescale/timescaledb:latest-pg13"}
23-
- {name: "TimescaleDB 2.x with Promscale extension (pg13)", image: "timescaledev/promscale-extension:latest-ts2-pg13"}
24-
- {name: "TimescaleDB 2.x with Promscale extension (pg12)", image: "timescaledev/promscale-extension:latest-ts2-pg12"}
25-
- {name: "TimescaleDB 1.x with Promscale extension (pg12)", image: "timescaledev/promscale-extension:latest-ts1-pg12"}
26-
- {name: "Test against first supported", image: "timescale/timescaledb:1.7.4-pg12"}
21+
pg:
22+
- 14
23+
- 13
24+
- 12
2725
steps:
2826
- name: Check out code into the Go module directory
2927
uses: actions/checkout@v3
@@ -34,8 +32,18 @@ jobs:
3432
go-version: ${{ env.golang-version }}
3533
id: go
3634

37-
- name: ${{ matrix.test-setups.name }}
38-
run: ./scripts/end_to_end_tests.sh ${{ matrix.test-setups.image }}
35+
- name: Prepare metadata
36+
id: metadata
37+
run: |
38+
branch_name=$(echo ${{github.head_ref || github.ref_name}} | sed 's#/#-#')
39+
possible_branch_tag=$(echo ${branch_name}-ts2-pg${{matrix.pg}})
40+
develop_branch_tag=$(echo develop-ts2-pg${{matrix.pg}})
41+
image_base="ghcr.io/timescale/dev_promscale_extension"
42+
docker_image=$(./scripts/fallback-docker.sh ${image_base}:${possible_branch_tag} ${image_base}:${develop_branch_tag})
43+
echo "::set-output name=docker_image::${docker_image}"
44+
45+
- name: TimescaleDB 2.x with Promscale extension (pg${{matrix.pg}})
46+
run: ./scripts/end_to_end_tests.sh ${{steps.metadata.outputs.docker_image}}
3947
shell: bash
4048

4149
# Added to summarize the matrix (otherwise we would need to list every single job in branch protection rules)

Makefile

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
GIT_COMMIT ?= $(shell git rev-list -1 HEAD)
22
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
3+
LOCAL_DOCKER_BASE := local/dev_promscale_extension
4+
GHCR_DOCKER_BASE := ghcr.io/timescale/dev_promscale_extension
35

46
.PHONY: build
57
build: generate
68
go build -ldflags "-X 'github.com/timescale/promscale/pkg/version.Branch=${GIT_BRANCH}' -X 'github.com/timescale/promscale/pkg/version.CommitHash=${GIT_COMMIT}'" -o dist/promscale ./cmd/promscale
79

810
.PHONY: test
9-
test: generate
10-
go test -v -race ./... -timeout 40m
11+
test: unit e2e
12+
13+
.PHONY: unit
14+
unit: generate
15+
go test -v -race $(shell go list ./... | grep -v tests/end_to_end_tests) -timeout 40m
1116

1217
# traces-dataset.sz is used by ./pkg/tests/end_to_end_tests/ingest_trace_test.go
1318
pkg/tests/testdata/traces-dataset.sz:
1419
wget https://github.com/timescale/promscale-test-data/raw/main/traces-dataset.sz -O ./pkg/tests/testdata/traces-dataset.sz
1520

16-
.PHONY: e2e-test
17-
e2e-test: pkg/tests/testdata/traces-dataset.sz generate
18-
go test -v ./pkg/tests/end_to_end_tests/
19-
go test -v ./pkg/tests/end_to_end_tests/ -use-timescaledb=false
20-
go test -v ./pkg/tests/end_to_end_tests/ -use-multinode
21+
.PHONY: e2e
22+
e2e: CURRENT_BRANCH?=$(shell git branch --show-current | sed 's#/#-#')
23+
e2e: DOCKER_IMAGE?=$(shell ./scripts/fallback-docker.sh $(LOCAL_DOCKER_BASE):head-ts2-pg14 $(GHCR_DOCKER_BASE):$(CURRENT_BRANCH)-ts2-pg14 $(GHCR_DOCKER_BASE):develop-ts2-pg14)
24+
e2e: pkg/tests/testdata/traces-dataset.sz generate
25+
go test -v ./pkg/tests/end_to_end_tests/ -timescale-docker-image=$(DOCKER_IMAGE)
26+
go test -v ./pkg/tests/end_to_end_tests/ -use-timescaledb=false -timescale-docker-image=$(DOCKER_IMAGE)
27+
go test -v ./pkg/tests/end_to_end_tests/ -use-multinode -timescale-docker-image=$(DOCKER_IMAGE)
2128

2229
.PHONY: go-fmt
2330
go-fmt:
@@ -38,4 +45,4 @@ check-alerts:
3845
promtool check rules docs/mixin/alerts/alerts.yaml
3946

4047
.PHONY: all
41-
all: build test e2e-test go-fmt go-lint
48+
all: build test go-fmt go-lint

docker-compose/docker-compose.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ version: '3.0'
22

33
services:
44
db:
5-
image: timescale/timescaledb-ha:pg14-latest
5+
#TODO (james): Replace hardcoded value
6+
image: ghcr.io/timescale/dev_promscale_extension:develop-ts2-pg14
67
ports:
78
- 5432:5432/tcp
89
environment:

docker-compose/high-availability/docker-compose.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ version: '3.0'
22

33
services:
44
db:
5-
image: timescale/timescaledb-ha:pg14-latest
5+
#TODO (james): Replace hardcoded value
6+
image: ghcr.io/timescale/dev_promscale_extension:develop-ts2-pg14
67
ports:
78
- 5432:5432/tcp
89
environment:

pkg/internal/testhelpers/containers_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ var (
2323
testDatabase = flag.String("database", "tmp_db_timescale_migrate_test", "database to run integration tests on")
2424
)
2525

26-
const extensionState = timescaleBit | postgres12Bit
27-
2826
func TestPGConnection(t *testing.T) {
2927
if testing.Short() {
3028
t.Skip("skipping integration test")
@@ -48,6 +46,8 @@ func TestWithDB(t *testing.T) {
4846
if testing.Short() {
4947
t.Skip("skipping integration test")
5048
}
49+
// TODO (james): Replace hardcoded value
50+
extensionState := NewTestOptions(timescaleBit, "ghcr.io/timescale/dev_promscale_extension:develop-ts2-pg14")
5151
WithDB(t, *testDatabase, Superuser, false, extensionState, func(db *pgxpool.Pool, t testing.TB, connectURL string) {
5252
var res int
5353
err := db.QueryRow(context.Background(), "SELECT 1").Scan(&res)
@@ -63,6 +63,8 @@ func TestWithDB(t *testing.T) {
6363
func runMain(m *testing.M) int {
6464
flag.Parse()
6565
ctx := context.Background()
66+
// TODO (james): Replace hardcoded value
67+
extensionState := NewTestOptions(timescaleBit, "ghcr.io/timescale/dev_promscale_extension:develop-ts2-pg14")
6668
if !testing.Short() && *useDocker {
6769
_, closer, err := StartPGContainer(ctx, extensionState, "", false)
6870
if err != nil {

0 commit comments

Comments
 (0)