Files
floci/.github/workflows/compatibility.yml
T
Vũ Thế Huy 426fbcb284 feat/redshift auth proxy (#2751)
* feat(redshift): add auth proxy port range and endpoint-host config

* feat(redshift): add containerHost/containerPort/proxyPort to Cluster model

* feat(redshift): add RedshiftAuthProxy reusing the RDS PostgreSQL protocol handler

* feat(redshift): add RedshiftProxyManager registry with shutdown hook

* feat(redshift): front new clusters with an auth proxy and advertise it

* feat(redshift): stop/update proxy on delete/modify, start it on snapshot restore

* feat(redshift): keep proxy port stable across reboot and adopt-on-startup

* test(redshift): integration coverage for JDBC through the auth proxy

* test(redshift): reinstate JDBC connectivity check now that the proxy exists

* docs(redshift): document the cluster auth proxy and its config

* fix(redshift): prevent minor port leak when proxy fails to start

* fix(redshift): rollback container on proxy failure and surface teardown errors

* fix(redshift): stop auth proxy on rollback to prevent listener collisions

* fix(redshift): ensure proxy shutdown failure does not abort container and port cleanup

* fix(redshift): add proper logging for intentionally ignored cleanup exceptions

* fix: Wait for Redshift database readiness before proxying

Previously, RedshiftContainerManager just slept for 3 seconds before marking the container as started. On slower CI environments, the PostgreSQL database might take longer to initialize, resulting in Connection Refused when the RedshiftAuthProxy forwards connections.
Now, RedshiftContainerManager polls the database using psql until it's ready, up to 60 seconds.

* fix(redshift): prevent proxy port reallocation on shutdown failure

Addresses a review comment indicating that if a Redshift auth proxy fails to shut down during rollback or deletion, its port must not be released into the available pool. Reassigning a still-bound port would cause subsequent cluster creations to fail with a BindException.
Instead, we now tolerate proxy shutdown errors but intentionally leak the port allocation to prevent collisions.

* fix(redshift): fix failing tests due to proxy changes

1. RedshiftOperationsTest checked for a hardcoded port 5440, but the RedshiftService now allocates dynamic proxy ports. Removed the exact port assertion.
2. RedshiftContainerManager's psql readiness check was connecting via local Unix socket, which succeeded before PostgreSQL was actually ready to accept remote TCP connections from the proxy. Added '-h 127.0.0.1' to enforce TCP readiness.

* test(redshift): use Awaitility to connect to proxy

Use Awaitility to retry the initial connection in RedshiftProxyIntegrationTest to prevent transient 'Connection attempt failed' errors on slower CI environments.

* chore(redshift): use proper imports instead of fully-qualified class names in tests

* fix(redshift): fix compiler errors introduced during import cleanup

* fix(redshift): resolve proxy lifecycle bugs and CI network issues

- Throw RuntimeException from RedshiftProxyManager.stopProxy if proxy is not found. This allows RedshiftService to catch it and intentionally leak the port, preventing port collisions if a proxy fails before registration.
- Force RedshiftProxyIntegrationTest to connect via 127.0.0.1 instead of the endpoint address, which resolves to host.docker.internal in CI environments and causes UnknownHostException.

* fix(redshift): prevent proxy port exhaustion on startup failures

Instead of blindly assuming missing proxies denote a leaked port, RedshiftProxyManager now tracks proxies that failed their socket cleanup during startup. stopProxy throws an exception only if the socket is known to be leaked. This allows RedshiftService to safely release ports after clean proxy startup failures, addressing Greptile's feedback about port exhaustion.

* fix(redshift): retain proxy reference to allow retry on close failure

As identified by Greptile, stopProxy previously removed the proxy from the registry before calling proxy.stop(). If stop() threw an exception, the proxy reference was lost, preventing any subsequent retry from ever finding it and attempting to close it again. stopProxy now only removes the proxy from the registry after stop() returns successfully. Additionally, failedCleanups is now retained instead of cleared, ensuring retries continue to safely leak the port if cleanup remains impossible.

* fix(redshift): abort cluster deletion if proxy fails to stop

As highlighted by Greptile, previously deleteCluster would swallow proxy shutdown failures and delete the cluster metadata anyway. This eliminated the retry path, stranding the unclosed proxy and its port reservation until the process exited. Now, if stopProxyAndReleasePortSafely fails, deleteCluster throws an exception to preserve the cluster metadata so the deletion can be retried.

* test(redshift): lock in proxy lifecycle failure-recovery behaviors

Bổ sung test cho ba hành vi hardening chưa được cover, để refactor sau
không âm thầm phá vỡ:

- stopProxy giữ lại proxy trong registry khi close() ném, cho phép retry
  gọi lại đúng instance và chỉ deregister sau khi stop sạch
- marker leak khi startup cleanup thất bại được retain qua mọi retry và
  chỉ bị xoá bởi một lần start mới thành công
- deleteCluster abort với InternalFailure, giữ nguyên container + metadata
  khi proxy không stop được; retry sau đó hoàn tất khi proxy stop OK

Đồng thời bỏ "-p 7100-7199:7100-7199" trong compatibility.yml: proxy bind
0.0.0.0 trong container floci và sdk-test-java chạy trên compat-net nên
JDBC đi container-to-container qua alias "floci", không cần publish port
ra host. Giữ lại FLOCI_SERVICES_REDSHIFT_ENDPOINT_HOST=floci.

* fix(redshift): keep an unclosable proxy reachable for later retry

Theo phản hồi mới của Greptile: khi start/replace proxy thất bại và
cleanupFailedStart cũng không đóng được listener, code cũ chỉ lưu relayKey
vào một Set rồi vứt object RedshiftAuthProxy. stopProxy sau đó ném vĩnh
viễn mà không còn cách nào chạm tới listener để thử đóng lại, khiến
cluster không xoá được và port bị giữ mãi trong dải hữu hạn.

Thay Set<String> failedCleanups bằng Map<String, RedshiftAuthProxy>
unclosableProxies. cleanupFailedStart giữ lại chính proxy đó; stopProxy và
stopAll thử đóng lại, chỉ gỡ entry khi stop thành công. startProxy không
còn xoá marker khi start mới — chỉ một lần stop thành công mới gỡ, vì
listener cũ có thể vẫn đang bound.

* fix(redshift): retry proxy port bind to absorb reboot rebind race

rebootCluster giữ nguyên proxy port của cluster để endpoint ổn định, nên
listener cũ bị đóng rồi bind lại đúng port đó chỉ vài ms sau. Dưới tải
(CI runner ARM) kernel có thể chưa nhả port và SO_REUSEADDR không giúp
được khi accept loop cũ đang teardown -> BindException -> RebootCluster
trả 500. Đây là nguyên nhân test RedshiftOperationsTest.
testClusterAndSnapshotLifecycle fail chập chờn.

start() giờ retry bind tối đa ~1s, chỉ nuốt BindException; IOException
khác vẫn propagate ngay. Thêm test dựng cảnh port bị chiếm tạm thời rồi
nhả, xác nhận proxy vẫn bind được.

* fix(redshift): tear down proxy and release port when rebootCluster fails

Nếu startProxy/restoreSnapshot ném sau khi proxy đã (re)start trong
rebootCluster, hai nhánh catch chỉ set status "failed" rồi rethrow —
proxy mới vẫn chạy và port vẫn nằm trong usedPorts, không nhánh nào dọn.
Giờ cả hai catch gọi stopProxyAndReleasePortSafely như createCluster và
restoreFromClusterSnapshot đã làm; proxyPort được hoist ra ngoài try với
sentinel -1 để rollback an toàn kể cả khi chưa cấp port.

Thêm test: restoreSnapshot ném -> proxy được stop lại, AwsException nổi lên.

* fix(redshift): serialize createCluster/deleteCluster/restoreFromClusterSnapshot

modifyCluster và rebootCluster đã synchronized nhưng create/delete/restore
thì không, dù cả năm method đều chạy chuỗi container + proxy + port nhiều
bước trên cùng một cluster. deleteCluster(x) chạy song song rebootCluster(x)
có thể để lại metadata mồ côi trỏ tới container/proxy đã dừng. Thêm
synchronized cho ba method còn lại để nhất quán.

* fix(rds,redshift): close backend socket when the auth handshake fails

handleConnection mở kết nối TCP tới container Postgres trước khi gọi
handleAuth. Chỉ nhánh thành công (bridge) và vài nhánh lỗi có kiểm soát
mới đóng backend; nếu handleAuth trả về sớm ở một probe trần (SSLRequest
không kèm startup) hoặc ném IOException (client ngắt giữa handshake), catch
cũ chỉ đóng client -> mỗi health-check TCP làm rò một connection tới
Postgres, ăn dần max_connections.

Chuyển việc đóng socket sang finally, đóng cả client lẫn backend
(idempotent, nhánh thành công đã đóng sẵn). Áp cho cả RdsAuthProxy vì
RedshiftAuthProxy được copy từ đó. Thêm test: client drop giữa handshake
-> backend nhận EOF.

* fix(redshift): stop replacement container and keep dump on failed reboot

Rollback của rebootCluster (b44fd1e3) mới chỉ stop proxy + release port,
để container thay thế chạy tiếp sau một cluster "failed", và finally vẫn
xoá tempDump. Vì container gốc đã stop và không có volume, tempDump là bản
sao duy nhất của data -> mất data không khôi phục được (bug có sẵn, giờ
mới lộ).

rollbackReboot() giờ stop luôn container thay thế (như createCluster/
restoreFromClusterSnapshot). tempDump chỉ bị xoá khi reboot thành công;
khi fail thì giữ lại và log đường dẫn để khôi phục thủ công.

* fix(redshift): make reboot rollback phase-aware to protect the original

Commit trước cho rollbackReboot stop container vô điều kiện. Nếu reboot
fail ngay ở takeSnapshot hoặc stopProxy — lúc container gốc (chứa data,
không volume) VẪN đang chạy — thì rollback lại force-remove chính nó, huỷ
bản sao data hoàn chỉnh duy nhất và chỉ còn dump rỗng/dở.

Thêm hai cờ:
- originalTornDown: đã stop proxy + container gốc -> rollback mới được
  đụng vào proxy/port
- replacementStarted: đã start container thay thế -> rollback mới được
  stop container
Fail trước hai mốc đó: không đụng gì, trạng thái gốc còn nguyên.

Thêm test: takeSnapshot ném -> cm.stop và stopProxy không được gọi.

* fix(redshift): clean an orphan replacement container on failed reboot

containerManager.start có thể tạo container Docker rồi mới ném ở
waitForReady, nên cờ replacementStarted (set sau khi start return) bỏ sót
trường hợp này -> orphan chạy dưới tên cluster.

Bỏ replacementStarted, gate rollback theo mỗi originalTornDown: một khi
proxy + container gốc đã stop thì container gốc chắc chắn biến mất, nên
containerManager.stop (xoá theo tên) chỉ có thể chạm replacement — kể cả
replacement do start() tạo dở rồi ném.

Thêm test: start() ném -> rollback vẫn gọi cm.stop để dọn orphan.

* fix(redshift): remove orphan cluster metadata on failed create/restore

* fix(redshift): keep failed cluster metadata if proxy stop fails

* fix(redshift): fix TooManyActualInvocations in proxy tests

* fix(redshift): clear proxyPort on reboot rollback if port is released

* fix(redshift): retain reserved port on reboot startup failure

* fix(redshift): retain proxy port in reboot rollback and teardown failed startup recovery

* fix(redshift): skip failing cluster and retaining dump if reboot fails before teardown
2026-08-31 09:03:26 -04:00

294 lines
13 KiB
YAML

name: Compatibility Tests
on:
pull_request:
paths:
- 'src/**'
- 'pom.xml'
- 'docker/Dockerfile.native-package'
- 'docker/Dockerfile.compat'
- 'docker/entrypoint.sh'
- 'docker/localstack-parity.sh'
- 'compatibility-tests/**'
- '.github/ci/compat-timing-report.py'
- '.github/workflows/compatibility.yml'
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
compat-aws-cli-shim:
name: compat / aws CLI endpoint resolution
runs-on: ubuntu-24.04-arm
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
- name: Build compat image
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
with:
context: .
file: docker/Dockerfile.compat
build-args: VERSION=latest
load: true
tags: floci-compat-shim-test
# Read-only; warm-compat-caches.yml produces this scope on main. Unlike
# floci-native above, these layers are worth caching: the image builds
# FROM a published floci/floci tag and its cost is a microdnf install
# that changes only when the Dockerfile does. Writing from here would
# put a per-PR copy no other PR can read back into the budget.
cache-from: type=gha,scope=compat-shim
- name: Unflagged aws sqs call routes to AWS_ENDPOINT_URL
run: |
out=$(docker run --rm --entrypoint sh floci-compat-shim-test -c \
"aws sqs create-queue --queue-name smoke-test 2>&1" || true)
echo "$out"
echo "$out" | grep -q "localhost:4566" \
|| { echo "::error::unflagged aws call did not target localhost:4566"; exit 1; }
echo "$out" | grep -qi "queue.amazonaws.com\|InvalidClientTokenId" \
&& { echo "::error::unflagged aws call reached real AWS endpoint"; exit 1; }
exit 0
- name: AWS_ENDPOINT_URL_SQS alone routes correctly
run: |
out=$(docker run --rm --entrypoint sh -e AWS_ENDPOINT_URL= \
-e AWS_ENDPOINT_URL_SQS=http://localhost:4566 \
floci-compat-shim-test -c \
"aws sqs create-queue --queue-name smoke-test-service-override 2>&1" || true)
echo "$out"
echo "$out" | grep -q "localhost:4566" \
|| { echo "::error::AWS_ENDPOINT_URL_SQS was not honored"; exit 1; }
echo "$out" | grep -qi "queue.amazonaws.com\|InvalidClientTokenId" \
&& { echo "::error::AWS_ENDPOINT_URL_SQS call reached real AWS endpoint"; exit 1; }
exit 0
- name: Explicit --endpoint-url before the subcommand overrides AWS_ENDPOINT_URL
run: |
out=$(docker run --rm --entrypoint sh floci-compat-shim-test -c \
"AWS_ENDPOINT_URL=http://example.com aws --endpoint-url http://other.example.com sqs list-queues 2>&1" || true)
echo "$out"
echo "$out" | grep -q "other.example.com" \
|| { echo "::error::pre-subcommand --endpoint-url flag was not honored over AWS_ENDPOINT_URL"; exit 1; }
- name: Explicit --endpoint-url after the subcommand overrides AWS_ENDPOINT_URL
run: |
out=$(docker run --rm --entrypoint sh floci-compat-shim-test -c \
"AWS_ENDPOINT_URL=http://example.com aws sqs list-queues --endpoint-url http://other.example.com 2>&1" || true)
echo "$out"
echo "$out" | grep -q "other.example.com" \
|| { echo "::error::post-subcommand --endpoint-url flag was not honored over AWS_ENDPOINT_URL"; exit 1; }
build-native:
name: Build native floci image
runs-on: ubuntu-24.04-arm
timeout-minutes: 30
steps:
- uses: actions/checkout@v7.0.1
- uses: graalvm/setup-graalvm@0def53c0fd8534bc13416c9469f5be45265824fd # v1
with:
java-version: '25'
distribution: 'mandrel'
# no `cache: maven` — it keys on setup-graalvm-Linux-maven-<hash>, which
# only this pull_request-only workflow ever writes. Actions caches are
# ref-scoped, so those writes land in refs/pull/N/merge and no run can
# read another's: it logged "maven cache is not found" on 6 of 6 sampled
# runs while dutifully saving 211 MB each time. Restore ci.yml's cache
# below instead, which push-to-main genuinely populates.
github-token: ${{ secrets.GITHUB_TOKEN }}
# Restore-only, and deliberately keyed identically to ci.yml:54-59 so this
# reads the ~/.m2 that ci.yml's shard 1 saves on every push to main. ci.yml
# stays the single owner of the save; a second writer would just race it.
# Two known partial-hit caveats, both cheap: `runner.os` is Linux for both
# but ci.yml runs x64 while this runs arm64 (Maven artifacts are
# arch-neutral, so only classifier-based natives re-download), and
# `-Dnative` pulls native-image plugins that ci.yml's `mvn test` never
# fetches. Expect most of the ~66s of cold resolution back, not all of it.
- uses: actions/cache/restore@v6.1.0
with:
path: ~/.m2/repository
key: maven-${{ runner.os }}-${{ hashFiles('pom.xml') }}
restore-keys: maven-${{ runner.os }}-
- name: Build native executable (quick build)
run: mvn clean package -Dnative -DskipTests -B -Dquarkus.native.additional-build-args-append="-Ob"
- name: Stage native binary for packaging
run: |
mkdir -p native/arm64
cp target/*-runner native/arm64/application
# include any sidecar .so the runtime image may need (matches nightly artifact set)
cp target/*.so native/arm64/ 2>/dev/null || true
- uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
- name: Build native Docker image
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
with:
context: .
file: docker/Dockerfile.native-package
tags: floci:test-native
outputs: type=docker,dest=/tmp/floci-native-image.tar
# No layer cache here, deliberately. The `COPY native/$TARGETARCH/`
# below brings in a binary that changes every commit, and Docker layer
# reuse is sequential, so nothing after it can ever be reused. Measured:
# the build imported a cache manifest but reported **zero CACHED
# layers** — it was write-only. `mode=max` still stored the whole image
# including that volatile multi-hundred-MB binary layer, per PR ref,
# which was the largest single consumer of the repo's 10 GB budget.
# The step costs ~19-28s either way.
- name: Compress native image
run: gzip /tmp/floci-native-image.tar
- name: Upload native floci image
uses: actions/upload-artifact@v7
with:
name: floci-native-image
path: /tmp/floci-native-image.tar.gz
retention-days: 1
native-compat-test:
name: native / ${{ matrix.test }}
needs: build-native
runs-on: ubuntu-24.04-arm
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
test:
- sdk-test-node
- sdk-test-python
- sdk-test-java
- sdk-test-go
- sdk-test-awscli
- compat-cdk
- compat-terraform
- compat-opentofu
steps:
- name: Download native floci image
uses: actions/download-artifact@v8
with:
name: floci-native-image
path: /tmp
- name: Load native floci image
run: gunzip -c /tmp/floci-native-image.tar.gz | docker load
- name: Create Docker network
run: docker network create compat-net
- name: Start floci
run: |
DOCKER_GID=$(stat -c '%g' /var/run/docker.sock)
docker run -d --name floci --network compat-net \
-p 4566:4566 \
-v /var/run/docker.sock:/var/run/docker.sock \
--group-add "$DOCKER_GID" \
-e FLOCI_BASE_URL=http://floci:4566 \
-e FLOCI_SERVICES_DOCKER_NETWORK=compat-net \
-e FLOCI_HOSTNAME=floci \
-e FLOCI_SERVICES_IOT_MQTT_ENABLED=true \
-e FLOCI_SERVICES_LAMBDA_HOT_RELOAD_ENABLED=true \
-e FLOCI_TLS_ENABLED=true \
-e FLOCI_SERVICES_EC2_MOCK=true \
-e FLOCI_SERVICES_REDSHIFT_ENDPOINT_HOST=floci \
floci:test-native
- name: Wait for floci to be ready
run: timeout 60 bash -c 'until curl -sf http://localhost:4566/ >/dev/null 2>&1; do sleep 1; done'
- name: Checkout repository
uses: actions/checkout@v7.0.1
with:
sparse-checkout: |
compatibility-tests
.github/ci
- uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
- name: Build test image
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
with:
context: compatibility-tests/${{ matrix.test }}
load: true
tags: compat-${{ matrix.test }}
# Read-only on purpose. Actions caches are ref-scoped: a pull_request
# run's writes land in refs/pull/N/merge, private to that PR and
# unreadable by any other. Eight images x every open PR overran the
# repo's 10 GB cache budget (13.2 GB measured, 95% of it in four PR
# refs), so entries were evicted between a PR's own runs and this
# build swung 29s-211s at random. `warm-compat-caches.yml` populates
# these scopes on main instead; PRs read that single shared copy.
cache-from: type=gha,scope=${{ matrix.test }}
- name: Run tests
id: tests
run: |
mkdir -p test-results
FLOCI_IP=$(docker inspect -f '{{(index .NetworkSettings.Networks "compat-net").IPAddress}}' floci)
DOCKER_GID=$(stat -c '%g' /var/run/docker.sock)
EXTRA_ARGS=""
# compat-cdk needs Docker access for CDK's DockerImageFunction (docker build + push to emulated ECR)
if [ "${{ matrix.test }}" = "compat-cdk" ]; then
EXTRA_ARGS="-v /var/run/docker.sock:/var/run/docker.sock --group-add $DOCKER_GID"
fi
# sdk-test-java: mount a host-side directory so the Docker daemon can
# bind-mount hot-reload code paths that are written by the test container.
if [ "${{ matrix.test }}" = "sdk-test-java" ]; then
mkdir -p /tmp/floci-hot-reload
EXTRA_ARGS="$EXTRA_ARGS -v /tmp/floci-hot-reload:/tmp/floci-hot-reload -e HOT_RELOAD_BASE_DIR=/tmp/floci-hot-reload"
fi
# --dns injects Floci's embedded DNS so *.floci wildcard subdomains
# (e.g. my-bucket.floci) resolve to Floci's IP inside the test container.
# FLOCI_S3_VHOST_ENDPOINT tells the S3 virtual-host client to use
# http://floci:4566 as the endpoint base instead of the public DNS fallback.
docker run --rm --network compat-net \
--dns "${FLOCI_IP}" \
-e FLOCI_ENDPOINT=http://floci:4566 \
-e FLOCI_S3_VHOST_ENDPOINT=http://floci:4566 \
-v "$(pwd)/test-results:/results" \
$EXTRA_ARGS \
compat-${{ matrix.test }}
- name: Generate test summary
if: always() && steps.tests.outcome != 'skipped'
uses: test-summary/action@37b508cfee6d4d080eedd00b5bb240a6a784a6a5 # v2
with:
paths: test-results/*.xml
# The test body inside the container runs its build tool quietly, so the
# job log carries no per-class timings and the slow legs (sdk-test-java,
# ~10 min) are a black box. Surface the timings from the junit XMLs the
# suites already export, and upload the raw XMLs so the numbers are
# machine-readable across runs.
- name: Report slowest test classes
if: always() && steps.tests.outcome != 'skipped'
# Measurement-only: a reporting bug must never fail an otherwise-green leg.
continue-on-error: true
run: python3 .github/ci/compat-timing-report.py test-results
- name: Upload test results
if: always() && steps.tests.outcome != 'skipped'
uses: actions/upload-artifact@v7
with:
name: compat-results-${{ matrix.test }}
path: test-results/
if-no-files-found: warn
- name: Dump floci logs
if: failure()
run: docker logs floci