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

[amqphandler] Don't truncate debug logs #168

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 2 additions & 40 deletions amqphandler/amqphandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const (
sendMaxTry = 3
sendTimeout = 1 * time.Minute
receiveChannelSize = 16
maxLenLogMessage = 340
)

const (
Expand Down Expand Up @@ -776,14 +775,6 @@ func (handler *AmqpHandler) scheduleMessage(data interface{}, important bool) er
}
}

func getMessageDataForLog(message interface{}, data []byte) string {
if len(data) > maxLenLogMessage && !isMessageImportant(message) {
return string(data[:maxLenLogMessage]) + "..."
}

return string(data)
}

func (handler *AmqpHandler) sendMessage(
message cloudprotocol.Message, amqpChannel *amqp.Channel, params cloudprotocol.SendParams,
) error {
Expand All @@ -793,9 +784,9 @@ func (handler *AmqpHandler) sendMessage(
}

if handler.sendTry > 1 {
log.WithField("data", getMessageDataForLog(message.Data, data)).Debug("AMQP retry message")
log.WithField("data", string(data)).Debug("AMQP retry message")
} else {
log.WithField("data", getMessageDataForLog(message.Data, data)).Debug("AMQP send message")
log.WithField("data", string(data)).Debug("AMQP send message")
}

if handler.sendTry++; handler.sendTry > sendMaxTry {
Expand All @@ -819,32 +810,3 @@ func (handler *AmqpHandler) sendMessage(

return nil
}

func isMessageImportant(message interface{}) bool {
switch message.(type) {
case cloudprotocol.DesiredStatus:
return true
case cloudprotocol.StateAcceptance:
return true
case cloudprotocol.RenewCertsNotification:
return true
case cloudprotocol.IssuedUnitCerts:
return true
case cloudprotocol.OverrideEnvVars:
return true
case cloudprotocol.NewState:
return true
case cloudprotocol.StateRequest:
return true
case cloudprotocol.UnitStatus:
return true
case cloudprotocol.IssueUnitCerts:
return true
case cloudprotocol.InstallCertData:
return true
case cloudprotocol.OverrideEnvVarsStatus:
return true
}

return false
}
Loading