-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Source Metabase: migrate to Beta YAML #19236
Conversation
/test connector=connectors/source-metabase
Build FailedTest summary info:
|
tests: | ||
- spec_path: "source_metabase/spec.yaml" | ||
backward_compatibility_tests_config: | ||
disable_for_version: "0.1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it still needed here? since the new version is 0.3.0 the test will be held against 0.2.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
- config_path: "secrets/config.json" | ||
configured_catalog_path: "integration_tests/configured_catalog.json" | ||
expect_records: | ||
path: "integration_tests/expected_records.txt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about full_refresh and incremental test cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
primary_key: "id" | ||
retriever: | ||
$ref: "*ref(definitions.retriever)" | ||
data_field_base_stream: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer removing this stream since it has a single child
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
API_URL = "instance_api_url" | ||
USERNAME = "username" | ||
PASSWORD = "password" | ||
SESSION_TOKEN = "session_token" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should have been removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
return session.has_valid_token(), None | ||
except Exception as e: | ||
return False, e | ||
finally: | ||
if session: | ||
session.close_session() | ||
|
||
def streams(self, config: Mapping[str, Any]) -> List[Stream]: | ||
self.session = MetabaseAuth(logging.getLogger("airbyte"), config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.close_session()
will never execute since self.session
is never set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
||
def check_connection(self, logger: logging.Logger, config: Mapping[str, Any]) -> Tuple[bool, Any]: | ||
session = None | ||
try: | ||
session = MetabaseAuth(logger, config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On one hand you are defining a check in yaml with a stream passed in, on the other hand you're overriding a check
method in python. This means yaml check will not work and has no sense. We have to leave just one of them, I'm in favour of yaml based check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, we need custom check because of updating session token, so I left check here, and removed from yaml.
def get_auth_header(self) -> Mapping[str, Any]: | ||
return {"X-Metabase-Session": self.session_token} | ||
|
||
def close_session(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this ever called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
raise ConnectionError(f"Failed to retrieve new session token, response code {response.status_code} because {response.reason}") | ||
return self.session_token | ||
|
||
def has_valid_token(self) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we leave just a yaml based check, I guess this method may be removed
API_URL_CONFIG_KEY = "instance_api_url" | ||
USERNAME_CONFIG_KEY = "username" | ||
PASSWORD_CONFIG_KEY = "password" | ||
SESSION_TOKEN_CONFIG_KEY = "session_token" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does not make much sense to me as it's not heavily reused
|
||
|
||
@dataclass | ||
class MetabaseAuth(HttpAuthenticator, JsonSchemaMixin): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add unit tests to cover the custom component
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
@dataclass | ||
class MetabaseAuth(HttpAuthenticator, JsonSchemaMixin): | ||
def __init__(self, config: Mapping[str, Any], options: Mapping[str, Any]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing: we used to have one session per sync, now we will have one session per stream. I suggest you make it a source instance attribute/cached property/etc
] | ||
self.session = MetabaseAuth(config, {}) | ||
|
||
return super().streams(config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once again: you're not passing session object here. This means new session will be instantiated per each stream if an authenticator is passed to a stream in yaml. After the sync succeeds, only the source session (defined two lines above) will be closed, but not those sessions in the streams, right?
/test connector=connectors/source-metabase
Build FailedTest summary info:
|
/test connector=connectors/source-metabase
Build FailedTest summary info:
|
30ed0b2
to
76a1632
Compare
/test connector=connectors/source-metabase
Build FailedTest summary info:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is great! Only request is to move the authenticator to the CDK's airbyte_cdk/sources/declarative/auth package so it can be reused. Will approve when it's done
|
||
|
||
@dataclass | ||
class MetabaseSessionTokenAuthenticator(AbstractHeaderAuthenticator, DeclarativeAuthenticator, JsonSchemaMixin): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to generalize this class and move it to the CDK. The only thing that is hardcoded is the auth_header, which we can also parameterize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, #19716
$options: | ||
name: "dashboards" | ||
path: "dashboard" | ||
users_stream: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this stream have a primary key? it's missing here
@@ -0,0 +1,136 @@ | |||
# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this file still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
@@ -5,7 +5,7 @@ | |||
|
|||
from setuptools import find_packages, setup | |||
|
|||
MAIN_REQUIREMENTS = ["airbyte-cdk~=0.2", "requests>=2.28.0", "types-requests>=2.27.30"] | |||
MAIN_REQUIREMENTS = ["airbyte-cdk", "requests>=2.28.0", "types-requests>=2.27.30", "cachetools"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we shouldn't need this dependency here since it'll be included in the cdk as part of #19716
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢
/test connector=connectors/source-metabase
Build PassedTest summary info:
|
/publish connector=connectors/source-metabase run-tests=false
if you have connectors that successfully published but failed definition generation, follow step 4 here |
source Metabase: check list