Skip to content

Conversation

learnitall
Copy link
Contributor

This commit modifies identified hot paths that contain the use of logrus' WithFields function, to add extra conditions to only call this expensive function as necessary. The most common case was a scoped logger created using WithFields that is only used to emit debug messages.

These hot paths were identified using profiles taken from cilium agents in a 100 node ClusterLoader2 scale test. For example, the function pkg/endpoint.(*Endpoint).removeDirectory had a wasted call to WithFields which accounted for 1.5% of overall memory allocations and 0.13% of overall CPU time, as it is called during endpoint regeneration.

I believe this needs the following labels:

  • release-note/misc
  • kind/bug

@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Jun 16, 2023
@sayboras sayboras added kind/bug This is a bug in the Cilium logic. kind/performance There is a performance impact of this. release-note/minor This PR changes functionality that users may find relevant to operating Cilium. labels Jun 22, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot removed dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. labels Jun 22, 2023
@learnitall learnitall force-pushed the pr/learnitall/logrus-debug-fields-fixes branch from c5a765b to 4085aa0 Compare June 23, 2023 16:37
@learnitall learnitall marked this pull request as ready for review June 23, 2023 16:37
@learnitall learnitall requested review from a team as code owners June 23, 2023 16:37
@christarazi christarazi added release-note/misc This PR makes changes that have no direct user impact. and removed release-note/minor This PR changes functionality that users may find relevant to operating Cilium. labels Jun 25, 2023
@christarazi
Copy link
Member

(Accidentally submitted review too soon...but below is what I was going to say)

The change looks good to me. I wonder how we can prevent the need to do PRs like these in the future. At some point I'd imagine we'll have some performance testing, but that might be too late in the feedback cycle to inform whether new debug logs caused a performance impact. Food for thought I guess :).

@learnitall
Copy link
Contributor Author

learnitall commented Jun 26, 2023

Definitely food for thought. Ideally, this will be a one-time PR for these changes. For 1.15, I am going to work on a CFP to explore some options to address the overhead we see here.

Copy link
Member

@ysksuzuki ysksuzuki left a comment

Choose a reason for hiding this comment

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

The changes look good to me. (The conflicts need to be resolved though)

Can I see the pprof result somewhere that indicates these paths which call logrus' WithFields function are expensive?

@learnitall
Copy link
Contributor Author

I haven't found a great way to share the flamegraphs yet, as go's pprof tool doesn't have a method for generating svg flamegraphs. I've attached tarballs of the CPU, Heap and Alloc

profiles that were taken during the course of the 100 node test. After extracting each, you can run:

go tool pprof -http :8080 *(CPU, Heap or Alloc)*

To view CPU, Heap or Alloc flamegraphs respectively.

alloc.tar.gz
cpu.tar.gz
heap.tar.gz

@learnitall learnitall force-pushed the pr/learnitall/logrus-debug-fields-fixes branch from 4085aa0 to eca0075 Compare June 27, 2023 21:40
@learnitall learnitall force-pushed the pr/learnitall/logrus-debug-fields-fixes branch from eca0075 to 6d0e6b7 Compare July 25, 2023 14:06
@learnitall
Copy link
Contributor Author

/test

@learnitall learnitall self-assigned this Jul 25, 2023
@learnitall learnitall force-pushed the pr/learnitall/logrus-debug-fields-fixes branch from 6d0e6b7 to 39dccd5 Compare July 27, 2023 15:32
@learnitall learnitall force-pushed the pr/learnitall/logrus-debug-fields-fixes branch from 39dccd5 to a34b7c2 Compare August 4, 2023 15:11
This commit modifies identified hot paths that contain the use of
logrus' WithFields function, to add extra conditions to only call this
expensive function as necessary. The most common case was a scoped
logger created using WithFields that is only used to emit debug
messages.

These hot paths were identified using profiles taken from cilium
agents in a 100 node ClusterLoader2 scale test. For example, the
function `pkg/endpoint.(*Endpoint).removeDirectory` had a wasted call
to WithFields which accounted for 1.5% of overall memory allocations
and 0.13% of overall CPU time, as it is called during endpoint
regeneration.

Signed-off-by: Ryan Drew <ryan.drew@isovalent.com>
@learnitall learnitall force-pushed the pr/learnitall/logrus-debug-fields-fixes branch from a34b7c2 to 8a96d7b Compare August 4, 2023 16:30
@learnitall
Copy link
Contributor Author

/test

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Aug 7, 2023
@ldelossa ldelossa merged commit 52c06e1 into cilium:main Aug 7, 2023
antonipp pushed a commit to DataDog/cilium that referenced this pull request Dec 7, 2023
[ upstream commit 00ab252 ]

[ Backporter's notes: ignoring changes from cilium#26327 and cilium#23971 ]

The DefaultLogger variable in the logging module serves as a parent logger
which all other loggers can be derived from. It is initialized using the
InitializeDefaultLogger function and then adjusted on startup based on
user configuration. Users should not call InitializeDefaultLogger to
create a parent logger for their logger, since the logger returned by
InitializeDefaultLogger will always use the hardcoded defaults. For
example, the logger returned will always be of level INFO, even if a user
has enabled debug logging. To make this clear, this commit renames
InitializeDefaultLogger to initializeDefaultLogger to signal that it should
not be used outside of the logging module.

Fixes: cilium#29215

Signed-off-by: Ryan Drew <ryan.drew@isovalent.com>
Signed-off-by: Anton Ippolitov <anton.ippolitov@datadoghq.com>
antonipp pushed a commit to DataDog/cilium that referenced this pull request Dec 7, 2023
[ upstream commit 00ab252 ]

[ Backporter's notes: ignoring changes from cilium#26327 and cilium#23971 ]

The DefaultLogger variable in the logging module serves as a parent logger
which all other loggers can be derived from. It is initialized using the
InitializeDefaultLogger function and then adjusted on startup based on
user configuration. Users should not call InitializeDefaultLogger to
create a parent logger for their logger, since the logger returned by
InitializeDefaultLogger will always use the hardcoded defaults. For
example, the logger returned will always be of level INFO, even if a user
has enabled debug logging. To make this clear, this commit renames
InitializeDefaultLogger to initializeDefaultLogger to signal that it should
not be used outside of the logging module.

Fixes: cilium#29215

Signed-off-by: Ryan Drew <ryan.drew@isovalent.com>
Signed-off-by: Anton Ippolitov <anton.ippolitov@datadoghq.com>
antonipp pushed a commit to DataDog/cilium that referenced this pull request Dec 7, 2023
[ upstream commit 00ab252 ]

[ Backporter's notes: ignoring changes from cilium#26327 and cilium#23971 ]

The DefaultLogger variable in the logging module serves as a parent logger
which all other loggers can be derived from. It is initialized using the
InitializeDefaultLogger function and then adjusted on startup based on
user configuration. Users should not call InitializeDefaultLogger to
create a parent logger for their logger, since the logger returned by
InitializeDefaultLogger will always use the hardcoded defaults. For
example, the logger returned will always be of level INFO, even if a user
has enabled debug logging. To make this clear, this commit renames
InitializeDefaultLogger to initializeDefaultLogger to signal that it should
not be used outside of the logging module.

Fixes: cilium#29215

Signed-off-by: Ryan Drew <ryan.drew@isovalent.com>
Signed-off-by: Anton Ippolitov <anton.ippolitov@datadoghq.com>
tklauser pushed a commit that referenced this pull request Dec 8, 2023
[ upstream commit 00ab252 ]

[ Backporter's notes: ignoring changes from #26327 and #23971 ]

The DefaultLogger variable in the logging module serves as a parent logger
which all other loggers can be derived from. It is initialized using the
InitializeDefaultLogger function and then adjusted on startup based on
user configuration. Users should not call InitializeDefaultLogger to
create a parent logger for their logger, since the logger returned by
InitializeDefaultLogger will always use the hardcoded defaults. For
example, the logger returned will always be of level INFO, even if a user
has enabled debug logging. To make this clear, this commit renames
InitializeDefaultLogger to initializeDefaultLogger to signal that it should
not be used outside of the logging module.

Fixes: #29215

Signed-off-by: Ryan Drew <ryan.drew@isovalent.com>
Signed-off-by: Anton Ippolitov <anton.ippolitov@datadoghq.com>
antonipp pushed a commit to DataDog/cilium that referenced this pull request Dec 8, 2023
[ upstream commit 00ab252 ]

[ Backporter's notes: ignoring changes from cilium#26327 and cilium#23971 ]

The DefaultLogger variable in the logging module serves as a parent logger
which all other loggers can be derived from. It is initialized using the
InitializeDefaultLogger function and then adjusted on startup based on
user configuration. Users should not call InitializeDefaultLogger to
create a parent logger for their logger, since the logger returned by
InitializeDefaultLogger will always use the hardcoded defaults. For
example, the logger returned will always be of level INFO, even if a user
has enabled debug logging. To make this clear, this commit renames
InitializeDefaultLogger to initializeDefaultLogger to signal that it should
not be used outside of the logging module.

Fixes: cilium#29215

Signed-off-by: Ryan Drew <ryan.drew@isovalent.com>
Signed-off-by: Anton Ippolitov <anton.ippolitov@datadoghq.com>
learnitall added a commit to learnitall/cilium that referenced this pull request Dec 12, 2023
[ upstream commit 00ab252 ]

[ Backporter's notes: ignoring changes from cilium#26327 ]

The DefaultLogger variable in the logging module serves as a parent logger
which all other loggers can be derived from. It is initialized using the
InitializeDefaultLogger function and then adjusted on startup based on
user configuration. Users should not call InitializeDefaultLogger to
create a parent logger for their logger, since the logger returned by
InitializeDefaultLogger will always use the hardcoded defaults. For
example, the logger returned will always be of level INFO, even if a user
has enabled debug logging. To make this clear, this commit renames
InitializeDefaultLogger to initializeDefaultLogger to signal that it should
not be used outside of the logging module.

Fixes: cilium#29215

Signed-off-by: Ryan Drew <ryan.drew@isovalent.com>
learnitall added a commit to learnitall/cilium that referenced this pull request Dec 12, 2023
[ upstream commit 00ab252 ]

[ Backporter's notes: ignoring changes from cilium#26327 ]

The DefaultLogger variable in the logging module serves as a parent logger
which all other loggers can be derived from. It is initialized using the
InitializeDefaultLogger function and then adjusted on startup based on
user configuration. Users should not call InitializeDefaultLogger to
create a parent logger for their logger, since the logger returned by
InitializeDefaultLogger will always use the hardcoded defaults. For
example, the logger returned will always be of level INFO, even if a user
has enabled debug logging. To make this clear, this commit renames
InitializeDefaultLogger to initializeDefaultLogger to signal that it should
not be used outside of the logging module.

Fixes: cilium#29215

Signed-off-by: Ryan Drew <ryan.drew@isovalent.com>
ldelossa pushed a commit that referenced this pull request Dec 15, 2023
[ upstream commit 00ab252 ]

[ Backporter's notes: ignoring changes from #26327 ]

The DefaultLogger variable in the logging module serves as a parent logger
which all other loggers can be derived from. It is initialized using the
InitializeDefaultLogger function and then adjusted on startup based on
user configuration. Users should not call InitializeDefaultLogger to
create a parent logger for their logger, since the logger returned by
InitializeDefaultLogger will always use the hardcoded defaults. For
example, the logger returned will always be of level INFO, even if a user
has enabled debug logging. To make this clear, this commit renames
InitializeDefaultLogger to initializeDefaultLogger to signal that it should
not be used outside of the logging module.

Fixes: #29215

Signed-off-by: Ryan Drew <ryan.drew@isovalent.com>
pchaigno pushed a commit that referenced this pull request Jan 8, 2024
[ upstream commit 00ab252 ]

[ Backporter's notes: ignoring changes from #26327 and #23971 ]

The DefaultLogger variable in the logging module serves as a parent logger
which all other loggers can be derived from. It is initialized using the
InitializeDefaultLogger function and then adjusted on startup based on
user configuration. Users should not call InitializeDefaultLogger to
create a parent logger for their logger, since the logger returned by
InitializeDefaultLogger will always use the hardcoded defaults. For
example, the logger returned will always be of level INFO, even if a user
has enabled debug logging. To make this clear, this commit renames
InitializeDefaultLogger to initializeDefaultLogger to signal that it should
not be used outside of the logging module.

Fixes: #29215

Signed-off-by: Ryan Drew <ryan.drew@isovalent.com>
Signed-off-by: Anton Ippolitov <anton.ippolitov@datadoghq.com>
Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug This is a bug in the Cilium logic. kind/performance There is a performance impact of this. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants