【问题标题】:Error in OpenCensus in Google Kubernetes Engine with Python使用 Python 在 Google Kubernetes Engine 中的 OpenCensus 中出错
【发布时间】:2020-01-27 06:26:56
【问题描述】:

我正在将包含 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 中的容器内运行有关。

要让 OpenCensus 在 GKE 容器中运行,是否需要一些特定的东西?

【问题讨论】:

  • 它是否在本地容器化中工作?我怀疑(希望)不会。您需要向容器提供您的服务凭据。您是否已将 Google Cloud Platform 服务帐号挂载到 Kubernetes 中?
  • 这是使用 GCP 服务帐户从 Kubernetes Engine pod 中访问任何 GCP 服务的样板:cloud.google.com/kubernetes-engine/docs/tutorials/…
  • @DazWilkin 我很欣赏这些建议,但这与没有服务帐户无关:该服务目前正在成功使用 Stackdriver 进行日志记录,并且还在使用 Firestore、Memorystore 和 PubSub 没有问题,所以凭据显然允许访问事物。是否有一个特定的角色必须分配给可能是罪魁祸首的服务帐户?
  • 进一步思考,我相信凭据可以完全消除。正如您在输出中看到的,我能够成功访问该服务。该错误与缺少数据的 API 调用有关,而不是与因访问原因而被拒绝的调用有关。

标签: python google-kubernetes-engine opencensus


【解决方案1】:

答案是你需要在你的容器中手动设置两个环境变量: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

【讨论】:

    猜你喜欢
    • 2020-12-15
    • 1970-01-01
    • 2019-07-02
    • 2018-09-07
    • 2019-02-01
    • 2018-04-23
    • 2018-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多