Skip to content

Commit

Permalink
Adjust vm latests values to be second to last day (#5385)
Browse files Browse the repository at this point in the history
  • Loading branch information
myersCody authored Nov 15, 2024
1 parent 11bee89 commit 7820bae
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions koku/masu/database/sql/openshift/reporting_ocp_vm_summary_p.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ WHERE usage_start >= {{start_date}}::date
AND source_uuid = {{source_uuid}}
;

WITH cte_latest_resources AS (
WITH second_to_last_day AS (
SELECT DISTINCT usage_start::date AS day
FROM reporting_ocpusagelineitem_daily_summary
WHERE usage_start >= {{start_date}}::date
AND usage_start <= {{end_date}}::date
AND source_uuid = {{source_uuid}}
AND pod_request_cpu_core_hours IS NOT NULL
ORDER BY day DESC
OFFSET 1 LIMIT 1 -- Get the second-to-last day
),
cte_latest_resources AS (
SELECT DISTINCT ON (vm_name)
all_labels->>'vm_kubevirt_io_name' AS vm_name,
pod_request_cpu_core_hours AS cpu_request_hours,
pod_request_memory_gigabyte_hours AS memory_request_hours,
node as node_name,
pod_labels as labels
FROM {{schema | sqlsafe}}.reporting_ocpusagelineitem_daily_summary
WHERE usage_start >= {{start_date}}::date
AND usage_start <= {{end_date}}::date
WHERE usage_start::date = (SELECT day FROM second_to_last_day)
AND pod_request_cpu_core_hours IS NOT NULL
AND all_labels ? 'vm_kubevirt_io_name'
ORDER BY vm_name, usage_start DESC
Expand Down

0 comments on commit 7820bae

Please sign in to comment.