Conversation
895c1fb to
ee4cba7
Compare
|
@templecloud do you have any insight into why the e2e tests are failing (I've merged your branch and rebased on top)? |
| ) | ||
|
|
||
| func init() { | ||
| flag.StringVar(&lvlString, "log-level", lvlString, "Adjusts the level of the logs that will be omitted.") |
There was a problem hiding this comment.
This can be cleaned up.
var (
lvl = zapcore.InfoLevel
logJSON = true
config *zap.Config
mu sync.Mutex
)
func init() {
flag.Var(&lvl, "log-level", "Adjusts the level of the logs that will be omitted.")
flag.BoolVar(&logJSON, "log-json", logJSON, "Log in json format.")
}
....
config.Level.SetLevel(lvl)There was a problem hiding this comment.
zapcore.Level is a int8 though. Doesn't that required --log-level=0 vs --log-level=info?
There was a problem hiding this comment.
That's why it's a Var. You'd pass strings. The level implements the flag interface https://github.com/uber-go/zap/blob/master/zapcore/level.go
There was a problem hiding this comment.
TIL there's a flag interface. Cheers 👍
| cfg = zap.NewProductionConfig() | ||
| } | ||
|
|
||
| if len(logfilePath) > 0 { |
There was a problem hiding this comment.
I mistakenly presumed filebeat would handle that for us. I guess I should add support for log rotation via https://github.com/natefinch/lumberjack?
There was a problem hiding this comment.
potentially? I was more so just curious how it works. If OKE is handling it with filebeat then that's fine.
There was a problem hiding this comment.
As far as I understand it Filebeat doesn't actually support log rotation though hence my suggestion we do it at the application level.
| if attachment.LifecycleState != core.VnicAttachmentLifecycleStateAttached { | ||
| glog.Infof("VNIC attachment %q for instance %q has a state of %q (not %q)", | ||
| *attachment.Id, instanceID, attachment.LifecycleState, core.VnicAttachmentLifecycleStateAttached) | ||
| c.logger.With( |
There was a problem hiding this comment.
You should create a context logger at the beginning of this method call with instance (and maybe compartment id) as fields.
| "vnicAttachmentID", *attachment.Id, | ||
| "expectedLifecycleState", core.VnicAttachmentLifecycleStateAttached, | ||
| "actualLifecycleState", attachment.LifecycleState, | ||
| ).Info("VNIC attachment in unexpected lifecycle state") |
There was a problem hiding this comment.
personally i'd just have the log msg as "VNIC attachment is not in attached state" and remove the expected msg.
| // in this method to obtain nodeaddresses. | ||
| func (cp *CloudProvider) NodeAddressesByProviderID(ctx context.Context, providerID string) ([]api.NodeAddress, error) { | ||
| glog.V(4).Infof("NodeAddressesByProviderID(%q) called", providerID) | ||
| cp.logger.Debugf("NodeAddressesByProviderID(%q) called", providerID) |
There was a problem hiding this comment.
These types of log messages are largely useless imo. It'd be more useful to say
cp.logger.With("providerID", providerID).Debug("fetching node addresses by provider id")
| // balancer, if it doesn't already exist. | ||
| func (cp *CloudProvider) ensureSSLCertificate(ctx context.Context, lb *loadbalancer.LoadBalancer, spec *LBSpec) error { | ||
| name := spec.SSLConfig.Name | ||
| logger := cp.logger.With("certificateName", name, "loadbalancerName", *lb.DisplayName) |
There was a problem hiding this comment.
I feel we should change this to always use ocid and not display names.
There was a problem hiding this comment.
I believe we always add the ocid as soon as we have it; just including display name as we often have that prior to getting an ocid. Thoughts?
| } | ||
|
|
||
| glog.V(4).Infof("CreateLoadBalancerDetails: %#v", details.String()) | ||
| logger.With("details", details).Debug("CreateLoadBalancerDetails") |
There was a problem hiding this comment.
This is gonna be a HUGE log message.... What if the cluster has 500+ nodes? Heck even 20 nodes would be a lot for this haha.
| } | ||
|
|
||
| glog.Infof("Created load balancer %q with OCID %q", *lb.DisplayName, *lb.Id) | ||
| logger.With("loadbalancerID", *lb.Id).Info("Loadbalancer created") |
| } | ||
|
|
||
| actions := sortAndCombineActions(backendSetActions, listenerActions) | ||
| actions := sortAndCombineActions(cp.logger, backendSetActions, listenerActions) |
There was a problem hiding this comment.
This and the one above should be context loggers I think w/ at a very minimum the lb id / service name/namespace / something.
| ) | ||
|
|
||
| glog.V(2).Infof("Applying %q action on backend set %q for lb %q (ports=%+v)", action.Type(), action.Name(), lbID, ports) | ||
| cp.logger.Infof("Applying %q action on backend set %q for lb %q (ports=%+v)", action.Type(), action.Name(), lbID, ports) |
There was a problem hiding this comment.
lb id should be on the logger already. it gets to be super complex/annoying if we need to add the same fields every where down the call stack.
|
what happens to the existing glog flags around files that never worked? |
|
@jhorwit2 Do you think it's worth adding no-op flags for the old glog flags for compat. or given they never worked can we just drop them (with a note in the CHANGELOG)? |
| cp, err := buildConfigurationProvider(config) | ||
| logger := logutil.Logger() | ||
| defer logger.Sync() | ||
| zap.ReplaceGlobals(logger) |
There was a problem hiding this comment.
Replacing it here means there will be logs emitted not following this logger since the CCM itself logs plus other various global things.
There was a problem hiding this comment.
Would you suggest swapping out the logger in func main() then?
|
@jhorwit2 My attempt at moving the logger override |
|
Awaiting a +1 review from @jhorwit2 |
|
@prydie do you know why? that seems odd. |
|
@jhorwit2 I was previously creating a new logger in both I'm not overly keen on how I'm getting that reference now but it's working: |
Setting env vars in the form LOG_VAR_field_name=value now adds fields
fields to the logger (e.g. zap.String("field_name", "value") in this
example).
| } | ||
|
|
||
| options := []zap.Option{zap.AddStacktrace(zapcore.FatalLevel)} | ||
| // Extract log fields from environment variables. |
There was a problem hiding this comment.
What's the need for this? Won't filebeat/fluentd/< insert log shipper > do that for you?
|
lgtm |
|
Actually @prydie could you please update the README for docs on this? |
|
@jhorwit2 I'm going to merge and create an issue for a broader effort to improve documentation. |
Migrates logging from to
go.uber.org/zapfromgithub.com/golang/glogand adds the following flags: