Skip to content

Use the new collector internal service for process information #2063

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

Open
wants to merge 14 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

Deployed this version of collector with the sensor version from stackrox/stackrox#14652 and checked process information is still available in the Risk tab.
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.88089% with 339 lines in your changes missing coverage. Please review.

Project coverage is 27.73%. Comparing base (215e5d4) to head (81a7b0c).

✅ 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/CollectorConfig.cpp 0.00% 2 Missing ⚠️
collector/lib/CollectorConfig.h 0.00% 2 Missing ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2063      +/-   ##
==========================================
- Coverage   28.40%   27.73%   -0.68%     
==========================================
  Files          94       99       +5     
  Lines        5717     6050     +333     
  Branches     2531     2701     +170     
==========================================
+ Hits         1624     1678      +54     
- Misses       3383     3611     +228     
- Partials      710      761      +51     
Flag Coverage Δ
collector-unit-tests 27.73% <15.88%> (-0.68%) ⬇️

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
@JoukoVirtanen
Copy link
Contributor

JoukoVirtanen commented Apr 11, 2025

This needs more explanation of how you validated your change. You should mention your stackrox/stackrox PR and how that passing CI validates the changes here. Since you are requiring that this works with old versions of sensor, you should also validate that. You could create a stackrox/stackrox PR that just updates the collector version and sets the environment variable that you introduced for the qa e2e tests. Having those tests pass should be enough.

Other than that, this looks good.

@Molter73 Molter73 force-pushed the mauro/ROX-28526-use-collector-iservice branch from a30992b to ddfe9e2 Compare April 14, 2025 14:34
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 mentioned this pull request Apr 15, 2025
5 tasks
@Molter73 Molter73 force-pushed the mauro/ROX-28526-use-collector-iservice branch 2 times, most recently from 9a81385 to 785dffb Compare April 23, 2025 15:20
@Molter73 Molter73 force-pushed the mauro/ROX-28526-use-collector-iservice branch from 785dffb to 81a7b0c Compare April 23, 2025 16:33
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