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

Support Logging GitHub requests #3054

Merged
merged 4 commits into from
Apr 12, 2024
Merged

Support Logging GitHub requests #3054

merged 4 commits into from
Apr 12, 2024

Conversation

puerco
Copy link
Member

@puerco puerco commented Apr 12, 2024

Summary

This commit adds a change to support wrapping the github client in a logger to log all requests minder send to the GitrHub API.

When setting the $MINDER_LOG_GITHUB_REQUESTS env var, minder will start logging all requests and responses:

The docker compose configuration now sets the variable to log everything when developing locally.

Bonus: I also fixed a bug in the docker conf that was mounting the github app private key path as a directory.

Change Type

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

Sample output:

minder_server  | {"level":"info","type":"REQ","method":"GET","Timestamp":1712897459407433227,"message":"https://api.github.com/installation/repositories?per_page=100"}
minder_server  | {"level":"info","type":"RESP","method":"GET","status":"200","Timestamp":1712897460484893720,"message":"https://api.github.com/installation/repositories?per_page=100"}

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

This commit fixes a bug where the github app key was being mounted as a directory when
bringing up docker compose

Signed-off-by: Adolfo García Veytia (Puerco) <puerco@stacklok.com>
@puerco puerco requested a review from a team as a code owner April 12, 2024 04:59
@coveralls
Copy link

coveralls commented Apr 12, 2024

Coverage Status

coverage: 48.117% (-0.05%) from 48.168%
when pulling 44821dc on puerco:reqlog
into 6e21fc0 on stacklok:main.

transport = &loghttp.Transport{
Transport: transport,
LogRequest: func(req *http.Request) {
zerolog.Ctx(context.Background()).Info().
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make this Trace not Info

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use the request's context with req.Context()

internal/providers/github/app/app.go Outdated Show resolved Hide resolved
internal/providers/github/app/app.go Show resolved Hide resolved
This commit introduces a change to log all github requests when
setting the MINDER_LOG_GITHUB_REQUESTS env var

Signed-off-by: Adolfo García Veytia (Puerco) <puerco@stacklok.com>
Log all github requests by default when running in docker compose

Signed-off-by: Adolfo García Veytia (Puerco) <puerco@stacklok.com>
Signed-off-by: Adolfo García Veytia (puerco) <puerco@stacklok.com>
@puerco puerco merged commit f8f0507 into stacklok:main Apr 12, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants