Python 3.x Google Cloud Monitoring Api-400无法写入一个或多个TimeSeries遇到重复的TimeSeries

Python 3.x Google Cloud Monitoring Api-400无法写入一个或多个TimeSeries遇到重复的TimeSeries,python-3.x,time-series,google-cloud-stackdriver,google-cloud-monitoring,Python 3.x,Time Series,Google Cloud Stackdriver,Google Cloud Monitoring,我试图将多个数据点推送到一个时间序列中,但每次我创建下一个数据点时,它都会沿着当前迭代拉动上一个迭代。下面举个例子 metric { type: "custom.googleapis.com/test/Cost_time" } resource { type: "global" labels { key: "project_id" value: "project-id-name" }

我试图将多个数据点推送到一个时间序列中,但每次我创建下一个数据点时,它都会沿着当前迭代拉动上一个迭代。下面举个例子

metric {
  type: "custom.googleapis.com/test/Cost_time"
}
resource {
  type: "global"
  labels {
    key: "project_id"
    value: "project-id-name"
  }
}
points {
  interval {
    end_time {
      seconds: 1594058659
    }
  }
  value {
    double_value: 0.044661431106760574
  }
}

[metric {
  type: "custom.googleapis.com/test/Cost_Time"
}
resource {
  type: "global"
  labels {
    key: "project_id"
    value: "project-id-name"
  }
}
points {
  interval {
    end_time {
      seconds: 1594058659
    }
  }
  value {
    double_value: 0.044661431106760574
  }
}
]
metrics are successfully sent
FINISHED <- works perfectly fine here
this is the iterator: 1
This the response keys: 0.0004929316673951689
Here is the result: 0.0004929316673951689
metric {
  type: "custom.googleapis.com/test/Cost_Time"
}
resource {
  type: "global"
  labels {
    key: "project_id"
    value: "project -id-name"
  }
}
points {
  interval {
    end_time {
      seconds: 1594058660
    }
  }
  value {
    double_value: 0.0004929316673951689
  }
}

[metric {
  type: "custom.googleapis.com/test/Cost_Time"
}
resource {
  type: "global"
  labels {
    key: "project_id"
    value: "project-id-name"
  }
}
points {
  interval {
    end_time {
      seconds: 1594058659
    }
  }
  value {
    double_value: 0.044661431106760574 <- duplicate is found here
  }
}
, metric {
  type: "custom.googleapis.com/test/Cost_Time"
}
resource {
  type: "global"
  labels {
    key: "project_id"
    value: "project-id-name"
  }
}
points {
  interval {
    end_time {
      seconds: 1594058660
    }
  }
  value {
    double_value: 0.0004929316673951689
  }
}
]
这里是我用来创建时间序列的方法

def get_time_series(result):
    series = monitoring_v3.types.TimeSeries()
    series.metric.type = 'custom.googleapis.com/test/Cost'
    series.resource.type = 'global'
    series.resource.labels['project_id'] = "project-name"
    points = series.points.add()
    points.interval.end_time.seconds = int(time.time())
    points.value.double_value = result
    return series
我已经阅读并遵循了文档,但我在这方面的进展已经停止。有人知道我错过了什么吗

以下是完整的堆栈跟踪:

Traceback (most recent call last):
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/grpc/_channel.py", line 826, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/grpc/_channel.py", line 729, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.INVALID_ARGUMENT
    details = "One or more TimeSeries could not be written: Field timeSeries[1] had an invalid value: Duplicate TimeSeries encountered. Only one point can be written per TimeSeries per request.: timeSeries[1]"
    debug_error_string = "{"created":"@1594133230.854639000","description":"Error received from peer ipv4:172.217.12.202:443","file":"src/core/lib/surface/call.cc","file_line":1056,"grpc_message":"One or more TimeSeries could not be written: Field timeSeries[1] had an invalid value: Duplicate TimeSeries encountered. Only one point can be written per TimeSeries per request.: timeSeries[1]","grpc_status":3}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/malcode/PycharmProjects/untitled/cost.py", line 108, in <module>
    print(main())
  File "/Users/malcode/PycharmProjects/untitled/cost.py", line 103, in main
    client.create_time_series("projects/project-id-name", timeseries)
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/google/cloud/monitoring_v3/gapic/metric_service_client.py", line 1060, in create_time_series
    request, retry=retry, timeout=timeout, metadata=metadata
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py", line 143, in __call__
    return wrapped_func(*args, **kwargs)
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/google/api_core/retry.py", line 286, in retry_wrapped_func
    on_error=on_error,
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/google/api_core/retry.py", line 184, in retry_target
    return target()
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/google/api_core/timeout.py", line 214, in func_with_timeout
    return func(*args, **kwargs)
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.InvalidArgument: 400 One or more TimeSeries could not be written: Field timeSeries[1] had an invalid value: Duplicate TimeSeries encountered. Only one point can be written per TimeSeries per request.: timeSeries[1]


 
 
回溯(最近一次呼叫最后一次):
文件“/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site packages/google/api_core/grpc_helpers.py”,第57行,错误\u重新映射\u可调用
返回可调用函数(*args,**kwargs)
文件“/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site packages/grpc/_channel.py”,第826行,在调用中__
返回\u结束\u一元\u响应\u阻塞(状态、调用、错误、无)
文件“/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site packages/grpc/_channel.py”,第729行,一元响应中
raise\u InactiveRpcError(状态)
grpc.\u信道。\u不活动覆盖PCERROR:
上述异常是以下异常的直接原因:
回溯(最近一次呼叫最后一次):
文件“/Users/malcode/PycharmProjects/untitled/cost.py”,第108行,在
打印(main())
文件“/Users/malcode/PycharmProjects/untitled/cost.py”,第103行,主视图
创建时间序列(“项目/项目id名称”,时间序列)
文件“/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site packages/google/cloud/monitoring\u v3/gapic/metric\u service\u client.py”,第1060行,创建时间序列
请求,重试=重试,超时=超时,元数据=元数据
文件“/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site packages/google/api_core/gapic_v1/method.py”,第143行,在调用中__
返回包装函数(*args,**kwargs)
文件“/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site packages/google/api_core/retry.py”,第286行,在retry_wrapped_func中
on_错误=on_错误,
文件“/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site packages/google/api_core/retry.py”,第184行,在retry_目标中
返回目标()
文件“/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/google/api_-core/timeout.py”,第214行,func_格式,带超时
返回函数(*args,**kwargs)
文件“/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site packages/google/api_core/grpc_helpers.py”,第59行,错误\u重新映射\u可调用
六、从(例外情况。从grpc错误(exc),exc)
文件“”,第3行,从
google.api_core.exceptions.InvalidArgument:400无法写入一个或多个时间序列:字段时间序列[1]的值无效:遇到重复的时间序列。每个请求的每个TimeSeries只能写入一个点。:TimeSeries[1]

hi,您在API中看到的实际错误是什么?@c69您好,我编辑了我的post@c69从错误中我推测,在一个时间点上发生的点太多了,我想这回避了一个问题,即是否可能错开一个数据点。嗨,您从API中看到的实际错误是什么?@c69您好我编辑了我的post@c69从错误中我推测,在一个时间点上发生的点太多了,我想这回避了一个问题,即是否可能错开一个数据点。
Traceback (most recent call last):
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/grpc/_channel.py", line 826, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/grpc/_channel.py", line 729, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.INVALID_ARGUMENT
    details = "One or more TimeSeries could not be written: Field timeSeries[1] had an invalid value: Duplicate TimeSeries encountered. Only one point can be written per TimeSeries per request.: timeSeries[1]"
    debug_error_string = "{"created":"@1594133230.854639000","description":"Error received from peer ipv4:172.217.12.202:443","file":"src/core/lib/surface/call.cc","file_line":1056,"grpc_message":"One or more TimeSeries could not be written: Field timeSeries[1] had an invalid value: Duplicate TimeSeries encountered. Only one point can be written per TimeSeries per request.: timeSeries[1]","grpc_status":3}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/malcode/PycharmProjects/untitled/cost.py", line 108, in <module>
    print(main())
  File "/Users/malcode/PycharmProjects/untitled/cost.py", line 103, in main
    client.create_time_series("projects/project-id-name", timeseries)
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/google/cloud/monitoring_v3/gapic/metric_service_client.py", line 1060, in create_time_series
    request, retry=retry, timeout=timeout, metadata=metadata
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py", line 143, in __call__
    return wrapped_func(*args, **kwargs)
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/google/api_core/retry.py", line 286, in retry_wrapped_func
    on_error=on_error,
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/google/api_core/retry.py", line 184, in retry_target
    return target()
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/google/api_core/timeout.py", line 214, in func_with_timeout
    return func(*args, **kwargs)
  File "/Users/malcode/PycharmProjects/untitled/venv/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.InvalidArgument: 400 One or more TimeSeries could not be written: Field timeSeries[1] had an invalid value: Duplicate TimeSeries encountered. Only one point can be written per TimeSeries per request.: timeSeries[1]