Skip to content

Commit

Permalink
[add_cloud_metadata processor] Update azure metadata api version (#35302
Browse files Browse the repository at this point in the history
)

* update azure metadata api version

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* fix linter

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

---------

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
  • Loading branch information
tetianakravchenko committed May 6, 2023
1 parent 3550280 commit 25e882f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ https://github.com/elastic/beats/compare/v8.7.1\...main[Check the HEAD diff]
- Fix performance issues when we have a lot of inputs starting and stopping by allowing to disable global processors under fleet. {issue}35000[35000] {pull}35031[35031]
- In cases where the matcher detects a non-string type in a match statement, report the error as a debug statement, and not a warning statement. {pull}35119[35119]
- 'add_cloud_metadata' processor - add cloud.region field for GCE cloud provider
- 'add_cloud_metadata' processor - update azure metadata api version to get missing `cloud.account.id` field


*Auditbeat*

Expand Down
2 changes: 1 addition & 1 deletion libbeat/processors/add_cloud_metadata/provider_azure_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var azureVMMetadataFetcher = provider{
Local: true,

Create: func(_ string, config *conf.C) (metadataFetcher, error) {
azMetadataURI := "/metadata/instance/compute?api-version=2017-04-02"
azMetadataURI := "/metadata/instance/compute?api-version=2021-02-01"
azHeaders := map[string]string{"Metadata": "true"}
azSchema := func(m map[string]interface{}) mapstr.M {
m["serviceName"] = "Virtual Machines"
Expand Down
65 changes: 48 additions & 17 deletions libbeat/processors/add_cloud_metadata/provider_azure_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,55 @@ import (
)

const azInstanceIdentityDocument = `{
"location": "eastus2",
"name": "test-az-vm",
"offer": "UbuntuServer",
"azEnvironment": "AzurePublicCloud",
"customData": "",
"evictionPolicy": "",
"isHostCompatibilityLayerVm": "false",
"licenseType": "",
"location": "eastus",
"name": "aks-agentpool-12628255-vmss_2",
"offer": "",
"osProfile": {
"adminUsername": "azureuser",
"computerName": "aks-agentpool-12628255-vmss000002",
"disablePasswordAuthentication": "true"
},
"osType": "Linux",
"placementGroupId": "43e6bd16-b9ae-4a0c-a7e3-6c9ab23482a7",
"plan": {
"name": "",
"product": "",
"publisher": ""
},
"platformFaultDomain": "0",
"platformUpdateDomain": "0",
"publisher": "Canonical",
"sku": "14.04.4-LTS",
"version": "14.04.201605091",
"vmId": "04ab04c3-63de-4709-a9f9-9ab8c0411d5e",
"vmSize": "Standard_D3_v2",
"subscriptionId": "5tfb04c3-63de-4709-a9f9-9ab8c0411d5e"
"priority": "",
"provider": "Microsoft.Compute",
"publicKeys": [],
"publisher": "",
"resourceGroupName": "MC_myname_group_myname_eastus",
"resourceId": "/subscriptions/0e073ec1-c22f-4488-adde-da35ed609ccd/resourceGroups/MC_myname_group_myname_eastus/providers/Microsoft.Compute/virtualMachineScaleSets/aks-agentpool-12628255-vmss/virtualMachines/2",
"securityProfile": {
"secureBootEnabled": "false",
"virtualTpmEnabled": "false"
},
"sku": "",
"storageProfile": {},
"subscriptionId": "0e073ec1-c22f-4488-adde-da35ed609ccd",
"tags": "aks-managed-coordination:true;aks-managed-createOperationID:29bea4bf-8a24-4dcb-aecb-c2fb07d5bd29;aks-managed-creationSource:vmssclient-aks-agentpool-12628255-vmss;aks-managed-kubeletIdentityClientID:64efabb1-53aa-4868-8a07-9e385f00e527;aks-managed-orchestrator:Kubernetes:1.25.6;aks-managed-poolName:agentpool;aks-managed-resourceNameSuffix:80220090",
"tagsList": [],
"userData": "",
"version": "",
"vmId": "220e2b43-0913-492f-ada0-b6b2795bdb9b",
"vmScaleSetName": "aks-agentpool-12628255-vmss",
"vmSize": "Standard_DS2_v2",
"zone": "3"
}`

func initAzureTestServer() *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.RequestURI == "/metadata/instance/compute?api-version=2017-04-02" && r.Header.Get("Metadata") == "true" {
w.Write([]byte(azInstanceIdentityDocument))
if r.RequestURI == "/metadata/instance/compute?api-version=2021-02-01" && r.Header.Get("Metadata") == "true" {
_, _ = w.Write([]byte(azInstanceIdentityDocument))
return
}

Expand All @@ -57,7 +88,7 @@ func initAzureTestServer() *httptest.Server {
}

func TestRetrieveAzureMetadata(t *testing.T) {
logp.TestingSetup()
_ = logp.TestingSetup()

server := initAzureTestServer()
defer server.Close()
Expand All @@ -83,19 +114,19 @@ func TestRetrieveAzureMetadata(t *testing.T) {
"cloud": mapstr.M{
"provider": "azure",
"instance": mapstr.M{
"id": "04ab04c3-63de-4709-a9f9-9ab8c0411d5e",
"name": "test-az-vm",
"id": "220e2b43-0913-492f-ada0-b6b2795bdb9b",
"name": "aks-agentpool-12628255-vmss_2",
},
"machine": mapstr.M{
"type": "Standard_D3_v2",
"type": "Standard_DS2_v2",
},
"account": mapstr.M{
"id": "5tfb04c3-63de-4709-a9f9-9ab8c0411d5e",
"id": "0e073ec1-c22f-4488-adde-da35ed609ccd",
},
"service": mapstr.M{
"name": "Virtual Machines",
},
"region": "eastus2",
"region": "eastus",
},
}
assert.Equal(t, expected, actual.Fields)
Expand Down

0 comments on commit 25e882f

Please sign in to comment.