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

[Framework] Delete entities which didn't pass the mapping selector in register_raw #490

Merged
merged 18 commits into from
Apr 17, 2024

Conversation

omby8888
Copy link
Contributor

@omby8888 omby8888 commented Apr 8, 2024

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:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • New Integration (non-breaking change which adds a new integration)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Non-breaking change (fix of existing functionality that will not change current behavior)
  • Documentation (added/updated documentation)

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.

@github-actions github-actions bot added framework A change in the ocean framework files size/S labels Apr 8, 2024
@github-actions github-actions bot added size/L integration A change in integration files and removed size/S labels Apr 9, 2024
@github-actions github-actions bot removed the integration A change in integration files label Apr 9, 2024
@github-actions github-actions bot added the integration A change in integration files label Apr 10, 2024
…e-entity-on-real-time-events

# Conflicts:
#	integrations/dynatrace/config.yaml
#	port_ocean/clients/port/mixins/entities.py
Copy link
Contributor

@Tankilevitch Tankilevitch left a 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:
Copy link
Contributor

Choose a reason for hiding this comment

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

👑

Comment on lines 137 to 141
query = {
"combinator": "and",
async def search_entities(
self, user_agent_type: UserAgentType, query: dict[Any, Any] | None = None
) -> list[Entity]:
default_query = {
"combinator": "or",
Copy link
Contributor

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

Copy link
Contributor Author

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,
Copy link
Contributor

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.

Comment on lines 85 to 88
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
Copy link
Contributor

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.

Comment on lines 145 to 146
passed = []
failed = []
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
passed = []
failed = []
passed_entities= []
failed_entities = []

)
)
for data in raw_data
for data in raw_results
]
entities = await asyncio.gather(*entities_tasks)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
entities = await asyncio.gather(*entities_tasks)
entities_results = await asyncio.gather(*entities_tasks)

Comment on lines 147 to 148
for flatten in entities:
for entity_data, did_entity_pass_selector in flatten:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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:

Copy link
Contributor

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

Copy link
Contributor Author

@omby8888 omby8888 Apr 16, 2024

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah it works

Comment on lines 155 to 162
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
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
entities_results = await asyncio.gather(*entities_tasks)
calculate_entities_results = await asyncio.gather(*calculate_entities_tasks)

Comment on lines 147 to 148
for entity_result in entities_results:
for entity, did_entity_pass_selector in entity_result:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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:

Comment on lines 157 to 158
f"Entity {entity_to_delete.identifier} either hasn't been created by this integration "
f"or it doesn't exist, skipping deletion..."
Copy link
Contributor

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.

@omby8888 omby8888 changed the title Delete entities which didn't pass the mapping selector in register_raw [Framework] Delete entities which didn't pass the mapping selector in register_raw Apr 17, 2024
Copy link
Contributor

@Tankilevitch Tankilevitch left a comment

Choose a reason for hiding this comment

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

LGTM

@omby8888 omby8888 merged commit f3ce269 into main Apr 17, 2024
5 checks passed
@omby8888 omby8888 deleted the PORT-7494-Ocean-Delete-entity-on-real-time-events branch April 17, 2024 15:46
@@ -3,16 +3,24 @@
from port_ocean.core.models import Entity


RawEntity = dict[Any, Any]
Copy link
Collaborator

Choose a reason for hiding this comment

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

use raw item instead

Comment on lines +156 to +160
if query is None:
query = default_query
elif query.get("rules"):
query["rules"].append(default_query)

Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework A change in the ocean framework files integration A change in integration files size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants