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

Use the new collector internal service for process information #2063

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

Molter73
Copy link
Collaborator

@Molter73 Molter73 commented Mar 18, 2025

Description

This PR makes it so collector starts using the new unified internal service for communicating with sensor. For now the implementation only handles process information, but lays the groundwork to also move network flows into this new internal service.

In order to better abstract how we forward messages, a new CollectorOutput class has been added. The responsibility for this class is to hold all gRPC clients that we might need for sending messages to collector, both through the new internal service and the legacy ones, as well as ensuring the connection between sensor and collector is up. This change means the responsibility for the ProcessSignalClient class has been reduced to simply sending the message through the grpc client it holds. A new client has also been added for the new service.

Alongside this new CollectorOutput class, a new formatter has been added to generate messages that will be sent through the new service and the existing process signal handler has been modified to start using it.

Sibling PR stackrox/stackrox#14652

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

Manually tested the changes and modified the existing integration tests to use the new service.

@codecov-commenter
Copy link

codecov-commenter commented Mar 18, 2025

Codecov Report

Attention: Patch coverage is 15.38462% with 341 lines in your changes missing coverage. Please review.

Project coverage is 26.94%. Comparing base (827fd6e) to head (a30992b).

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
collector/lib/SensorClientFormatter.cpp 17.89% 112 Missing and 44 partials ⚠️
collector/lib/CollectorOutput.cpp 18.29% 62 Missing and 5 partials ⚠️
collector/lib/ProcessSignalHandler.cpp 0.00% 51 Missing ⚠️
collector/lib/SensorClient.cpp 0.00% 29 Missing ⚠️
collector/lib/SensorClient.h 16.66% 10 Missing ⚠️
collector/lib/ProcessSignalFormatter.cpp 40.00% 5 Missing and 1 partial ⚠️
collector/lib/CollectorOutput.h 54.54% 2 Missing and 3 partials ⚠️
collector/lib/SignalServiceClient.h 16.66% 5 Missing ⚠️
collector/lib/ProcessSignalHandler.h 0.00% 3 Missing ⚠️
collector/lib/CollectorConfig.cpp 0.00% 2 Missing ⚠️
... and 4 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2063      +/-   ##
==========================================
- Coverage   27.49%   26.94%   -0.56%     
==========================================
  Files          93       98       +5     
  Lines        5731     6064     +333     
  Branches     2538     2708     +170     
==========================================
+ Hits         1576     1634      +58     
- Misses       3488     3711     +223     
- Partials      667      719      +52     
Flag Coverage Δ
collector-unit-tests 26.94% <15.38%> (-0.56%) ⬇️

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.

@Molter73 Molter73 force-pushed the mauro/ROX-28526-use-collector-iservice branch from 5770ec0 to a2d44bc Compare March 24, 2025 16:48
@Molter73 Molter73 changed the base branch from master to mauro/collector-service-use-raii March 24, 2025 16:48
@Molter73 Molter73 force-pushed the mauro/ROX-28526-use-collector-iservice branch from 4a61b27 to 3ce1606 Compare March 26, 2025 14:22
@Molter73 Molter73 force-pushed the mauro/collector-service-use-raii branch from 1c58c3c to 98ff9f9 Compare March 26, 2025 15:09
@Molter73 Molter73 force-pushed the mauro/ROX-28526-use-collector-iservice branch 5 times, most recently from 6c65509 to a39570d Compare March 28, 2025 17:08
Base automatically changed from mauro/collector-service-use-raii to master March 31, 2025 08:49
@Molter73 Molter73 force-pushed the mauro/ROX-28526-use-collector-iservice branch from a39570d to 45d33bc Compare March 31, 2025 09:19
@Molter73
Copy link
Collaborator Author

/retest

@Molter73 Molter73 force-pushed the mauro/ROX-28526-use-collector-iservice branch from 9a78993 to 10b071b Compare March 31, 2025 15:14
@Molter73 Molter73 changed the title [WIP] Use the new collector internal service Use the new collector internal service for process information Apr 1, 2025
@Molter73 Molter73 marked this pull request as ready for review April 1, 2025 16:40
@Molter73 Molter73 requested a review from a team as a code owner April 1, 2025 16:40
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This file is essentially a copy of ProcessSignalFormatter.cpp, but building a sensor::MsgFromCollector instead of a storage::ProcessSignal.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This file is essentially a copy of ProcessSignalFormatter.h, but building a sensor::MsgFromCollector instead of a storage::ProcessSignal.

@Molter73 Molter73 requested a review from Stringy April 4, 2025 11:01

if (first_write_ && msg.has_process_signal()) {
first_write_ = false;
return SignalHandler::NEEDS_REFRESH;
Copy link
Contributor

@JoukoVirtanen JoukoVirtanen Apr 6, 2025

Choose a reason for hiding this comment

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

It seems that SignalHandler::NEEDS_REFRESH is returned when first_write_ is true and that is the case only after Refresh has been called. So, SignalHandler::NEEDS_REFRESH is returned after a refresh has been done and returning SignalHandler::NEEDS_REFRESH does not result in a refresh, as the name implies. It does result in SendMsg being called again. In which case first_write_ will be true and this will be skipped and the message will be sent the second time. I don't understand what returning here instead of sending the message the first time accomplishes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is poor naming conventions on my part. NEEDS_REFRESH is used when the process stream has just started and it causes collector to send all processes that are stored in the threadinfo table, at startup this sends all scraped processes, while running it will ensure any processes that were not sent as part of a disconnect to be sent on reconnection.

I probably need to come up with a better term than Refresh for the method called after grpc is reconnected. I'll think it over and rename the method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've renamed the Refresh method to Recreate, hopefully that makes it less ambiguous.

@Molter73 Molter73 force-pushed the mauro/ROX-28526-use-collector-iservice branch from 0ce72d6 to a30992b Compare April 7, 2025 14:09
@Molter73 Molter73 requested a review from JoukoVirtanen April 7, 2025 14:10
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.

4 participants