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

feat: log retriever endpoint #2601

Merged
merged 5 commits into from
Jul 11, 2024
Merged

feat: log retriever endpoint #2601

merged 5 commits into from
Jul 11, 2024

Conversation

zzzming
Copy link
Collaborator

@zzzming zzzming commented Jul 9, 2024

Implemented a feature to allow all LangFlow logs to be retrieved through an API /logs

  • /logs endpoint with pagination support
  • /logs endpoint to support the last number lines
  • implements a loguru sink to stream logs to an in-memory buffer. The size can be specified by OS env variable. If the size is 0, this feature is disabled.

Limitation, this endpoint does not filter out logs based on flow, nor user, therefore it's disabled by default. Once it's enabled the logs can be retrieved by any user.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Jul 9, 2024
Copy link
Contributor

github-actions bot commented Jul 9, 2024

Pull Request Validation Report

This comment is automatically generated by Conventional PR

Whitelist Report

Whitelist Active Result
Pull request is a draft and should be ignored
Pull request is made by a whitelisted user and should be ignored
Pull request is submitted by a bot and should be ignored
Pull request is submitted by administrators and should be ignored

Result

Pull request does not satisfy any enabled whitelist criteria. Pull request will be validated.

Validation Report

Validation Active Result
All commits in this pull request has valid messages
Pull request does not introduce too many changes
Pull request has a valid title
Pull request has mentioned issues
Pull request has valid branch name
Pull request should have a non-empty body

Result

Pull request satisfies all enabled pull request rules.

Last Modified at 09 Jul 24 04:02 UTC

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 9, 2024
Copy link
Contributor

@nicoloboschi nicoloboschi left a comment

Choose a reason for hiding this comment

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

Thanks for this work.

My opinion is that the common use case is to follow the logs in "real time". The endpoint is not designed for that and I find it very hard to implement on client side and also not efficient. Pagination for real time logs isn't a common pattern.
Polling the server again and again results in adding overhead.
I think we plan to add this feature to the UI so it has to be lightweight as possible.

My suggestion is that we implement the endpoint as unbounded stream of text.
The client could decide to start from the beginning or tail to the end (getting only new logs).
Plus, in this way we get rid of:

  • pagination handling (which is expensive in terms of cpu/mem - you're doing a lot of memory allocations)
  • sessions management

Additionally, I think we should stream to file to not impact memory usage at all and make all the logs available for the client. (currently is limited to the buffer size)

return session_id

def get_page(self, session_id: str, page: int) -> Dict[str, Any]:
self.cleanup_sessions()
Copy link
Contributor

Choose a reason for hiding this comment

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

we need to setup a timer to run every x time to check for sessions to cleanup. get_page could not be called for a while

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

session and pagination is removed

if session_id not in self.sessions:
return {"error": "Invalid or expired session ID"}

session = self.sessions[session_id]
Copy link
Contributor

Choose a reason for hiding this comment

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

we need a lock for accessing the sessions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed session

total_logs = len(logs)
total_pages = ceil(total_logs / self.page_size)

if page < 1 or page > total_pages:
Copy link
Contributor

Choose a reason for hiding this comment

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

does page start from 1 or 0 ?
if the page is not valid, we should return error

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

pagination removed

Copy link
Contributor

@ogabrielluiz ogabrielluiz left a comment

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 10, 2024
@zzzming zzzming enabled auto-merge (squash) July 10, 2024 20:39
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 10, 2024
@zzzming zzzming merged commit 81849d5 into main Jul 11, 2024
30 checks passed
@zzzming zzzming deleted the feat/log-retrieve-endpoint branch July 11, 2024 09:19
nicoloboschi pushed a commit to datastax/ragstack-ai-langflow that referenced this pull request Jul 11, 2024
* log retriever endpoint

* disabled by default

* realtime log stream via http/2 SSE

* read and write lock

* unit test

(cherry picked from commit 81849d5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants