provider.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. package cloud
  2. import (
  3. "database/sql"
  4. "errors"
  5. "fmt"
  6. "io"
  7. "regexp"
  8. "strconv"
  9. "strings"
  10. "time"
  11. "k8s.io/klog"
  12. "cloud.google.com/go/compute/metadata"
  13. "github.com/kubecost/cost-model/pkg/clustercache"
  14. "github.com/kubecost/cost-model/pkg/env"
  15. "github.com/kubecost/cost-model/pkg/log"
  16. v1 "k8s.io/api/core/v1"
  17. )
  18. const authSecretPath = "/var/secrets/service-key.json"
  19. const storageConfigSecretPath = "/var/azure-storage-config/azure-storage-config.json"
  20. const defaultShareTenancyCost = "true"
  21. var createTableStatements = []string{
  22. `CREATE TABLE IF NOT EXISTS names (
  23. cluster_id VARCHAR(255) NOT NULL,
  24. cluster_name VARCHAR(255) NULL,
  25. PRIMARY KEY (cluster_id)
  26. );`,
  27. }
  28. // ReservedInstanceData keeps record of resources on a node should be
  29. // priced at reserved rates
  30. type ReservedInstanceData struct {
  31. ReservedCPU int64 `json:"reservedCPU"`
  32. ReservedRAM int64 `json:"reservedRAM"`
  33. CPUCost float64 `json:"CPUHourlyCost"`
  34. RAMCost float64 `json:"RAMHourlyCost"`
  35. }
  36. // Node is the interface by which the provider and cost model communicate Node prices.
  37. // The provider will best-effort try to fill out this struct.
  38. type Node struct {
  39. Cost string `json:"hourlyCost"`
  40. VCPU string `json:"CPU"`
  41. VCPUCost string `json:"CPUHourlyCost"`
  42. RAM string `json:"RAM"`
  43. RAMBytes string `json:"RAMBytes"`
  44. RAMCost string `json:"RAMGBHourlyCost"`
  45. Storage string `json:"storage"`
  46. StorageCost string `json:"storageHourlyCost"`
  47. UsesBaseCPUPrice bool `json:"usesDefaultPrice"`
  48. BaseCPUPrice string `json:"baseCPUPrice"` // Used to compute an implicit RAM GB/Hr price when RAM pricing is not provided.
  49. BaseRAMPrice string `json:"baseRAMPrice"` // Used to compute an implicit RAM GB/Hr price when RAM pricing is not provided.
  50. BaseGPUPrice string `json:"baseGPUPrice"`
  51. UsageType string `json:"usageType"`
  52. GPU string `json:"gpu"` // GPU represents the number of GPU on the instance
  53. GPUName string `json:"gpuName"`
  54. GPUCost string `json:"gpuCost"`
  55. InstanceType string `json:"instanceType,omitempty"`
  56. Region string `json:"region,omitempty"`
  57. Reserved *ReservedInstanceData `json:"reserved,omitempty"`
  58. ProviderID string `json:"providerID,omitempty"`
  59. PricingType PricingType `json:"pricingType,omitempty"`
  60. }
  61. // IsSpot determines whether or not a Node uses spot by usage type
  62. func (n *Node) IsSpot() bool {
  63. if n != nil {
  64. return strings.Contains(n.UsageType, "spot") || strings.Contains(n.UsageType, "emptible")
  65. } else {
  66. return false
  67. }
  68. }
  69. // LoadBalancer is the interface by which the provider and cost model communicate LoadBalancer prices.
  70. // The provider will best-effort try to fill out this struct.
  71. type LoadBalancer struct {
  72. IngressIPAddresses []string `json:"IngressIPAddresses"`
  73. Cost float64 `json:"hourlyCost"`
  74. }
  75. // TODO: used for dynamic cloud provider price fetching.
  76. // determine what identifies a load balancer in the json returned from the cloud provider pricing API call
  77. // type LBKey interface {
  78. // }
  79. // Network is the interface by which the provider and cost model communicate network egress prices.
  80. // The provider will best-effort try to fill out this struct.
  81. type Network struct {
  82. ZoneNetworkEgressCost float64
  83. RegionNetworkEgressCost float64
  84. InternetNetworkEgressCost float64
  85. }
  86. // PV is the interface by which the provider and cost model communicate PV prices.
  87. // The provider will best-effort try to fill out this struct.
  88. type PV struct {
  89. Cost string `json:"hourlyCost"`
  90. CostPerIO string `json:"costPerIOOperation"`
  91. Class string `json:"storageClass"`
  92. Size string `json:"size"`
  93. Region string `json:"region"`
  94. ProviderID string `json:"providerID,omitempty"`
  95. Parameters map[string]string `json:"parameters"`
  96. }
  97. // Key represents a way for nodes to match between the k8s API and a pricing API
  98. type Key interface {
  99. ID() string // ID represents an exact match
  100. Features() string // Features are a comma separated string of node metadata that could match pricing
  101. GPUType() string // GPUType returns "" if no GPU exists, but the name of the GPU otherwise
  102. }
  103. type PVKey interface {
  104. Features() string
  105. GetStorageClass() string
  106. ID() string
  107. }
  108. // OutOfClusterAllocation represents a cloud provider cost not associated with kubernetes
  109. type OutOfClusterAllocation struct {
  110. Aggregator string `json:"aggregator"`
  111. Environment string `json:"environment"`
  112. Service string `json:"service"`
  113. Cost float64 `json:"cost"`
  114. Cluster string `json:"cluster"`
  115. }
  116. type CustomPricing struct {
  117. Provider string `json:"provider"`
  118. Description string `json:"description"`
  119. CPU string `json:"CPU"`
  120. SpotCPU string `json:"spotCPU"`
  121. RAM string `json:"RAM"`
  122. SpotRAM string `json:"spotRAM"`
  123. GPU string `json:"GPU"`
  124. SpotGPU string `json:"spotGPU"`
  125. Storage string `json:"storage"`
  126. ZoneNetworkEgress string `json:"zoneNetworkEgress"`
  127. RegionNetworkEgress string `json:"regionNetworkEgress"`
  128. InternetNetworkEgress string `json:"internetNetworkEgress"`
  129. FirstFiveForwardingRulesCost string `json:"firstFiveForwardingRulesCost"`
  130. AdditionalForwardingRuleCost string `json:"additionalForwardingRuleCost"`
  131. LBIngressDataCost string `json:"LBIngressDataCost"`
  132. SpotLabel string `json:"spotLabel,omitempty"`
  133. SpotLabelValue string `json:"spotLabelValue,omitempty"`
  134. GpuLabel string `json:"gpuLabel,omitempty"`
  135. GpuLabelValue string `json:"gpuLabelValue,omitempty"`
  136. ServiceKeyName string `json:"awsServiceKeyName,omitempty"`
  137. ServiceKeySecret string `json:"awsServiceKeySecret,omitempty"`
  138. SpotDataRegion string `json:"awsSpotDataRegion,omitempty"`
  139. SpotDataBucket string `json:"awsSpotDataBucket,omitempty"`
  140. SpotDataPrefix string `json:"awsSpotDataPrefix,omitempty"`
  141. ProjectID string `json:"projectID,omitempty"`
  142. AthenaProjectID string `json:"athenaProjectID,omitempty"`
  143. AthenaBucketName string `json:"athenaBucketName"`
  144. AthenaRegion string `json:"athenaRegion"`
  145. AthenaDatabase string `json:"athenaDatabase"`
  146. AthenaTable string `json:"athenaTable"`
  147. MasterPayerARN string `json:"masterPayerARN"`
  148. BillingDataDataset string `json:"billingDataDataset,omitempty"`
  149. CustomPricesEnabled string `json:"customPricesEnabled"`
  150. DefaultIdle string `json:"defaultIdle"`
  151. AzureSubscriptionID string `json:"azureSubscriptionID"`
  152. AzureClientID string `json:"azureClientID"`
  153. AzureClientSecret string `json:"azureClientSecret"`
  154. AzureTenantID string `json:"azureTenantID"`
  155. AzureBillingRegion string `json:"azureBillingRegion"`
  156. CurrencyCode string `json:"currencyCode"`
  157. Discount string `json:"discount"`
  158. NegotiatedDiscount string `json:"negotiatedDiscount"`
  159. SharedOverhead string `json:"sharedOverhead"`
  160. ClusterName string `json:"clusterName"`
  161. SharedNamespaces string `json:"sharedNamespaces"`
  162. SharedLabelNames string `json:"sharedLabelNames"`
  163. SharedLabelValues string `json:"sharedLabelValues"`
  164. ShareTenancyCosts string `json:"shareTenancyCosts"` // TODO clean up configuration so we can use a type other that string (this should be a bool, but the app panics if it's not a string)
  165. ReadOnly string `json:"readOnly"`
  166. KubecostToken string `json:"kubecostToken"`
  167. }
  168. // GetSharedOverheadCostPerMonth parses and returns a float64 representation
  169. // of the configured monthly shared overhead cost. If the string version cannot
  170. // be parsed into a float, an error is logged and 0.0 is returned.
  171. func (cp *CustomPricing) GetSharedOverheadCostPerMonth() float64 {
  172. // Empty string should be interpreted as "no cost", i.e. 0.0
  173. if cp.SharedOverhead == "" {
  174. return 0.0
  175. }
  176. // Attempt to parse, but log and return 0.0 if that fails.
  177. sharedCostPerMonth, err := strconv.ParseFloat(cp.SharedOverhead, 64)
  178. if err != nil {
  179. log.Errorf("SharedOverhead: failed to parse shared overhead \"%s\": %s", cp.SharedOverhead, err)
  180. return 0.0
  181. }
  182. return sharedCostPerMonth
  183. }
  184. type ServiceAccountStatus struct {
  185. Checks []*ServiceAccountCheck `json:"checks"`
  186. }
  187. type ServiceAccountCheck struct {
  188. Message string `json:"message"`
  189. Status bool `json:"status"`
  190. AdditionalInfo string `json:"additionalInfo"`
  191. }
  192. type PricingSources struct {
  193. PricingSources map[string]*PricingSource
  194. }
  195. type PricingSource struct {
  196. Name string `json:"name"`
  197. Available bool `json:"available"`
  198. Error string `json:"error"`
  199. }
  200. type PricingType string
  201. const (
  202. Api PricingType = "api"
  203. Spot PricingType = "spot"
  204. Reserved PricingType = "reserved"
  205. SavingsPlan PricingType = "savingsPlan"
  206. CsvExact PricingType = "csvExact"
  207. CsvClass PricingType = "csvClass"
  208. DefaultPrices PricingType = "defaultPrices"
  209. )
  210. type PricingMatchMetadata struct {
  211. TotalNodes int `json:"TotalNodes"`
  212. PricingTypeCounts map[PricingType]int `json:"PricingType"`
  213. }
  214. // Provider represents a k8s provider.
  215. type Provider interface {
  216. ClusterInfo() (map[string]string, error)
  217. GetAddresses() ([]byte, error)
  218. GetDisks() ([]byte, error)
  219. NodePricing(Key) (*Node, error)
  220. PVPricing(PVKey) (*PV, error)
  221. NetworkPricing() (*Network, error) // TODO: add key interface arg for dynamic price fetching
  222. LoadBalancerPricing() (*LoadBalancer, error) // TODO: add key interface arg for dynamic price fetching
  223. AllNodePricing() (interface{}, error)
  224. DownloadPricingData() error
  225. GetKey(map[string]string, *v1.Node) Key
  226. GetPVKey(*v1.PersistentVolume, map[string]string, string) PVKey
  227. UpdateConfig(r io.Reader, updateType string) (*CustomPricing, error)
  228. UpdateConfigFromConfigMap(map[string]string) (*CustomPricing, error)
  229. GetConfig() (*CustomPricing, error)
  230. GetManagementPlatform() (string, error)
  231. GetLocalStorageQuery(time.Duration, time.Duration, bool, bool) string
  232. ExternalAllocations(string, string, []string, string, string, bool) ([]*OutOfClusterAllocation, error)
  233. ApplyReservedInstancePricing(map[string]*Node)
  234. ServiceAccountStatus() *ServiceAccountStatus
  235. PricingSourceStatus() map[string]*PricingSource
  236. ClusterManagementPricing() (string, float64, error)
  237. CombinedDiscountForNode(string, bool, float64, float64) float64
  238. Regions() []string
  239. }
  240. // ClusterName returns the name defined in cluster info, defaulting to the
  241. // CLUSTER_ID environment variable
  242. func ClusterName(p Provider) string {
  243. info, err := p.ClusterInfo()
  244. if err != nil {
  245. return env.GetClusterID()
  246. }
  247. name, ok := info["name"]
  248. if !ok {
  249. return env.GetClusterID()
  250. }
  251. return name
  252. }
  253. // CustomPricesEnabled returns the boolean equivalent of the cloup provider's custom prices flag,
  254. // indicating whether or not the cluster is using custom pricing.
  255. func CustomPricesEnabled(p Provider) bool {
  256. config, err := p.GetConfig()
  257. if err != nil {
  258. return false
  259. }
  260. // TODO:CLEANUP what is going on with this?
  261. if config.NegotiatedDiscount == "" {
  262. config.NegotiatedDiscount = "0%"
  263. }
  264. return config.CustomPricesEnabled == "true"
  265. }
  266. // AllocateIdleByDefault returns true if the application settings specify to allocate idle by default
  267. func AllocateIdleByDefault(p Provider) bool {
  268. config, err := p.GetConfig()
  269. if err != nil {
  270. return false
  271. }
  272. return config.DefaultIdle == "true"
  273. }
  274. // SharedNamespace returns a list of names of shared namespaces, as defined in the application settings
  275. func SharedNamespaces(p Provider) []string {
  276. namespaces := []string{}
  277. config, err := p.GetConfig()
  278. if err != nil {
  279. return namespaces
  280. }
  281. if config.SharedNamespaces == "" {
  282. return namespaces
  283. }
  284. // trim spaces so that "kube-system, kubecost" is equivalent to "kube-system,kubecost"
  285. for _, ns := range strings.Split(config.SharedNamespaces, ",") {
  286. namespaces = append(namespaces, strings.Trim(ns, " "))
  287. }
  288. return namespaces
  289. }
  290. // SharedLabel returns the configured set of shared labels as a parallel tuple of keys to values; e.g.
  291. // for app:kubecost,type:staging this returns (["app", "type"], ["kubecost", "staging"]) in order to
  292. // match the signature of the NewSharedResourceInfo
  293. func SharedLabels(p Provider) ([]string, []string) {
  294. names := []string{}
  295. values := []string{}
  296. config, err := p.GetConfig()
  297. if err != nil {
  298. return names, values
  299. }
  300. if config.SharedLabelNames == "" || config.SharedLabelValues == "" {
  301. return names, values
  302. }
  303. ks := strings.Split(config.SharedLabelNames, ",")
  304. vs := strings.Split(config.SharedLabelValues, ",")
  305. if len(ks) != len(vs) {
  306. klog.V(2).Infof("[Warning] shared labels have mis-matched lengths: %d names, %d values", len(ks), len(vs))
  307. return names, values
  308. }
  309. for i := range ks {
  310. names = append(names, strings.Trim(ks[i], " "))
  311. values = append(values, strings.Trim(vs[i], " "))
  312. }
  313. return names, values
  314. }
  315. // ShareTenancyCosts returns true if the application settings specify to share
  316. // tenancy costs by default.
  317. func ShareTenancyCosts(p Provider) bool {
  318. config, err := p.GetConfig()
  319. if err != nil {
  320. return false
  321. }
  322. return config.ShareTenancyCosts == "true"
  323. }
  324. func NewCrossClusterProvider(ctype string, overrideConfigPath string, cache clustercache.ClusterCache) (Provider, error) {
  325. if ctype == "aws" {
  326. return &AWS{
  327. Clientset: cache,
  328. Config: NewProviderConfig(overrideConfigPath),
  329. }, nil
  330. } else if ctype == "gcp" {
  331. return &GCP{
  332. Clientset: cache,
  333. Config: NewProviderConfig(overrideConfigPath),
  334. }, nil
  335. } else if ctype == "azure" {
  336. return &Azure{
  337. Clientset: cache,
  338. Config: NewProviderConfig(overrideConfigPath),
  339. }, nil
  340. }
  341. return &CustomProvider{
  342. Clientset: cache,
  343. Config: NewProviderConfig(overrideConfigPath),
  344. }, nil
  345. }
  346. // NewProvider looks at the nodespec or provider metadata server to decide which provider to instantiate.
  347. func NewProvider(cache clustercache.ClusterCache, apiKey string) (Provider, error) {
  348. nodes := cache.GetAllNodes()
  349. if len(nodes) == 0 {
  350. return nil, fmt.Errorf("Could not locate any nodes for cluster.")
  351. }
  352. provider := strings.ToLower(nodes[0].Spec.ProviderID)
  353. if env.IsUseCSVProvider() {
  354. klog.Infof("Using CSV Provider with CSV at %s", env.GetCSVPath())
  355. configFileName := ""
  356. if metadata.OnGCE() {
  357. configFileName = "gcp.json"
  358. } else if strings.HasPrefix(provider, "aws") {
  359. configFileName = "aws.json"
  360. } else if strings.HasPrefix(provider, "azure") {
  361. configFileName = "azure.json"
  362. } else {
  363. configFileName = "default.json"
  364. }
  365. return &CSVProvider{
  366. CSVLocation: env.GetCSVPath(),
  367. CustomProvider: &CustomProvider{
  368. Clientset: cache,
  369. Config: NewProviderConfig(configFileName),
  370. },
  371. }, nil
  372. }
  373. if metadata.OnGCE() {
  374. klog.V(3).Info("metadata reports we are in GCE")
  375. if apiKey == "" {
  376. return nil, errors.New("Supply a GCP Key to start getting data")
  377. }
  378. return &GCP{
  379. Clientset: cache,
  380. APIKey: apiKey,
  381. Config: NewProviderConfig("gcp.json"),
  382. }, nil
  383. }
  384. if strings.HasPrefix(provider, "aws") {
  385. klog.V(2).Info("Found ProviderID starting with \"aws\", using AWS Provider")
  386. return &AWS{
  387. Clientset: cache,
  388. Config: NewProviderConfig("aws.json"),
  389. }, nil
  390. } else if strings.HasPrefix(provider, "azure") {
  391. klog.V(2).Info("Found ProviderID starting with \"azure\", using Azure Provider")
  392. return &Azure{
  393. Clientset: cache,
  394. Config: NewProviderConfig("azure.json"),
  395. }, nil
  396. } else {
  397. klog.V(2).Info("Unsupported provider, falling back to default")
  398. return &CustomProvider{
  399. Clientset: cache,
  400. Config: NewProviderConfig("default.json"),
  401. }, nil
  402. }
  403. }
  404. func UpdateClusterMeta(cluster_id, cluster_name string) error {
  405. pw := env.GetRemotePW()
  406. address := env.GetSQLAddress()
  407. connStr := fmt.Sprintf("postgres://postgres:%s@%s:5432?sslmode=disable", pw, address)
  408. db, err := sql.Open("postgres", connStr)
  409. if err != nil {
  410. return err
  411. }
  412. defer db.Close()
  413. updateStmt := `UPDATE names SET cluster_name = $1 WHERE cluster_id = $2;`
  414. _, err = db.Exec(updateStmt, cluster_name, cluster_id)
  415. if err != nil {
  416. return err
  417. }
  418. return nil
  419. }
  420. func CreateClusterMeta(cluster_id, cluster_name string) error {
  421. pw := env.GetRemotePW()
  422. address := env.GetSQLAddress()
  423. connStr := fmt.Sprintf("postgres://postgres:%s@%s:5432?sslmode=disable", pw, address)
  424. db, err := sql.Open("postgres", connStr)
  425. if err != nil {
  426. return err
  427. }
  428. defer db.Close()
  429. for _, stmt := range createTableStatements {
  430. _, err := db.Exec(stmt)
  431. if err != nil {
  432. return err
  433. }
  434. }
  435. insertStmt := `INSERT INTO names (cluster_id, cluster_name) VALUES ($1, $2);`
  436. _, err = db.Exec(insertStmt, cluster_id, cluster_name)
  437. if err != nil {
  438. return err
  439. }
  440. return nil
  441. }
  442. func GetClusterMeta(cluster_id string) (string, string, error) {
  443. pw := env.GetRemotePW()
  444. address := env.GetSQLAddress()
  445. connStr := fmt.Sprintf("postgres://postgres:%s@%s:5432?sslmode=disable", pw, address)
  446. db, err := sql.Open("postgres", connStr)
  447. defer db.Close()
  448. query := `SELECT cluster_id, cluster_name
  449. FROM names
  450. WHERE cluster_id = ?`
  451. rows, err := db.Query(query, cluster_id)
  452. if err != nil {
  453. return "", "", err
  454. }
  455. defer rows.Close()
  456. var (
  457. sql_cluster_id string
  458. cluster_name string
  459. )
  460. for rows.Next() {
  461. if err := rows.Scan(&sql_cluster_id, &cluster_name); err != nil {
  462. return "", "", err
  463. }
  464. }
  465. return sql_cluster_id, cluster_name, nil
  466. }
  467. func GetOrCreateClusterMeta(cluster_id, cluster_name string) (string, string, error) {
  468. id, name, err := GetClusterMeta(cluster_id)
  469. if err != nil {
  470. err := CreateClusterMeta(cluster_id, cluster_name)
  471. if err != nil {
  472. return "", "", err
  473. }
  474. }
  475. if id == "" {
  476. err := CreateClusterMeta(cluster_id, cluster_name)
  477. if err != nil {
  478. return "", "", err
  479. }
  480. }
  481. return id, name, nil
  482. }
  483. // ParseID attempts to parse a ProviderId from a string based on formats from the various providers and
  484. // returns the string as is if it cannot find a match
  485. func ParseID(id string) string {
  486. // It's of the form aws:///us-east-2a/i-0fea4fd46592d050b and we want i-0fea4fd46592d050b, if it exists
  487. rx := regexp.MustCompile("aws://[^/]*/[^/]*/([^/]+)")
  488. match := rx.FindStringSubmatch(id)
  489. if len(match) >= 2 {
  490. return match[1]
  491. }
  492. // gce://guestbook-227502/us-central1-a/gke-niko-n1-standard-2-wljla-8df8e58a-hfy7
  493. // => gke-niko-n1-standard-2-wljla-8df8e58a-hfy7
  494. rx = regexp.MustCompile("gce://[^/]*/[^/]*/([^/]+)")
  495. match = rx.FindStringSubmatch(id)
  496. if len(match) >= 2 {
  497. return match[1]
  498. }
  499. // Return id for Azure Provider, CSV Provider and Custom Provider
  500. return id
  501. }
  502. // ParsePVID attempts to parse a PV ProviderId from a string based on formats from the various providers and
  503. // returns the string as is if it cannot find a match
  504. func ParsePVID(id string) string {
  505. // Capture "vol-0fc54c5e83b8d2b76" from "aws://us-east-2a/vol-0fc54c5e83b8d2b76"
  506. rx := regexp.MustCompile("aws:/[^/]*/[^/]*/([^/]+)")
  507. match := rx.FindStringSubmatch(id)
  508. if len(match) >= 2 {
  509. return match[1]
  510. }
  511. // Return id for GCP Provider, Azure Provider, CSV Provider and Custom Provider
  512. return id
  513. }
  514. // ParseLBID attempts to parse a LB ProviderId from a string based on formats from the various providers and
  515. // returns the string as is if it cannot find a match
  516. func ParseLBID(id string) string {
  517. rx := regexp.MustCompile("^([^-]+)-.+amazonaws\\.com$") // Capture "ad9d88195b52a47c89b5055120f28c58" from "ad9d88195b52a47c89b5055120f28c58-1037804914.us-east-2.elb.amazonaws.com"
  518. match := rx.FindStringSubmatch(id)
  519. if len(match) >= 2 {
  520. return match[1]
  521. }
  522. // Return id for GCP Provider, Azure Provider, CSV Provider and Custom Provider
  523. return id
  524. }