Using Google Cloud Platform labels to report costs

In Google Cloud Platform, a label is a key-value pair that helps you organize your Google Cloud instances. Each label consists of a <key> and an optional <value>, both of which you define. You can add a label to each resource and then filter the resources based on their labels. 

Collecting labels from GCP

Different types of labels are available in BigQuery, such as resource labels, project labels, and system labels. Resource-level and project-level labels are user-defined. System-level labels are generated by Google Cloud Platform. You can add project-level labels and resource-level labels in GCP and create resource pools by selecting the tags (labels) based on which you want to include the resources in the resource pool. For example, you can create a resource pool of the projects in your GCP cloud that have the labels "devops" and "production" applied to them.

To differentiate between the type of label in BMC Helix Cloud Cost, project labels are prefixed with project. and system labels are prefixed with system. 

If a label is removed from the resource in the GCP console, it is also removed from Cloud Cost during the next collection cycle.

Calculating the resource-level cost of your GCP resources

GCP recommends the use of labels to collect resource-level costs. In particular, resource labels can be applied to resources to help you distinguish between usage within or across projects. For example, if a project contains all of the resources for an application, one set of labels could represent resources for components of that application (for example, front end, back end), and another set of labels could represent common costs across applications (for example, security, testing, development). Labels are available in the Billing export to BigQuery, and BMC Helix Cloud Costuses these labels to calculate resource-level costs.

In general, the cost of a GCP resource is reported by the stock-keeping unit (SKU), and billing exports in BigQuery contain information in the SKU format. BMC Helix Cloud Cost gathers information about the project and resource labels using BigQuery and then calculates the aggregated cost of the resources. 

To obtain the cost of each resource, you must create the labels with instance id as the key and instance name as the value in the GCP console. To get a separate cost entry for each resource, the value of the labels must be unique between resources. You can view the instance names in the Resource Name column in the Dashboard > Explore Bill option.

Resource-level cost is calculated based on the availability of labels in the resources:

  • No labels are available in the resources: If no unique labels are added to the resources, BMC Helix Cloud Cost collects the SKU level costs
  • Labels are available partially: If some resources contain unique labels and others do not have any labels, then the resource-level cost is obtained only for the tagged resources and SKU-level cost obtained for the remaining resources
  • All the labels are available in the resources: If all the resources contain unique labels (instanceid, instancename), then each instance is considered as a resource, and the resource-level cost is obtained

The resource-level labels and system labels are obtained only if you have configured resource-level cost. If the resource-level cost is not configured, only the project-level labels will be ingested in Cloud Cost.

If you have already added the instance ID and instance names in the GCP console, contact BMC support to clean up the cost data of the GCP account to avoid duplicate resource-level and SKU-level entries.

Creating labels automatically using the GCP Cloud Function

BMC Helix Cloud Cost provides a function named GCP Cloud Function to automatically create labels for your new and existing compute instances. To create labels automatically for the instances, you must add this function to each project in your GCP infrastructure. This is a one-time activity, and after you upload it to your GCP projects you do not have to manually create the labels for your instances. For details, see  Automatically label Google Cloud instances and disks. Open link

To create labels using the GCP Cloud Function

  1. Create a Cloud Sink (Router) by selecting destination as Cloud Pub/Sub topic – “create/existing topic”
  2. Use the Cloud Sink (Router) inclusion filter:

    resource.type="gce_instance“
    protoPayload.methodName:"compute.instances.insert“
    operation.first="true“
  3. Create a GCP Cloud Function with the source (zip file provided by BMC team)
  4. Select a trigger point as Cloud PubSub topic name (used in step 1)

The sink will route an event from cloud audit logs to the GCP cloud function through cloud Pub/Sub topic whenever a compute instance is created. 

Related topics

Managing Resource pools

Creating and managing labels in GCP Open link

Using labels to gain visibility into GCP resource usage Open link

Was this page helpful? Yes No Submitting... Thank you

Comments