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: Add contextual logger #527

Merged
merged 12 commits into from
Mar 5, 2025
Merged

feat: Add contextual logger #527

merged 12 commits into from
Mar 5, 2025

Conversation

bgins
Copy link
Contributor

@bgins bgins commented Mar 4, 2025

Summary

This pull request makes the following changes:

  • Add GetLogger helper to get a logger with service context
  • Update solver with new logger
    • Add solver command logger
    • Add top-level solver logger
    • Replace solver controller service logger
    • Add solver server logger
    • Add solver metric logger
    • Add solver stats logger
  • Rename SetupLogging to SetupGlobalLogger (to clarify its purpose)

This pull request moves us towards a uniform logging system built around the zerolog interface.

We have also made a small naming change:

  • Rename solverServer instances to server (we know we're in the solver)

Task/Issue reference

Implements: #303

Test plan

Start the stack. Run a job. Make sure it all works.

Also may be of interest to run a job and compare the logs on main with the logs in this pull request.

Details

Our system currently uses a global zerolog implementation in some places and a service logger in others. We would like to move to individualized zerolog loggers for each package or component that can be configured with additional context. This pull request starts with loggers configured with the service they log from.

This pull request also updates the solver logs to replace global logger and service logger calls with the new contextualized logs. We have updated many of the existing logs with additional key-pairs which in some cases were not possible using the service logger. The additional key-pair fields support our upcoming OpenTelemetry work.

Related issues or PRs

Epic: https://github.com/Lilypad-Tech/internal/issues/345

@cla-bot cla-bot bot added the cla-signed label Mar 4, 2025
@bgins bgins marked this pull request as ready for review March 4, 2025 22:19
@bgins bgins requested a review from a team as a code owner March 4, 2025 22:19
@@ -413,7 +421,7 @@ func (controller *SolverController) addJobOffer(jobOffer data.JobOffer) (*data.J
}
jobOffer.ID = id

controller.log.Info("add job offer", jobOffer)
controller.log.Info().Any("jobOffer", jobOffer).Msg("add job offer")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's also add the jobOfferId as a key-value so it'll be a little easier to spot in the logs

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! Great idea. Added in 157cc4c

return nil, nil
}

controller.log.Info("add resource offer", resourceOffer)
controller.log.Info().Any("resourceOffer", resourceOffer).Msg("add resource offer")
Copy link
Collaborator

@narbs91 narbs91 Mar 5, 2025

Choose a reason for hiding this comment

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

Let's also add the resourceOfferId and resourceProviderId as a key-value so it'll be a little easier to spot in the logs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ Done: 157cc4c

@@ -520,7 +535,7 @@ func (controller *SolverController) addDeal(ctx context.Context, deal data.Deal)
span.SetAttributes(attribute.String("deal.id", deal.ID))
span.AddEvent("data.get_deal_id.done")

controller.log.Info("add deal", deal)
controller.log.Info().Any("deal", deal).Msg("add deal")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's also add the dealId and the resourceProviderId of the RP whose going to do the job as key-value pairs here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also done in 157cc4c. Did the job creator ID as well.

Copy link
Collaborator

@narbs91 narbs91 left a comment

Choose a reason for hiding this comment

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

LGTM! Just left some comments on additions to some of the log statements

@bgins bgins merged commit a5461fb into main Mar 5, 2025
5 checks passed
@bgins bgins deleted the bgins/feat-add-contextual-logger branch March 5, 2025 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants