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

Better logging for backend components #3939

Merged
merged 13 commits into from Apr 18, 2023

Conversation

namkyu1999
Copy link
Member

@namkyu1999 namkyu1999 commented Apr 3, 2023

Proposed changes

Currently, our server logs provide limited information, making it difficult to diagnose issues and track user activity. So, I made Todos for better logging. Codes about custom log fields will be handled after LFX sync-up meeting and will be raised in the next pr.

Result
스크린샷 2023-04-08 오전 3 00 21

TODO

  • change default 'log' package to 'logrus' package
  • change name 'logrus' to 'log' for generality
  • log gRPC request by using middleware
  • log HTTP request by using Gin
  • support setting log format(JSON/text) at the start flag
  • add a custom field to logrus(will be addressed in next pr)

Issue No. #3932

Types of changes

What types of changes does your code introduce to Litmus? Put an x in the boxes that apply

  • New feature (non-breaking change which adds functionality)
  • Bugfix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices applies)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc
  • I have signed the commit for DCO to be passed.
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added necessary documentation (if appropriate)

Dependency

  • Please add the links to the dependent PR need to be merged before this (if any).

Special notes for your reviewer:

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
…tter-logging

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
@namkyu1999 namkyu1999 changed the title Add better logging for backend components Better logging for backend components Apr 7, 2023
@namkyu1999 namkyu1999 marked this pull request as ready for review April 7, 2023 18:14
Copy link
Member

@imrajdas imrajdas left a comment

Choose a reason for hiding this comment

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

@namkyu1999 - Few changes:

  1. logs should be in small cases
  2. Log field should be in camel cases eg, logrus.Withfield({workflowId: "123"})
  3. Please use logrus.SetReportCaller(true)- this will report the line number in the log where the error occurred.

@imrajdas
Copy link
Member

  1. Logs should be printing in the base caller function or graphql resolver function. Otherwise the logs will be printed twice. From other function, we can return the error with required info,
return fmt.Errorf("failed due to ...., error: %v", err)

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
@namkyu1999
Copy link
Member Author

namkyu1999 commented Apr 11, 2023

Can you assign me, please? @imrajdas
And I resolved all changes you mentioned.

Copy link
Member

@imrajdas imrajdas left a comment

Choose a reason for hiding this comment

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

Please make the same changes in other areas also.

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
@S-ayanide S-ayanide added the LFX-MENTORSHIP Linux Foundation Mentor ship Issue label Apr 17, 2023
litmus-portal/graphql-server/graph/analytics.resolvers.go Outdated Show resolved Hide resolved
litmus-portal/graphql-server/graph/analytics.resolvers.go Outdated Show resolved Hide resolved
@@ -149,7 +149,7 @@ func (r *subscriptionResolver) ClusterConnect(ctx context.Context, clusterInfo m

err = dbOperationsCluster.UpdateCluster(query, update)
if err != nil {
logrus.Print("Error", err)
log.Error(err)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
log.Error(err)
log.Fatal(err)

@@ -22,7 +22,7 @@ func (r *mutationResolver) CreateImageRegistry(ctx context.Context, projectID st

ciResponse, err := imageRegistryOps.CreateImageRegistry(ctx, projectID, imageRegistryInfo)
if err != nil {
logrus.Error(err)
log.Error(err)
Copy link
Member

Choose a reason for hiding this comment

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

Can you convert all

if err != nil 

condition logs to log.Fatal?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey @S-ayanide,
log.Fatal called os.Exit(1) so that process will exit with status set to 1. Is it okay?

https://pkg.go.dev/github.com/sirupsen/logrus#Fatal

Copy link
Member

Choose a reason for hiding this comment

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

Yes that is the expectation, if something in the middle goes wrong we'd want to terminate that function with a Fatal message.

@amityt correct me if I'm wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

No log.Fatal is not required here. It will impact the complete server. Rather a return statement can be added here in this error block.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we use log.Fatal() to exit the process, k8s Deployment obj restarts the pod automatically. IMO, It's an unnecessary task. Moreover, all of the logs are deleted so we cannot analyze what is the problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, log.Fatal() should not be used here. 👍🏼

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Copy link
Contributor

@amityt amityt left a comment

Choose a reason for hiding this comment

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

LGTM, requested some minor changes.

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Copy link
Member

@S-ayanide S-ayanide left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
@Jonsy13 Jonsy13 merged commit 48379a4 into litmuschaos:master Apr 18, 2023
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LFX-MENTORSHIP Linux Foundation Mentor ship Issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants