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 pino instead of console.log #2263

Merged

Conversation

DracFiendMG
Copy link
Contributor

@DracFiendMG DracFiendMG commented Nov 14, 2023

This fixes #674.

@NimJay NimJay changed the title Issue #674 Use pino instead of console.log Nov 14, 2023
Copy link
Collaborator

@NimJay NimJay left a comment

Choose a reason for hiding this comment

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

@DracFiendMG, thanks so much for starting this!
It looks like currencyservice is failing to build because the logger object hasn't been initialized inside server.js.

      > [currencyservice-6f5d5cf7b6-vwlmb server] /usr/src/app/server.js:18
      > [currencyservice-6f5d5cf7b6-vwlmb server]   logger.info("Profiler disabled.")
      > [currencyservice-6f5d5cf7b6-vwlmb server]   ^
      > [currencyservice-6f5d5cf7b6-vwlmb server] ReferenceError: Cannot access 'logger' before initialization
      > [currencyservice-6f5d5cf7b6-vwlmb server]     at Object.<anonymous> (/usr/src/app/server.js:18:3)

You may want to test your changes locally by deploying Online Boutique to a kind (or minikube) Kubernetes cluster on your machine.
You can set this up by following /docs/development-guide.md

@DracFiendMG
Copy link
Contributor Author

Sure @NimJay, I'll do that and get back to you

@DracFiendMG
Copy link
Contributor Author

Hi @NimJay, I've deployed and tested this locally and also committed the relevant changes, can you check it now?

And I have one question: When I did skaffold run i noticed that almost 15-20 GB was occupied on my disk, do you know where these files are getting stored? I was not able to find them

@NimJay
Copy link
Collaborator

NimJay commented Nov 17, 2023

@DracFiendMG, you asked:

almost 15-20 GB was occupied on my disk, do you know where these files are getting stored?

That's likely a result of the Docker container images that are stored locally on your machine — when you run skaffold run.

You can list Docker images and containers on your machine using:

docker image ls

You can delete all images and containers using:

docker rmi $(docker images -a -q) -f
docker rm $(docker ps -a -q) -f

Copy link
Contributor Author

@DracFiendMG DracFiendMG left a comment

Choose a reason for hiding this comment

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

I've initialized pino as per the requirements and updated the branch as well

}
}
});

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: (feel free to ignore)
Feel free to create a separate logger.js file (in each Node.js microservice) where we initialize the logger = pino(...) object (just once for each microservice) and re-use that object in other files (by importing the object from the logger.js file) but that's a bonus (out-of-scope) for this pull-request.

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, in the beginning I was going to do it this way, but creating multiple logger files for different services seemed a bit too much so I only made changes in the required services.
If you have a suggestion where we only use one logger.js and that can be used across all the services then do tell me about it. Because the only change in the logger is the name of the service, if we know how to set the name of the logger's service dynamically then it should be good.
If that's not possible then maybe you can raise another issue for this and I'll create separate logger.js files for all the services.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, I've created logger.js for paymentservice only.
Please check and validate that

Copy link
Collaborator

@NimJay NimJay Nov 21, 2023

Choose a reason for hiding this comment

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

Thanks for going the extra mile (but know that you don't have do)!

Issue: The logger.js file of the paymentservice should live at /src/paymentservice/logger.js.

src/paymentservice/index.js Outdated Show resolved Hide resolved
@NimJay
Copy link
Collaborator

NimJay commented Nov 20, 2023

Thanks for your continual progress on this change, @DracFiendMG! :)
I left 2 more comments — only one issue needs to be fixed.

@DracFiendMG
Copy link
Contributor Author

@NimJay, can you look into this header-check issue, I don't know about this

@@ -0,0 +1,27 @@
/*
* Copyright 2018 Google LLC
Copy link
Collaborator

@NimJay NimJay Nov 21, 2023

Choose a reason for hiding this comment

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

First off, thank you for creating a separate logger.js file!
The header-check is failing before the year should be 2023 on new files introduced by this pull-request.

Suggested change
* Copyright 2018 Google LLC
* Copyright 2023 Google LLC

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've resolved this one

@DracFiendMG
Copy link
Contributor Author

@NimJay, I've performed the suggested changes.
I think it won't fail this time

return { severity: logLevelString }
}
}
});
Copy link
Collaborator

@NimJay NimJay Nov 23, 2023

Choose a reason for hiding this comment

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

Suggestion: We should use this in src/paymentservice/charge.js as well.

Copy link
Collaborator

@NimJay NimJay left a comment

Choose a reason for hiding this comment

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

Nice, it works! 😄 👏
@DracFiendMG, thanks so much for your patience with this pull-request.

Approved!
Remaining work:

  1. Introduce a logger.js file in currencyservice.
  2. Update src/paymentservice/charge.js to also use src/paymentservice/logger.js .

But someone can do those things outside of the pull-request — I don't want this pull-request to exhaust you.

@NimJay NimJay merged commit 515f5c5 into GoogleCloudPlatform:main Nov 23, 2023
6 checks passed
@DracFiendMG DracFiendMG deleted the main-pino-implementation-re branch November 24, 2023 04:00
@DracFiendMG DracFiendMG restored the main-pino-implementation-re branch November 24, 2023 04:05
@DracFiendMG
Copy link
Contributor Author

@NimJay Thank you, I loved doing this~
If there's any other issues that I may be able to take up then please mention those

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.

Use pino instead of console.log
2 participants