Skip to content

Commit 28f24e1

Browse files
Revert useless metric keeping useful changes (#179)
* Revert "feat(fqdn): compute fqdn whenever possible (#172)" This reverts commit 0690533. * feat(revert): keep useful changes
1 parent 4a5a220 commit 28f24e1

File tree

6 files changed

+12
-116
lines changed

6 files changed

+12
-116
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## v1.4.1 (2024-02-28)
8+
### Fixed
9+
- Reverted a new metric that was reporting a FQDN different from the one reported by the infra-agent
10+
711
## v1.3.0 (2023-10-10)
812
### Changed
913
- Dependencies have been updated: testify, logrus, govmomi

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/newrelic/nri-vsphere
33
go 1.19
44

55
require (
6-
github.com/newrelic/infra-integrations-sdk v3.8.0+incompatible
6+
github.com/newrelic/infra-integrations-sdk v3.8.2+incompatible
77
github.com/sirupsen/logrus v1.9.3
88
github.com/stretchr/testify v1.8.4
99
github.com/vmware/govmomi v0.34.2
@@ -16,7 +16,7 @@ require (
1616
github.com/google/uuid v1.4.0 // indirect
1717
github.com/pkg/errors v0.9.1 // indirect
1818
github.com/pmezard/go-difflib v1.0.0 // indirect
19-
github.com/rogpeppe/go-internal v1.11.0 // indirect
19+
github.com/rogpeppe/go-internal v1.12.0 // indirect
2020
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
2121
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
2222
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
66
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
77
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
88
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
9-
github.com/newrelic/infra-integrations-sdk v3.8.0+incompatible h1:QvwHLsgHyGw4ZULOSnnWQnVPE744K1eda+2XLp2eHtg=
10-
github.com/newrelic/infra-integrations-sdk v3.8.0+incompatible/go.mod h1:tMUHRMq6mJS0YyBnbWrTXAnREnQqC1AGO6Lu45u5xAM=
9+
github.com/newrelic/infra-integrations-sdk v3.8.2+incompatible h1:Ktcm1aPAl7CW3o+FXAIKJ+jygWVXDXaUIWFyf2CXQTk=
10+
github.com/newrelic/infra-integrations-sdk v3.8.2+incompatible/go.mod h1:tMUHRMq6mJS0YyBnbWrTXAnREnQqC1AGO6Lu45u5xAM=
1111
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
1212
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1313
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1414
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
15-
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
16-
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
15+
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
16+
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
1717
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
1818
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
1919
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

internal/collect/vms.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func VirtualMachines(config *config.Config) {
1818
m := config.ViewManager
1919

2020
// Reference: http://pubs.vmware.com/vsphere-60/topic/com.vmware.wssdk.apiref.doc/vim.VirtualMachine.html
21-
propertiesToRetrieve := []string{"name", "summary", "network", "config", "guest", "guest.ipStack", "runtime", "resourcePool", "datastore", "overallStatus"}
21+
propertiesToRetrieve := []string{"name", "summary", "network", "config", "guest", "runtime", "resourcePool", "datastore", "overallStatus"}
2222
if config.Args.EnableVsphereSnapshots {
2323
config.Logrus.Debug("collecting as well snapshot and layoutEx properties")
2424
propertiesToRetrieve = append(propertiesToRetrieve, "snapshot", "layoutEx.file", "layoutEx.disk", "layoutEx.snapshot")

internal/process/vms.go

+1-45
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/newrelic/infra-integrations-sdk/data/metric"
1212
"github.com/newrelic/nri-vsphere/internal/config"
13-
"github.com/vmware/govmomi/vim25/mo"
1413
)
1514

1615
func createVirtualMachineSamples(config *config.Config) {
@@ -191,13 +190,8 @@ func createVirtualMachineSamples(config *config.Config) {
191190
}
192191
}
193192
}
194-
195-
if fqdn := computeFullHostname(vm); fqdn != "" {
196-
checkError(config.Logrus, ms.SetMetric("vmFullHostname", fqdn, metric.ATTRIBUTE))
197-
}
198-
199193
ipAddressesTrimmed := strings.TrimSuffix(ipAddresses.String(), "|")
200-
// it might be empty, but we still add the attribute for consistency
194+
// it might be empty but we still add the attribute for consistency
201195
checkError(config.Logrus, ms.SetMetric("ipAddresses", ipAddressesTrimmed, metric.ATTRIBUTE))
202196
}
203197

@@ -245,41 +239,3 @@ func createVirtualMachineSamples(config *config.Config) {
245239
}
246240
}
247241
}
248-
249-
// computeFullHostname joins hostname and domain for each VM
250-
// These data depends on the vmwareTools, therefore they need to be installed,
251-
// and we depend on how such tool is collecting the value.
252-
// Moreover, notice that we are returning the first domain contained in IpStack array.
253-
func computeFullHostname(vm *mo.VirtualMachine) string {
254-
if vm.Guest == nil {
255-
return ""
256-
}
257-
if vm.Summary.Guest == nil {
258-
return ""
259-
}
260-
261-
for _, is := range vm.Guest.IpStack {
262-
if is.DnsConfig == nil {
263-
continue
264-
}
265-
266-
var domain = is.DnsConfig.DomainName
267-
var hostname = is.DnsConfig.HostName
268-
if domain == "" || hostname == "" {
269-
continue
270-
}
271-
if hostname != vm.Summary.Guest.HostName {
272-
continue
273-
}
274-
275-
// we noticed that the hostname is sometimes the short one and sometimes the fqdn
276-
hostname = strings.TrimSuffix(hostname, domain)
277-
hostname = strings.TrimSuffix(hostname, ".")
278-
279-
var fullHostname = hostname + "." + domain
280-
fullHostname = strings.TrimSuffix(fullHostname, ".")
281-
282-
return fullHostname
283-
}
284-
return ""
285-
}

internal/process/vms_test.go

-64
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ import (
77
"github.com/newrelic/nri-vsphere/internal/collect"
88
"github.com/newrelic/nri-vsphere/internal/config"
99
"github.com/newrelic/nri-vsphere/internal/model"
10-
"github.com/newrelic/nri-vsphere/internal/process/testdata"
1110
"github.com/sirupsen/logrus"
1211
"github.com/stretchr/testify/assert"
1312
"github.com/vmware/govmomi/simulator"
1413
"github.com/vmware/govmomi/view"
1514
"github.com/vmware/govmomi/vim25"
1615
"github.com/vmware/govmomi/vim25/mo"
17-
"github.com/vmware/govmomi/vim25/types"
1816
"testing"
1917
)
2018

@@ -56,65 +54,3 @@ func getDatacenter(ctx context.Context, vm *view.Manager) *model.Datacenter {
5654
_ = cv.Retrieve(ctx, []string{"Datacenter"}, []string{"name"}, &datacenters)
5755
return model.NewDatacenter(&datacenters[0])
5856
}
59-
60-
const hostname = "test"
61-
const fullHostname = "test.this.com"
62-
const domain = "this.com"
63-
64-
func TestComputeFullHostname(t *testing.T) {
65-
var vm = &mo.VirtualMachine{}
66-
assert.Equal(t, "", computeFullHostname(vm))
67-
68-
vm = &mo.VirtualMachine{
69-
Guest: &types.GuestInfo{
70-
IpStack: []types.GuestStackInfo{
71-
{
72-
DnsConfig: &types.NetDnsConfigInfo{
73-
HostName: hostname + "different",
74-
DomainName: domain,
75-
},
76-
},
77-
{
78-
DnsConfig: &types.NetDnsConfigInfo{
79-
HostName: hostname,
80-
},
81-
},
82-
{
83-
DnsConfig: &types.NetDnsConfigInfo{
84-
DomainName: domain,
85-
},
86-
},
87-
{ // This is the only entry that the implementation should consider
88-
DnsConfig: &types.NetDnsConfigInfo{
89-
HostName: hostname,
90-
DomainName: domain,
91-
},
92-
},
93-
},
94-
},
95-
Summary: types.VirtualMachineSummary{
96-
Guest: &types.VirtualMachineGuestSummary{
97-
HostName: hostname,
98-
},
99-
},
100-
}
101-
assert.Equal(t, fullHostname, computeFullHostname(vm))
102-
103-
// No matter if in hostname there is the fqdn, we do not place the suffix twice
104-
vm.Guest.IpStack[3].DnsConfig.HostName = fullHostname
105-
vm.Summary.Guest.HostName = fullHostname
106-
assert.Equal(t, fullHostname, computeFullHostname(vm))
107-
108-
// No matter if in hostname there is the fqdn, we do not place the suffix twice
109-
vm.Guest.IpStack[3].DnsConfig.HostName = hostname + "."
110-
vm.Summary.Guest.HostName = hostname + "."
111-
assert.Equal(t, fullHostname, computeFullHostname(vm))
112-
113-
// if the hostname is different in the summary we avoid computing the fqdn
114-
vm.Guest.IpStack[3].DnsConfig.HostName = hostname + "different"
115-
assert.Equal(t, "", computeFullHostname(vm))
116-
117-
// Testing it with mock from real data
118-
realVM := testdata.GetVMFromStaticData(t)
119-
assert.Equal(t, "vm-3.test.com", computeFullHostname(&realVM))
120-
}

0 commit comments

Comments
 (0)