-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RM-124: Add command to perform a healthcheck against airbyte server
- adds new optional arugment that can be passed to mvrec that will query the healthcheck endpoint on the configured airbyte instance and return either true or false depending on if that endpoint returns a 200 status code - adds "feature flag" so this can dark launch - Added new class to support argument - Added initial methods for retieving airbyte credentials - Added unit tests for new class method
- Loading branch information
1 parent
e6f54f3
commit e106732
Showing
12 changed files
with
191 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import logging | ||
from http import HTTPStatus | ||
import requests | ||
from records_mover import Session | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class AirbyteEngine: | ||
""" | ||
Intention: Main engine of activity for connecting to and managing airflow "stuff." | ||
General thoughts, maybe this should encapsulate making a request to airbyte | ||
Thus we'd have a method for making a request which'd know how to authenticate | ||
""" | ||
session: Session | ||
|
||
def __init__(self, session: Session): | ||
""" | ||
Args: | ||
session: Optional records mover Session, exposed for testing. | ||
If a session isn't provided, one will be requested | ||
""" | ||
if session is None: | ||
self.session = Session() | ||
else: | ||
self.session = session | ||
|
||
def healthcheck(self) -> bool: | ||
self.session.set_stream_logging() | ||
data = self.session.creds.airbyte() | ||
if data is None: | ||
logger.error("Could not retrieve credentials from secrets store") | ||
return False | ||
url = f"{data['host']}:{data['port']}/health" | ||
username = data['user'] | ||
password = data['password'] | ||
try: | ||
response = requests.get(url, auth=(username, password)) | ||
logger.debug(f"""Airbyte instance {data['host']}. HTTP status code | ||
{response.status_code}""") | ||
if response.status_code is HTTPStatus.OK.value: | ||
return True | ||
else: | ||
return False | ||
except Exception as e: | ||
logger.error(f"""Exception encountered executing HTTP request against configured | ||
airbyte instance: {e}""") | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import unittest | ||
from http import HTTPStatus | ||
from unittest.mock import patch, MagicMock | ||
|
||
from records_mover.creds.base_creds import BaseCreds | ||
from records_mover.records.airbyte.airbyte import AirbyteEngine | ||
|
||
|
||
class MockCreds(BaseCreds): | ||
""" | ||
Helper class to provide credentials to the airbyte engine | ||
""" | ||
|
||
def airbyte(self): | ||
return { | ||
'user': 'username', | ||
'password': 'password', | ||
'host': 'host', | ||
'port': '8000', | ||
'endpoint': 'endpoint' | ||
} | ||
|
||
|
||
class MockSession: | ||
""" | ||
Helper class to provide credentials, just so we don't have to worry about db-facts | ||
""" | ||
|
||
def __init__(self): | ||
self.creds = MockCreds() | ||
|
||
def set_stream_logging(self): | ||
pass | ||
|
||
|
||
class AirbyteHealthCheckTest(unittest.TestCase): | ||
@patch('requests.Session.send') | ||
def test_airbyte_healthcheck_returns_true_when_healthy(self, send): | ||
# Given | ||
engine = AirbyteEngine(session=MockSession()) | ||
response = MagicMock() | ||
response.status_code = HTTPStatus.OK.value | ||
send.return_value = response | ||
|
||
# When | ||
result = engine.healthcheck() | ||
|
||
# Then | ||
self.assertTrue(result) | ||
|
||
@patch('requests.Session.send') | ||
def test_airbyte_healthcheck_returns_false_when_unhealthy(self, send): | ||
# Given | ||
engine = AirbyteEngine(session=MockSession()) | ||
response = MagicMock() | ||
response.status_code = HTTPStatus.NOT_FOUND.value | ||
send.return_value = response | ||
|
||
# When | ||
result = engine.healthcheck() | ||
|
||
# Then | ||
self.assertFalse(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def get(url, params=None, **kwargs): | ||
... |