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

Replace Glog with Zap Logger #378

Closed
wants to merge 2 commits into from
Closed

Conversation

xWink
Copy link
Member

@xWink xWink commented Aug 31, 2023

What type of PR is this?

cleanup

Which issue does this PR fix:
#126 partially

What does this PR do / Why do we need it:

  • Removes glog entirely
  • All previous uses of glog are replaced with zap logger
  • Tests that now must use an implementation of zap logger use the fallback logger
  • Removal of redundant newlines in logs
  • NO controller functionality changes or log content changes, this is only a change from glog to zap

If an issue # is not available please add repro steps and logs from aws-gateway-controller showing the issue:

Testing done on this change:

N/A

Automation added to e2e:

N/A

Will this PR introduce any new dependencies?:

No

Will this break upgrades or downgrades. Has updating a running cluster been tested?:
No. N/A

Does this PR introduce any user-facing change?:

Logs will be a bit cleaner, but nothing else.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@xWink xWink requested a review from mikhail-aws August 31, 2023 20:19
@xWink xWink changed the title Logging improvements Replace Glog with Zap Logger Aug 31, 2023
@coveralls
Copy link

coveralls commented Aug 31, 2023

Pull Request Test Coverage Report for Build 6042045094

  • 270 of 354 (76.27%) changed or added relevant lines in 22 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 39.248%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/aws/cloud.go 0 1 0.0%
pkg/deploy/lattice/targets_manager.go 12 13 92.31%
pkg/gateway/model_build_targetgroup.go 1 2 50.0%
controllers/gateway_controller.go 0 2 0.0%
controllers/service_controller.go 0 2 0.0%
pkg/aws/services/vpclattice.go 0 2 0.0%
controllers/eventhandlers/gateway.go 0 3 0.0%
pkg/deploy/lattice/listener_synthesizer.go 14 17 82.35%
pkg/deploy/lattice/service_network_synthesizer.go 19 22 86.36%
pkg/deploy/lattice/target_group_manager.go 22 25 88.0%
Totals Coverage Status
Change from base Build 6040753957: 0.02%
Covered Lines: 4019
Relevant Lines: 10240

💛 - Coveralls

Copy link
Contributor

@mikhail-aws mikhail-aws left a comment

Choose a reason for hiding this comment

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

Reviewed half of it. Before going further few major comments.

  1. Approach, lets agree on the that. If we touch code, we dont want to come back again for another logging improvement. So it's better to have a fewer but complete changes, than many and come back again. Why come back again, will list below.
  2. glog.V6 is debug, there are many places where debug converted into info log.
  3. glog.v2 is info, there are places where info converted into debug.
  4. multi-line logging - merge into one
  5. log error or return error, dont do both
  6. statements with foo,err := getFoo(), and then we log both log.Info(foo, err), not good, if error happened and we handle it by logging, we do if err != nil { log(err) }
  7. Info logging with %v - we talked about it - no %v, log only fields that we care about. If not sure which fields are important, log name or id. For debugging %v can be used, carefully.

@@ -39,7 +40,7 @@ func NewDefaultLattice(sess *session.Session, region string) *defaultLattice {

latticeSess = vpclattice.New(sess, aws.NewConfig().WithRegion(region).WithEndpoint(endpoint).WithMaxRetries(20))

glog.V(2).Infoln("Lattice Service EndPoint:", endpoint)
log.Debugln("Lattice Service EndPoint:", endpoint)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be removed. I dont think we need log in defaultLattice, can be at controller_config since it's env_variable

cloud: cloud,
latticeDataStore: latticeDataStore,
}
}

func (s *defaultListenerManager) Create(ctx context.Context, listener *latticemodel.Listener) (latticemodel.ListenerStatus, error) {
glog.V(6).Infof("Creating listener >>>> %v \n", listener)
s.log.Infof("Creating listener >>>> %v", listener)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would log only a few fields from listener, not %v, most important ones, like name and may be port. Especially with info level.

Comment on lines +51 to 52
s.log.Infof("Error during create listner %s", errmsg)
return latticemodel.ListenerStatus{}, errors.New(errmsg)
Copy link
Contributor

Choose a reason for hiding this comment

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

no error logging, when we return error

return latticemodel.ListenerStatus{}, errors.New(errmsg)
}

lis, err := s.findListenerByNamePort(ctx, serviceStatus.ID, listener.Spec.Port)

glog.V(6).Infof("findListenerByNamePort %v , lisenter %v error %v\n", listener, lis, err)
s.log.Infof("findListenerByNamePort %v , lisenter %v error %v", listener, lis, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we already logged listener above, no need to dump it again. Also when there is error I would log error separately with if condition. It seems in this case we drop error handling, so logging error right here is ok.

Comment on lines +96 to +100
s.log.Debugln("############req creating listner ###########")
s.log.Debugln(listenerInput)
s.log.Debugln("############resp creating listner ###########")
s.log.Debugf("create listener err :%v", err)
s.log.Debugln(resp)
Copy link
Contributor

Choose a reason for hiding this comment

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

em...

@@ -29,28 +36,28 @@ func (r *ruleSynthesizer) Synthesize(ctx context.Context) error {

err := r.stack.ListResources(&resRule)

glog.V(6).Infof("Synthesize rule = %v, err :%v \n", resRule, err)
r.log.Infof("Synthesize rule = %v, err :%v", resRule, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

if err, then log error

Comment on lines -39 to 47
glog.V(6).Infof("Failed to create rule %v, err :%v \n", rule, err)
r.log.Infof("Failed to create rule %v, err :%v", rule, err)
return err
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 on error return

rule.Status = &ruleResp
}

// handle delete
sdkRules, err := r.getSDKRules(ctx)
glog.V(6).Infof("rule>>> synthesize, sdkRules :%v err: %v \n", sdkRules, err)
r.log.Infof("rule>>> synthesize, sdkRules :%v err: %v", sdkRules, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

if err, then log

Comment on lines -83 to 91
glog.V(6).Infof("findMatchRule, rule not found err:%v\n", err)
r.log.Infof("findMatchRule, rule not found err:%v", err)
return modelRule, errors.New("rule not found")
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

Comment on lines -89 to 97
glog.V(6).Infof("no HTTPMatch ")
r.log.Infof("no HTTPMatch ")
return modelRule, errors.New("rule not found")
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

@solmonk
Copy link
Contributor

solmonk commented Aug 31, 2023

In addition - let's remove "#####" or ">>>>>" style logs whenever possible (sorry not sure how to call these)

This could be too much for one PR so we may just split the PR by components - (do controller, do manager, do modelbuild, and so on)

@solmonk
Copy link
Contributor

solmonk commented Aug 31, 2023

btw I'm totally happy with replacing a few info logs with debug logs by good judgement. I would like to see minimal set of logs when debug mode is off

@xWink
Copy link
Member Author

xWink commented Sep 24, 2023

Going to close this and use it as reference for fresh, smaller PRs.

First one is up
#410

@xWink xWink closed this Sep 24, 2023
@xWink xWink deleted the logging-improvements branch October 3, 2023 19:54
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.

4 participants