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

[Core] [Logging] | Integration logs not being ingested #1120

Merged

Conversation

ivankalinovski
Copy link
Contributor

@ivankalinovski ivankalinovski commented Nov 5, 2024

Description

What:

  • Fix logs not being ingested on integrations fails or exceptions.

Why:

  • The logger flush method is spawning a new thread that is not awaited when the program exists.
  • The logger accepts 'exc_info' that cannot be serialized.
  • Upon shutdown of the program the logger writes a message that needs to be awaited in order to be sent to Port API.

How:

  • Added method - 'wait_for_lingering_threads' to 'HTTPMemoryHandler' that will wait for running threads.
    'wait_for_lingering_threads' is invoked via the 'SignalHandler' upon exit.
  • Modified method - '_serialize_record' to look for 'exc_info' in each log and serialize it using 'traceback'.
  • Added call - 'logger.complete' so log that is sent on exit of program will be sent to Port API.

Type of change

Please leave one option from the following and delete the rest:

  • Bug fix (non-breaking change which fixes an issue)

All tests should be run against the port production environment(using a testing org).

Core testing checklist

  • Integration able to create all default resources from scratch
  • Resync finishes successfully
  • Resync able to create entities
  • Resync able to update entities
  • Resync able to detect and delete entities
  • Scheduled resync able to abort existing resync and start a new one
  • Tested with at least 2 integrations from scratch
  • Tested with Kafka and Polling event listeners
  • Tested deletion of entities that don't pass the selector

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.

@ivankalinovski ivankalinovski requested a review from a team as a code owner November 5, 2024 16:12
@github-actions github-actions bot added the size/S label Nov 5, 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.

Great to have you contributing to ocean 🌊 and diving straight to a painful bug 🤩
Left a few comments, also make sure you update the version in the pyproject.toml as well :)

port_ocean/clients/port/mixins/integrations.py Outdated Show resolved Hide resolved
port_ocean/clients/port/mixins/integrations.py Outdated Show resolved Hide resolved
port_ocean/clients/port/mixins/integrations.py Outdated Show resolved Hide resolved
port_ocean/clients/port/mixins/integrations.py Outdated Show resolved Hide resolved
async def ingest_integration_logs(self, logs: list[dict[str, Any]]) -> None:
logger.debug("Ingesting logs")
sirealized_logs=self.sirealize_logs(logs)
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
sirealized_logs=self.sirealize_logs(logs)
serialized_logs=self.serialize_logs(logs)

@@ -99,15 +100,24 @@ async def patch_integration(
handle_status_code(response)
return response.json()["integration"]

def sirealize_logs(self,logs: list[dict[str, Any]]):
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a pretty isolated method, lets add a test for it

Comment on lines 90 to 93
clear_thread_pool()
thread=threading.Thread(target=_wrap_event_loop, args=(self.ocean, logs))
thread.start()
self._thread_pool.append(thread)
Copy link
Contributor

Choose a reason for hiding this comment

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

are we supporting multiple threads flushing logs concurrently?
lets test long running, scheduled resync to verify we didn't break anything.

shalev007 and others added 3 commits November 6, 2024 11:02
# Description

What - bump fastapi version to 0.115.3 to upgrade starlette

Why - https://github.com/port-labs/ocean/security/dependabot/433 

How - bump fastapi version

## 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)
- [X] Non-breaking change (fix of existing functionality that will not
change current behavior)
- [ ] Documentation (added/updated documentation)

<h4> All tests should be run against the port production
environment(using a testing org). </h4>

### Core testing checklist

- [x] Integration able to create all default resources from scratch
- [x] Resync finishes successfully
- [x] Resync able to create entities
- [x] Resync able to update entities
- [x] Resync able to detect and delete entities
- [x] Scheduled resync able to abort existing resync and start a new one
- [x] Tested with at least 2 integrations from scratch
- [x] Tested with Kafka and Polling event listeners
- [x] Tested deletion of entities that don't pass the selector


### Integration testing checklist

- [ ] Integration able to create all default resources from scratch
- [ ] Resync able to create entities
- [ ] Resync able to update entities
- [ ] Resync able to detect and delete entities
- [ ] Resync finishes successfully
- [ ] If new resource kind is added or updated in the integration, add
example raw data, mapping and expected result to the `examples` folder
in the integration directory.
- [ ] If resource kind is updated, run the integration with the example
data and check if the expected result is achieved
- [ ] If new resource kind is added or updated, validate that
live-events for that resource are working as expected
- [ ] Docs PR link [here](#)

### Preflight checklist

- [ ] Handled rate limiting
- [ ] Handled pagination
- [ ] Implemented the code in async
- [ ] Support Multi account

## 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.

---------

Co-authored-by: Shalev Avhar <[email protected]>
Co-authored-by: Tom Tankilevitch <[email protected]>
This PR was automatically created by a GitHub Action.

## What does this PR do?
Apply Ocean version 0.12.8 to all integrations

## How should this be manually tested?
./scripts/bump-all.sh ^0.12.8

---------

Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: Shalev Avhar <[email protected]>
@github-actions github-actions bot added size/M and removed size/S labels Nov 7, 2024
Copy link
Member

@erikzaadi erikzaadi left a comment

Choose a reason for hiding this comment

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

Be sure to rebase to fix your conflict
The commit messages themselves are a bit long, put the main change list you added there to the commit body
Besides that 3 small NITs
Approving in the meanwhile to save you a hop, be sure to validate the testing Q @Tankilevitch asked



def assert_extra(extra: dict):
assert "exc_info" in extra
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert "exc_info" in extra
exc_info = extra.get("exc_info", None)
assert type(exec_info) is str
return exec_info

return exc_info


def log_record(cb: Callable[[None], None]) -> "loguru.Record":
Copy link
Member

Choose a reason for hiding this comment

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

Why a string based type?


- Await logger writing exception on exit (Integration logs not being ingested)
- Await logger thread on exit (Integration logs not being ingested)
- Sirealize exception (Integration logs not being ingested)
Copy link
Member

Choose a reason for hiding this comment

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

git grep -i sirealize

Ivan Kalinovski added 6 commits November 7, 2024 10:42
1.Extend method "_serialize_record" to stringify exceptions in "exc_info". 2.Await logger on thread exit. 3.Await logger writing exception on exit.
1.Extend method "_serialize_record" to stringify exceptions in "exc_info". 2.Await logger on thread exit. 3.Await logger writing exception on exit.
@github-actions github-actions bot added size/XXL and removed size/M labels Nov 7, 2024
1.Extend method "_serialize_record" to stringify exceptions in "exc_info".
2.Await logger on thread exit.
3.Await logger writing exception on exit.
@ivankalinovski ivankalinovski merged commit 0faaf0d into main Nov 7, 2024
74 checks passed
@ivankalinovski ivankalinovski deleted the PORT-10719-bug-integration-logs-not-being-ingested branch November 7, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants