@@ -4,16 +4,25 @@ WHERE usage_start >= {{start_date}}::date
4
4
AND source_uuid = {{source_uuid}}
5
5
;
6
6
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 (
8
18
SELECT DISTINCT ON (vm_name)
9
19
all_labels- >> ' vm_kubevirt_io_name' AS vm_name,
10
20
pod_request_cpu_core_hours AS cpu_request_hours,
11
21
pod_request_memory_gigabyte_hours AS memory_request_hours,
12
22
node as node_name,
13
23
pod_labels as labels
14
24
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)
17
26
AND pod_request_cpu_core_hours IS NOT NULL
18
27
AND all_labels ? ' vm_kubevirt_io_name'
19
28
ORDER BY vm_name, usage_start DESC
0 commit comments