Skip to content

Commit

Permalink
[exporter/signalfx] use azure.vm.name to build azure resource id (#12931
Browse files Browse the repository at this point in the history
)

Use the resource attribute azure.vm.name instead of host.name to build azure_resource_id because host.name is also used by the system detector.
  • Loading branch information
pmcollins authored Aug 3, 2022
1 parent f92920f commit 4260dd6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion internal/splunk/hostid.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func azureID(attrs pcommon.Map, cloudAccount string) string {
}

var hostname string
if attr, ok := attrs.Get(conventions.AttributeHostName); ok {
if attr, ok := attrs.Get("azure.vm.name"); ok {
hostname = attr.StringVal()
}
if hostname == "" {
Expand Down
16 changes: 4 additions & 12 deletions internal/splunk/hostid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var (
attrs.InsertString(conventions.AttributeCloudRegion, "myCloudRegion")
attrs.InsertString(conventions.AttributeHostID, "myHostID")
attrs.InsertString(conventions.AttributeCloudAccountID, "myCloudAccount")
attrs.InsertString("azure.vm.name", "myVMName")
attrs.InsertString("azure.vm.size", "42")
attrs.InsertString("azure.resourcegroup.name", "myResourcegroupName")
return res
Expand All @@ -82,10 +83,11 @@ var (
attrs := res.Attributes()
attrs.InsertString(conventions.AttributeCloudProvider, conventions.AttributeCloudProviderAzure)
attrs.InsertString(conventions.AttributeCloudPlatform, conventions.AttributeCloudPlatformAzureVM)
attrs.InsertString(conventions.AttributeHostName, "myVMScalesetName_1")
attrs.InsertString(conventions.AttributeHostName, "my.fq.host.name")
attrs.InsertString(conventions.AttributeCloudRegion, "myCloudRegion")
attrs.InsertString(conventions.AttributeHostID, "myHostID")
attrs.InsertString(conventions.AttributeCloudAccountID, "myCloudAccount")
attrs.InsertString("azure.vm.name", "myVMScalesetName_1")
attrs.InsertString("azure.vm.size", "42")
attrs.InsertString("azure.vm.scaleset.name", "myVMScalesetName")
attrs.InsertString("azure.resourcegroup.name", "myResourcegroupName")
Expand Down Expand Up @@ -189,7 +191,7 @@ func TestResourceToHostID(t *testing.T) {
args: args{azureResource},
want: HostID{
Key: "azure_resource_id",
ID: "mycloudaccount/myresourcegroupname/microsoft.compute/virtualmachines/myhostname",
ID: "mycloudaccount/myresourcegroupname/microsoft.compute/virtualmachines/myvmname",
},
ok: true,
},
Expand Down Expand Up @@ -256,13 +258,3 @@ func TestResourceToHostID(t *testing.T) {
})
}
}

func TestAzureID(t *testing.T) {
attrs := pcommon.NewMap()
attrs.Insert("azure.resourcegroup.name", pcommon.NewValueString("myResourceGroup"))
attrs.Insert("azure.vm.scaleset.name", pcommon.NewValueString("myScalesetName"))
attrs.Insert(conventions.AttributeHostName, pcommon.NewValueString("myScalesetName_1"))
id := azureID(attrs, "myCloudAccount")
expected := "mycloudaccount/myresourcegroup/microsoft.compute/virtualmachinescalesets/myscalesetname/virtualmachines/1"
assert.Equal(t, expected, id)
}
16 changes: 16 additions & 0 deletions unreleased/azure-resource-id.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: signalfxexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: use azure.vm.name instead of host.name to build azure resource id

# One or more tracking issues related to the change
issues: [12779]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

0 comments on commit 4260dd6

Please sign in to comment.