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

Allow passing logger into k8s controller | improve logs structure #35

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

taimoorgit
Copy link
Contributor

Issues

https://github.com/OpsLevel/team-platform/issues/214

Changelog

  • Add log as a controller property that can be passed by dependents on instantiation
  • Make log structuring a little better
  • Make a changie entry

Tophatting

@taimoorgit taimoorgit self-assigned this Mar 9, 2024
@@ -42,25 +44,27 @@ type K8SEvent struct {
}

func (c *K8SController) mainloop(item interface{}) {
log.Debug().Str("queue_addr", fmt.Sprintf("%p", &c.queue)).Int("queue_len", c.queue.Len()).Msg("mainloop: running from top")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

queue_addr is not really useful since it's ephemeral, I added this a while ago when I was debugging and learning about the repo.

@@ -42,25 +44,27 @@ type K8SEvent struct {
}

func (c *K8SController) mainloop(item interface{}) {
log.Debug().Str("queue_addr", fmt.Sprintf("%p", &c.queue)).Int("queue_len", c.queue.Len()).Msg("mainloop: running from top")
log := c.log.With().Str("where", "mainloop").Int("queue_len", c.queue.Len()).Logger()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Create a local logger here with info that's relevant to the scope of the function.

return
}
event := item.(K8SEvent)
log = log.With().Str("k8s_event_key", event.Key).Str("k8s_event_type", string(event.Type)).Logger()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

updates scope for the rest of the function here

if !ready {
runtime.HandleError(fmt.Errorf("[%s] Timed out waiting for caches to sync", c.id))
return
}
log.Info().Msgf("[%s] Informer is ready and synced", c.id)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not really info worthy, lowered this to debug.

- golangci-lint run
- nilaway -test=false -include-pkgs='github.com/opslevel/opslevel-k8s-controller' ./...
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed nilaway was missing, so I added it in. no changes are required 👍

@taimoorgit taimoorgit marked this pull request as draft March 11, 2024 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant