docstr: Prometheus collector implementation for opencensus proxy export.
  
  Prometheus collector requires to implement `collect` which is
  invoked whenever Prometheus queries the endpoint.
  
  The class is thread-safe.
  
  Args:
      namespace: Prometheus namespace.
docstr_tok: ["Prometheus","collector","implementation","for","opencensus","proxy","export",".","Prometheus","collector","requires","to","implement","`","collect","`","which","is","invoked","whenever","Prometheus","queries","the","endpoint",".","The","class","is","thread-safe",".","Args",":","namespace",":","Prometheus","namespace","."]
code: def __init__(self, namespace: str, component_timeout_s: int = 60):
      """Prometheus collector implementation for opencensus proxy export.
  
      Prometheus collector requires to implement `collect` which is
      invoked whenever Prometheus queries the endpoint.
  
      The class is thread-safe.
  
      Args:
          namespace: Prometheus namespace.
      """
      # -- Protect `self._components` --
      self._components_lock = threading.Lock()
      # -- Timeout until the component is marked as stale --
      # Once the component is considered as stale,
      # the metrics from that worker won't be exported.
      self._component_timeout_s = component_timeout_s
      # -- Prometheus namespace --
      self._namespace = namespace
      # -- Component that requests to proxy export metrics --
      # Component means core worker, raylet, and GCS.
      # component_id -> Components
      # For workers, they contain worker ids.
      # For other components (raylet, GCS),
      # they contain the global key `GLOBAL_COMPONENT_KEY`.
      self._components = {}
  
imports: import json
  import logging
  import os
  import re
  import threading
  import time
  import traceback
  from collections import namedtuple
  from typing import List, Tuple, Any, Dict
  from prometheus_client.core import CounterMetricFamily, GaugeMetricFamily, HistogramMetricFamily
  from opencensus.metrics.export.value import ValueDouble
  from opencensus.stats import aggregation
  from opencensus.stats import measure
  from opencensus.stats.view_manager import ViewManager
  from opencensus.stats.stats_recorder import StatsRecorder
  from opencensus.stats.base_exporter import StatsExporter
  from prometheus_client.core import Metric
  from opencensus.stats.aggregation_data import CountAggregationData, DistributionAggregationData, LastValueAggregationData
  from opencensus.stats.view import View
  from opencensus.tags import tag_key
  from opencensus.tags import tag_map
  from opencensus.tags import tag_value
  import ray
  from ray._raylet import GcsClient
  from ray.core.generated.metrics_pb2 import Metric
label_desc: Use image node_id 1 to create a new OpenCensusProxyCollector object  with example: obj = OpenCensusProxyCollector(namespace, component_timeout_s)