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

[CDF-22379] Hosted Extractors: Source #1893

Merged
merged 34 commits into from
Sep 3, 2024
Merged

[CDF-22379] Hosted Extractors: Source #1893

merged 34 commits into from
Sep 3, 2024

Conversation

doctrino
Copy link
Contributor

@doctrino doctrino commented Aug 29, 2024

Description

Part 1 of 5 planned. (Mapping, Destination, Job + adding Rest + kafka to Source)
Avoid adding more to keep PR smaller

Checklist:

  • Tests added/updated.
  • Documentation updated. Documentation is generated from docstrings - these must be updated according to your change.
    If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.
  • Changelog updated in CHANGELOG.md.
  • Version bumped. If triggering a new release is desired, bump the version number in _version.py and pyproject.toml per semantic versioning.

Copy link

codecov bot commented Aug 29, 2024

Codecov Report

Attention: Patch coverage is 89.43489% with 43 lines in your changes missing coverage. Please review.

Project coverage is 90.75%. Comparing base (02e4305) to head (2d2c72c).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...e/client/data_classes/hosted_extractors/sources.py 87.81% 39 Missing ⚠️
cognite/client/_api/hosted_extractors/sources.py 94.02% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1893      +/-   ##
==========================================
- Coverage   90.78%   90.75%   -0.04%     
==========================================
  Files         126      130       +4     
  Lines       19700    20104     +404     
==========================================
+ Hits        17885    18245     +360     
- Misses       1815     1859      +44     
Files with missing lines Coverage Δ
cognite/client/_api/hosted_extractors/__init__.py 100.00% <100.00%> (ø)
cognite/client/_api_client.py 89.72% <ø> (ø)
cognite/client/_cognite_client.py 93.54% <100.00%> (+0.14%) ⬆️
cognite/client/_version.py 100.00% <100.00%> (ø)
cognite/client/data_classes/_base.py 92.78% <100.00%> (ø)
...te/client/data_classes/datapoints_subscriptions.py 90.54% <100.00%> (-0.50%) ⬇️
.../client/data_classes/hosted_extractors/__init__.py 100.00% <100.00%> (ø)
cognite/client/testing.py 100.00% <100.00%> (ø)
cognite/client/_api/hosted_extractors/sources.py 94.02% <94.02%> (ø)
...e/client/data_classes/hosted_extractors/sources.py 87.81% <87.81%> (ø)

@doctrino doctrino marked this pull request as ready for review August 29, 2024 12:15
@doctrino doctrino requested review from a team as code owners August 29, 2024 12:15
@doctrino doctrino requested review from amorken and removed request for a team August 29, 2024 12:15
def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None:
super().__init__(config, api_version, cognite_client)
self._warning = FeaturePreviewWarning(
api_maturity="alpha", sdk_maturity="alpha", feature_name="Hosted Extractors"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add rest and kafka which are alpha, the eventhub and mqtt are beta.

Copy link
Contributor

Choose a reason for hiding this comment

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

In this PR? Or a later one?

Copy link
Contributor Author

@doctrino doctrino Sep 2, 2024

Choose a reason for hiding this comment

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

Later on, this is 1 /5 while I added kafka and rest in 5/5

Copy link
Contributor

@mathialo mathialo left a comment

Choose a reason for hiding this comment

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

Looks good!

Copy link
Contributor

@haakonvt haakonvt left a comment

Choose a reason for hiding this comment

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

First part of review!

I wonder if the word Source is a bit too generic? Should we add ExtractorSource or HostedExtractorSource? 🤔

@@ -106,6 +106,7 @@ class APIClient:
"transformations/(filter|byids|jobs/byids|schedules/byids|query/run)",
"extpipes/(list|byids|runs/list)",
"workflows/.*",
"hostedextractors/.*",
Copy link
Contributor

Choose a reason for hiding this comment

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

This now also retries delete and update of sources, is that intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

Comment on lines +22 to +24
self._warning = FeaturePreviewWarning(
api_maturity="alpha", sdk_maturity="alpha", feature_name="Hosted Extractors"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to not move this to HostedExtractorsAPI.__init__?

Suggested change
self._warning = FeaturePreviewWarning(
api_maturity="alpha", sdk_maturity="alpha", feature_name="Hosted Extractors"
)
self._warning = FeaturePreviewWarning(
api_maturity="alpha", sdk_maturity="alpha", feature_name="Hosted Extractors"
)

Copy link
Contributor Author

@doctrino doctrino Sep 2, 2024

Choose a reason for hiding this comment

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

Just convenience. Does not matter much as it will be removed in the future.

CHANGELOG.md Outdated Show resolved Hide resolved
cognite/client/data_classes/_base.py Outdated Show resolved Hide resolved
Comment on lines +13 to +15
"hostedExtractorsAcl": {
"actions": ["READ", "WRITE"],
"scope": {"all": {}},
Copy link
Contributor

Choose a reason for hiding this comment

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

Add this new ACL? Then we can use the better syntax:

HostedExtractorsAcl(
    [HostedExtractorsAcl.Action.Read, HostedExtractorsAcl.Action.Write],
    HostedExtractorsAcl.Scope.All,
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did not spend the time to update the script to the new syntax.

@@ -1218,6 +1224,7 @@ def _convert_resource_to_patch_object(
resource: CogniteResource,
update_attributes: list[PropertySpec],
mode: Literal["replace_ignore_null", "patch", "replace"] = "replace_ignore_null",
identifying_properties: dict[str, Any] | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Where does the word "identifying" come from? Is there a more general term we could use in case we need to add "extra-but-not-identifying-properties" in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried another solution. Wdyt?

Comment on lines +83 to +86
@classmethod
@abstractmethod
def _load_source(cls, resource: dict[str, Any]) -> Self:
raise NotImplementedError()
Copy link
Contributor

Choose a reason for hiding this comment

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

I vote to remove this and just use _load for subclasses - but maybe there's a strong reason to keep it this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes infinite recursion.

Comment on lines +56 to +59
try:
return cast(Self, _SOURCE_WRITE_CLASS_BY_TYPE[type_]._load_source(resource))
except KeyError:
raise TypeError(f"Unknown source type: {type_}")
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this pattern - write version raises on "unknown", while read version is lenient! Nice!👌

Comment on lines 216 to 218
def as_write(self, key_value: str | None = None) -> EventHubSourceWrite:
if key_value is None:
raise ValueError("key_value must be provided")
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps?

Suggested change
def as_write(self, key_value: str | None = None) -> EventHubSourceWrite:
if key_value is None:
raise ValueError("key_value must be provided")
def as_write(self, key_value: str) -> EventHubSourceWrite:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It breaks the overload. Almost tempted to just write a TypeError here instead. You cannot make a write version as there is no key.

Comment on lines +26 to +27
if retrieved:
return retrieved
Copy link
Contributor

Choose a reason for hiding this comment

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

This will probably never trigger since you use random_string(10). What about

f"{platform.system()}-{platform.python_version()"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe something I am missing here, but why would I need that if I have a random string?

Copy link
Contributor

Choose a reason for hiding this comment

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

Point is you will never retrieve it when using a random string, hence make each test runner have its own

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks finally got it now.

key_value="myKey",
event_hub_name="myEventHub",
)
retrieved = cognite_client.hosted_extractors.sources.retrieve(my_hub.external_id, ignore_unknown_ids=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Dont need this when just fetching one, right?

Suggested change
retrieved = cognite_client.hosted_extractors.sources.retrieve(my_hub.external_id, ignore_unknown_ids=True)
retrieved = cognite_client.hosted_extractors.sources.retrieve(my_hub.external_id)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For these endpoints you do

Copy link
Contributor

Choose a reason for hiding this comment

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

Why? That breaks with other APIs

@doctrino doctrino requested a review from haakonvt September 3, 2024 10:57
# Conflicts:
#	CHANGELOG.md
#	cognite/client/_version.py
#	pyproject.toml
output = super()._convert_resource_to_patch_object(resource, update_attributes, mode)
if hasattr(resource, "type"):
output["type"] = resource.type
return output
Copy link
Contributor

Choose a reason for hiding this comment

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

This solution LGTM to me!

Copy link
Contributor

@haakonvt haakonvt left a comment

Choose a reason for hiding this comment

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

A few comments left but I'll leave that up to you

@doctrino doctrino enabled auto-merge (squash) September 3, 2024 13:00
@doctrino doctrino merged commit 9c16977 into master Sep 3, 2024
13 checks passed
@doctrino doctrino deleted the hosted-extractors branch September 3, 2024 13:00
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.

3 participants