Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Metabase tests #20

Merged
merged 41 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
db1398c
Add Metabase tests
bobbyiliev Jul 31, 2023
bdf6d9f
Add dpes.edn file
bobbyiliev Jul 31, 2023
4bb49f4
Update the dpes.edn file
bobbyiliev Jul 31, 2023
7f45b5b
Add default test datasets
bobbyiliev Jul 31, 2023
8e8e088
dislabe ssl for test container
bobbyiliev Jul 31, 2023
999d214
Try to disable set-timezone
bobbyiliev Aug 2, 2023
65abc00
Add init container to increase max_tables
bobbyiliev Aug 2, 2023
feb2aba
Disable setting timezone
bobbyiliev Aug 3, 2023
81eabed
Try to fix expression-using-aggregation-test
bobbyiliev Aug 3, 2023
377406f
Fixing tests
bobbyiliev Aug 3, 2023
221afa2
Disable percentile-aggregations due to missing func
bobbyiliev Aug 3, 2023
5834e27
Add json type
bobbyiliev Aug 3, 2023
c64e15c
Fix weeks interval tests
bobbyiliev Aug 3, 2023
a1dbc6f
Fix weeks interval tests
bobbyiliev Aug 4, 2023
99f784e
Upgrade node and clojure versions
bobbyiliev Aug 14, 2023
cd06813
Upgrade Metabase version
bobbyiliev Aug 14, 2023
f210deb
Change jdk from 17 to 11
bobbyiliev Aug 14, 2023
4c7ba86
Exclude materialize from faulty timezone tests
bobbyiliev Aug 14, 2023
79acf7a
Disable :temporal-extract
bobbyiliev Aug 14, 2023
94f36be
Re enable :temporal-extract
bobbyiliev Aug 14, 2023
de8d99d
Re enable :temporal-extract
bobbyiliev Aug 14, 2023
1a5471a
Disable :temporal-extract during tests
bobbyiliev Aug 14, 2023
625a86a
Disable test with failing FK
bobbyiliev Aug 14, 2023
a68ef44
Disable test with failing FK
bobbyiliev Aug 15, 2023
68f1f20
Fix failing FK tests
bobbyiliev Aug 15, 2023
fc1a80f
Disable test due to inconsistent results
bobbyiliev Aug 15, 2023
0e79404
Fix git diff apply
bobbyiliev Aug 15, 2023
cd56201
Add cluster conn option
bobbyiliev Aug 15, 2023
3fbbcaf
Add CONTRIBUTING.md file
bobbyiliev Aug 15, 2023
f1d7695
Update readme and add build script
bobbyiliev Aug 15, 2023
2dd304e
Update resources/metabase-plugin.yaml
bobbyiliev Aug 16, 2023
5d3a884
Small fixes
bobbyiliev Aug 16, 2023
5140f9e
Update contributing.md file
bobbyiliev Aug 16, 2023
91f2919
Small fixes
bobbyiliev Aug 16, 2023
9193399
PR change requests
bobbyiliev Aug 17, 2023
1922569
Sanitize the conn details
bobbyiliev Aug 17, 2023
9aab1bb
Update cluster display name
bobbyiliev Aug 17, 2023
7f26855
Update src/metabase/driver/materialize.clj
bobbyiliev Aug 18, 2023
dee4f9b
Add hostname and port validation
bobbyiliev Aug 18, 2023
dc9d4a6
Remove port validation
bobbyiliev Aug 18, 2023
51c7c2e
Add release version table
bobbyiliev Aug 21, 2023
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
4 changes: 4 additions & 0 deletions .github/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{:aliases
{:user/materialize
{:extra-paths ["PWD/modules/drivers/materialize/test"]
:extra-deps {metabase/materialize {:local/root "PWD/modules/drivers/materialize"}}}}}
89 changes: 89 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Tests

on:
workflow_dispatch:
push:
branches:
- master
paths-ignore:
- "**.md"
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout Metabase Repo
uses: actions/checkout@v3
with:
repository: metabase/metabase
ref: v0.46.7

- name: Checkout Driver Repo
uses: actions/checkout@v3
with:
path: modules/drivers/materialize

- name: Set up JDK 11
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 11

- name: Add Materialize TLS instance to /etc/hosts
run: |
sudo echo "127.0.0.1 materialize" | sudo tee -a /etc/hosts

- name: Start Materialize in Docker
uses: isbang/[email protected]
with:
compose-file: "modules/drivers/materialize/docker-compose.yml"
services: |
materialize
init

# Apply the scripts/exclude_tests.diff patch to exclude tests that are not relevant to Materialize
- name: Apply exclude_tests.diff
run: |
git apply modules/drivers/materialize/scripts/exclude_tests.diff

- name: Install Clojure CLI
run: |
curl -O https://download.clojure.org/install/linux-install-1.11.1.1262.sh &&
sudo bash ./linux-install-1.11.1.1262.sh

- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: "16"
cache: "yarn"

- name: Get M2 cache
uses: actions/cache@v2
with:
path: |
~/.m2
~/.gitlibs
key: ${{ runner.os }}-materialize-${{ hashFiles('**/deps.edn') }}

- name: Prepare stuff for pulses
run: yarn build-static-viz

# Use custom deps.edn containing "user/materialize" alias to include driver sources
- name: Run tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test takes 12 minutes because it tests all the drivers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it only tests Materialize as we add the DRIVERS=materialize before the clojure command. It's just that there are too many tests, around 15k assertions.

run: |
mkdir -p /home/runner/.config/clojure
cat modules/drivers/materialize/.github/deps.edn | sed -e "s|PWD|$PWD|g" > /home/runner/.config/clojure/deps.edn
DRIVERS=materialize clojure -X:dev:drivers:drivers-dev:test:user/materialize

- name: Build Materialize driver
run: |
echo "{:deps {metabase/materialize {:local/root \"materialize\" }}}" > modules/drivers/deps.edn
bin/build-driver.sh materialize
ls -lah resources/modules

- name: Archive driver JAR
uses: actions/upload-artifact@v3
with:
name: materialize.metabase-driver.jar
path: resources/modules/materialize.metabase-driver.jar
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/target
.clj-kondo/
.lsp/
.cpcache/
.build
114 changes: 114 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
## Getting started

* Please report any issues you encounter during operations.
* Feel free to create a pull request, preferably with a test or five.

## Setting up a development environment

### Requirements

* Clojure 1.11+
* OpenJDK 17
* Node.js 16.x
* Yarn

For testing: Docker Compose

Please refer to the extensive documentation available on the Metabase website: [Guide to writing a Metabase driver](https://www.metabase.com/docs/latest/developers-guide/drivers/start.html)

Materialize driver's code should be inside the main Metabase repository checkout in `modules/drivers/materialize` directory.

The easiest way to set up a development environment is as follows (mostly the same as in the [CI](https://github.com/MaterializeInc/metabase-materialize-driver/blob/master/.github/workflows/tests.yml)):

* Clone Metabase and Materialize driver repositories
```bash
git clone https://github.com/metabase/metabase.git
cd metabase
checkout v0.46.7
git clone https://github.com/MaterializeInc/metabase-materialize-driver.git modules/drivers/materialize
```

* Create custom Clojure profiles, you can get it using the following command:

```bash
cat modules/drivers/materialize/.github/deps.edn | sed -e "s|PWD|$PWD|g" | tr -d '\n'
```

Modifying `~/.clojure/deps.edn` will create two useful profiles: `user/materialize` that adds driver's sources to the classpath, and `user/test` that includes all the Metabase tests that are guaranteed to work with the driver.

* Install the Metabase dependencies:

```bash
clojure -X:deps:drivers prep
```

* Build the frontend:

```bash
yarn && yarn build-static-viz
```

* Add `/etc/hosts` entry

Required for TLS tests.

```bash
sudo -- sh -c "echo 127.0.0.1 materialize >> /etc/hosts"
```

* Start Materialize as a Docker container

```bash
docker compose -f modules/drivers/materialize/docker-compose.yml up -d materialize init
```

Now, you should be able to run the tests:

```bash
mz_deps=$(cat modules/drivers/materialize/.github/deps.edn | sed -e "s|PWD|$PWD|g" | tr -d '\n')
DRIVERS=materialize clojure -Sdeps ${mz_deps} -X:dev:drivers:drivers-dev:test:user/materialize
```

you can see that we have our profiles `:user/materialize:user/test` added to the command above, and with `DRIVERS=materialize` we instruct Metabase to run the tests only for Materialize.

> **Note** Omitting `DRIVERS` will run the tests for all the built-in database drivers.

If you want to run tests for only a specific test:

```bash
mz_deps=$(cat modules/drivers/materialize/.github/deps.edn | sed -e "s|PWD|$PWD|g" | tr -d '\n')
DRIVERS=materialize clojure -Sdeps ${mz_deps} -X:dev:drivers:drivers-dev:test:user/materialize :only metabase.query-processor.middleware.parameters.mbql-test
```

## Building a jar

You need to add an entry for Materialize in `modules/drivers/deps.edn`

```clj
{:deps
{...
metabase/materialize {:local/root "materialize"}
...}}
```

or just run this from the root Metabase directory, overwriting the entire file:

```bash
echo "{:deps {metabase/materialize {:local/root \"materialize\" }}}" > modules/drivers/deps.edn
```

Now, you should be able to build the final jar:

```bash
bin/build-driver.sh materialize
```

As the result, `resources/modules/materialize.metabase-driver.jar` should be created.

For smoke testing, there is a Metabase with the link to the driver available as a Docker container:

```bash
docker compose -f modules/drivers/materialize/docker-compose.yml up -d metabase
```

It should pick up the driver jar as a volume.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG METABASE_VERSION=latest
FROM metabase/metabase:${METABASE_VERSION}

ADD target/dist/materialize-driver.jar /plugins/
ADD .build/materialize-driver.jar /plugins/
RUN chmod 744 /plugins/materialize-driver.jar
83 changes: 5 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# metabase-materialize-driver
# Materialize driver for Metabase

The `metabase-materialize-driver` lets
[Metabase](https://github.com/metabase/metabase) connect to an instance of
Expand Down Expand Up @@ -26,85 +26,12 @@ connect:
| Port | 6875 |
| Database username | default |
| Database password | default |
| Cluster name | default |

[releases]: https://github.com/MaterializeInc/metabase-materialize-driver/releases
[materialize/metabase]: https://hub.docker.com/repository/docker/materialize/metabase

## Contributing

### With Docker

To generate a Metabase Docker image containing the Materialize driver, use [our
Dockerfile](Dockerfile) and run the following command from your terminal:

```shell script
cd /path/to/metabase-materialize-driver
bin/build.sh --build
```

Then, to start the container, run:
```shell script
docker run --rm -p 3000:3000 --name metabase materialize/metabase:latest
```

Once it's finished loading, you can access Metabase at <localhost:3000>.

**NB: If you are running this on a Mac and running Materialize locally, you can
connect by substituting the following connection information:**

| Field | Value |
| ------- |:--------------------:|
| Host | [host.docker.internal](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach/24326540#24326540) |


### Without Docker

Use this driver in two steps:

1. Download a copy of the driver by running:
```shell script
bin/build.sh --release v0.1.0 --no-docker
```
or visiting the [releases](./releases) page and downloading one of the
jars

1. Move the downloaded copy of the plugin (from the previous step) into the
`/plugins` directory of your Metabase instance.

For more info, check out these resources:
* [Managing databases in Metabase](https://www.metabase.com/docs/latest/administration-guide/01-managing-databases.html)
* [Driver plugins in Metabase](https://github.com/metabase/metabase/wiki/Writing-a-Driver:-Packaging-a-Driver-&-Metabase-Plugin-Basics)


## To Build the Driver

**NB: These steps are not necessary to use the `metabase-materialize-driver`!
They are only for the curious or those attempting to make updates. To just use
the driver, stick to `How to use the driver` above.**

### Step 1: Build and move the metabase-materialize-driver

1. Once we've successfully completed copying over the code from the forked
Driver, we're ready to build the `metabase-materialize-driver`.

```shell script
cd /path/to/metabase-materialize-driver
lein clean && lein uberjar
```
When the `uberjar` command finishes executing, it will output the path to
the newly created uberjar like:

```shell script
Compiling metabase.driver.materialize
Created /path/to/metabase-materialize-driver/target/materialize-driver-0.1.0-SNAPSHOT.jar
Created /path/to/metabase-materialize-driver/target/ materialize-driver-0.1.0-SNAPSHOT-standalone.jar
```

1. Move the `standalone.jar` (the uberjar) over to the `/plugin` directory of
our local copy of Metabase:

```shell script
cp /path/to/metabase-materialize-driver/target/ materialize-driver-0.1.0-SNAPSHOT-standalone.jar /path/to/metabase/plugins/
```

Once the `metabase-materialize-driver` jar is in the `/plugins` directory,
Metabase will register the plugin on startup!
Check out our [contributing guide](CONTRIBUTING.md) for more information on how
to contribute to this project.
Loading