OS description attribute detector#1840
Conversation
…OS resource attributes
…ription and related functions
…ilable file from a list of candidates
The function restoreProcessAttributesProviders was renamed to simply restoreAttributesProviders to better reflect its broader scope, which not only applies to process attribute's providers.
The suffix on os_linux.go was overriding the build tags already defined in that file. The file was renamed to os_release_unix.go, reflecting the main function defined in the file. For consistency, os_darwin.go was renamed to os_release_darwing.go, as its primary purpose is to also define the osRelease function.
Codecov Report
@@ Coverage Diff @@
## main #1840 +/- ##
=====================================
Coverage 72.7% 72.8%
=====================================
Files 164 166 +2
Lines 8081 8168 +87
=====================================
+ Hits 5878 5949 +71
- Misses 1974 1989 +15
- Partials 229 230 +1
|
c3609bb to
256e537
Compare
…ion-attribute-detector
|
I've added an Right now it doesn't include It seems that Makes sense? Good news is that as it's now, the project also compiles under these four |
| // properties of the os-release file. If no os-release file is found, or if the | ||
| // required properties to build the release description string are missing, an empty | ||
| // string is returned instead. For more information about os-release files, see: | ||
| // https://www.freedesktop.org/software/systemd/man/os-release.html |
There was a problem hiding this comment.
👍🏻 I love linked references!
There was a problem hiding this comment.
Glad you liked it!
| } | ||
|
|
||
| os.Remove(filename1) | ||
| os.Remove(filename2) |
There was a problem hiding this comment.
These files aren't removed if the test fails. I'm not sure what Go versions we intend to support in tests, but
- Go 1.14 has
t.Cleanup()which acts a bit likedefer. It will call something even if the test fails. - Go 1.15 has
t.TempDir()which is automatically cleaned up. - Go 1.16 has effectively deprecated the
ioutilpackage.
There was a problem hiding this comment.
I originally went with os.CreateTemp instead of ioutil.TempFile, but reverted back (725d90f) when the CI failed for Go < 1.16.
Go 1.14 was still listed on the project's README when I started to work on this, but it has been updated since then to reflect only the last two versions of Go as supported, so I guess it's safe to assume we can use t.TempDir().
I've updated the code based on your suggestion to use t.TempDir() here ea07b21, and realized I can use t.Cleanup() in a couple of other places (f94b783).
I will leave this thread open just in case a maintainer has something to comment on.
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // +build js plan9 |
There was a problem hiding this comment.
Should this be the opposite of the known/supported tags? Like, "not darwin and not linux and not windows…"
The question I suppose is what should happen for a new or unexpected GOOS? By filling this file with negations, a new GOOS will successfully build using this file. Supporting it would be a matter of including its tag in its implementation and adding the negation here.
There was a problem hiding this comment.
I see your point here. The negation approach will be more future-proof, guaranteeing that the project will always build.
Including all but Linux, macOS and Windows (!linux,!darwin,!windows) on the os_unsupported file will be the right way to demonstrate on which platforms we tested on, and thus are confident the resource works.
On the other hand, I wasn't sure to preclude the availability of a working OS description for *BSD in that way. Altought I haven't tested on such platforms, technically it should work.
Going with the current approach, in the wake of a new GOOS, it shouldn't be much of a hassle to include it either, but it can be more daunting for someone that is just learning about the project to face a compilation error at first try.
I think if we go for the "strict negation" strategy, the other _unix files should be stripped from all but the linux and darwin tags too.
There was a problem hiding this comment.
I don't mean to limit it to those three. I didn't want to type out everything in _unix in my question.
I don't have as strong opinion on what counts as "supported". Your choice to trust the sys/unix package makes sense to me.
There was a problem hiding this comment.
I don't mean to limit it to those three. I didn't want to type out everything in _unix in my question.
Oh, got it! Got confused for a sec because Linux, macOS and Windows are the platforms with a "compatibility guarantee" (as stated in the README) so I thought you were referring exclusively to them.
Pushed this change for others to also see the final form of this approach.
Co-authored-by: Chris Bandy <bandy.chris@gmail.com>
Co-authored-by: Chris Bandy <bandy.chris@gmail.com>
…ion-attribute-detector
For example, CI machine runs on: Windows Server 2019 Datacenter (1809) [Version 10.0.17763.1999] So, to not add an extra white space due to missing DisplayVersion, this value is checked to be not empty, and only in such case a trailing space is added for that component.
…ion-attribute-detector
…ion-attribute-detector
|
Hi! Just wanted to ask if we're OK to merge this one, or if it's preferred to postpone it after the v1.0.0 milestone. I'm good either way, will check periodically to keep it merge-ready. |
We discussed in the last SIG meeting that we would like to minimize new feature additions in RCs, but I also don't want to keep PRs that are ready to go from landing. These detectors are going to land, whether that's in 1.0.0-RC# or 1.0.1 shouldn't matter too much. I'll poll the SIG at today's meeting and see if we have consensus to land it. |
|
🎉 |
This is a follow up of #1788 that I had in the works.
It adds the following resource options functions:
WithOSDescription: detects and adds theos.descriptionattribute.WithOS: detects and adds bothos.typeandos.descriptionattributes.Although the examples in the spec only shows a short, high level description, I thought it would be useful to include a bit more detail.
As the purpose of this attribute is to provide human-readable information, I think there's room to add details when it makes sense, and no implementation (processor, observability backend, etc) should make assumptions on its format or amount of information included.
Example captures
Here are some captures showing how the OS description is displayed for different OSes.
Windows
Ubuntu (running natively on WSL2)
Alpine (container)
Debian (container)
macOS
Implementation details
A reference to
golang.org/x/syswas added to access platform specific syscalls and functions.The primary (and only) function consumed by the
osDescriptionDetectorisplatformOSDescription(). This function returns a(string, error)with the description of the OS.There are two definitions for this function: one for Unix-like OSes and other for Windows.
In the case of *NIX systems, the OS description is composed by two parts:
golang.org/x/syspackage, which hides differences for systems which doesn't have a properunamesyscall (like Darwin). This part of the OS description it's assumed to exist on all these systems. Implemented as anuname()Go function.os-releasefiles (only tested on some linux distros, but it seems FreeBSD follows the same convention), and a separate impementation for Darwin, which has the release information in a different file and format. This part of the OS description is optional, meaning that if errors are found building the OS release string, it's not included in the final OS description. Implemented as anosRelease()Go function.The implementation is distributed in the following files:
os_unix.go: it defines theplatformOSDescription()anduname()functions, common for al *NIX systems. Build tags are included to target these common OSes.os_release_unix.go: it defines theosRelease()for al *NIX systems except Darwin. Thedarwintag is omitted.os_release_darwin.go: it defines theosRelease()for Darwin.os_windows.go: it defines theplatformOSDescription()for Windows.When it comes to os-release files, there are differences between distros on the number of properties present and the amount of detail in their values.
Based on the following examples:
I took some decisions on which properties to select to compose the final release description string, trying to maximize the amount of detail and avoiding redundancy. This is of course open to debate.
Tests for most unexported functions are
TODO at the moment, but can/should beincluded.Let me know what you think and any improvements you would make.