google-cloud-node icon indicating copy to clipboard operation
google-cloud-node copied to clipboard

Stackdriver Monitoring v4.0.0 raising errors when try to write TimeSeries

Open jonnysgomes-ia opened this issue 3 months ago • 0 comments

Environment details

  • which product (packages/*): Stackdriver Monitoring v4.0.0
  • OS: Ubuntu 22.04 LTS
  • Node.js version: v20.8.1
  • npm version:
  • google-cloud-node version: 4.0.0

Steps to reproduce

  const monitoring = require('@google-cloud/monitoring');

  const client = new monitoring.MetricServiceClient();

  const jobBillableTimeInMinutes = (job.billable_time_ms / 1000) / 60;
  const metricType = `custom.googleapis.com/workflow/${resource_name}/job-duration`;

  const dataPoint = {
    interval: {
      endTime: {
        seconds: Date.now() / 1000
      },
    },
    value: {
      doubleValue: jobBillableTimeInMinutes
    },
  };

  const timeSeriesData = {
    metric: {
      type: metricType,
      labels: {
        run_id: run_id,
        job_name: job.name
      },
    },
    resource: {
      type: 'global',
      labels: {
        project_id: project_id,
      },
    },
    points: [dataPoint],
  };

  const request = {
    name: client.projectPath(project_id),
    timeSeries: [timeSeriesData],
  };

  console.log("Sending data to Google Cloud Monitoring")
  await client.createTimeSeries(request);

The provided code snippet throws the following error:

Error: 3 INVALID_ARGUMENT: 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.: global{} timeSeries[0]:

The same code works with @google-cloud/monitoring: 3.0.5.

Thanks!

jonnysgomes-ia avatar May 15 '24 23:05 jonnysgomes-ia