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

Tests: Add integration tests for the "SNAPSHOT" strategy #33

Merged
merged 3 commits into from
Jul 10, 2023

Conversation

amotl
Copy link
Member

@amotl amotl commented Jul 9, 2023

Introduction

The "SNAPSHOT" strategy has not been tested thoroughly yet.

- # FIXME: This currently can not be tested, because it needs a snapshot repository.
- # TODO: Provide an embedded MinIO S3 instance to the test suite.

Improvement

This patch provides additional infrastructure to the test suite, and validates the full roundtrip by creating a snapshot repository, running the snapshot procedure, and verifying that data has moved correctly.

Details

For verifying different repository types, different helper services and APIs are used.

  • Filesystem: Uses the Python Docker API to introspect the filesystem of the OCI container where CrateDB is running.
  • AWS S3: Uses MinIO to provide a compatible service.
  • Azure Blob Storage: Uses Azurite to provide a compatible service.
    Does not work yet, because CrateDB does not support custom endpoints for Azure Blob Storage.

@amotl amotl marked this pull request as ready for review July 9, 2023 11:06
@amotl amotl requested a review from hammerhead July 9, 2023 11:07
@amotl amotl force-pushed the amo/snapshot-testing branch 4 times, most recently from 145666c to 21b0990 Compare July 9, 2023 13:29
@amotl amotl force-pushed the amo/snapshot-testing branch 3 times, most recently from 25d2dcf to 114f0e2 Compare July 9, 2023 15:10
@amotl amotl changed the title Tests: Add full-roundtrip/integration test for the "snapshot" strategy Tests: Add integration tests for the "SNAPSHOT" strategy Jul 9, 2023
@amotl amotl marked this pull request as draft July 9, 2023 15:19
Comment on lines 17 to 44
class ExtendedMinioContainer(MinioContainer):
"""
A Testcontainer for MinIO with two properties.

- Use the `latest` OCI image.
- Provide convenience methods for getting the Docker-internal endpoint address.
"""

def __init__(self, *args, **kwargs):
# Use most recent stable release of MinIO.
image = "quay.io/minio/minio:latest"
kwargs.setdefault("image", image)

super().__init__(*args, **kwargs)

def get_real_host_ip(self):
"""
To let containers talk to each other, explicitly provide the real IP address
of the container. In corresponding jargon, it appears to be the "bridge IP".
"""
return self.get_docker_client().bridge_ip(self._container.id)

def get_real_host_address(self):
"""
Provide Docker-internal full endpoint address `<host>:<port>` of the service.
For example, `172.17.0.4:9000`.
"""
return f"{self.get_real_host_ip()}:{self.port_to_expose}"
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: Hand in get_real_host_ip() and get_real_host_address() as a patch to upstream testcontainers-python.

Copy link
Member Author

@amotl amotl Jul 9, 2023

Choose a reason for hiding this comment

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

port_to_expose is not standardized across container wrapper implementations. So, get_real_host_address() will not be able to go into a generic API module.

Comment on lines 71 to 132
# TODO: DROP REPOSITORY IF EXISTS
try:
sql = f"DROP REPOSITORY {name};"
self.run_sql(sql)
except ProgrammingError as ex:
if "RepositoryUnknownException" not in str(ex):
raise

# TODO: CREATE REPOSITORY IF NOT EXISTS
sql = f"""
CREATE REPOSITORY
{name}
TYPE
{typename}
WITH (
protocol = 'http',
endpoint = '{endpoint}',
access_key = '{access_key}',
secret_key = '{secret_key}',
bucket = '{bucket}'
);
"""
self.run_sql(sql)
Copy link
Member Author

Choose a reason for hiding this comment

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

I missed those IF [NOT] EXISTS modifiers on the REPOSITORY statements. Do you think it makes sense to hand in a request to crate/crate about adding them?

CREATE|DROP REPOSITORY IF [NOT] EXISTS

/cc @hlcianfagna, @proddata, @seut

@amotl amotl force-pushed the amo/snapshot-testing branch 2 times, most recently from 3658fc0 to a750aae Compare July 9, 2023 20:52
@amotl amotl marked this pull request as ready for review July 9, 2023 21:03
Comment on lines +314 to +315
@pytest.mark.skip(reason="CrateDB does not support custom endpoints for Azure Blob Storage")
def test_run_snapshot_azure_blob(caplog, store, database, sensor_readings, sensor_readings_snapshot_policy, azurite):
Copy link
Member Author

@amotl amotl Jul 9, 2023

Choose a reason for hiding this comment

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

TODO: Verifying snapshotting here does not work, because CrateDB does not support custom endpoints for Azure Blob Storage yet. The "skip" will be removed as soon as support has landed.

Base automatically changed from amo/this-and-that to main July 10, 2023 12:48
Provide a MinIO service to the test suite, in order to verify
snapshotting to a CrateDB repository on AWS S3.
Provide an Azurite service to the test suite, in order to verify
snapshotting to a CrateDB repository on Microsoft Azure Blob Storage.

Does not work yet, because CrateDB does not support custom endpoints for
Azure Blob Storage.
Introspect the OCI container where CrateDB is running, in order to
verify snapshotting to a CrateDB repository on the filesystem.
@amotl amotl merged commit c50835d into main Jul 10, 2023
3 checks passed
@amotl amotl deleted the amo/snapshot-testing branch July 10, 2023 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants