Skip to content

Commit

Permalink
[amqphandler] Don't truncate debug logs
Browse files Browse the repository at this point in the history
Signed-off-by: Mykhailo Lohvynenko <[email protected]>
  • Loading branch information
mlohvynenko committed Oct 2, 2024
1 parent cf48642 commit 8affbff
Showing 1 changed file with 2 additions and 40 deletions.
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
}

0 comments on commit 8affbff

Please sign in to comment.