version: 1
kind: platform-infra-observability

metadata:
  id: observability
  owner: unidesk
  spec: PJ2026-01060501 OTel追踪 draft-2026-06-19-p0
  relatedIssues:
    - 489
    - 1181

defaults:
  targetId: NC01

images:
  collector:
    repository: docker.m.daocloud.io/otel/opentelemetry-collector-contrib
    tag: 0.130.1
    pullPolicy: IfNotPresent
  tempo:
    repository: docker.m.daocloud.io/grafana/tempo
    tag: 2.8.1
    pullPolicy: IfNotPresent
  prometheus:
    repository: docker.m.daocloud.io/prom/prometheus
    tag: v3.5.0
    pullPolicy: IfNotPresent

targets:
  - id: NC01
    route: NC01:k3s
    namespace: platform-infra
    role: active
    enabled: true
    createNamespace: true
  - id: D518
    route: D518:k3s
    namespace: platform-infra
    role: active
    enabled: true
    createNamespace: true
  - id: JD01
    route: JD01:k3s
    namespace: platform-infra
    role: active
    enabled: true
    createNamespace: true

collector:
  deploymentName: otel-collector
  serviceName: otel-collector
  configMapName: otel-collector-config
  replicas: 1
  healthPort: 13133
  otlp:
    grpcPort: 4317
    httpPort: 4318

traceBackend:
  type: tempo
  deploymentName: tempo
  serviceName: tempo
  configMapName: tempo-config
  replicas: 1
  httpPort: 3200
  otlp:
    grpcPort: 4317
    httpPort: 4318
  storage:
    mode: emptyDir
    retention: 24h

metricsBackend:
  type: prometheus
  enabled: true
  targetIds:
    - NC01
  deploymentName: prometheus
  serviceName: prometheus
  configMapName: prometheus-config
  serviceAccountName: prometheus
  clusterRoleName: platform-infra-prometheus
  clusterRoleBindingName: platform-infra-prometheus
  persistentVolumeClaimName: prometheus-data
  replicas: 1
  httpPort: 9090
  storage:
    mode: persistentVolumeClaim
    size: 20Gi
    retention: 15d
  discovery:
    namespaces: []
    labelSelector:
      key: unidesk.ai/metrics
      value: "true"
    annotationKeys:
      scrape: prometheus.io/scrape
      path: prometheus.io/path
      port: prometheus.io/port
    defaultPath: /metrics
    scrapeInterval: 30s
    scrapeTimeout: 10s
  query:
    path: /api/v1/query
    timeoutSeconds: 15
    maxSeries: 200
    maxResponseBytes: 262144
    maxCloseoutQueries: 8

sampling:
  mode: parentbased_traceidratio
  ratio: 1

instrumentation:
  contextPropagation:
    - tracecontext
    - baggage
  serviceConnections:
    - serviceName: hwlab-cloud-api
      owningRepo: pikasTech/HWLAB
      configRefs:
        targetNode: config/hwlab-node-lanes.yaml#lanes.v03.targets.NC01.node
        lane: config/hwlab-node-lanes.yaml#lanes.v03.version
        namespace: config/hwlab-node-lanes.yaml#lanes.v03.targets.NC01.runtime.namespace
      requiredSpans:
        - POST /v1/agent/chat
        - durable_admission
        - billing_preflight
        - agentrun_dispatch
        - projection_write
        - trace_events_read
        - turn_status_read
    - serviceName: hwlab-cloud-api
      owningRepo: pikasTech/HWLAB
      targetNode: D518
      lane: v03
      namespace: hwlab-v03
      requiredSpans:
        - POST /v1/agent/chat
        - durable_admission
        - billing_preflight
        - agentrun_dispatch
        - projection_write
        - trace_events_read
        - turn_status_read
    - serviceName: hwlab-cloud-api
      owningRepo: pikasTech/HWLAB
      targetNode: JD01
      lane: v03
      namespace: hwlab-v03
      requiredSpans:
        - POST /v1/agent/chat
        - durable_admission
        - billing_preflight
        - agentrun_dispatch
        - projection_write
        - trace_events_read
        - turn_status_read
    - serviceName: user-billing
      owningRepo: pikasTech/HWLAB
      configRefs:
        targetNode: config/hwlab-node-lanes.yaml#lanes.v03.targets.NC01.node
        lane: config/hwlab-node-lanes.yaml#lanes.v03.version
        namespace: config/hwlab-node-lanes.yaml#lanes.v03.targets.NC01.runtime.namespace
      requiredSpans:
        - billing_preflight
    - serviceName: user-billing
      owningRepo: pikasTech/HWLAB
      targetNode: D518
      lane: v03
      namespace: hwlab-v03
      requiredSpans:
        - billing_preflight
    - serviceName: user-billing
      owningRepo: pikasTech/HWLAB
      targetNode: JD01
      lane: v03
      namespace: hwlab-v03
      requiredSpans:
        - billing_preflight
    - serviceName: agentrun-manager
      owningRepo: pikasTech/agentrun
      targetNode: NC01
      lane: nc01-v02
      namespace: agentrun-v02
      requiredSpans:
        - agentrun_dispatch
        - run_created
        - command_result
        - projection_sync
    - serviceName: agentrun-manager
      owningRepo: pikasTech/agentrun
      targetNode: JD01
      lane: v0.2
      namespace: agentrun-v02
      requiredSpans:
        - agentrun_dispatch
        - run_created
        - command_result
        - projection_sync

resourceAttributes:
  required:
    - service.name
    - deployment.environment
    - unidesk.node
    - hwlab.lane
    - k8s.namespace.name
    - git.commit
  businessCorrelationAttributes:
    - traceId
    - sessionId
    - turnId
    - runId
    - commandId

probes:
  readinessPath: /ready
  traceQueryPathTemplate: /api/traces/{{traceId}}
  statusEndpoints:
    - name: tempo-ready
      service: tempo
      portName: http
      path: /ready
    - name: collector-health
      service: otel-collector
      portName: health
      path: /
    - name: prometheus-ready
      service: prometheus
      portName: http
      path: /-/ready
