provider.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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. }
  239. // ClusterName returns the name defined in cluster info, defaulting to the
  240. // CLUSTER_ID environment variable
  241. func ClusterName(p Provider) string {
  242. info, err := p.ClusterInfo()
  243. if err != nil {
  244. return env.GetClusterID()
  245. }
  246. name, ok := info["name"]
  247. if !ok {
  248. return env.GetClusterID()
  249. }
  250. return name
  251. }
  252. // CustomPricesEnabled returns the boolean equivalent of the cloup provider's custom prices flag,
  253. // indicating whether or not the cluster is using custom pricing.
  254. func CustomPricesEnabled(p Provider) bool {
  255. config, err := p.GetConfig()
  256. if err != nil {
  257. return false
  258. }
  259. // TODO:CLEANUP what is going on with this?
  260. if config.NegotiatedDiscount == "" {
  261. config.NegotiatedDiscount = "0%"
  262. }
  263. return config.CustomPricesEnabled == "true"
  264. }
  265. // AllocateIdleByDefault returns true if the application settings specify to allocate idle by default
  266. func AllocateIdleByDefault(p Provider) bool {
  267. config, err := p.GetConfig()
  268. if err != nil {
  269. return false
  270. }
  271. return config.DefaultIdle == "true"
  272. }
  273. // SharedNamespace returns a list of names of shared namespaces, as defined in the application settings
  274. func SharedNamespaces(p Provider) []string {
  275. namespaces := []string{}
  276. config, err := p.GetConfig()
  277. if err != nil {
  278. return namespaces
  279. }
  280. if config.SharedNamespaces == "" {
  281. return namespaces
  282. }
  283. // trim spaces so that "kube-system, kubecost" is equivalent to "kube-system,kubecost"
  284. for _, ns := range strings.Split(config.SharedNamespaces, ",") {
  285. namespaces = append(namespaces, strings.Trim(ns, " "))
  286. }
  287. return namespaces
  288. }
  289. // SharedLabel returns the configured set of shared labels as a parallel tuple of keys to values; e.g.
  290. // for app:kubecost,type:staging this returns (["app", "type"], ["kubecost", "staging"]) in order to
  291. // match the signature of the NewSharedResourceInfo
  292. func SharedLabels(p Provider) ([]string, []string) {
  293. names := []string{}
  294. values := []string{}
  295. config, err := p.GetConfig()
  296. if err != nil {
  297. return names, values
  298. }
  299. if config.SharedLabelNames == "" || config.SharedLabelValues == "" {
  300. return names, values
  301. }
  302. ks := strings.Split(config.SharedLabelNames, ",")
  303. vs := strings.Split(config.SharedLabelValues, ",")
  304. if len(ks) != len(vs) {
  305. klog.V(2).Infof("[Warning] shared labels have mis-matched lengths: %d names, %d values", len(ks), len(vs))
  306. return names, values
  307. }
  308. for i := range ks {
  309. names = append(names, strings.Trim(ks[i], " "))
  310. values = append(values, strings.Trim(vs[i], " "))
  311. }
  312. return names, values
  313. }
  314. // ShareTenancyCosts returns true if the application settings specify to share
  315. // tenancy costs by default.
  316. func ShareTenancyCosts(p Provider) bool {
  317. config, err := p.GetConfig()
  318. if err != nil {
  319. return false
  320. }
  321. return config.ShareTenancyCosts == "true"
  322. }
  323. func NewCrossClusterProvider(ctype string, overrideConfigPath string, cache clustercache.ClusterCache) (Provider, error) {
  324. if ctype == "aws" {
  325. return &AWS{
  326. Clientset: cache,
  327. Config: NewProviderConfig(overrideConfigPath),
  328. }, nil
  329. } else if ctype == "gcp" {
  330. return &GCP{
  331. Clientset: cache,
  332. Config: NewProviderConfig(overrideConfigPath),
  333. }, nil
  334. } else if ctype == "azure" {
  335. return &Azure{
  336. Clientset: cache,
  337. Config: NewProviderConfig(overrideConfigPath),
  338. }, nil
  339. }
  340. return &CustomProvider{
  341. Clientset: cache,
  342. Config: NewProviderConfig(overrideConfigPath),
  343. }, nil
  344. }
  345. // NewProvider looks at the nodespec or provider metadata server to decide which provider to instantiate.
  346. func NewProvider(cache clustercache.ClusterCache, apiKey string) (Provider, error) {
  347. nodes := cache.GetAllNodes()
  348. if len(nodes) == 0 {
  349. return nil, fmt.Errorf("Could not locate any nodes for cluster.")
  350. }
  351. provider := strings.ToLower(nodes[0].Spec.ProviderID)
  352. if env.IsUseCSVProvider() {
  353. klog.Infof("Using CSV Provider with CSV at %s", env.GetCSVPath())
  354. configFileName := ""
  355. if metadata.OnGCE() {
  356. configFileName = "gcp.json"
  357. } else if strings.HasPrefix(provider, "aws") {
  358. configFileName = "aws.json"
  359. } else if strings.HasPrefix(provider, "azure") {
  360. configFileName = "azure.json"
  361. } else {
  362. configFileName = "default.json"
  363. }
  364. return &CSVProvider{
  365. CSVLocation: env.GetCSVPath(),
  366. CustomProvider: &CustomProvider{
  367. Clientset: cache,
  368. Config: NewProviderConfig(configFileName),
  369. },
  370. }, nil
  371. }
  372. if metadata.OnGCE() {
  373. klog.V(3).Info("metadata reports we are in GCE")
  374. if apiKey == "" {
  375. return nil, errors.New("Supply a GCP Key to start getting data")
  376. }
  377. return &GCP{
  378. Clientset: cache,
  379. APIKey: apiKey,
  380. Config: NewProviderConfig("gcp.json"),
  381. }, nil
  382. }
  383. if strings.HasPrefix(provider, "aws") {
  384. klog.V(2).Info("Found ProviderID starting with \"aws\", using AWS Provider")
  385. return &AWS{
  386. Clientset: cache,
  387. Config: NewProviderConfig("aws.json"),
  388. }, nil
  389. } else if strings.HasPrefix(provider, "azure") {
  390. klog.V(2).Info("Found ProviderID starting with \"azure\", using Azure Provider")
  391. return &Azure{
  392. Clientset: cache,
  393. Config: NewProviderConfig("azure.json"),
  394. }, nil
  395. } else {
  396. klog.V(2).Info("Unsupported provider, falling back to default")
  397. return &CustomProvider{
  398. Clientset: cache,
  399. Config: NewProviderConfig("default.json"),
  400. }, nil
  401. }
  402. }
  403. func UpdateClusterMeta(cluster_id, cluster_name string) error {
  404. pw := env.GetRemotePW()
  405. address := env.GetSQLAddress()
  406. connStr := fmt.Sprintf("postgres://postgres:%s@%s:5432?sslmode=disable", pw, address)
  407. db, err := sql.Open("postgres", connStr)
  408. if err != nil {
  409. return err
  410. }
  411. defer db.Close()
  412. updateStmt := `UPDATE names SET cluster_name = $1 WHERE cluster_id = $2;`
  413. _, err = db.Exec(updateStmt, cluster_name, cluster_id)
  414. if err != nil {
  415. return err
  416. }
  417. return nil
  418. }
  419. func CreateClusterMeta(cluster_id, cluster_name string) error {
  420. pw := env.GetRemotePW()
  421. address := env.GetSQLAddress()
  422. connStr := fmt.Sprintf("postgres://postgres:%s@%s:5432?sslmode=disable", pw, address)
  423. db, err := sql.Open("postgres", connStr)
  424. if err != nil {
  425. return err
  426. }
  427. defer db.Close()
  428. for _, stmt := range createTableStatements {
  429. _, err := db.Exec(stmt)
  430. if err != nil {
  431. return err
  432. }
  433. }
  434. insertStmt := `INSERT INTO names (cluster_id, cluster_name) VALUES ($1, $2);`
  435. _, err = db.Exec(insertStmt, cluster_id, cluster_name)
  436. if err != nil {
  437. return err
  438. }
  439. return nil
  440. }
  441. func GetClusterMeta(cluster_id string) (string, string, error) {
  442. pw := env.GetRemotePW()
  443. address := env.GetSQLAddress()
  444. connStr := fmt.Sprintf("postgres://postgres:%s@%s:5432?sslmode=disable", pw, address)
  445. db, err := sql.Open("postgres", connStr)
  446. defer db.Close()
  447. query := `SELECT cluster_id, cluster_name
  448. FROM names
  449. WHERE cluster_id = ?`
  450. rows, err := db.Query(query, cluster_id)
  451. if err != nil {
  452. return "", "", err
  453. }
  454. defer rows.Close()
  455. var (
  456. sql_cluster_id string
  457. cluster_name string
  458. )
  459. for rows.Next() {
  460. if err := rows.Scan(&sql_cluster_id, &cluster_name); err != nil {
  461. return "", "", err
  462. }
  463. }
  464. return sql_cluster_id, cluster_name, nil
  465. }
  466. func GetOrCreateClusterMeta(cluster_id, cluster_name string) (string, string, error) {
  467. id, name, err := GetClusterMeta(cluster_id)
  468. if err != nil {
  469. err := CreateClusterMeta(cluster_id, cluster_name)
  470. if err != nil {
  471. return "", "", err
  472. }
  473. }
  474. if id == "" {
  475. err := CreateClusterMeta(cluster_id, cluster_name)
  476. if err != nil {
  477. return "", "", err
  478. }
  479. }
  480. return id, name, nil
  481. }
  482. // ParseID attempts to parse a ProviderId from a string based on formats from the various providers and
  483. // returns the string as is if it cannot find a match
  484. func ParseID(id string) string {
  485. // It's of the form aws:///us-east-2a/i-0fea4fd46592d050b and we want i-0fea4fd46592d050b, if it exists
  486. rx := regexp.MustCompile("aws://[^/]*/[^/]*/([^/]+)")
  487. match := rx.FindStringSubmatch(id)
  488. if len(match) >= 2 {
  489. return match[1]
  490. }
  491. // gce://guestbook-227502/us-central1-a/gke-niko-n1-standard-2-wljla-8df8e58a-hfy7
  492. // => gke-niko-n1-standard-2-wljla-8df8e58a-hfy7
  493. rx = regexp.MustCompile("gce://[^/]*/[^/]*/([^/]+)")
  494. match = rx.FindStringSubmatch(id)
  495. if len(match) >= 2 {
  496. return match[1]
  497. }
  498. // Return id for Azure Provider, CSV Provider and Custom Provider
  499. return id
  500. }
  501. // ParsePVID attempts to parse a PV ProviderId from a string based on formats from the various providers and
  502. // returns the string as is if it cannot find a match
  503. func ParsePVID(id string) string {
  504. // Capture "vol-0fc54c5e83b8d2b76" from "aws://us-east-2a/vol-0fc54c5e83b8d2b76"
  505. rx := regexp.MustCompile("aws:/[^/]*/[^/]*/([^/]+)")
  506. match := rx.FindStringSubmatch(id)
  507. if len(match) >= 2 {
  508. return match[1]
  509. }
  510. // Return id for GCP Provider, Azure Provider, CSV Provider and Custom Provider
  511. return id
  512. }
  513. // ParseLBID attempts to parse a LB ProviderId from a string based on formats from the various providers and
  514. // returns the string as is if it cannot find a match
  515. func ParseLBID(id string) string {
  516. rx := regexp.MustCompile("^([^-]+)-.+amazonaws\\.com$") // Capture "ad9d88195b52a47c89b5055120f28c58" from "ad9d88195b52a47c89b5055120f28c58-1037804914.us-east-2.elb.amazonaws.com"
  517. match := rx.FindStringSubmatch(id)
  518. if len(match) >= 2 {
  519. return match[1]
  520. }
  521. // Return id for GCP Provider, Azure Provider, CSV Provider and Custom Provider
  522. return id
  523. }