-
Notifications
You must be signed in to change notification settings - Fork 20
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
[Framework] Delete entities which didn't pass the mapping selector in register_raw #490
[Framework] Delete entities which didn't pass the mapping selector in register_raw #490
Conversation
…ded a ownership check on real time deletion
…e-entity-on-real-time-events # Conflicts: # integrations/dynatrace/config.yaml # port_ocean/clients/port/mixins/entities.py
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 would prefer that you organize the methods you use, and separate them so its more readable other than trying to re-use existing ones. When using the unregister_raw and register_raw there is no meaning for passing it as diff IIRC
@@ -58,7 +58,7 @@ For example, if you configure the integration to listen to the `/webhook` endpoi | |||
|
|||
::: | |||
|
|||
Here is an example definition that exposes a `/integrations/webhook` route the integration will listen to: | |||
Here is an example definition that exposes a `/integration/webhook` route the integration will listen to: |
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.
👑
query = { | ||
"combinator": "and", | ||
async def search_entities( | ||
self, user_agent_type: UserAgentType, query: dict[Any, Any] | None = None | ||
) -> list[Entity]: | ||
default_query = { | ||
"combinator": "or", |
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.
seems like the default search entities has changed from and
to or
is that on purpose, this has a huge performance impact on the query behavior and might result with different results
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.
oops...
self, | ||
data: dict[str, Any], | ||
raw_entity_mappings: dict[str, Any], | ||
selector_query: str, | ||
ignore_selector: bool = False, |
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.
there is inconsistency with the parameter across all the functions that pass it through.
if ignore_selector or should_run: | ||
mapped_entity = await self._search_as_object(data, raw_entity_mappings) | ||
mapped_entity[DOES_ENTITY_PASSED_SELECTOR_KEY] = should_run | ||
return mapped_entity |
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 am not a fan at all of passing flags through unrelated objects, you can change the data structure of how you return that data, we can discuss it offline, but injecting into an object which is user related shouldn't be done, and is very hard to debug.
passed = [] | ||
failed = [] |
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.
passed = [] | |
failed = [] | |
passed_entities= [] | |
failed_entities = [] |
) | ||
) | ||
for data in raw_data | ||
for data in raw_results | ||
] | ||
entities = await asyncio.gather(*entities_tasks) |
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.
entities = await asyncio.gather(*entities_tasks) | |
entities_results = await asyncio.gather(*entities_tasks) |
for flatten in entities: | ||
for entity_data, did_entity_pass_selector in flatten: |
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.
for flatten in entities: | |
for entity_data, did_entity_pass_selector in flatten: | |
for entity_result in entities_results: | |
for entity, did_entity_pass_selector in entity_result: |
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.
btw I don't think this unpacking of tuple will work as flatten
isn't an iterator.
I think entity_result[0]
entity_result[1]
will suit better
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'll make sure but flatten is a list of tuples so it should work
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.
yeah it works
if not is_owner: | ||
logger.info( | ||
f"Entity {entity_to_delete.identifier} hasn't been created by this integration, " | ||
f"skipping deletion..." | ||
) | ||
continue | ||
await self.entities_state_applier.delete( | ||
objects_diff[0]["failed"], user_agent_type |
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 log might be confusing, as it is possible that the entity doesn't exists in port which in that case will return is_owner=False
as well.
"before": entities_before, | ||
"after": entities_after, | ||
} | ||
entities_results = await asyncio.gather(*entities_tasks) |
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.
entities_results = await asyncio.gather(*entities_tasks) | |
calculate_entities_results = await asyncio.gather(*calculate_entities_tasks) |
for entity_result in entities_results: | ||
for entity, did_entity_pass_selector in entity_result: |
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.
for entity_result in entities_results: | |
for entity, did_entity_pass_selector in entity_result: | |
for entities_results in calculate_entities_results: | |
for entity, did_entity_pass_selector in entities_results: |
f"Entity {entity_to_delete.identifier} either hasn't been created by this integration " | ||
f"or it doesn't exist, skipping deletion..." |
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.
Skipping deletion of entity {entity_to_delete.identifier}, couldn't find entity that is related to integration.
…e-entity-on-real-time-events
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.
LGTM
@@ -3,16 +3,24 @@ | |||
from port_ocean.core.models import Entity | |||
|
|||
|
|||
RawEntity = dict[Any, 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.
use raw item instead
if query is None: | ||
query = default_query | ||
elif query.get("rules"): | ||
query["rules"].append(default_query) | ||
|
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.
why not splitting this function?
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.
why?
Description
What - Delete entities which didn't pass the mapping selector in register_raw
Type of change
Please leave one option from the following and delete the rest:
Screenshots
Include screenshots from your environment showing how the resources of the integration will look.
API Documentation
Provide links to the API documentation used for this integration.