@@ -181,6 +181,7 @@ INSERT INTO hive.{{schema | sqlsafe}}.gcp_openshift_daily_resource_matched_temp
181
181
instance_type,
182
182
service_id,
183
183
service_alias,
184
+ data_transfer_direction,
184
185
sku_id,
185
186
sku_alias,
186
187
region,
@@ -205,6 +206,11 @@ SELECT cast(uuid() as varchar),
205
206
json_extract_scalar(json_parse(gcp .system_labels ), ' $["compute.googleapis.com/machine_spec"]' ) as instance_type,
206
207
gcp .service_id ,
207
208
max (nullif(gcp .service_description , ' ' )) as service_alias,
209
+ CASE
210
+ WHEN service_description = ' Compute Engine' AND STRPOS(lower (sku_description), ' data transfer in' ) != 0 THEN ' IN'
211
+ WHEN service_description = ' Compute Engine' AND STRPOS(lower (sku_description), ' data transfer' ) != 0 THEN ' OUT'
212
+ ELSE NULL
213
+ END as data_transfer_direction,
208
214
max (nullif(gcp .sku_id , ' ' )) as sku_id,
209
215
max (nullif(gcp .sku_description , ' ' )) as sku_alias,
210
216
gcp .location_region as region,
@@ -233,7 +239,8 @@ GROUP BY gcp.usage_start_time,
233
239
gcp .service_id ,
234
240
gcp .location_region ,
235
241
gcp .invoice_month ,
236
- gcp .labels
242
+ gcp .labels ,
243
+ 10 -- data transfer direction
237
244
;
238
245
239
246
INSERT INTO hive.{{schema | sqlsafe}}.gcp_openshift_daily_tag_matched_temp (
@@ -438,6 +445,8 @@ WHERE ocp.source = {{ocp_source_uuid}}
438
445
AND gcp .ocp_source = {{ocp_source_uuid}}
439
446
AND gcp .year = {{year}}
440
447
AND gcp .month = {{month}}
448
+ -- Filter out Node Network Costs because they cannot be tied to namespace level
449
+ AND data_transfer_direction IS NULL
441
450
GROUP BY gcp .uuid , ocp .namespace , ocp .data_source , ocp .pod_labels , ocp .volume_labels
442
451
;
443
452
@@ -590,6 +599,7 @@ INSERT INTO hive.{{schema | sqlsafe}}.reporting_ocpgcpcostlineitem_project_daily
590
599
instance_type,
591
600
service_id,
592
601
service_alias,
602
+ data_transfer_direction,
593
603
sku_id,
594
604
sku_alias,
595
605
region,
@@ -657,6 +667,7 @@ SELECT pds.gcp_uuid,
657
667
instance_type,
658
668
service_id,
659
669
service_alias,
670
+ NULL as data_transfer_direction,
660
671
sku_id,
661
672
sku_alias,
662
673
region,
@@ -711,6 +722,110 @@ JOIN cte_rankings as r
711
722
WHERE pds .ocp_source = {{ocp_source_uuid}} AND pds .year = {{year}} AND pds .month = {{month}}
712
723
;
713
724
725
+ -- Network costs are currently not mapped to pod metrics
726
+ -- and are filtered out of the above SQL since that is grouped by namespace
727
+ -- and costs are split out by pod metrics, this puts all network costs per node
728
+ -- into a "Network unattributed" project with no cost split and one record per
729
+ -- data direction
730
+ INSERT INTO hive.{{schema | sqlsafe}}.reporting_ocpgcpcostlineitem_project_daily_summary (
731
+ gcp_uuid,
732
+ cluster_id,
733
+ cluster_alias,
734
+ data_source,
735
+ namespace,
736
+ node,
737
+ persistentvolumeclaim,
738
+ persistentvolume,
739
+ storageclass,
740
+ resource_id,
741
+ usage_start,
742
+ usage_end,
743
+ account_id,
744
+ project_id,
745
+ project_name,
746
+ instance_type,
747
+ service_id,
748
+ service_alias,
749
+ data_transfer_direction,
750
+ sku_id,
751
+ sku_alias,
752
+ region,
753
+ unit,
754
+ usage_amount,
755
+ currency,
756
+ invoice_month,
757
+ credit_amount,
758
+ unblended_cost,
759
+ markup_cost,
760
+ project_markup_cost,
761
+ pod_cost,
762
+ pod_credit,
763
+ tags,
764
+ cost_category_id,
765
+ gcp_source,
766
+ ocp_source,
767
+ year,
768
+ month,
769
+ day
770
+ )
771
+ SELECT gcp .uuid as gcp_uuid,
772
+ max (ocp .cluster_id ) as cluster_id,
773
+ max (ocp .cluster_alias ) as cluster_alias,
774
+ max (ocp .data_source ),
775
+ ' Network unattributed' as namespace,
776
+ ocp .node as node,
777
+ max (nullif(ocp .persistentvolumeclaim , ' ' )) as persistentvolumeclaim,
778
+ max (nullif(ocp .persistentvolume , ' ' )) as persistentvolume,
779
+ max (nullif(ocp .storageclass , ' ' )) as storageclass,
780
+ max (ocp .resource_id ) as resource_id,
781
+ max (gcp .usage_start ) as usage_start,
782
+ max (gcp .usage_start ) as usage_end,
783
+ max (gcp .account_id ) as account_id,
784
+ max (gcp .project_id ) as project_id,
785
+ max (gcp .project_name ) as project_name,
786
+ max (instance_type) as instance_type,
787
+ max (nullif(gcp .service_id , ' ' )) as service_id,
788
+ max (gcp .service_alias ) as service_alias,
789
+ max (data_transfer_direction) as data_transfer_direction,
790
+ max (gcp .sku_id ) as sku_id,
791
+ max (gcp .sku_alias ) as sku_alias,
792
+ max (nullif(gcp .region , ' ' )) as region,
793
+ max (gcp .unit ) as unit,
794
+ max (gcp .usage_amount ) as usage_amount,
795
+ max (gcp .currency ) as currency,
796
+ max (gcp .invoice_month ) as invoice_month,
797
+ max (gcp .credit_amount ) as credit_amount,
798
+ max (gcp .unblended_cost ) as unblended_cost,
799
+ max (gcp .unblended_cost * {{markup | sqlsafe}}) as markup_cost,
800
+ max (gcp .unblended_cost * {{markup | sqlsafe}}) AS project_markup_cost,
801
+ max (gcp .unblended_cost ) AS pod_cost,
802
+ cast(NULL AS double) AS pod_credit,
803
+ max (gcp .labels ) as tags,
804
+ max (ocp .cost_category_id ) as cost_category_id,
805
+ {{gcp_source_uuid}} as gcp_source,
806
+ {{ocp_source_uuid}} as ocp_source,
807
+ cast(year(max (gcp .usage_start )) as varchar ) as year,
808
+ cast(month(max (gcp .usage_start )) as varchar ) as month,
809
+ cast(day(max (gcp .usage_start )) as varchar ) as day
810
+ FROM hive.{{ schema | sqlsafe}}.reporting_ocpusagelineitem_daily_summary as ocp
811
+ JOIN hive.{{schema | sqlsafe}}.gcp_openshift_daily_resource_matched_temp as gcp
812
+ ON gcp .usage_start = ocp .usage_start
813
+ AND (
814
+ (strpos(gcp .resource_name , ocp .node ) != 0 AND ocp .data_source = ' Pod' )
815
+ )
816
+ WHERE ocp .source = {{ocp_source_uuid}}
817
+ AND ocp .year = {{year}}
818
+ AND lpad(ocp .month , 2 , ' 0' ) = {{month}} -- Zero pad the month when fewer than 2 characters
819
+ AND ocp .day IN {{days | inclause}}
820
+ AND (ocp .resource_id IS NOT NULL AND ocp .resource_id != ' ' )
821
+ AND gcp .ocp_source = {{ocp_source_uuid}}
822
+ AND gcp .year = {{year}}
823
+ AND gcp .month = {{month}}
824
+ -- Filter for Node Network Costs to tie them to the Network unattributed project
825
+ AND data_transfer_direction IS NOT NULL
826
+ GROUP BY gcp .uuid , ocp .node
827
+ ;
828
+
714
829
INSERT INTO postgres.{{schema | sqlsafe}}.reporting_ocpgcpcostlineitem_project_daily_summary_p (
715
830
uuid,
716
831
report_period_id,
@@ -733,6 +848,9 @@ INSERT INTO postgres.{{schema | sqlsafe}}.reporting_ocpgcpcostlineitem_project_d
733
848
instance_type,
734
849
service_id,
735
850
service_alias,
851
+ infrastructure_data_in_gigabytes,
852
+ infrastructure_data_out_gigabytes,
853
+ data_transfer_direction,
736
854
sku_id,
737
855
sku_alias,
738
856
region,
@@ -771,6 +889,25 @@ SELECT uuid(),
771
889
instance_type,
772
890
service_id,
773
891
service_alias,
892
+ CASE
893
+ WHEN upper (data_transfer_direction) = ' IN' THEN
894
+ -- GCP uses gibibyte but we are tracking this field in gigabytes
895
+ CASE unit
896
+ WHEN ' gibibyte' THEN usage_amount * 1 .07374
897
+ ELSE usage_amount
898
+ END
899
+ ELSE 0
900
+ END as infrastructure_data_in_gigabytes,
901
+ CASE
902
+ WHEN upper (data_transfer_direction) = ' OUT' THEN
903
+ -- GCP uses gibibyte but we are tracking this field in gigabytes
904
+ CASE unit
905
+ WHEN ' gibibyte' THEN usage_amount * 1 .07374
906
+ ELSE usage_amount
907
+ END
908
+ ELSE 0
909
+ END as infrastructure_data_out_gigabytes,
910
+ data_transfer_direction as data_transfer_direction,
774
911
sku_id,
775
912
sku_alias,
776
913
region,
0 commit comments