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

Use logrusctx instead of logrus on task #716

Merged
merged 1 commit into from
Nov 14, 2022
Merged

Conversation

0x2b3bfa0
Copy link
Member

@0x2b3bfa0 0x2b3bfa0 commented Nov 11, 2022

The modifications introduced with this pull request can be used to provide detailed operation status, to avoid a a “The Cloudformation” experience where users have no insight on the operation progress.

Uses github.com/0x2b3bfa0/logrusctx, which is in turn based on github.com/juju/zaputil/zapctx, mentioned by @tasdomas in a casual conversation, unsuspecting of my implementation impetus.

Use case

logger := logrus.WithField("session", sesssionID)
logger.SetOutput(&buf)
ctx = logrusctx.WithLogger(ctx, logger)
tsk.Create(ctx)
// buf will contain the real-time progress of the operation

@0x2b3bfa0 0x2b3bfa0 added enhancement New feature or request logs labels Nov 11, 2022
@0x2b3bfa0 0x2b3bfa0 requested a review from tasdomas November 11, 2022 21:12
@0x2b3bfa0 0x2b3bfa0 self-assigned this Nov 11, 2022
@0x2b3bfa0 0x2b3bfa0 marked this pull request as ready for review November 11, 2022 21:13
@0x2b3bfa0 0x2b3bfa0 temporarily deployed to automatic November 11, 2022 21:13 Inactive
@0x2b3bfa0 0x2b3bfa0 temporarily deployed to automatic November 11, 2022 21:13 Inactive
@0x2b3bfa0 0x2b3bfa0 temporarily deployed to automatic November 11, 2022 21:13 Inactive
@0x2b3bfa0 0x2b3bfa0 temporarily deployed to automatic November 11, 2022 21:13 Inactive
@0x2b3bfa0 0x2b3bfa0 temporarily deployed to automatic November 11, 2022 23:14 Inactive
@0x2b3bfa0 0x2b3bfa0 requested a deployment to automatic November 11, 2022 23:14 Abandoned
@0x2b3bfa0 0x2b3bfa0 requested a deployment to automatic November 11, 2022 23:14 Abandoned
@0x2b3bfa0 0x2b3bfa0 requested a deployment to automatic November 11, 2022 23:14 Abandoned
@0x2b3bfa0 0x2b3bfa0 temporarily deployed to automatic November 11, 2022 23:14 Inactive
@dacbd
Copy link
Contributor

dacbd commented Nov 12, 2022

I have a couple of questions.

  1. why do we need this change?
  2. can you show or say how the behavior is being changed as a result of this?
  3. Is this something that could be accepted upstream to lorgrus itself?
  4. perhaps using a logging library where context is supported already?

@0x2b3bfa0
Copy link
Member Author

  1. As stated on the pull the body, to provide [service] users with detailed operation status instead of a laconic and opaque “doing stuff, will take time” message. We don't need this change, but it seems like a nice addition to me.
  2. Behavior will stay the same after merging this pull request, but it will be really easy to alter it so logs for individual requests can be stored or sent individually to requesters.
  3. No, logrus is in maintenance mode and does not accept new features. See the official repository for more information.
  4. Yes, that would be nice but would require us to rewrite more code, and we'd risk breaking other unorthodox use cases of the logger like the command-line tool.

See #423 (review) for context (pun intended) on the introduction of logrus to this project.

@dacbd
Copy link
Contributor

dacbd commented Nov 12, 2022

  1. As stated on the pull the body, to provide [service] users with detailed operation status instead of a laconic and opaque “doing stuff, will take time” message. We don't need this change, but it seems like a nice addition to me.

I'm still missing this, I did read the body. To me looks like this lets the logging write out to some buffer that we could then print out to a user via an API call (this is to help enable that correct?), but I see no changes that actually enable this, all is see is %s/ logger.Info(string)/logger.Info(ctx, string)/gc with no other changes

  1. Behavior will stay the same after merging this pull request, but it will be really easy to alter it so logs for individual requests can be stored or sent individually to requesters.

Should this just go with the changes which utilize the feature?1

  1. No, logrus is in maintenance mode and does not accept new features. See the official repository for more information.

More for validity Q4?

  1. Yes, that would be nice but would require us to rewrite more code, and we'd risk breaking other unorthodox use cases of the logger like the command-line tool.

Maybe I'm missing some hacky-ness somewhere but I think that swapping out the logger should be the easiest update/rewrite/refactor that we could do for this codebase?

Footnotes

  1. see response to Q1

@tasdomas
Copy link
Contributor

I think this is a step in the right direction. The internal task package is going to be used (hopefully) in several different contexts: in the CLI tool, in TPI and in the server. These all have different logging requirements. By adding context support to logrus we will be able to use different log writers in different setups.

@0x2b3bfa0
Copy link
Member Author

I'm still missing this, I did read the body. To me looks like this lets the logging write out to some buffer that we could then print out to a user via an API call (this is to help enable that correct?), but I see no changes that actually enable this, all is see is %s/ logger.Info(string)/logger.Info(ctx, string)/gc with no other changes

Yes, this pull request just enables the possibility of injecting a custom logger into the context, but doesn't introduce any example.

Should this just go with the changes which utilize the feature?1

I would explicily like to separate both changes for pull requests like #716 (this) and #710, so they can be easily cherry-picked to the main branch and separated from commits related to the LEO server implementation.

Maybe I'm missing some hacky-ness somewhere but I think that swapping out the logger should be the easiest update/rewrite/refactor that we could do for this codebase?

Sure! What could possibly go wrong? 😅

@0x2b3bfa0 0x2b3bfa0 merged commit 5734af4 into feature-leo-server Nov 14, 2022
@0x2b3bfa0 0x2b3bfa0 deleted the logrusctx branch November 14, 2022 11:03
@0x2b3bfa0 0x2b3bfa0 mentioned this pull request Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request logs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants