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

ROX-19898: refactor collector configuration in tests #1348

Merged
merged 2 commits into from
Oct 5, 2023

Conversation

Stringy
Copy link
Collaborator

@Stringy Stringy commented Sep 29, 2023

Description

To avoid having to provide (1) a hard-coded json string and (2) duplicated default options across all tests, this PR introduces CollectorStartupOptions structure which allows tests to set specific options/environment variables/mount points before starting collector. The collector manager itself is responsible for serializing this information as necessary and tests only need to modify the options that they need to.

Options provided by a test always supersede those defined by default in the collector manager.

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

Tested and built locally against Garden Linux (of all things) CI will catch everything else. This should have no impact on the outcome of the tests.

@Stringy Stringy requested a review from a team as a code owner September 29, 2023 09:47
}

// isSelinuxPermissiveNeeded returns whether or not a given VM requires
// SELinux permissive mode. e.g. rhel, or fedora-coreos
func (s *IntegrationTestSuiteBase) isSelinuxPermissiveNeeded() bool {
vmType := config.VMInfo().Config
if strings.Contains(vmType, "coreos") || strings.Contains(vmType, "rhcos") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure how this change made it in, I think I hadn't pushed the base branch when I created this branch. I'll juggle commits at some point, or we can just merge this change as part of this PR (I don't think it strictly affects either of them)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's fine, we can merge it as part of this PR.

s.Collector().Env["ROX_ENABLE_AFTERGLOW"] = strconv.FormatBool(s.EnableAfterglow)
collectorOptions := common.CollectorStartupOptions{
Config: map[string]any{
"scrapeInterval": s.ScrapeInterval,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JoukoVirtanen is this correct? it seems in this test we're specifically setting a scrape interval, but always turn scraping off.

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 tested this locally and the test still passes with turnScrapeOff=false. I think this probably better represents what is intended in this test, but could do with some confirmation in case there is some nuance here that I'm missing

Copy link
Contributor

Choose a reason for hiding this comment

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

The scrapeInterval is also the reporting interval. Even if scrape is off the scrapeInterval will be used to determine when connections and endpoint are reported. It is a bit confusing and should be changed. In this case it shouldn't matter if scraping is done or not. In that case network connections will come from NetworkSignalHandler.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! I'll turn off scraping again and fix the conflicts and hopefully we can merge this today

@github-actions
Copy link

github-actions bot commented Sep 29, 2023

Kernel Method Without Collector Time (secs) With Collector Time (secs) Baseline median (secs) Collector median (secs) PValue
ubuntu-os.ubuntu-2004-lts ebpf 224.61 250.17 236.1 234.97 🟢

@Stringy Stringy changed the title ROX-14542: refactor collector configuration in tests ROX-19898: refactor collector configuration in tests Oct 2, 2023
Copy link
Collaborator

@Molter73 Molter73 left a comment

Choose a reason for hiding this comment

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

This is great! I think the new way of organizing configuration for collector is a lot cleaner to read and I love we are using proper JSON serialization (although I'd prefer we didn't have that JSON env variable, but that will be dealt with at some other point in time).

LGTM! But I'd still like to hear from @JoukoVirtanen on your comment.

Comment on lines +188 to +191
configJson, err := json.Marshal(c.config)
if err != nil {
return err
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd pay for go to implement something like the ? from rust so we could do configJson := json.Marshal(c.config)? and be done...

}

// isSelinuxPermissiveNeeded returns whether or not a given VM requires
// SELinux permissive mode. e.g. rhel, or fedora-coreos
func (s *IntegrationTestSuiteBase) isSelinuxPermissiveNeeded() bool {
vmType := config.VMInfo().Config
if strings.Contains(vmType, "coreos") || strings.Contains(vmType, "rhcos") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's fine, we can merge it as part of this PR.

Base automatically changed from giles/ROX-14542-no-more-boltdb to master October 2, 2023 15:57
@Stringy Stringy force-pushed the giles/ROX-14542-collector-config-refactor branch from cd2b715 to d94fa77 Compare October 3, 2023 08:06
@Stringy Stringy force-pushed the giles/ROX-14542-collector-config-refactor branch from d94fa77 to b8fc304 Compare October 4, 2023 14:15
@Stringy Stringy merged commit 7fcfdef into master Oct 5, 2023
43 checks passed
@Stringy Stringy deleted the giles/ROX-14542-collector-config-refactor branch October 5, 2023 06:36
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.

3 participants