Cherry-pick #25771 to 7.x: First refactor of the system module - system/cpu and system/core#26359
Merged
fearful-symmetry merged 1 commit intoelastic:7.xfrom Jun 21, 2021
Conversation
…stic#25771) * initial commit * finux linux refactor * fix up freebsd * port main metricset, start openbsd * start work on openbsd vagrantfile * refactors of API, add darwin support * fix darwin implementation * refactor API, move tests, remove old code, take a crack at AIX * fix aix init func * fix tests * regenerate core data.json * small fixes, fix host field * update tests * run correct mage commands * try to fix system tests * more fixes for windows python tests * refactor CPU struct, use reflection * refactor reflection code, add validation * move metrics to its own internal folder * move directories, again * move directories, again * use optional Uint type * cleanup opt files * move around naming of opt types * fix up if block * change opt names * move around opt methods, cpu stat reader refactor * fix IsZero usage * add changelog (cherry picked from commit 2871d29)
Contributor
|
Pinging @elastic/integrations (Team:Integrations) |
Contributor
💚 Build Succeeded
Expand to view the summary
Build stats
Test stats 🧪
Trends 🧪💚 Flaky test reportTests succeeded. Expand to view the summary
Test stats 🧪
|
Contributor
Author
|
/test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry-pick of PR #25771 to 7.x branch. Original message:
What does this PR do?
This is part of a long-discussed refactor of the system module focused on preparing the system module for fleet GA. This is just
system/cpuandsystem/core, and by starting off the refactor with just two metricsets, I'm hoping to get feedback on the new structure of the system integration, as the design of a separatemetricslibrary, with different implementation around wrapper functions, will be a template for the refactor going forward. This design is based on the go standard library, which takes a similar approach to implementing OS-specific APIs. seeos/file*.gofor an example of this.As this change is entirely backwards compatible, we don't need any special logic to determine if we're running on fleet or metricbeat. That will probably become an issue in future PRs, where we'll want wrappers to prevent us from changing field names or metricset locations in metricbeat.
Right now, the only part of
gosigarthat remains issys/windows, which I'd like feedback from @narph on. Most of this library is autogenerated bygo generate, so I'm not sure it makes sense to "break it up" by metricset, as it just makes more work if we have to update it in the future. Do we want to to move this library intolibbeatormetricbeat/module/system, or should we spit apart and re-generate the code based on what API calls are used by what metricset?I'm also fairly ambivalent about the public API here. The design of
Percentages(*common.MapStr)is mostly a matter of convenience for the conditional logic that fills in the event MapStr, and returning separate MapStr objects would require us to just do a deep merge later. Still, I'm open to other ideas, if someone has them.EDIT: I'm still thinking of "less ugly" ways of dealing with OS-specific data, as opposed to just returning an opaque
MapStr. I wonder if we can add OS fields to the tag structs, and then implement aMapStrunmarshaller that filters the values based on the OS. For example:Why is it important?
This refactor has a few goals in mind:
libbeat/metric/andgosigarthat was unused outside outside of the system module has been moved into the newcpu/metricslibrary.Option<T>type we can put on struct fields or anything, so the next best thing are hashmaps, which aren't perfect. We've worked around this in the past by developing a mess ofif runtime.GOOS == ...logic, which isn't particularly pretty.metrics_PLATFORM.gois the only component that needs to worry about what is compatible with what, and logic that cares about OS-specific metrics remains in one place.gosigar. Large portions of this library are exclusively used by the system module., and most other beats components usego-sysinfoinstead.Checklist
CHANGELOG.next.asciidocorCHANGELOG-developer.next.asciidoc.Author's Checklist
gosigar/sys/windowsmetricsup the library, as it's used by two metricsets.How to test this PR locally
metricbeat, and run thesystem/cpuandsystem/coremetricsets to make sure we're generating data correctly.freebsdandopenbsdboxes have been updated, and should work without much further tinkering.