SQL查询可在此链接上找到 https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-usage-metering#expandable-1-label
即使Billing数据集和表格以及GKE使用情况计量数据集和表格都没有问题。
SELECT
resource_usage.cluster_name,
resource_usage.cluster_location,
resource_usage.namespace,
resource_usage.resource_name,
resource_usage.sku_id,
MIN(resource_usage.start_time) AS usage_start_time,
MAX(resource_usage.end_time) AS usage_end_time,
SUM(resource_usage.usage.amount * gcp_billing_export.rate) AS cost
FROM
'cluster-gcp-project.usage-metering-dataset.gke_cluster_resource_usage' AS resource_usage
LEFT JOIN (
SELECT
sku.id AS sku_id,
SUM(cost) / SUM(usage.amount) AS rate,
MIN(usage_start_time) AS min_usage_start_time,
MAX(usage_end_time) AS max_usage_end_time
FROM
'cluster-gcp-project.billing-dataset.billing-table'
WHERE
project.id = "cluster-gcp-project"
GROUP BY
sku_id) AS gcp_billing_export
ON
resource_usage.sku_id = gcp_billing_export.sku_id
WHERE
resource_usage.start_time >= gcp_billing_export.min_usage_start_time
AND resource_usage.end_time <= gcp_billing_export.max_usage_end_time
GROUP BY
resource_usage.cluster_name,
resource_usage.cluster_location,
resource_usage.namespace,
resource_usage.resource_name,
resource_usage.sku_id
答案 0 :(得分:0)
我发现了一个问题,就是该查询中的WHERE条件
WHERE
resource_usage.start_time >= gcp_billing_export.min_usage_start_time
AND resource_usage.end_time <= gcp_billing_export.max_usage_end_time
如您所见,以下条件失败,因此不会返回任何结果。
仅供参考,逻辑是检查并验证两个不同表的开始时间和结束时间并返回值。
感谢大家的回应。