athenaintegration.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. package aws
  2. import (
  3. "context"
  4. "fmt"
  5. "strconv"
  6. "strings"
  7. "time"
  8. "github.com/aws/aws-sdk-go-v2/service/athena/types"
  9. "github.com/opencost/opencost/core/pkg/log"
  10. "github.com/opencost/opencost/core/pkg/opencost"
  11. "github.com/opencost/opencost/core/pkg/util/timeutil"
  12. "github.com/opencost/opencost/pkg/cloud"
  13. )
  14. const LabelColumnPrefix = "resource_tags_user_"
  15. const AWSLabelColumnPrefix = "resource_tags_aws_"
  16. const AthenaResourceTagPrefix = "resource_tags_"
  17. // athenaDateLayout is the default AWS date format
  18. const AthenaDateLayout = "2006-01-02 15:04:05.000"
  19. // Cost Columns
  20. const AthenaPricingColumn = "line_item_unblended_cost"
  21. // Amortized Cost Columns
  22. const AthenaRIPricingColumn = "reservation_effective_cost"
  23. const AthenaSPPricingColumn = "savings_plan_savings_plan_effective_cost"
  24. // Net Cost Columns
  25. const AthenaNetPricingColumn = "line_item_net_unblended_cost"
  26. var AthenaNetPricingCoalesce = fmt.Sprintf("COALESCE(%s, %s, 0)", AthenaNetPricingColumn, AthenaPricingColumn)
  27. // Amortized Net Cost Columns
  28. const AthenaNetRIPricingColumn = "reservation_net_effective_cost"
  29. var AthenaNetRIPricingCoalesce = fmt.Sprintf("COALESCE(%s, %s, 0)", AthenaNetRIPricingColumn, AthenaRIPricingColumn)
  30. const AthenaNetSPPricingColumn = "savings_plan_net_savings_plan_effective_cost"
  31. var AthenaNetSPPricingCoalesce = fmt.Sprintf("COALESCE(%s, %s, 0)", AthenaNetSPPricingColumn, AthenaSPPricingColumn)
  32. // athenaDateTruncColumn Aggregates line items from the hourly level to daily. "line_item_usage_start_date" is used because at
  33. // all time values 00:00-23:00 it will truncate to the correct date.
  34. const AthenaDateColumn = "line_item_usage_start_date"
  35. const AthenaDateTruncColumn = "DATE_TRUNC('day'," + AthenaDateColumn + ") as usage_date"
  36. const AthenaWhereDateFmt = `line_item_usage_start_date >= date '%s' AND line_item_usage_start_date < date '%s'`
  37. const AthenaWhereUsage = "(line_item_line_item_type = 'Usage' OR line_item_line_item_type = 'DiscountedUsage' OR line_item_line_item_type = 'SavingsPlanCoveredUsage' OR line_item_line_item_type = 'EdpDiscount' OR line_item_line_item_type = 'PrivateRateDiscount')"
  38. // AthenaQueryIndexes is a struct for holding the context of a query
  39. type AthenaQueryIndexes struct {
  40. Query string
  41. ColumnIndexes map[string]int
  42. TagColumns []string
  43. AWSTagColumns []string
  44. ListCostColumn string
  45. NetCostColumn string
  46. AmortizedNetCostColumn string
  47. AmortizedCostColumn string
  48. IsK8sColumn string
  49. }
  50. type AthenaIntegration struct {
  51. AthenaQuerier
  52. }
  53. // Query Athena for CUR data and build a new CloudCostSetRange containing the info
  54. func (ai *AthenaIntegration) GetCloudCost(start, end time.Time) (*opencost.CloudCostSetRange, error) {
  55. return ai.getCloudCost(start, end, 0)
  56. }
  57. func (ai *AthenaIntegration) RefreshStatus() cloud.ConnectionStatus {
  58. end := time.Now().UTC().Truncate(timeutil.Day)
  59. start := end.Add(-7 * timeutil.Day)
  60. // getCloudCost already sets ConnectionStatus in the event there is no error, so we don't need to handle the positive
  61. // case here
  62. _, err := ai.getCloudCost(start, end, 1)
  63. if err != nil {
  64. ai.ConnectionStatus = cloud.FailedConnection
  65. }
  66. return ai.ConnectionStatus
  67. }
  68. func (ai *AthenaIntegration) getCloudCost(start, end time.Time, limit int) (*opencost.CloudCostSetRange, error) {
  69. log.Infof("AthenaIntegration[%s]: GetCloudCost: %s", ai.Key(), opencost.NewWindow(&start, &end).String())
  70. // Query for all column names
  71. allColumns, err := ai.GetColumns()
  72. if err != nil {
  73. return nil, fmt.Errorf("GetCloudCost: error getting Athena columns: %w", err)
  74. }
  75. // List known, hard-coded columns to query
  76. groupByColumns := []string{
  77. AthenaDateTruncColumn,
  78. "line_item_resource_id",
  79. "bill_payer_account_id",
  80. "line_item_usage_account_id",
  81. "line_item_product_code",
  82. "line_item_usage_type",
  83. "product_region_code",
  84. "line_item_availability_zone",
  85. }
  86. // Create query indices
  87. aqi := AthenaQueryIndexes{}
  88. // Add is k8s column
  89. isK8sColumn := ai.GetIsKubernetesColumn(allColumns)
  90. groupByColumns = append(groupByColumns, isK8sColumn)
  91. aqi.IsK8sColumn = isK8sColumn
  92. // Determine which columns are user-defined tags and add those to the list
  93. // of columns to query.
  94. for column := range allColumns {
  95. if strings.HasPrefix(column, LabelColumnPrefix) {
  96. quotedTag := fmt.Sprintf(`"%s"`, column)
  97. groupByColumns = append(groupByColumns, quotedTag)
  98. aqi.TagColumns = append(aqi.TagColumns, quotedTag)
  99. }
  100. if strings.HasPrefix(column, AWSLabelColumnPrefix) {
  101. groupByColumns = append(groupByColumns, column)
  102. aqi.AWSTagColumns = append(aqi.AWSTagColumns, column)
  103. }
  104. }
  105. var selectColumns []string
  106. // Duplicate GroupBy Columns into select columns
  107. selectColumns = append(selectColumns, groupByColumns...)
  108. // Clean Up group by columns
  109. ai.RemoveColumnAliases(groupByColumns)
  110. // Build list cost column and add it to the select columns
  111. listCostColumn := ai.GetListCostColumn()
  112. selectColumns = append(selectColumns, listCostColumn)
  113. aqi.ListCostColumn = listCostColumn
  114. // Build net cost column and add it to select columns
  115. netCostColumn := ai.GetNetCostColumn(allColumns)
  116. selectColumns = append(selectColumns, netCostColumn)
  117. aqi.NetCostColumn = netCostColumn
  118. // Build amortized net cost column and add it to select columns
  119. amortizedNetCostColumn := ai.GetAmortizedNetCostColumn(allColumns)
  120. selectColumns = append(selectColumns, amortizedNetCostColumn)
  121. aqi.AmortizedNetCostColumn = amortizedNetCostColumn
  122. // Build Amortized cost column and add it to select columns
  123. amortizedCostColumn := ai.GetAmortizedCostColumn(allColumns)
  124. selectColumns = append(selectColumns, amortizedCostColumn)
  125. aqi.AmortizedCostColumn = amortizedCostColumn
  126. // Build map of query columns to use for parsing query
  127. aqi.ColumnIndexes = map[string]int{}
  128. for i, column := range selectColumns {
  129. aqi.ColumnIndexes[column] = i
  130. }
  131. whereDate := fmt.Sprintf(AthenaWhereDateFmt, start.Format("2006-01-02"), end.Format("2006-01-02"))
  132. wherePartitions := ai.GetPartitionWhere(start, end)
  133. // Query for all line items with a resource_id or from AWS Marketplace, which did not end before
  134. // the range or start after it. This captures all costs with any amount of
  135. // overlap with the range, for which we will only extract the relevant costs
  136. whereConjuncts := []string{
  137. wherePartitions,
  138. whereDate,
  139. AthenaWhereUsage,
  140. }
  141. columnStr := strings.Join(selectColumns, ", ")
  142. whereClause := strings.Join(whereConjuncts, " AND ")
  143. groupByStr := strings.Join(groupByColumns, ", ")
  144. queryStr := `
  145. SELECT %s
  146. FROM "%s"
  147. WHERE %s
  148. GROUP BY %s
  149. `
  150. if limit > 0 {
  151. queryStr = fmt.Sprintf("%s LIMIT %d", queryStr, limit)
  152. }
  153. aqi.Query = fmt.Sprintf(queryStr, columnStr, ai.Table, whereClause, groupByStr)
  154. ccsr, err := opencost.NewCloudCostSetRange(start, end, opencost.AccumulateOptionDay, ai.Key())
  155. if err != nil {
  156. return nil, err
  157. }
  158. // Generate row handling function.
  159. rowHandler := func(row types.Row) {
  160. cc, err2 := athenaRowToCloudCost(row, aqi)
  161. if err2 != nil {
  162. log.Errorf("AthenaIntegration: GetCloudCost: error while parsing row: %s", err2.Error())
  163. return
  164. }
  165. ccsr.LoadCloudCost(cc)
  166. }
  167. log.Debugf("AthenaIntegration[%s]: GetCloudCost: querying: %s", ai.Key(), aqi.Query)
  168. // Query CUR data and fill out CCSR
  169. err = ai.Query(context.TODO(), aqi.Query, GetAthenaQueryFunc(rowHandler))
  170. if err != nil {
  171. return nil, err
  172. }
  173. ai.ConnectionStatus = ai.GetConnectionStatusFromResult(ccsr, ai.ConnectionStatus)
  174. return ccsr, nil
  175. }
  176. func (ai *AthenaIntegration) GetListCostColumn() string {
  177. var listCostBuilder strings.Builder
  178. listCostBuilder.WriteString("CASE line_item_line_item_type")
  179. listCostBuilder.WriteString(" WHEN 'EdpDiscount' THEN 0")
  180. listCostBuilder.WriteString(" WHEN 'PrivateRateDiscount' THEN 0")
  181. listCostBuilder.WriteString(" ELSE ")
  182. listCostBuilder.WriteString(AthenaPricingColumn)
  183. listCostBuilder.WriteString(" END")
  184. return fmt.Sprintf("SUM(%s) as list_cost", listCostBuilder.String())
  185. }
  186. func (ai *AthenaIntegration) GetNetCostColumn(allColumns map[string]bool) string {
  187. netCostColumn := ""
  188. if allColumns[AthenaNetPricingColumn] { // if Net pricing exists
  189. netCostColumn = AthenaNetPricingCoalesce
  190. } else { // Non-net for if there's no net pricing.
  191. netCostColumn = AthenaPricingColumn
  192. }
  193. return fmt.Sprintf("SUM(%s) as net_cost", netCostColumn)
  194. }
  195. func (ai *AthenaIntegration) GetAmortizedCostColumn(allColumns map[string]bool) string {
  196. amortizedCostCase := ai.GetAmortizedCostCase(allColumns)
  197. return fmt.Sprintf("SUM(%s) as amortized_cost", amortizedCostCase)
  198. }
  199. func (ai *AthenaIntegration) GetAmortizedNetCostColumn(allColumns map[string]bool) string {
  200. amortizedNetCostCase := ""
  201. if allColumns[AthenaNetPricingColumn] { // if Net pricing exists
  202. amortizedNetCostCase = ai.GetAmortizedNetCostCase(allColumns)
  203. } else { // Non-net for if there's no net pricing.
  204. amortizedNetCostCase = ai.GetAmortizedCostCase(allColumns)
  205. }
  206. return fmt.Sprintf("SUM(%s) as amortized_net_cost", amortizedNetCostCase)
  207. }
  208. func (ai *AthenaIntegration) GetAmortizedCostCase(allColumns map[string]bool) string {
  209. // Use unblended costs if Reserved Instances/Savings Plans aren't in use
  210. if !allColumns[AthenaRIPricingColumn] && !allColumns[AthenaSPPricingColumn] {
  211. return AthenaPricingColumn
  212. }
  213. var costBuilder strings.Builder
  214. costBuilder.WriteString("CASE line_item_line_item_type")
  215. if allColumns[AthenaRIPricingColumn] {
  216. costBuilder.WriteString(" WHEN 'DiscountedUsage' THEN ")
  217. costBuilder.WriteString(AthenaRIPricingColumn)
  218. }
  219. if allColumns[AthenaSPPricingColumn] {
  220. costBuilder.WriteString(" WHEN 'SavingsPlanCoveredUsage' THEN ")
  221. costBuilder.WriteString(AthenaSPPricingColumn)
  222. }
  223. costBuilder.WriteString(" ELSE ")
  224. costBuilder.WriteString(AthenaPricingColumn)
  225. costBuilder.WriteString(" END")
  226. return costBuilder.String()
  227. }
  228. func (ai *AthenaIntegration) GetAmortizedNetCostCase(allColumns map[string]bool) string {
  229. // Use net unblended costs if Reserved Instances/Savings Plans aren't in use
  230. if !allColumns[AthenaNetRIPricingColumn] && !allColumns[AthenaNetSPPricingColumn] {
  231. return AthenaNetPricingCoalesce
  232. }
  233. var costBuilder strings.Builder
  234. costBuilder.WriteString("CASE line_item_line_item_type")
  235. if allColumns[AthenaNetRIPricingColumn] {
  236. costBuilder.WriteString(" WHEN 'DiscountedUsage' THEN ")
  237. costBuilder.WriteString(AthenaNetRIPricingCoalesce)
  238. }
  239. if allColumns[AthenaNetSPPricingColumn] {
  240. costBuilder.WriteString(" WHEN 'SavingsPlanCoveredUsage' THEN ")
  241. costBuilder.WriteString(AthenaNetSPPricingCoalesce)
  242. }
  243. costBuilder.WriteString(" ELSE ")
  244. costBuilder.WriteString(AthenaNetPricingCoalesce)
  245. costBuilder.WriteString(" END")
  246. return costBuilder.String()
  247. }
  248. func (ai *AthenaIntegration) RemoveColumnAliases(columns []string) {
  249. for i, column := range columns {
  250. if strings.Contains(column, " as ") {
  251. columnValues := strings.Split(column, " as ")
  252. columns[i] = columnValues[0]
  253. }
  254. }
  255. }
  256. func (ai *AthenaIntegration) ConvertLabelToAWSTag(label string) string {
  257. // if the label already has the column prefix assume that it is in the correct format
  258. if strings.HasPrefix(label, LabelColumnPrefix) {
  259. return label
  260. }
  261. // replace characters with underscore
  262. tag := label
  263. tag = strings.ReplaceAll(tag, ".", "_")
  264. tag = strings.ReplaceAll(tag, "/", "_")
  265. tag = strings.ReplaceAll(tag, ":", "_")
  266. tag = strings.ReplaceAll(tag, "-", "_")
  267. // add prefix and return
  268. return LabelColumnPrefix + tag
  269. }
  270. // GetIsKubernetesColumn builds a column that determines if a row represents kubernetes spend
  271. func (ai *AthenaIntegration) GetIsKubernetesColumn(allColumns map[string]bool) string {
  272. disjuncts := []string{
  273. "line_item_product_code = 'AmazonEKS'", // EKS is always kubernetes
  274. }
  275. // tagColumns is a list of columns where the presence of a value indicates that a resource is part of a kubernetes cluster
  276. tagColumns := []string{
  277. "resource_tags_aws_eks_cluster_name",
  278. "resource_tags_user_eks_cluster_name",
  279. "resource_tags_user_alpha_eksctl_io_cluster_name",
  280. "resource_tags_user_kubernetes_io_service_name",
  281. "resource_tags_user_kubernetes_io_created_for_pvc_name",
  282. "resource_tags_user_kubernetes_io_created_for_pv_name",
  283. }
  284. for _, tagColumn := range tagColumns {
  285. // if tag column is present in the CUR check for it
  286. if _, ok := allColumns[tagColumn]; ok {
  287. disjunctStr := fmt.Sprintf("%s <> ''", tagColumn)
  288. disjuncts = append(disjuncts, disjunctStr)
  289. }
  290. }
  291. return fmt.Sprintf("(%s) as is_kubernetes", strings.Join(disjuncts, " OR "))
  292. }
  293. func (ai *AthenaIntegration) GetPartitionWhere(start, end time.Time) string {
  294. month := time.Date(start.Year(), start.Month(), 1, 0, 0, 0, 0, time.UTC)
  295. endMonth := time.Date(end.Year(), end.Month(), 1, 0, 0, 0, 0, time.UTC)
  296. var disjuncts []string
  297. // For CUR 2.0, check if billing_period partitions actually exist
  298. useBillingPeriodPartitions := false
  299. if ai.CURVersion != "1.0" {
  300. // Check if billing_period partitions exist in the table
  301. if hasBillingPeriod, err := ai.HasBillingPeriodPartitions(); err == nil && hasBillingPeriod {
  302. useBillingPeriodPartitions = true
  303. }
  304. }
  305. for !month.After(endMonth) {
  306. if ai.CURVersion == "1.0" {
  307. // CUR 1.0 uses year and month columns for partitioning
  308. disjuncts = append(disjuncts, fmt.Sprintf("(year = '%d' AND month = '%d')", month.Year(), month.Month()))
  309. } else if useBillingPeriodPartitions {
  310. // CUR 2.0 with billing_period partitions
  311. disjuncts = append(disjuncts, fmt.Sprintf("(billing_period = '%d-%02d')", month.Year(), month.Month()))
  312. } else {
  313. // CUR 2.0 fallback - use date_format functions (less efficient but works without partitions)
  314. disjuncts = append(disjuncts, fmt.Sprintf("(date_format(line_item_usage_start_date, '%%Y') = '%d' AND date_format(line_item_usage_start_date, '%%m') = '%02d')",
  315. month.Year(), month.Month()))
  316. }
  317. month = month.AddDate(0, 1, 0)
  318. }
  319. str := fmt.Sprintf("(%s)", strings.Join(disjuncts, " OR "))
  320. return str
  321. }
  322. func athenaRowToCloudCost(row types.Row, aqi AthenaQueryIndexes) (*opencost.CloudCost, error) {
  323. if len(row.Data) < len(aqi.ColumnIndexes) {
  324. return nil, fmt.Errorf("rowToCloudCost: row with fewer than %d columns (has only %d)", len(aqi.ColumnIndexes), len(row.Data))
  325. }
  326. // Iterate through the slice of tag columns, assigning
  327. // values to the column names, minus the tag prefix.
  328. labels := opencost.CloudCostLabels{}
  329. for _, tagColumnName := range aqi.TagColumns {
  330. // remove quotes
  331. labelName := strings.TrimPrefix(tagColumnName, `"`)
  332. labelName = strings.TrimSuffix(labelName, `"`)
  333. // remove prefix
  334. labelName = strings.TrimPrefix(labelName, LabelColumnPrefix)
  335. value := GetAthenaRowValue(row, aqi.ColumnIndexes, tagColumnName)
  336. if value != "" {
  337. labels[labelName] = value
  338. }
  339. }
  340. for _, awsColumnName := range aqi.AWSTagColumns {
  341. // partially remove prefix leaving "aws_"
  342. labelName := strings.TrimPrefix(awsColumnName, AthenaResourceTagPrefix)
  343. value := GetAthenaRowValue(row, aqi.ColumnIndexes, awsColumnName)
  344. if value != "" {
  345. labels[labelName] = value
  346. }
  347. }
  348. invoiceEntityID := GetAthenaRowValue(row, aqi.ColumnIndexes, "bill_payer_account_id")
  349. accountID := GetAthenaRowValue(row, aqi.ColumnIndexes, "line_item_usage_account_id")
  350. startStr := GetAthenaRowValue(row, aqi.ColumnIndexes, AthenaDateTruncColumn)
  351. providerID := GetAthenaRowValue(row, aqi.ColumnIndexes, "line_item_resource_id")
  352. productCode := GetAthenaRowValue(row, aqi.ColumnIndexes, "line_item_product_code")
  353. usageType := GetAthenaRowValue(row, aqi.ColumnIndexes, "line_item_usage_type")
  354. regionCode := GetAthenaRowValue(row, aqi.ColumnIndexes, "product_region_code")
  355. availabilityZone := GetAthenaRowValue(row, aqi.ColumnIndexes, "line_item_availability_zone")
  356. isK8s, _ := strconv.ParseBool(GetAthenaRowValue(row, aqi.ColumnIndexes, aqi.IsK8sColumn))
  357. k8sPct := 0.0
  358. if isK8s {
  359. k8sPct = 1.0
  360. }
  361. listCost, err := GetAthenaRowValueFloat(row, aqi.ColumnIndexes, aqi.ListCostColumn)
  362. if err != nil {
  363. return nil, err
  364. }
  365. netCost, err := GetAthenaRowValueFloat(row, aqi.ColumnIndexes, aqi.NetCostColumn)
  366. if err != nil {
  367. return nil, err
  368. }
  369. amortizedNetCost, err := GetAthenaRowValueFloat(row, aqi.ColumnIndexes, aqi.AmortizedNetCostColumn)
  370. if err != nil {
  371. return nil, err
  372. }
  373. amortizedCost, err := GetAthenaRowValueFloat(row, aqi.ColumnIndexes, aqi.AmortizedCostColumn)
  374. if err != nil {
  375. return nil, err
  376. }
  377. // Identify resource category in the CUR
  378. category := SelectAWSCategory(providerID, usageType, productCode)
  379. // Retrieve final stanza of product code for ProviderID
  380. if productCode == "AWSELB" || productCode == "AmazonFSx" {
  381. providerID = ParseARN(providerID)
  382. }
  383. if productCode == "AmazonEKS" && category == opencost.ComputeCategory {
  384. if strings.Contains(usageType, "CPU") {
  385. providerID = fmt.Sprintf("%s/CPU", providerID)
  386. } else if strings.Contains(usageType, "GB") {
  387. providerID = fmt.Sprintf("%s/RAM", providerID)
  388. }
  389. }
  390. properties := opencost.CloudCostProperties{
  391. ProviderID: providerID,
  392. Provider: opencost.AWSProvider,
  393. AccountID: accountID,
  394. AccountName: accountID,
  395. InvoiceEntityID: invoiceEntityID,
  396. InvoiceEntityName: invoiceEntityID,
  397. RegionID: regionCode,
  398. AvailabilityZone: availabilityZone,
  399. Service: productCode,
  400. Category: category,
  401. Labels: labels,
  402. }
  403. start, err := time.Parse(AthenaDateLayout, startStr)
  404. if err != nil {
  405. return nil, fmt.Errorf("unable to parse %s: '%s'", AthenaDateTruncColumn, err.Error())
  406. }
  407. end := start.AddDate(0, 0, 1)
  408. cc := &opencost.CloudCost{
  409. Properties: &properties,
  410. Window: opencost.NewWindow(&start, &end),
  411. ListCost: opencost.CostMetric{
  412. Cost: listCost,
  413. KubernetesPercent: k8sPct,
  414. },
  415. NetCost: opencost.CostMetric{
  416. Cost: netCost,
  417. KubernetesPercent: k8sPct,
  418. },
  419. AmortizedNetCost: opencost.CostMetric{
  420. Cost: amortizedNetCost,
  421. KubernetesPercent: k8sPct,
  422. },
  423. AmortizedCost: opencost.CostMetric{
  424. Cost: amortizedCost,
  425. KubernetesPercent: k8sPct,
  426. },
  427. InvoicedCost: opencost.CostMetric{
  428. Cost: netCost, // We are using Net Cost for Invoiced Cost for now as it is the closest approximation
  429. KubernetesPercent: k8sPct,
  430. },
  431. }
  432. return cc, nil
  433. }
  434. func (ai *AthenaIntegration) GetConnectionStatusFromResult(result cloud.EmptyChecker, currentStatus cloud.ConnectionStatus) cloud.ConnectionStatus {
  435. if result.IsEmpty() && currentStatus != cloud.SuccessfulConnection {
  436. return cloud.MissingData
  437. }
  438. return cloud.SuccessfulConnection
  439. }