Skip to content
This repository was archived by the owner on Sep 3, 2020. It is now read-only.
This repository was archived by the owner on Sep 3, 2020. It is now read-only.

GKE Usage Metering Data Studio connector fails on divide-by-zero error  #319

@JoshuaFox

Description

@JoshuaFox

Create a DataStudio report following instructions.

With some projects, you get a blank widget that is based on cost_with_unallocated_untracked. See attachment missing data.jpg. This is ultimately because for some values of sku, the SUM(usage.amount) is 0 in the billing-export table. Presumably this is an ordinary occurrence when an SKU is unused, and so this case should be handled.

Minimal reproduction of divide-by-zero error follows. (To run it, replace table and project identifiers). This is a subquery directly from the connector sourcecode and only uses one table, so the problem is not in complex joins, just in the usage of data that can have zero values.

SELECT
  sku.id AS sku_id,
  project.id AS project_id,
  MIN(usage_start_time) AS min_usage_start_time,
  MAX(usage_end_time) AS max_usage_end_time,
  SUM(usage.amount) AS amount,
  usage.unit AS usage_unit,
  SUM(cost) AS cost,
   (SUM(cost) / SUM(usage.amount)) AS rate
FROM
  `MY_BILLING_EXPORT_PROJECT.BILLING_EXPORT_DATASET.BILLING_EXPORT_TABLE`
WHERE
  usage_start_time >= TIMESTAMP("2010-00-00")
  AND usage_end_time <= TIMESTAMP("2030-01-01")
 AND project.id = "MYPROJECT"
GROUP BY
  project.id,
  sku.id,
  usage.unit

Solution: Handle cases with value 0.

A related issue is at the Google Issue tracker, but apparently here at GitHub is the right place for the elements of this bug that involve the connector.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions