使用Python的Google Kubernetes引擎中OpenCensus出错

2024-05-08 01:08:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在将包含Python应用程序的容器部署到GKE,在尝试使用OpenCensus发送跟踪消息时遇到错误:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/opencensus/metrics/transport.py", line 59, in func
    return self.func(*aa, **kw)
  File "/usr/local/lib/python3.7/site-packages/opencensus/metrics/transport.py", line 113, in export_all
    export(itertools.chain(*all_gets))
  File "/usr/local/lib/python3.7/site-packages/opencensus/ext/stackdriver/stats_exporter/__init__.py", line 162, in export_metrics
    self.client.project_path(self.options.project_id), ts_batch)
  File "/usr/local/lib/python3.7/site-packages/google/cloud/monitoring_v3/gapic/metric_service_client.py", line 1024, in create_time_series
    request, retry=retry, timeout=timeout, metadata=metadata
  File "/usr/local/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py", line 143, in __call__
    return wrapped_func(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/google/api_core/retry.py", line 273, in retry_wrapped_func
    on_error=on_error,
  File "/usr/local/lib/python3.7/site-packages/google/api_core/retry.py", line 182, in retry_target
    return target()
  File "/usr/local/lib/python3.7/site-packages/google/api_core/timeout.py", line 214, in func_with_timeout
    return func(*args, **kwargs)
  File "/usr/local/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: The set of resource labels is incomplete. Missing labels: (container_name namespace_name).: timeSeries[0-199]

有趣的是这句话:Missing labels: (container_name namespace_name)。你知道吗

当我在本地运行完全相同的代码时,我没有收到任何错误,而且我确实看到我的跟踪出现在Stackdriver Metrics Explorer中,因此问题似乎与在GKE中的容器内运行有关。你知道吗

在GKE容器中运行OpenCensus需要什么特定的东西吗?你知道吗


Tags: inpycoreapireturnlibpackagesusr
1条回答
网友
1楼 · 发布于 2024-05-08 01:08:56

答案是您需要在容器中手动设置两个环境变量:CONTAINER_NAMENAMESPACE。我认为GKE应该设置这些,而不是,因此OpenCensus无法找到期望值。一个示例修复将包括podspec中的这两个变量:

        spec:
          containers:
            env:
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: CONTAINER_NAME
              value: {{ APP }}-collectors-{{ NAME }}

更多详细信息:https://github.com/census-instrumentation/opencensus-python/issues/796#issuecomment-539109321

相关问题 更多 >