Writing Cloud Monitoring metrics in Cloud Functions using NodeJS

Viewed 188

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: {
      type: `custom.googleapis.com/mymetrics/association_success`,
      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.

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

0 Answers
Related