apiVersion: v1
kind: ConfigMap
metadata:
  name: ubbagent-config
data:
  config.yaml: |
    # This billing agent ubbagent config has been adapted from:
    #   https://github.com/GoogleCloudPlatform/marketplace-k8s-app-tools/blob/master/docs/billing-integration.md#agent-deployment-and-configuration

    # The identity section contains authentication information used
    # by the agent.
    identities:
    - name: gcp
      gcp:
        # This parameter accepts a base64-encoded JSON service
        # account key. The value comes from the reporting secret.
        encodedServiceAccountKey: $AGENT_ENCODED_KEY

    # The metrics section defines the metric that will be reported.
    # Metric names should match verbatim the identifiers created
    # during pricing setup.
    metrics:
    # Metric usage reports are either generated by the agent as
    # defined in "sources", or externally, i.e. by the application.
    # Since this metric is not supported by the "sources" section,
    # the application must send usage reports for this metric to
    # the agent.

    # This is the list of metrics from our current pricing:
    # gateway___gmail_encryption__per_user_per_day_
    # gateway___gdrive_encryption__per_user_per_day_
    # gateway___gmail___gdrive_encryption__per_user_per_day_
    # gateway_network_level_encryption_per_day_
    # gateway__gmail_encryption_with_customer_hosted_keys___per_user_per_day_
    # gateway__gdrive_encryption_with_customer_hosted_keys___per_user_per_day_
    # gateway__gmail___gdrive_encryption_with_customer_hosted_keys__per_user_per_day_
    # gateway_network_level_encryption_with_customer_hosted_keys__per_user_per_day_

    # each one should show the number of licensed users purchased from Virtru.
    # The units are "User-days"  - metrics are billed per licensed user per day
    # Reporting is per hour at a fractional rate.

    - name: gateway___gmail_encryption__per_user_per_day_
      type: double
      endpoints:
      - name: on_disk
      - name: servicecontrol
      passthrough: {}
    - name: gateway___gdrive_encryption__per_user_per_day_
      type: double
      endpoints:
      - name: on_disk
      - name: servicecontrol
      passthrough: {}
    - name: gateway___gmail___gdrive_encryption__per_user_per_day_
      type: double
      endpoints:
      - name: on_disk
      - name: servicecontrol
      passthrough: {}
    - name: gateway_network_level_encryption_per_day_
      type: double
      endpoints:
      - name: on_disk
      - name: servicecontrol
      passthrough: {}
    - name: gateway__gmail_encryption_with_customer_hosted_keys___per_user_per_day_
      type: double
      endpoints:
      - name: on_disk
      - name: servicecontrol
      passthrough: {}
    - name: gateway__gdrive_encryption_with_customer_hosted_keys___per_user_per_day_
      type: double
      endpoints:
      - name: on_disk
      - name: servicecontrol
      passthrough: {}
    - name: gateway__gmail___gdrive_encryption_with_customer_hosted_keys__per_user_per_day_
      type: double
      endpoints:
      - name: on_disk
      - name: servicecontrol
      passthrough: {}
    - name: gateway_network_level_encryption_with_customer_hosted_keys__per_user_per_day_
      type: double
      endpoints:
      - name: on_disk
      - name: servicecontrol
      passthrough: {}

    # The endpoints section of a metric defines which endpoints the
    # metric data is sent to.

    # Metrics reported by the application are aggregated by the
    # agent for a specified period of time and sent to the
    # reporting endpoint (e.g. Google Service Control)

    # The reporting unit which the application should use to report
    # usage to the agent should align with the metric unit in the
    # backend service config (set from the "reporting unit" in the
    # portal).
    #
    # For unit/time metrics, the reporting metric should likely be
    # more granular than the pricing metric, since usage should be
    # reported frequently
    # e.g. metric may be reported in MiBy/min but priced in GiBy/day
    #
    # The reporting metric is recommended to be more granular than
    # the pricing metric. If it is not, a double type is likely
    # needed to provide sufficient precision.

    # The agent is able to automatically send instance time usage
    # reports, configured in the "source" section.
    - name: instance_time
      type: int
      endpoints:
      - name: on_disk
      - name: servicecontrol

      # The passthrough marker indicates that no aggregation should
      # occur for this metric. Reports received are immediately sent
      # to the reporting endpoint. We use passthrough for the
      # instance_time metric since reports are generated
      # automatically by a heartbeat source defined in a later
      # section.
      passthrough: {}

    # The endpoints section defines where metering data is ultimately
    # sent. Currently supported endpoints include:
    # - disk - some directory on the local filesystem
    # - servicecontrol - Google Service Control
    endpoints:
    - name: on_disk
      # The disk endpoint is useful for debugging, but its inclusion
      # is not necessary in a production deployment.
      disk:
        reportDir: /var/lib/ubbagent/reports
        expireSeconds: 3600
    - name: servicecontrol
      servicecontrol:
        identity: gcp
        # The service name is unique to your application and will be
        # provided during onboarding.
        serviceName: {{ .Chart.Name }}.mp-virtru-public.appspot.com
        consumerId: $AGENT_CONSUMER_ID  # From the reporting secret.
