From 95550e0e36e4a11eea046693111d79a1a2110e22 Mon Sep 17 00:00:00 2001 From: Maximilian Stinsky <26960620+mstinsky@users.noreply.github.com> Date: Thu, 1 Feb 2024 18:13:07 +0100 Subject: [PATCH] Remove huaweicloud - revert #27607 (#35184) * Remove huaweicloud - revert #27607 The huaweicloud is just openstack therefore revert #27607 to fix detection of all public and private openstack installations. * make huawei an alias for openstack * change doc * Update CHANGELOG.next.asciidoc --------- Co-authored-by: kaiyan-sheng --- CHANGELOG.next.asciidoc | 4 + .../docs/add_cloud_metadata.asciidoc | 22 +---- .../provider_huawei_cloud.go | 81 --------------- .../provider_huawei_cloud_test.go | 98 ------------------- .../add_cloud_metadata/providers.go | 2 +- 5 files changed, 10 insertions(+), 197 deletions(-) delete mode 100644 libbeat/processors/add_cloud_metadata/provider_huawei_cloud.go delete mode 100644 libbeat/processors/add_cloud_metadata/provider_huawei_cloud_test.go diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 48d87b1dd86f..8d09997f774d 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -11,6 +11,10 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] *Affecting all Beats* - Upgrade to Go 1.21.6. Removes support for Windows 8.1. See https://tip.golang.org/doc/go1.21#windows. {pull}37615[37615] +- add_cloud_metadata processor: `huawei` provider is now treated as `openstack`. Huawei cloud runs on OpenStack +platform, and when viewed from a metadata API standpoint, it is impossible to differentiate it from OpenStack. If you +know that your deployments run on Huawei Cloud exclusively, and you wish to have `cloud.provider` value as `huawei`, +you can achieve this by overwriting the value using an `add_fields` processor. {pull}35184[35184] *Auditbeat* diff --git a/libbeat/processors/add_cloud_metadata/docs/add_cloud_metadata.asciidoc b/libbeat/processors/add_cloud_metadata/docs/add_cloud_metadata.asciidoc index 9e61cac2e8cf..322bf4bd7575 100644 --- a/libbeat/processors/add_cloud_metadata/docs/add_cloud_metadata.asciidoc +++ b/libbeat/processors/add_cloud_metadata/docs/add_cloud_metadata.asciidoc @@ -16,7 +16,10 @@ The following cloud providers are supported: - Google Compute Engine (GCE) - https://www.qcloud.com/?lang=en[Tencent Cloud] (QCloud) - Alibaba Cloud (ECS) -- Huawei Cloud (ECS) +- Huawei Cloud (ECS)footnote:[`huawei` is an alias for `openstack`. Huawei cloud runs on OpenStack platform, and when +viewed from a metadata API standpoint, it is impossible to differentiate it from OpenStack. If you know that your +deployments run on Huawei Cloud exclusively, and you wish to have `cloud.provider` value as `huawei`, you can achieve +this by overwriting the value using an `add_fields` processor.] - Azure Virtual Machine - Openstack Nova - Hetzner Cloud @@ -53,10 +56,9 @@ List of names the `providers` setting supports: - "digitalocean" for Digital Ocean (enabled by default). - "aws", or "ec2" for Amazon Web Services (enabled by default). - "gcp" for Google Copmute Enging (enabled by default). -- "openstack", or "nova" for Openstack Nova (enabled by default). +- "openstack", "nova", or "huawei" for Openstack Nova (enabled by default). - "openstack-ssl", or "nova-ssl" for Openstack Nova when SSL metadata APIs are enabled (enabled by default). - "tencent", or "qcloud" for Tencent Cloud (disabled by default). -- "huawei" for Huawei Cloud (enabled by default). - "hetzner" for Hetzner Cloud (enabled by default). The third optional configuration setting is `overwrite`. When `overwrite` is @@ -128,20 +130,6 @@ _Tencent Cloud_ } ------------------------------------------------------------------------------- -_Huawei Cloud_ - -[source,json] -------------------------------------------------------------------------------- -{ - "cloud": { - "availability_zone": "cn-east-2b", - "instance.id": "37da9890-8289-4c58-ba34-a8271c4a8216", - "provider": "huawei", - "region": "cn-east-2" - } -} -------------------------------------------------------------------------------- - _Alibaba Cloud_ This metadata is only available when VPC is selected as the network type of the diff --git a/libbeat/processors/add_cloud_metadata/provider_huawei_cloud.go b/libbeat/processors/add_cloud_metadata/provider_huawei_cloud.go deleted file mode 100644 index 36683e74a134..000000000000 --- a/libbeat/processors/add_cloud_metadata/provider_huawei_cloud.go +++ /dev/null @@ -1,81 +0,0 @@ -// 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. - -package add_cloud_metadata - -import ( - "encoding/json" - - conf "github.com/elastic/elastic-agent-libs/config" - "github.com/elastic/elastic-agent-libs/mapstr" -) - -type hwMeta struct { - ImageName string `json:"image_name"` - VpcID string `json:"vpc_id"` -} - -type hwMetadata struct { - UUID string `json:"uuid"` - AvailabilityZone string `json:"availability_zone"` - RegionID string `json:"region_id"` - Meta *hwMeta `json:"meta"` - ProjectID string `json:"project_id"` - Name string `json:"name"` -} - -// Huawei Cloud Metadata Service -// Document https://support.huaweicloud.com/usermanual-ecs/ecs_03_0166.html -var huaweiMetadataFetcher = provider{ - Name: "huawei-cloud", - - Local: true, - - Create: func(_ string, c *conf.C) (metadataFetcher, error) { - metadataHost := "169.254.169.254" - huaweiCloudMetadataJSONURI := "/openstack/latest/meta_data.json" - - huaweiCloudSchema := func(m map[string]interface{}) mapstr.M { - m["service"] = mapstr.M{ - "name": "ECS", - } - return mapstr.M{"cloud": m} - } - - urls, err := getMetadataURLs(c, metadataHost, []string{ - huaweiCloudMetadataJSONURI, - }) - if err != nil { - return nil, err - } - responseHandlers := map[string]responseHandler{ - urls[0]: func(all []byte, result *result) error { - data := new(hwMetadata) - err := json.Unmarshal(all, data) - if err != nil { - return err - } - result.metadata.Put("instance.id", data.UUID) - result.metadata.Put("region", data.RegionID) - result.metadata.Put("availability_zone", data.AvailabilityZone) - return nil - }, - } - fetcher := &httpMetadataFetcher{"huawei", nil, responseHandlers, huaweiCloudSchema} - return fetcher, nil - }, -} diff --git a/libbeat/processors/add_cloud_metadata/provider_huawei_cloud_test.go b/libbeat/processors/add_cloud_metadata/provider_huawei_cloud_test.go deleted file mode 100644 index 0ae6fc332f09..000000000000 --- a/libbeat/processors/add_cloud_metadata/provider_huawei_cloud_test.go +++ /dev/null @@ -1,98 +0,0 @@ -// 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. - -package add_cloud_metadata - -import ( - "net/http" - "net/http/httptest" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/elastic/beats/v7/libbeat/beat" - conf "github.com/elastic/elastic-agent-libs/config" - "github.com/elastic/elastic-agent-libs/logp" - "github.com/elastic/elastic-agent-libs/mapstr" -) - -func initHuaweiCloudTestServer() *httptest.Server { - return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.RequestURI == "/openstack/latest/meta_data.json" { - w.Write([]byte(`{ - "random_seed": "CWIZtYK4y5pzMtShTtCKx16qB1DsA/2kL0US4u1fHxedODNr7gos4RgdE/z9eHucnltnlJfDY1remfGL60yzTsvEIWPdECOpPaJm1edIYQaUvQzdeQwKcOQAHjUP5wLQzGA3j3Pw10p7u+M7glHEwNRoEY1WsbVYwzyOOkBnqb+MJ1aOhiRnfNtHOxjLNBSDvjHaQZzoHL+1YNAxDYFezE83nE2m3ciVwZO7xWpdKDQ+W5hYBUsYAWODRMOYqIR/5ZLsfAfxE2DhK+NvuMyJ5yjO+ObQf0DN5nRUSrM5ajs84UVMr9ylJuT78ckh83CLSttsjzXJ+sr07ZFsB6/6NABzziFL7Xn8z/mEBVmFXBiBgg7KcWSoH756w42VSdUezwTy9lW0spRmdvNBKV/PzrYyy0FMiGXXZwMOCyBD05CBRJlsPorwxZLlfRVmNvsTuMYB8TG3UUbFhoR8Bd5en+EC3ncH3QIUDWn0oVg28BVjWe5rADVQLX1h83ti6GD08YUGaxoNPXnJLZfiaucSacby2mG31xysxd8Tg0qPRq7744a1HPVryuauWR9pF0+qDmtskhenxK0FR+TQ4w0fRxTigteBsXx1pQu0iz+B8rP68uokU2faCC2IMHY2Tf9RPCe6Eef0/DdQhBft88PuJLwq52o/0qZ/n9HFL6LdgCU=", - "uuid": "37da9890-8289-4c58-ba34-a8271c4a8216", - "availability_zone": "cn-east-2b", - "enterprise_project_id": "0", - "launch_index": 0, - "instance_type": "c3.large.2", - "meta": { - "os_bit": "64", - "image_name": "CentOS 7.4", - "vpc_id": "6dad7f50-db1d-4cce-b095-d27bc837d4bb" - }, - "region_id": "cn-east-2", - "project_id": "c09b8baf28b845a9b53ed37575cfd61f", - "name": "hwdev-test-1" - }`)) - return - } - - http.Error(w, "not found", http.StatusNotFound) - })) -} - -func TestRetrieveHuaweiCloudMetadata(t *testing.T) { - logp.TestingSetup() - - server := initHuaweiCloudTestServer() - defer server.Close() - - config, err := conf.NewConfigFrom(map[string]interface{}{ - "providers": []string{"huawei"}, - "host": server.Listener.Addr().String(), - }) - - if err != nil { - t.Fatal(err) - } - - p, err := New(config) - if err != nil { - t.Fatal(err) - } - - actual, err := p.Run(&beat.Event{Fields: mapstr.M{}}) - if err != nil { - t.Fatal(err) - } - - expected := mapstr.M{ - "cloud": mapstr.M{ - "provider": "huawei", - "instance": mapstr.M{ - "id": "37da9890-8289-4c58-ba34-a8271c4a8216", - }, - "region": "cn-east-2", - "availability_zone": "cn-east-2b", - "service": mapstr.M{ - "name": "ECS", - }, - }, - } - assert.Equal(t, expected, actual.Fields) -} diff --git a/libbeat/processors/add_cloud_metadata/providers.go b/libbeat/processors/add_cloud_metadata/providers.go index 55e68f756071..77c4c7042add 100644 --- a/libbeat/processors/add_cloud_metadata/providers.go +++ b/libbeat/processors/add_cloud_metadata/providers.go @@ -64,7 +64,7 @@ var cloudMetaProviders = map[string]provider{ "nova-ssl": openstackNovaSSLMetadataFetcher, "qcloud": qcloudMetadataFetcher, "tencent": qcloudMetadataFetcher, - "huawei": huaweiMetadataFetcher, + "huawei": openstackNovaMetadataFetcher, "hetzner": hetznerMetadataFetcher, }