Writing Cloud Monitoring metrics in Cloud Functions

143 views
Skip to first unread message

AP Fritts

unread,
Aug 7, 2021, 2:58:36 PM8/7/21
to Firebase Google Group
Hi!

I've been using Cloud Monitoring for a while and have started receiving more and more errors as our service gets more traffic:

{
  "details": "One or more TimeSeries could not be written: One or more points were written more frequently than the maximum sampling period configured for the metric.: timeSeries[0]",
  "metadata": {"internalRepr": {}, "options":{}}},
  "code":3
}

Here is a snapshot of my code, which pretty much just follows Google's example:

async function recordMetric() {
  const seconds = Date.now() / 1000
  const dataPoint: google.monitoring.v3.IPoint = {
    interval: {endTime: {seconds}},
    value: {int64Value: 1},
  }
  const labels: Record<string, string> = {backendVersion}
  const timeSeriesData = {
    metric: {
      labels,
    },
    resource: {
      type: 'global',
      labels: {
        project_id: projectId!,
      },
    },
    points: [dataPoint],
  }
  const request = {name: client.projectPath(projectId!), timeSeries: [timeSeriesData]}
  await client.createTimeSeries(request)
}

From my research, it looks like this writes immediately and doesn't do any batching of requests. Google doesn't mention anywhere in their instructions for using this client that I'd need to manage batching on my own. Since the Cloud Functions shut down after the request is complete, I think that also means delaying metric submission will delay metrics showing up or even being dropped.

Has anyone else run into this? Am I using the client incorrectly? I don't see any configuration options for batching.

Thanks!
AP

Kato Richardson

unread,
Aug 10, 2021, 3:22:25 PM8/10/21
to Firebase Google Group
Hello AP,

If several requests are sent in a single Functions call, you could certainly batch those; you're already calling await on client.createTimeSeries(...) which could just as easily await the batch call.

Given that Cloud Monitoring provides support for Cloud Functions and for Cloud Run, you might reach out to them and ask if either of those integrations are compatible with Cloud Functions for Firebase or if they'd mind making a tweak so they could be. Short-lived microservices are clearly a solved problem. I'm also curious why they don't have an integration listed for Cloud Logging. Seems like a natural way to ferry events in cases like this.

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/d9a23c47-a1ed-4499-955f-bc40e521da70n%40googlegroups.com.


--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Reply all
Reply to author
Forward
0 new messages