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

Conversation

jessicarod7
Copy link
Member

What?

https://issues.redhat.com/browse/RHCLOUD-30651

Why?

Dispatcher entries can be pulled directly from debug log messages for alternative parsing and application.

How?

The dispatcher map is marshalled to JSON and printed.

Testing

Tested with TestProcessDispatchers(). Example output:

=== RUN   TestProcessDispatchers
time="2024-10-31T12:26:30-04: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
--- PASS: TestProcessDispatchers (0.00s)
PASS

Secure Coding Practices Checklist Link

Secure Coding Checklist

  • Input Validation
  • Output Encoding
  • Authentication and Password Management
  • Session Management
  • Access Control
  • Cryptographic Practices
  • Error Handling and Logging
  • Data Protection
  • Communication Security
  • System Configuration
  • Database Security
  • File Management
  • Memory Management
  • General Coding Practices

Copy link
Contributor

@dehort dehort left a comment

Choose a reason for hiding this comment

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

Looking good. I left a comment.

Comment on lines +221 to +225
} else {
dispatchersMessage, dispatchersMarshalled := json.Marshal(dispatchers)
if dispatchersMarshalled == nil {
logger.Debugf("Dispatchers found: %s", dispatchersMessage)
}
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants