{{- $reportingValues :=  index .Values "openshift-reporting" -}}
apiVersion: metering.openshift.io/v1
kind: ReportQuery
metadata:
  name: persistentvolumeclaim-capacity-raw
  labels:
    operator-metering: "true"
spec:
  columns:
  - name: namespace
    type: varchar
  - name: persistentvolumeclaim
    type: varchar
  - name: labels
    tableHidden: true
    type: map<varchar, varchar>
  - name: persistentvolumeclaim_capacity_bytes
    type: double
    unit: bytes
  - name: timeprecision
    type: double
    unit: seconds
  - name: persistentvolumeclaim_capacity_byte_seconds
    type: double
    unit: byte_seconds
  - name: timestamp
    type: timestamp
    unit: date
  - name: dt
    type: varchar
  inputs:
  - name: PersistentvolumeclaimCapacityBytesDataSourceName
    type: ReportDataSource
    default: persistentvolumeclaim-capacity-bytes
  query: |
    SELECT
        coalesce(element_at(labels, 'exported_namespace'), element_at(labels, 'namespace')) as namespace,
        labels['persistentvolumeclaim'] as persistentvolumeclaim,
        labels,
        amount as persistentvolumeclaim_capacity_bytes,
        timeprecision,
        amount * timeprecision as persistentvolumeclaim_capacity_byte_seconds,
        "timestamp",
        dt
    FROM {| dataSourceTableName .Report.Inputs.PersistentvolumeclaimCapacityBytesDataSourceName |}
---
apiVersion: metering.openshift.io/v1
kind: ReportQuery
metadata:
  name: persistentvolumeclaim-capacity
  labels:
    operator-metering: "true"
spec:
  columns:
  - name: period_start
    type: timestamp
    unit: date
  - name: period_end
    type: timestamp
    unit: date
  - name: namespace
    type: varchar
    unit: kubernetes_namespace
  - name: persistentvolumeclaim
    type: varchar
    unit: kubernetes_persistentvolumeclaim
  - name: persistentvolumeclaim_capacity_bytes
    type: double
    unit: bytes
  inputs:
  - name: ReportingStart
    type: time
  - name: ReportingEnd
    type: time
  - name: PersistentvolumeclaimCapacityRawDataSourceName
    type: ReportDataSource
    default: persistentvolumeclaim-capacity-raw
  query: |
    SELECT
      timestamp '{| default .Report.ReportingStart .Report.Inputs.ReportingStart| prestoTimestamp |}' AS period_start,
      timestamp '{| default .Report.ReportingEnd .Report.Inputs.ReportingEnd | prestoTimestamp |}' AS period_end,
      namespace,
      persistentvolumeclaim,
      sum(persistentvolumeclaim_capacity_bytes) AS persistentvolumeclaim_capacity_bytes
    FROM {| dataSourceTableName .Report.Inputs.PersistentvolumeclaimCapacityRawDataSourceName |}
    WHERE "timestamp" >= timestamp '{| default .Report.ReportingStart .Report.Inputs.ReportingStart | prestoTimestamp |}'
    AND "timestamp" < timestamp '{| default .Report.ReportingEnd .Report.Inputs.ReportingEnd | prestoTimestamp |}'
    AND dt >= '{| default .Report.ReportingStart .Report.Inputs.ReportingStart | prometheusMetricPartitionFormat |}'
    AND dt <= '{| default .Report.ReportingEnd .Report.Inputs.ReportingEnd | prometheusMetricPartitionFormat |}'
    GROUP BY namespace, persistentvolumeclaim
