Skip to content

Conversation

Molter73
Copy link
Collaborator

@Molter73 Molter73 commented Apr 7, 2025

Description

This is a small PR to prevent protobuf message serialization on the stdout clients when log level would discard the result.

This changed was triggered by this comment: #2063 (comment)

Checklist

  • Investigated and inspected CI test results
  • Updated documentation accordingly

Automated testing

  • Added unit tests
  • Added integration tests
  • Added regression tests

If any of these don't apply, please comment below.

Testing Performed

Was not able to test this locally, help would be appreciated.

@Molter73 Molter73 requested a review from a team as a code owner April 7, 2025 09:29
@codecov-commenter
Copy link

codecov-commenter commented Apr 7, 2025

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 27.50%. Comparing base (4de6015) to head (f517932).

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
collector/lib/Utility.cpp 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2077      +/-   ##
==========================================
- Coverage   27.51%   27.50%   -0.01%     
==========================================
  Files          93       93              
  Lines        5728     5730       +2     
  Branches     2534     2535       +1     
==========================================
  Hits         1576     1576              
- Misses       3485     3487       +2     
  Partials      667      667              
Flag Coverage Δ
collector-unit-tests 27.50% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JoukoVirtanen
Copy link
Contributor

Did the following testing. Applied the following diff

diff --git a/collector/lib/NetworkStatusNotifier.cpp b/collector/lib/NetworkStatusNotifier.cpp
index 27efaa6ad..5abe8e046 100644
--- a/collector/lib/NetworkStatusNotifier.cpp
+++ b/collector/lib/NetworkStatusNotifier.cpp
@@ -342,6 +342,7 @@ void NetworkStatusNotifier::AddConnections(::google::protobuf::RepeatedPtrField<
 
     added_events++;
     updates->AddAllocated(conn_proto);
+    LogProtobufMessage(*conn_proto);
   }
 
   for (const auto& [id, events] : rate_limited_containers) {
diff --git a/collector/lib/Utility.cpp b/collector/lib/Utility.cpp
index 92f0a0b03..10e017df2 100644
--- a/collector/lib/Utility.cpp
+++ b/collector/lib/Utility.cpp
@@ -255,7 +255,9 @@ std::optional<std::string> SanitizedUTF8(std::string_view str) {
 void LogProtobufMessage(const google::protobuf::Message& msg) {
   using namespace google::protobuf::util;
 
+  CLOG(INFO) << "In LogProtobufMessage";
   if (!logging::CheckLogLevel(logging::LogLevel::DEBUG)) {
+    CLOG(INFO) << "Leaving early";
     return;
   }

Built collector and ran an integration test

make -C integration-tests TestRuntimeConfigFile

It doesn't matter which one is run. Checked the collector logs

[INFO    2025/04/09 23:03:40] (Utility.cpp:258) In LogProtobufMessage
[DEBUG   2025/04/09 23:03:40] (Utility.cpp:267) GRPC: {"remoteAddress":{"port":53,"ipNetwork":"CAgICCA="},"protocol":"L4_PROTOCOL_TCP","role":"ROLE_CLIENT","containerId":"63f007f892f5"}

When running with log level set to info

COLLECTOR_LOG_LEVEL=info make -C integration-tests TestRuntimeConfigFile
[INFO    2025/04/09 23:20:43] In LogProtobufMessage
[INFO    2025/04/09 23:20:43] Leaving early

Copy link
Contributor

@JoukoVirtanen JoukoVirtanen left a comment

Choose a reason for hiding this comment

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

LGTM!

@Molter73 Molter73 merged commit feaaf30 into master Apr 10, 2025
75 of 78 checks passed
@Molter73 Molter73 deleted the mauro/add-check-logprotobufmessage branch April 10, 2025 08:20
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.

3 participants