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

[RHCLOUD-30651] Independently log cloud-connector dispatchers map #315

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions internal/cloud_connector/message_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ func processDispatchers(logger *logrus.Entry, sourcesRecorder controller.Sources
if gotDispatchers == false {
logger.Debug("No dispatchers found")
return
} else {
dispatchersMessage, dispatchersMarshalled := json.Marshal(dispatchers)
if dispatchersMarshalled == nil {
logger.Debugf("Dispatchers found: %s", dispatchersMessage)
}
Comment on lines +221 to +225
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 this might be a little easier to read if we take this out of the if/else statement.

Let's add dispatchers as a logging field like this:

logger = logger.WithFields(logrus.Fields{"dispatchers": dispatchers})

How does the log message look if we do not marshal the dispatchers field and just log it as a field?

Copy link
Member Author

Choose a reason for hiding this comment

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

It works, but it's not pretty. Running TestProcessDispatchers(), this is marshalled:

time="2024-11-08T09:53:31-05:00" level=debug msg="Dispatchers found: {\"catalog\":{\"ApplicationType\":\"ima_app_type\",\"SourceRef\":\"ima_source_ref\",\"SrcName\":\"ima_source_name\",\"SrcType\":\"ima_source_type\"}}" func=github.com/RedHatInsights/cloud-connector/internal/cloud_connector.processDispatchers file="/home/jrodri/develop/cloud-connector/internal/cloud_connector/message_handlers.go:224" account=12345 client_id=98765 org_id=54321

And this is with the logging field:

time="2024-11-08T09:53:31-05:00" level=debug msg="dispatchers found:" func=github.com/RedHatInsights/cloud-connector/internal/cloud_connector.processDispatchers file="/home/jrodri/develop/cloud-connector/internal/cloud_connector/message_handlers.go:226" account=12345 client_id=98765 dispatchers="map[catalog:map[ApplicationType:ima_app_type SourceRef:ima_source_ref SrcName:ima_source_name SrcType:ima_source_type]]" org_id=54321

}

dispatchersMap := dispatchers.(map[string]interface{})
Expand Down
Loading