-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
SAT: Capture configuration updates from connectors' control messages #19979
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5f5948a
use observed config in bing ads for testing
alafanechere b37d788
update local configurations and use most recent
alafanechere aebc8a5
test connector runner changes
alafanechere 7a8ecde
test_connector_config_path_fixture
alafanechere 234ba61
make connector_configuration_path optional in ContainerRunner
alafanechere c251eb9
add docstrings
alafanechere f879c01
bump version
alafanechere 0cd81af
Merge branch 'master' into augustin/sat/capture-config-messages
alafanechere da3917e
gitingore updated_configurations
alafanechere e1255a7
revert changes on source-bing-ads
alafanechere File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions
3
airbyte-integrations/bases/source-acceptance-test/CHANGELOG.md
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
91 changes: 91 additions & 0 deletions
91
airbyte-integrations/bases/source-acceptance-test/unit_tests/test_container_runner.py
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,91 @@ | ||
# | ||
# Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
|
||
import json | ||
|
||
import pytest | ||
from airbyte_cdk.models import ( | ||
AirbyteControlConnectorConfigMessage, | ||
AirbyteControlMessage, | ||
AirbyteMessage, | ||
AirbyteRecordMessage, | ||
OrchestratorType, | ||
) | ||
from airbyte_cdk.models import Type as AirbyteMessageType | ||
from source_acceptance_test.utils import connector_runner | ||
|
||
|
||
class TestContainerRunner: | ||
def test_run_call_persist_configuration(self, mocker, tmp_path): | ||
old_configuration_path = tmp_path / "config.json" | ||
new_configuration = {"field_a": "new_value_a"} | ||
mocker.patch.object(connector_runner, "docker") | ||
records_reads = [ | ||
AirbyteMessage( | ||
type=AirbyteMessageType.RECORD, record=AirbyteRecordMessage(stream="test_stream", data={"foo": "bar"}, emitted_at=1.0) | ||
).json(exclude_unset=False), | ||
AirbyteMessage( | ||
type=AirbyteMessageType.CONTROL, | ||
control=AirbyteControlMessage( | ||
type=OrchestratorType.CONNECTOR_CONFIG, | ||
emitted_at=1.0, | ||
connectorConfig=AirbyteControlConnectorConfigMessage(config=new_configuration), | ||
), | ||
).json(exclude_unset=False), | ||
] | ||
mocker.patch.object(connector_runner.ConnectorRunner, "read", mocker.Mock(return_value=records_reads)) | ||
mocker.patch.object(connector_runner.ConnectorRunner, "_persist_new_configuration") | ||
|
||
runner = connector_runner.ConnectorRunner("source-test:dev", tmp_path, connector_configuration_path=old_configuration_path) | ||
list(runner.run("dummy_cmd")) | ||
runner._persist_new_configuration.assert_called_once_with(new_configuration, 1) | ||
|
||
@pytest.mark.parametrize( | ||
"pass_configuration_path, old_configuration, new_configuration, new_configuration_emitted_at, expect_new_configuration", | ||
[ | ||
pytest.param( | ||
True, | ||
{"field_a": "value_a"}, | ||
{"field_a": "value_a"}, | ||
1, | ||
False, | ||
id="Config unchanged: No new configuration persisted", | ||
), | ||
pytest.param( | ||
True, {"field_a": "value_a"}, {"field_a": "new_value_a"}, 1, True, id="Config changed: New configuration persisted" | ||
), | ||
pytest.param( | ||
False, | ||
{"field_a": "value_a"}, | ||
{"field_a": "new_value_a"}, | ||
1, | ||
False, | ||
id="Config changed but persistence is disable: New configuration not persisted", | ||
), | ||
], | ||
) | ||
def test_persist_new_configuration( | ||
self, | ||
mocker, | ||
tmp_path, | ||
pass_configuration_path, | ||
old_configuration, | ||
new_configuration, | ||
new_configuration_emitted_at, | ||
expect_new_configuration, | ||
): | ||
if pass_configuration_path: | ||
old_configuration_path = tmp_path / "config.json" | ||
with open(old_configuration_path, "w") as old_configuration_file: | ||
json.dump(old_configuration, old_configuration_file) | ||
else: | ||
old_configuration_path = None | ||
mocker.patch.object(connector_runner, "docker") | ||
runner = connector_runner.ConnectorRunner("source-test:dev", tmp_path, old_configuration_path) | ||
new_configuration_path = runner._persist_new_configuration(new_configuration, new_configuration_emitted_at) | ||
if not expect_new_configuration: | ||
assert new_configuration_path is None | ||
else: | ||
assert new_configuration_path == tmp_path / "updated_configurations" / f"config|{new_configuration_emitted_at}.json" |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 the calling context automatically get this new config? if yes can you clarify how in a comment?
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.
All the tests using the
ConnectorRunner
are using theconnector_config
fixture (also function scoped) . Theconnector_config
fixture is loading the config from theconnector_config_path
fixture. Theconnector_config_path
fixture dynamically retrieves the latest configuration written to theupdated_configurations
folder. So all tests usingconnector_config
fixture are callingdocker_runner
methods with the "new" config.I don't think clarifying the behavior here is a good idea as it's fixture related, not an internal logic of the runner. I wrote something here in the
connector_config_path
fixture.