4

I want to know how much is each one of my cloud functions spending (break up the total costs on Google Cloud Functions that is shown in my Billing Console). I know I may be able to estimate it probably looking at the metrics and configuration of each function but it would be a hassle to do it one by one (I have a lot of functions).

I couldn't find any way of doing it using the Billing Console alone, it only shows the total cost.

If there was a tool/script it would also be appreciated.

josue.0
  • 775
  • 1
  • 10
  • 23

2 Answers2

4

You need to add labels on each of your functions (more about labels) and to sink the billing in BigQuery.

Now, you will be able to find the cost of each Cloud Functions label in BigQuery. Create a dashboard to view the summary, with datastudio for example.

josue.0
  • 775
  • 1
  • 10
  • 23
guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
  • Thanks, I overlooked the labels thing because in the intro it mentions instances (compute instances) so I thought it only worked with those kinds of resources. Also I couldn't find a way to assign labels in the Cloud Functions dashboard. I will try using the API or cli, I guess it is possible that way. – josue.0 May 05 '21 at 19:32
  • For everyone coming here I found it is possible to add labels with the `gcloud functions deploy` command, but I couldn't make it with the `firebase deploy` command (which is the one I use). So I guess I will use the rest api. – josue.0 May 05 '21 at 22:44
  • 1
    It should be noted here that the BigQuery portion of this solution is not necessary. Once you've added labels, you can group by label in the billing console. – Tim Aug 13 '21 at 14:29
  • You couldn't filter with label in the console previously! – guillaume blaquiere Aug 14 '21 at 08:20
  • is there a way to add a label to the cloud function via console? I looked through all the settings and it doesn't seem like it. – jason Jan 22 '23 at 13:29
  • Yes you can. Follow the documentation: https://cloud.google.com/resource-manager/docs/creating-managing-labels#create-labels – guillaume blaquiere Jan 22 '23 at 16:39
-1

I am unaware of any tool in Billing that would help with what you are after. And I don't think that Google's infrastructure is set up for what you are after.

The Cloud Function Pricing document details how pricing is broken down.

But understand that your Cloud Functions are actually deployed inside of a single (kubernetes) container and run inside of GCP. The GCP infrastructure is able to monitor that container's CPU use, and monitor individual calls to your Cloud Functions, but I strongly doubt that it is monitoring the CPU use of each and every invocation of a function (consider how complex that would be in a project where there is high load/concurrency...how would that even work?)

Your question is specific to a particular approach to solving a problem. I suggest you detail what the underlying problem is to see if there might be a different solution than "Google Billing breaking up Cloud Function costs".

Greg Fenton
  • 1,233
  • 9
  • 15
  • I think the underlying problem is that we have many teams (each team working on a separate "project") using the same GCP project, and we need to separate the costs that each team is generating. Each team has deployed a bunch of functions. – josue.0 May 05 '21 at 17:21
  • btw, I am not sure if all my functions are inside a single container, if that is what you mean, because as far as I understand google creates a new container instance for each concurrent request on each cloud function. Each of these instances can only handle one request at a time https://cloud.google.com/functions/docs/max-instances – josue.0 May 05 '21 at 17:42
  • 1
    I don't see any evidence that there is a breakdown of Cloud Functions as a service beyond project-level memory, CPU, invocation and network. My experience and their documentation leads me to think of GCP's "project" being the level of granularity I expect from the services they offer. Seems like your team has decided to use a single GCP project to do multiple "sub-projects" and are now struggling with the billing granularity. I'd be interested to know if you find a solution. I don't see a path to one. – Greg Fenton May 05 '21 at 18:34
  • Labels are the solution – jamiet Sep 27 '21 at 20:44