Skip to main content

Prerequisites:

  1. Think about the last time you had to increase the resources of the database ? was it because of the storage size or the compute resources ?
  • If it was because of the storage size, you should reallocate the cost using the storage size metric per team.
  • If it was because of the compute resources, you should reallocate the cost using the compute resources metric per team.
  1. Where is that metric available ? DataDog, Google logging metrics ?

Output:

  • Gain visibility of each team’s cost contribution !

Steps:

1

Step 1: Choose the correct metric

Metric TypeDataDog MetricGoogle SQL Metric
Storage Sizeavg:postgresql.database_size{<yourWhereClause>} by {db}.rollup(avg, daily, 'UTC')na
Compute Resourcessum:postgresql.queries.time{<yourWhereClause>} by {user}.rollup(sum, daily, 'UTC')sum by ("user")(rate({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database"}[${__interval}]))
2

Step 2: Import the metric in Costory

Go to Costory and import the metric.CostoryCostoryFor compute resources and storage size, we advise to use the SUM when aggregating the metric on weekly or monthly levels: We could use maximum aggregation but it might over allocate the cost to the team responsible of a one day spike.
  • Click import: the first import might take a few minutes to complete !
3

Step 3: Get a preview of the result using the advanced explorer !

Coming soon !
4

Step 4: Create a virtual dimension to correctly allocate the cost

  1. Go to Virtual Dimensions and create a new virtual dimension.
  2. rely on a filter on resource_id or resource name to scope the database cost correctly.
  3. Instead of relying on Dimension value mapping, you should use a dynamic allocation based on usage metrics option: Virtual Dimensions
  4. You now need to correctly map the group by dimensions to the correct team / owner: You have 3 options:
    • Your db name equals your team name: you can use the identity mapping option.
    • Your db name contains your team name: you can use the regex mapping option to extract from the db name the team name.
    • Your DB name has no relation to the team name: we need to manually map the db name to the team name: choose Manual mapping option. Virtual Dimensions
      • In that case be careful: if a new db name appears you will need to manually edit the virtual dimension to allocate the new db name to the correct team.
  5. Save the virtual dimension.
5

Step 5: Create a report to visualize the cost allocation

Go to Explorer and create a new report, you can also schedule it !