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

Fix bug in filtering, cleanup #31595

Merged
merged 3 commits into from
May 12, 2022

Conversation

fearful-symmetry
Copy link
Contributor

What does this PR do?

This PR fixes a bug results in the top_n filtering options not being applied in system/process, as well as refactors a bunch of components to make the new linter happy.

Why is it important?

This is an actual bug.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

How to test this PR locally

Pull down and build, make sure the include_top_n flags work in metricbeat.

@fearful-symmetry fearful-symmetry added bug Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team backport-v8.2.0 Automated backport with mergify labels May 11, 2022
@fearful-symmetry fearful-symmetry requested a review from a team as a code owner May 11, 2022 18:05
@fearful-symmetry fearful-symmetry self-assigned this May 11, 2022
@fearful-symmetry fearful-symmetry requested review from cmacknz and faec and removed request for a team May 11, 2022 18:05
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels May 11, 2022
totalCPUDeltaMillis := int64(s1.CPU.Total.Ticks.ValueOr(0) - s0.CPU.Total.Ticks.ValueOr(0))

pct := float64(totalCPUDeltaMillis) / float64(timeDeltaMillis)
// In theory this can only happen if the time delta is 0, which is unlikely but possible.
if timeDeltaMillis == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

You are doing this comparison against a float now, which leaves it open to floating point precisions issues comparing against an exact value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good point.

}
// We use this to track processes over time.
procStats.ProcsMap = pidMap

// filter the process list that will be passed down to users
procStats.includeTopProcesses(plist)
plist = procStats.includeTopProcesses(plist)
Copy link
Member

Choose a reason for hiding this comment

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

Is this the primary bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup.

t.Logf("Proc: %s", procData[0].StringToPrint())
}

func TestFilter(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

This was the missing test from the looks of things?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yah, added that.

@elasticmachine
Copy link
Collaborator

elasticmachine commented May 11, 2022

❕ Build Aborted

There is a new build on-going so the previous on-going builds have been aborted.

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Start Time: 2022-05-11T18:55:19.757+0000

  • Duration: 362 min 29 sec

Test stats 🧪

Test Results
Failed 0
Passed 17084
Skipped 1282
Total 18366

Steps errors 2

Expand to view the steps failures

Checks if running on a Unix-like node
  • Took 0 min 0 sec . View more details here
Error signal
  • Took 0 min 0 sec . View more details here
  • Description: untar: step failed with error null

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@fearful-symmetry
Copy link
Contributor Author

@kvch have we solved the "typecheck failing on stuff that has cgo" issue yet?

@fearful-symmetry
Copy link
Contributor Author

After talking with @kvch, I'm going to merge this without the linters passing, as we don't really care about them here, and the rest of the tests are passing. Tested this myself with a full build of metricbeat.

@fearful-symmetry fearful-symmetry merged commit 2a6624d into elastic:main May 12, 2022
mergify bot pushed a commit that referenced this pull request May 12, 2022
* fix bug in filtering, cleanup

* continuing to make linter happy

* deal with platform-specific code issues

(cherry picked from commit 2a6624d)

# Conflicts:
#	libbeat/metric/system/process/process.go
#	libbeat/metric/system/process/process_darwin.go
#	libbeat/metric/system/process/process_linux_common.go
kvch added a commit to kvch/elastic-agent-system-metrics that referenced this pull request May 16, 2022
fearful-symmetry added a commit that referenced this pull request May 17, 2022
* Fix bug in filtering, cleanup (#31595)

* fix bug in filtering, cleanup

* continuing to make linter happy

* deal with platform-specific code issues

(cherry picked from commit 2a6624d)

# Conflicts:
#	libbeat/metric/system/process/process.go
#	libbeat/metric/system/process/process_darwin.go
#	libbeat/metric/system/process/process_linux_common.go

* fix cherry-pick

* format again

Co-authored-by: Alex K <8418476+fearful-symmetry@users.noreply.github.com>
Co-authored-by: Alex Kristiansen <alex.kristiansen@elastic.co>
kvch added a commit to elastic/elastic-agent-system-metrics that referenced this pull request May 17, 2022
chrisberkhout pushed a commit that referenced this pull request Jun 1, 2023
* fix bug in filtering, cleanup

* continuing to make linter happy

* deal with platform-specific code issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.2.0 Automated backport with mergify bug Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants