Skip to content

Commit 7820bae

Browse files
authored
Adjust vm latests values to be second to last day (#5385)
1 parent 11bee89 commit 7820bae

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

koku/masu/database/sql/openshift/reporting_ocp_vm_summary_p.sql

+12-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@ WHERE usage_start >= {{start_date}}::date
44
AND source_uuid = {{source_uuid}}
55
;
66

7-
WITH cte_latest_resources AS (
7+
WITH second_to_last_day AS (
8+
SELECT DISTINCT usage_start::date AS day
9+
FROM reporting_ocpusagelineitem_daily_summary
10+
WHERE usage_start >= {{start_date}}::date
11+
AND usage_start <= {{end_date}}::date
12+
AND source_uuid = {{source_uuid}}
13+
AND pod_request_cpu_core_hours IS NOT NULL
14+
ORDER BY day DESC
15+
OFFSET 1 LIMIT 1 -- Get the second-to-last day
16+
),
17+
cte_latest_resources AS (
818
SELECT DISTINCT ON (vm_name)
919
all_labels->>'vm_kubevirt_io_name' AS vm_name,
1020
pod_request_cpu_core_hours AS cpu_request_hours,
1121
pod_request_memory_gigabyte_hours AS memory_request_hours,
1222
node as node_name,
1323
pod_labels as labels
1424
FROM {{schema | sqlsafe}}.reporting_ocpusagelineitem_daily_summary
15-
WHERE usage_start >= {{start_date}}::date
16-
AND usage_start <= {{end_date}}::date
25+
WHERE usage_start::date = (SELECT day FROM second_to_last_day)
1726
AND pod_request_cpu_core_hours IS NOT NULL
1827
AND all_labels ? 'vm_kubevirt_io_name'
1928
ORDER BY vm_name, usage_start DESC

0 commit comments

Comments
 (0)