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
85 changes: 85 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
version: 2.1

orbs:
aws-ecr: circleci/aws-ecr@8.2.1

jobs:
test:
docker:
- image: cimg/openjdk:24.0.2
steps:
- checkout
- run:
name: test with coverage
command: |
cd plugin/trino-af/
../../mvnw clean test -Djacoco.skip=false -Djava.vendor="Eclipse Adoptium"
- store_test_results:
path: plugin/trino-af/target/surefire-reports
- store_artifacts:
path: plugin/trino-af/target/site/jacoco
destination: coverage-report
- run:
name: verify coverage summary
command: |
cd plugin/trino-af/
if [ -f target/site/jacoco/index.html ]; then
echo "Coverage report generated successfully"
echo "View coverage report in CircleCI artifacts"
else
echo "Coverage report generation failed"
exit 1
fi

build-and-push:
docker:
- image: cimg/openjdk:24.0.2
steps:
- checkout
- run:
name: build
command: |
cd plugin/trino-af/
../../mvnw clean package -Djava.vendor="Eclipse Adoptium"
- run:
name: set environment variables
command: |
echo 'export REGISTRY_ACCOUNT_ID="307946643675"' >> "$BASH_ENV"
source "$BASH_ENV"

SHORT_COMMIT_SHA=${CIRCLE_SHA1:0:7}
echo "export SHORT_COMMIT_SHA='${SHORT_COMMIT_SHA}'" >> $BASH_ENV

TAG=${CIRCLE_BRANCH//\//-}-${SHORT_COMMIT_SHA}
echo "export TAG='${TAG}'" >> $BASH_ENV

DOCKER_HOST_BLOCK=$(curl -fsSL http://npm-yarn-blocklist.security.appf.io | tr ' ' '\n' | sed 's/^/--add-host=/' | sed 's/$/:127.0.0.1/' | tr '\n' ' ' | sed 's/ $//')
echo "export DOCKER_HOST_BLOCK='${DOCKER_HOST_BLOCK}'" >> $BASH_ENV

echo "ACCESS KEY ID: ${DATA_API_MACHINE_USER_AWS_ACCESS_KEY_ID}"
- setup_remote_docker:
docker_layer_caching: true
- aws-ecr/build-and-push-image:
registry-id: REGISTRY_ACCOUNT_ID
aws-access-key-id: DATA_API_MACHINE_USER_AWS_ACCESS_KEY_ID
aws-secret-access-key: DATA_API_MACHINE_USER_AWS_SECRET_ACCESS_KEY
region: us-west-2
create-repo: false
repo: data-api/trino-af
build-path: plugin/trino-af/
path: plugin/trino-af/
tag: ${TAG}
platform: linux/amd64,linux/arm64
skip-when-tags-exist: true
extra-build-args: ${DOCKER_HOST_BLOCK}


workflows:
version: 2
test-build-push:
jobs:
- test
- build-and-push:
requires:
- test
context: data-api-pipeline-trigger-group
4 changes: 4 additions & 0 deletions plugin/trino-af/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM trinodb/trino:476

# Copy the trino-af plugin files
COPY --chown=trino:trino target/trino-af-476/ /usr/lib/trino/plugin/trino-af
112 changes: 112 additions & 0 deletions plugin/trino-af/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Guide for trino-af Plugin
The `trino-af` plugin implements the `af_find_datasource_by_guid` function which receives a vhost guid and then calls [the registry app](https://github.com/appfolio/registry_app) to get the slice the vhost is active on.

Vhost databases with the same guid can exist on multiple slices. The function can be used in Trino's row filter to make sure Trino only return rows belong to the slice a vhost is active on.

# Development

## Install dependencies

```commandline
brew install trino jenv
```

## Install Java

Trino works with Temurin JDK 24.
```commandline
brew install temurin
jenv add /Library/Java/JavaVirtualMachines/temurin-24.jdk/Contents/Home
```

## Create a branch

### Pull all tags

May need to run the following if new trino verions are released.

```commandline
git remote add upstream https://github.com/trinodb/trino.git
git fetch upstream --tags
git push origin --tags
```

### Check out the Branch

```commandline
git checkout 476-af
```

All development work happen in this branch.

## Test

Run automated tests:

```commandline
cd plugin/trino-af/
../../mvnw test
```

Start a test server for manual testing:

```commandline
cd plugin/trino-af
../../mvnw compile test-compile exec:java
```

Access the test server:

```commandline
trino --server http://localhost:8080 --execute "select af.af.af_find_datasource_by_guid('test-guid-1')"
```

### Code Coverage

JaCoCo code coverage report is generated on CircleCI.

To manually generate coverage reports:

```commandline
cd plugin/trino-af/
mvn clean test -Djacoco.skip=false -Djava.vendor="Eclipse Adoptium"
```

After running, view the coverage report:

```commandline
open target/site/jacoco/index.html
```

The coverage report shows:
- **Instruction Coverage**: Percentage of bytecode instructions executed
- **Branch Coverage**: Percentage of conditional branches tested
- **Line Coverage**: Percentage of source code lines executed
- **Method Coverage**: Percentage of methods called
- **Class Coverage**: Percentage of classes instantiated

## Build

The plugin is built on CircleCI.

To manually build the plugin:

```commandline
cd plugin/trino-af/
../../mvnw package
```

`target/trino-af-476.zip` is the plugin file

## Push

CircleCI pushes a Trino container image with the plugin installed to ECR in the data-api-prod account.

To manually push an image:

```commandline
awsume data-api-prod
./build-and-push.sh
```

The output should have the image tag which can be used in Kubernetes Trino setup.
36 changes: 36 additions & 0 deletions plugin/trino-af/build-and-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
set -e

TRINO_BASE_VERSION=476
TRINO_AF_REPO=data-api/trino-af

echo "Step 1: Building Maven package..."
../../mvnw clean package

echo "Step 2: Finding ECR repository for trino-af..."
ECR_REPO_URI=$(aws ecr describe-repositories --repository-names $TRINO_AF_REPO --query 'repositories[0].repositoryUri' --output text)
if [ "$ECR_REPO_URI" == "None" ] || [ -z "$ECR_REPO_URI" ]; then
echo "Error: ECR repository 'trino-af' not found"
exit 1
fi
echo "Found ECR repository: $ECR_REPO_URI"

echo "Step 3: Finding latest version tag..."
LATEST_VERSION=$(aws ecr list-images --repository-name $TRINO_AF_REPO --query 'imageIds[?imageTag!=`null`].imageTag' --output text | tr '\t' '\n' | grep -E '\-[0-9]+$' | sort -V | tail -1)
if [ -z "$LATEST_VERSION" ]; then
NEW_VERSION="$TRINO_BASE_VERSION-1"
else
# Extract the number after the dash and increment it
VERSION_NUMBER=$(echo "$LATEST_VERSION" | grep -oE '[0-9]+$')
NEW_VERSION="$TRINO_BASE_VERSION-$((VERSION_NUMBER + 1))"
fi
echo "Latest version: ${LATEST_VERSION:-none}, New version: $NEW_VERSION"

echo "Step 4: Authenticating with ECR..."
aws ecr get-login-password | docker login --username AWS --password-stdin $ECR_REPO_URI

echo "Step 5: Building multi-architecture Docker image..."
docker buildx create --use --name multiarch-builder 2>/dev/null || docker buildx use multiarch-builder
docker buildx build --platform linux/arm64,linux/amd64 -t $ECR_REPO_URI:$NEW_VERSION --push .

echo "Successfully built and pushed $ECR_REPO_URI:$NEW_VERSION"
Loading