Skip to content

Commit

Permalink
Merge pull request #6 from port-labs/dev
Browse files Browse the repository at this point in the history
Ehanced Logs
  • Loading branch information
mk-armah authored Jul 7, 2024
2 parents aeb3cfd + a9bfeb6 commit 774e6f9
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions integration/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def remove_symbols_and_title_case(input_string: str) -> str:
return title_case_string

async def sync_applications(self) -> None:
logger.info("Started syncing applications")
logger.info(f"Syncing entities for blueprint {BLUEPRINT.APPLICATION}")
applications = await self.humanitec_client.get_all_applications()

def create_entity(application):
Expand All @@ -58,9 +58,10 @@ def create_entity(application):
]

await asyncio.gather(*tasks)
logger.info(f"Finished syncing entities for blueprint {BLUEPRINT.APPLICATION}")

async def sync_environments(self) -> None:

logger.info(f"Syncing entities for blueprint {BLUEPRINT.ENVIRONMENT}")
applications = await self.humanitec_client.get_all_applications()

def create_entity(application, environment):
Expand Down Expand Up @@ -95,8 +96,10 @@ def create_entity(application, environment):
for environment in environments
]
await asyncio.gather(*tasks)
logger.info(f"Finished syncing entities for blueprint {BLUEPRINT.ENVIRONMENT}")

async def sync_workloads(self):
logger.info(f"Syncing entities for blueprint {BLUEPRINT.WORKLOAD}")
def create_workload_entity(resource):
return {
"identifier": resource["res_id"].replace("modules.", ""),
Expand Down Expand Up @@ -124,9 +127,6 @@ def create_workload_entity(resource):
resources = await self.humanitec_client.get_all_resources(
application, environment
)
logger.info(
f"Received resources batch with size {len(resources)} from app: {application['name']} and env: {environment['name']}"
)
resource_group = humanitec_client.group_resources_by_type(resources)
tasks = [
self.port_client.upsert_entity(
Expand All @@ -137,8 +137,10 @@ def create_workload_entity(resource):
if resource and resource["type"] == "workload"
]
await asyncio.gather(*tasks)
logger.info(f"Finished syncing entities for blueprint {BLUEPRINT.WORKLOAD}")

async def sync_resource_graphs(self) -> None:
logger.info(f"Syncing entities for blueprint {BLUEPRINT.RESOURCE_GRAPH}")
def get_resource_graph_request_body(modules):
return [
{
Expand Down Expand Up @@ -207,6 +209,7 @@ def create_resource_graph_entity(graph_data, include_relations):
for graph_data in resource_graph
]
await asyncio.gather(*tasks)
logger.info(f"Finished syncing entities for blueprint {BLUEPRINT.RESOURCE_GRAPH}")

async def enrich_resource_with_graph(self, resource, application, environment):
data = {
Expand All @@ -224,6 +227,7 @@ async def enrich_resource_with_graph(self, resource, application, environment):
return resource

async def sync_resources(self) -> None:
logger.info(f"Syncing entities for blueprint {BLUEPRINT.RESOURCE}")
def create_resource_entity(resource):
workload_id = (
resource["res_id"].split(".")[1]
Expand Down Expand Up @@ -284,6 +288,7 @@ async def fetch_resources(application, environment):
for resource in all_resources
]
await asyncio.gather(*entity_tasks)
logger.info(f"Finished syncing entities for blueprint {BLUEPRINT.RESOURCE}")

async def sync_all(self) -> None:
await self.sync_applications()
Expand Down

0 comments on commit 774e6f9

Please sign in to comment.