Skip to content

Commit

Permalink
Fixed logging
Browse files Browse the repository at this point in the history
- Logs were not logging parameterized values correctly
- Switch logging to INFO level for prod

Signed-off-by: Michael Wilkerson <[email protected]>
  • Loading branch information
wilkermichael committed Feb 7, 2024
1 parent ef6db4b commit 0208478
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var handshakeConfig = goPlugin.HandshakeConfig{

func main() {
logCtx := log.WithFields(log.Fields{"plugin": "trafficrouter"})
log.SetLevel(log.DebugLevel)
log.SetLevel(log.InfoLevel)

rpcPluginImp := &plugin.RpcPlugin{
LogCtx: logCtx,
Expand Down
12 changes: 5 additions & 7 deletions pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ func (r *RpcPlugin) InitPlugin() pluginTypes.RpcError {
return pluginTypes.RpcError{ErrorString: err.Error()}
}

r.LogCtx = logrus.NewEntry(logrus.New())

return pluginTypes.RpcError{}
}

Expand Down Expand Up @@ -89,7 +87,7 @@ func (r *RpcPlugin) SetWeight(rollout *v1alpha1.Rollout, desiredWeight int32, _
// This checks that we are performing a canary rollout, it is not
// an error if this is empty. This will be empty on the initial rollout
if rollout.Status.Canary == (v1alpha1.CanaryStatus{}) {
r.LogCtx.Debug("Rollout does not have a CanaryStatus yet", "desiredWeight", desiredWeight)
r.LogCtx.WithFields(logrus.Fields{"desiredWeight": desiredWeight}).Debug("Rollout does not have a CanaryStatus yet")
return pluginTypes.RpcError{}
}

Expand All @@ -105,22 +103,22 @@ func (r *RpcPlugin) SetWeight(rollout *v1alpha1.Rollout, desiredWeight int32, _

// If the rollout is successful (not aborted) then modify the resolver
if rolloutAborted(rollout) {
r.LogCtx.Debug("Updating ServiceResolver for aborted rollout", "canarySubsetName", canarySubsetName, "serviceResolver", serviceResolver)
r.LogCtx.WithFields(logrus.Fields{"canarySubsetName": canarySubsetName, "serviceResolver": serviceResolver}).Debug("Updating ServiceResolver for aborted rollout")
serviceResolver, err = r.updateResolverForAbortedRollout(canarySubsetName, serviceResolver)
if err != nil {
return pluginTypes.RpcError{ErrorString: err.Error()}
}
} else {
// Check if the pods have completely rolled over, and we are finished, now set the resolver to the stable version
if rolloutComplete(rollout) {
r.LogCtx.Debug("Updating ServiceResolver after completion", "stableSubsetName", stableSubsetName, "canarySubsetName", canarySubsetName, "serviceMetaVersion", serviceMetaVersion, "serviceResolver", serviceResolver)
r.LogCtx.WithFields(logrus.Fields{"stableSubsetName": stableSubsetName, "canarySubsetName": canarySubsetName, "serviceMetaVersion": serviceMetaVersion, "serviceResolver": serviceResolver}).Debug("Updating ServiceResolver after completion")
serviceResolver, err = r.updateResolverAfterCompletion(stableSubsetName, canarySubsetName, serviceMetaVersion, suffix, serviceResolver)
if err != nil {
return pluginTypes.RpcError{ErrorString: err.Error()}
}
} else {
// Update the resolver so that canary subset points to the desired version
r.LogCtx.Debug("Updating ServiceResolver for rollout", "canarySubsetName", canarySubsetName, "serviceMetaVersion", serviceMetaVersion, "serviceResolver", serviceResolver)
r.LogCtx.WithFields(logrus.Fields{"canarySubsetName": canarySubsetName, "serviceMetaVersion": serviceMetaVersion, "serviceResolver": serviceResolver}).Debug("Updating ServiceResolver for in progress rollout")
serviceResolver, err = r.updateResolverForInProgressRollouts(canarySubsetName, serviceMetaVersion, suffix, serviceResolver)
if err != nil {
return pluginTypes.RpcError{ErrorString: err.Error()}
Expand Down Expand Up @@ -164,7 +162,7 @@ func (r *RpcPlugin) SetWeight(rollout *v1alpha1.Rollout, desiredWeight int32, _
}

// Persist changes to the ServiceSplitter
r.LogCtx.Debug("Updating ServiceSplitter", "serviceSplitter", serviceSplitter)
r.LogCtx.WithFields(logrus.Fields{"serviceSplitter": serviceSplitter}).Debug("Updating ServiceSplitter")
if err := r.K8SClient.Update(ctx, serviceSplitter, &client.UpdateOptions{}); err != nil {
return pluginTypes.RpcError{ErrorString: err.Error()}
}
Expand Down

0 comments on commit 0208478

Please sign in to comment.