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

Report FQDN #144

Merged
merged 67 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
fac6132
linux and windows done
AndersonQ Jan 4, 2023
0c3f9c2
send
AndersonQ Jan 4, 2023
6843a8f
using gethostname and getdomainname instead of hostname -f
AndersonQ Jan 5, 2023
38abc2e
don't use deprecated functions
AndersonQ Jan 5, 2023
a79bc82
.
AndersonQ Jan 5, 2023
c1b9c48
nocgo fallback and fix darwin types
AndersonQ Jan 5, 2023
9232921
add doc
AndersonQ Jan 17, 2023
78a3239
wip
AndersonQ Jan 17, 2023
7128e81
remove unnecessary C import
AndersonQ Jan 17, 2023
e387f3c
wip
AndersonQ Jan 23, 2023
79a48f4
.
AndersonQ Jan 23, 2023
21d5286
.
AndersonQ Jan 23, 2023
8b03c7a
.
AndersonQ Jan 23, 2023
65bd274
add license header
AndersonQ Jan 23, 2023
2b02410
add integration build tag and run them on ci
AndersonQ Jan 23, 2023
0587e49
adjust tests
AndersonQ Jan 23, 2023
c5a4262
more info on test errors
AndersonQ Jan 24, 2023
99d7550
force ci build
AndersonQ Jan 24, 2023
b09b009
force ci build - undo changes
AndersonQ Jan 24, 2023
791efa3
force ci build
AndersonQ Jan 26, 2023
47ca564
force ci build - undo changes
AndersonQ Jan 26, 2023
6ea8012
fetch FQDN instead of building it on windows
AndersonQ Jan 26, 2023
8102002
use local instead of lan for darwin
AndersonQ Jan 26, 2023
1d7b6b3
avoid shadowing
AndersonQ Jan 26, 2023
d28c9df
fix darwin no Cgo
AndersonQ Jan 26, 2023
edf1a6f
remove integration tests
AndersonQ Jan 27, 2023
00761d9
enable integration tests
AndersonQ Jan 27, 2023
10bca72
testing things
AndersonQ Jan 27, 2023
fc0392f
Merge branch 'main' into report-fqdn
v1v Jan 27, 2023
a58e096
change permissions
v1v Jan 27, 2023
f9900cb
run all tests and add TODO
AndersonQ Jan 27, 2023
3f79759
WIP
AndersonQ Jan 30, 2023
30eb9e6
parse fqdn from hosts file
AndersonQ Jan 31, 2023
7b81bb8
get fqdn from /etc/hosts for linux and darwin
AndersonQ Jan 31, 2023
5446c0c
add fallback using net.Lookup
AndersonQ Jan 31, 2023
d5226bc
.
AndersonQ Jan 31, 2023
24cb68f
more logs
AndersonQ Jan 31, 2023
2a2e222
try to fix formating
AndersonQ Jan 31, 2023
9f41195
update go versions 1.18 and tests to 1.18 and 1.19
AndersonQ Feb 1, 2023
17c0e2d
restore check_format and remove debug log
AndersonQ Feb 1, 2023
b062876
add build tag to test file
AndersonQ Feb 1, 2023
eca2e34
.
AndersonQ Feb 1, 2023
1061a2c
goimports
AndersonQ Feb 1, 2023
5209338
allow FQDN errors on test
AndersonQ Feb 1, 2023
bd62e40
restore jenkins info level
AndersonQ Feb 1, 2023
4461fbc
trigger build
AndersonQ Feb 1, 2023
e3567d3
undo - trigger build
AndersonQ Feb 1, 2023
db6bdac
improve error message
AndersonQ Feb 1, 2023
02f9780
not fail on Hosts tests
AndersonQ Feb 1, 2023
0df9a28
.
AndersonQ Feb 1, 2023
2d1b47a
.
AndersonQ Feb 1, 2023
6fc8457
.
AndersonQ Feb 1, 2023
69f45ef
.
AndersonQ Feb 1, 2023
64a11df
quote tabs on tests
AndersonQ Feb 1, 2023
d664ddb
remove debug
AndersonQ Feb 1, 2023
4da8ad9
removing dot suffix
AndersonQ Feb 1, 2023
c8b0e3d
.
AndersonQ Feb 1, 2023
85120c0
remove comments
AndersonQ Feb 2, 2023
c31ec2d
Update providers/shared/fqdn.go
jlind23 Feb 7, 2023
8b7b674
Update providers/linux/host_fqdn_integration_docker_linux_test.go
jlind23 Feb 7, 2023
687a468
Update providers/linux/host_fqdn_integration_docker_linux_test.go
jlind23 Feb 7, 2023
01676da
review changes
AndersonQ Feb 14, 2023
a34bbd3
Merge remote-tracking branch 'origin/report-fqdn' into report-fqdn
AndersonQ Feb 14, 2023
88dc9f8
add missing import
AndersonQ Feb 14, 2023
f8d318e
don't parse /etc/hosts to get FQDN on linux and darwin
AndersonQ Feb 15, 2023
9c01d40
remove tests for removed things
AndersonQ Feb 15, 2023
d88406a
add changelog
AndersonQ Feb 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pipeline {
REPO = "go-sysinfo"
BASE_DIR = "src/github.com/elastic/${env.REPO}"
JOB_GIT_CREDENTIALS = "f6c7695a-671e-4f4f-a331-acdce44ff9ba"
PIPELINE_LOG_LEVEL = 'INFO'
PIPELINE_LOG_LEVEL = 'DEBUG'
}
options {
timeout(time: 1, unit: 'HOURS')
Expand Down
2 changes: 1 addition & 1 deletion .ci/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ fi
# Run the tests
export OUT_FILE="build/test-report.out"
mkdir -p build
gotestsum --format testname --junitfile "build/junit-${GO_VERSION}.xml" -- ./...
gotestsum --format testname --junitfile "build/junit-${GO_VERSION}.xml" -- -tags integration -run TestHost_FQDN$ ./...
Copy link
Member

Choose a reason for hiding this comment

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

This particular -tags integration behaves differently when running on MacOS,

For instance, any builds in the main branch run the tests

image

but this change does not run anything on MacOS

image

I guess that's only for testing purposes, if so, please forgive me :)

but

Copy link
Member Author

Choose a reason for hiding this comment

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

that is correct, the tests enabled by the integration build flag are only for linux

Copy link
Member

@v1v v1v Jan 27, 2023

Choose a reason for hiding this comment

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

If so, then macos will need to use a different script, otherwise it will not run any tests. In case you'd like to validate your changes

25 changes: 21 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,33 @@ module github.com/elastic/go-sysinfo
go 1.17

require (
github.com/docker/docker v20.10.22+incompatible
github.com/elastic/go-windows v1.0.0
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901
github.com/prometheus/procfs v0.8.0
github.com/stretchr/testify v1.3.0
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a
github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.1.0
howett.net/plist v0.0.0-20181124034731-591f970eefbb
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
Copy link

@michalpristas michalpristas Feb 7, 2023

Choose a reason for hiding this comment

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

this seems off, so many new imports?

Copy link
Member Author

Choose a reason for hiding this comment

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

They are indirect, I believe most come from test dependencies, most likely github.com/docker/docker. I'm using it to be able to do a integration test for the FQDN.

Here is why go-winio is needed

# github.com/Microsoft/go-winio
github.com/elastic/go-sysinfo/providers/linux
github.com/elastic/go-sysinfo/providers/linux.test
github.com/docker/docker/client
github.com/docker/go-connections/sockets
github.com/Microsoft/go-winio

# v0.6.0
(main module does not need module v0.6.0)

Copy link
Member Author

Choose a reason for hiding this comment

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

besides the only direct dependency added was github.com/docker/docker

github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.1.12 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
gotest.tools/v3 v3.4.0 // indirect
)
98 changes: 95 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,29 +1,121 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE=
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68=
github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v20.10.22+incompatible h1:6jX4yB+NtcbldT90k7vBSaWJDB3i+zkVJT9BEK8kQkk=
github.com/docker/docker v20.10.22+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/elastic/go-windows v1.0.0 h1:qLURgZFkkrYyTTkvYpsZIgf83AUsdIHfvlJaqaZ7aSY=
github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6CcloAxnPgU=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4=
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 h1:HfkjXDfhgVaN5rmueG8cL8KKeFNecRCXFhaJ2qZ5SKA=
github.com/moby/term v0.0.0-20221205130635-1aeaba878587/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo=
github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g=
howett.net/plist v0.0.0-20181124034731-591f970eefbb h1:jhnBjNi9UFpfpl8YZhA9CrOqpnJdvzuiHsl/dnxl11M=
howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0=
20 changes: 20 additions & 0 deletions providers/darwin/host_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ func newHost() (*host, error) {
r.architecture(h)
r.bootTime(h)
r.hostname(h)
r.domain(h)
r.fqdn(h)
r.network(h)
r.kernelVersion(h)
r.os(h)
Expand Down Expand Up @@ -213,6 +215,24 @@ func (r *reader) hostname(h *host) {
h.info.Hostname = v
}

func (r *reader) domain(h *host) {
v, err := domainname()
if r.addErr(err) {
return
}
h.info.Domain = v
}

func (r *reader) fqdn(h *host) {
fqdn, err := fqdn()
if err != nil {
r.addErr(fmt.Errorf("could not get darwin FQDN: %w", err))
return
}

h.info.FQDN = fqdn
}

func (r *reader) network(h *host) {
ips, macs, err := shared.Network()
if r.addErr(err) {
Expand Down
41 changes: 41 additions & 0 deletions providers/darwin/host_darwin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

//go:build amd64 || arm64
// +build amd64 arm64

package darwin

import (
"encoding/json"
"testing"

"github.com/elastic/go-sysinfo/internal/registry"
)

var _ registry.HostProvider = darwinSystem{}

func TestHost(t *testing.T) {
host, err := darwinSystem{}.Host()
if err != nil {
t.Fatal(err)
}

info := host.Info()
data, _ := json.MarshalIndent(info, "", " ")
t.Log(string(data))
}
62 changes: 62 additions & 0 deletions providers/darwin/host_fqdn_cgo_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

//go:build cgo

package darwin

// #include <unistd.h>
// #include <stdlib.h>
import "C"
import (
"fmt"
"os"
"unsafe"
)

func fqdn() (string, error) {
hostname, err := os.Hostname()
Copy link
Member

Choose a reason for hiding this comment

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

If I use sudo scutil --set HostName foo.engineering.example.com. Then hostname returns:

% sudo scutil --set HostName foo.engineering.example.com
% hostname -f
foo.engineering.example.com
% hostname -s
foo
% hostname -d
engineering.example.com

But go-sysinfo returns:

            "name": "foo.engineering.example.com",
            "domain": "",
            "fqdn": "foo.engineering.example.com.local",

Copy link
Member

@andrewkroh andrewkroh Jan 26, 2023

Choose a reason for hiding this comment

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

It gets even more confusing if the machine has a NIS domain set AND the HostName is fully-qualified. I think we need to be clearify what we are reporting. Do we want to report the NIS domain or do we want to report domain suffix that is part of the machine's fully-qualified DNS name (man hostname has some details).

sudo sysctl kern.nisdomainname=nis.domain

            "name": "foo.engineering.example.com",
            "domain": "nis.domain",
            "fqdn": "foo.engineering.example.com.nis.domain",

if err != nil {
return "", err
}

domain, err := domainname()
if err != nil {
return "", err
}

if domain == "" || domain == "(none)" { // mimicking 'hostname -f' behaviour
Copy link
Member

Choose a reason for hiding this comment

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

When I run hostname -f on my machine it doesn't add .local?

% hostname
mac16-m1
% hostname -f
mac16-m1
% hostname -d
mac16-m1

Copy link
Member Author

Choose a reason for hiding this comment

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

are you sure you haven't set your domain name to "" somehow?
I'm assuming it's your Elastic laptop, thus with Elastic Shield installed. Am I correct?

Have you used the tool in Elastic shield to rename the laptop? That would explain this behaviour

domain = "local"
}

return fmt.Sprintf("%s.%s", hostname, domain), nil
}

func domainname() (string, error) {
const buffSize = 64
buff := make([]byte, buffSize)
size := buffSize
cString := C.CString(string(buff))
defer C.free(unsafe.Pointer(cString))

_, errno := C.getdomainname(cString, C.int(size))
if errno != nil {
return "", fmt.Errorf("syscall getdomainname errored: %v", errno)
}

return C.GoString(cString), nil
}
28 changes: 28 additions & 0 deletions providers/darwin/host_fqdn_nocgo_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

//go:build !cgo

package darwin

func fqdn() (string, error) {
return "", nil
}

func domainname() (string, error) {
return "", nil
Copy link
Member

@andrewkroh andrewkroh Jan 26, 2023

Choose a reason for hiding this comment

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

Could we use sysctl to fetch kern.nisdomainname here? That looks like it returns the same thing in my testing. Then you would not need a CGO and non-CGO implementation.

Copy link
Member Author

Choose a reason for hiding this comment

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

this is already the no Cgo implementation. I'm already using Cgo for the getdomainname syscall.

sysctl is an external application, right? I'm avoiding invoking any external application.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I wasn't clear. We can invoke the sysctl syscall without needing CGO. Then we can have a single implementation that works for all darwin builds. There should be some examples already in the codebase (if not see the os.Hostname() implementation in the stdlib for darwin).

}
2 changes: 1 addition & 1 deletion providers/linux/boottime_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func bootTime(fs procfs.FS) (time.Time, error) {
return bootTimeValue, nil
}

stat, err := fs.NewStat()
stat, err := fs.Stat()
if err != nil {
return time.Time{}, err
}
Expand Down
Loading