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

Trim project from GCE cloud metadata #10987

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Allow Central Management to send events back to kibana. {issue}9382[9382]
- Initialize the Paths before the keystore and save the keystore into `data/{beatname}.keystore`. {pull}10706[10706]
- Add `cleanup_timeout` option to docker autodiscover, to wait some time before removing configurations after a container is stopped. {issue]10374[10374] {pull}10905[10905]
- On Google Cloud Engine (GCE) the add_cloud_metadata will now trim the project
info from the cloud.machine.type and cloud.availability_zone. {issue}10968[10968]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be listed as a breaking change, to be on the safe side?

Copy link
Member Author

Choose a reason for hiding this comment

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

Being safe. If you are using GCE and have queries or aggs based on the old values, they will be broken.


*Auditbeat*

Expand Down
90 changes: 38 additions & 52 deletions libbeat/docs/processors-using.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,12 @@ _EC2_
[source,json]
-------------------------------------------------------------------------------
{
"meta": {
"cloud": {
"availability_zone": "us-east-1c",
"instance_id": "i-4e123456",
"machine_type": "t2.medium",
"provider": "ec2",
"region": "us-east-1"
}
"cloud": {
"availability_zone": "us-east-1c",
"instance_id": "i-4e123456",
"machine_type": "t2.medium",
"provider": "ec2",
"region": "us-east-1"
}
}
-------------------------------------------------------------------------------
Expand All @@ -539,12 +537,10 @@ _Digital Ocean_
[source,json]
-------------------------------------------------------------------------------
{
"meta": {
"cloud": {
"instance_id": "1234567",
"provider": "digitalocean",
"region": "nyc2"
}
"cloud": {
"instance_id": "1234567",
"provider": "digitalocean",
"region": "nyc2"
}
}
-------------------------------------------------------------------------------
Expand All @@ -554,14 +550,12 @@ _GCE_
[source,json]
-------------------------------------------------------------------------------
{
"meta": {
"cloud": {
"availability_zone": "projects/1234567890/zones/us-east1-b",
"instance_id": "1234556778987654321",
"machine_type": "projects/1234567890/machineTypes/f1-micro",
"project_id": "my-dev",
"provider": "gce"
}
"cloud": {
"availability_zone": "us-east1-b",
"instance_id": "1234556778987654321",
"machine_type": "f1-micro",
"project_id": "my-dev",
"provider": "gce"
}
}
-------------------------------------------------------------------------------
Expand All @@ -571,13 +565,11 @@ _Tencent Cloud_
[source,json]
-------------------------------------------------------------------------------
{
"meta": {
"cloud": {
"availability_zone": "gz-azone2",
"instance_id": "ins-qcloudv5",
"provider": "qcloud",
"region": "china-south-gz"
}
"cloud": {
"availability_zone": "gz-azone2",
"instance_id": "ins-qcloudv5",
"provider": "qcloud",
"region": "china-south-gz"
}
}
-------------------------------------------------------------------------------
Expand All @@ -590,13 +582,11 @@ ECS instance.
[source,json]
-------------------------------------------------------------------------------
{
"meta": {
"cloud": {
"availability_zone": "cn-shenzhen",
"instance_id": "i-wz9g2hqiikg0aliyun2b",
"provider": "ecs",
"region": "cn-shenzhen-a"
}
"cloud": {
"availability_zone": "cn-shenzhen",
"instance_id": "i-wz9g2hqiikg0aliyun2b",
"provider": "ecs",
"region": "cn-shenzhen-a"
}
}
-------------------------------------------------------------------------------
Expand All @@ -606,14 +596,12 @@ _Azure Virtual Machine_
[source,json]
-------------------------------------------------------------------------------
{
"meta": {
"cloud": {
"provider": "az",
"instance_id": "04ab04c3-63de-4709-a9f9-9ab8c0411d5e",
"instance_name": "test-az-vm",
"machine_type": "Standard_D3_v2",
"region": "eastus2"
}
"cloud": {
"provider": "az",
"instance_id": "04ab04c3-63de-4709-a9f9-9ab8c0411d5e",
"instance_name": "test-az-vm",
"machine_type": "Standard_D3_v2",
"region": "eastus2"
}
}
-------------------------------------------------------------------------------
Expand All @@ -623,14 +611,12 @@ _Openstack Nova_
[source,json]
-------------------------------------------------------------------------------
{
"meta": {
"cloud": {
"provider": "openstack",
"instance_name": "test-998d932195.mycloud.tld",
"availability_zone": "xxxx-az-c",
"instance_id": "i-00011a84",
"machine_type": "m2.large"
}
"cloud": {
"provider": "openstack",
"instance_name": "test-998d932195.mycloud.tld",
"availability_zone": "xxxx-az-c",
"instance_id": "i-00011a84",
"machine_type": "m2.large"
}
}
-------------------------------------------------------------------------------
Expand Down
16 changes: 16 additions & 0 deletions libbeat/processors/add_cloud_metadata/provider_google_gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package add_cloud_metadata

import (
"path"

"github.com/elastic/beats/libbeat/common"
s "github.com/elastic/beats/libbeat/common/schema"
c "github.com/elastic/beats/libbeat/common/schema/mapstriface"
Expand All @@ -30,6 +32,18 @@ func newGceMetadataFetcher(config *common.Config) (*metadataFetcher, error) {
gceSchema := func(m map[string]interface{}) common.MapStr {
out := common.MapStr{}

trimLeadingPath := func(key string) {
v, err := out.GetValue(key)
if err != nil {
return
}
p, ok := v.(string)
if !ok {
return
}
out.Put(key, path.Base(p))
}

if instance, ok := m["instance"].(map[string]interface{}); ok {
s.Schema{
"instance": s.Object{
Expand All @@ -41,6 +55,8 @@ func newGceMetadataFetcher(config *common.Config) (*metadataFetcher, error) {
},
"availability_zone": c.Str("zone"),
}.ApplyTo(out, instance)
trimLeadingPath("machine.type")
trimLeadingPath("availability_zone")
}

if project, ok := m["project"].(map[string]interface{}); ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ func TestRetrieveGCEMetadata(t *testing.T) {
"name": "test-gce-dev",
},
"machine": common.MapStr{
"type": "projects/111111111111/machineTypes/f1-micro",
"type": "f1-micro",
},
"availability_zone": "projects/111111111111/zones/us-east1-b",
"availability_zone": "us-east1-b",
"project": common.MapStr{
"id": "test-dev",
},
Expand Down