Observability API 概览

Observability API 使用 Kubernetes 自定义资源,并依赖 Kubernetes 资源模型 (KRM) 来预配和管理日志记录和监控资源。

使用 Observability API 管理指定组织或自定义项目中可观测性服务的生命周期。可观测性服务的生命周期包括安装、升级和卸载等操作。您必须根据要管理的 Observability 服务将自定义资源部署到项目中。

许多可观测性服务会自动提供给已预配的项目,例如日志记录、监控和提醒。

服务端点

以下网址是 Observability KRM API 的 API 端点:

  • 日志记录组

    https://MANAGEMENT_API_SERVER_ENDPOINT/apis/logging.gdc.goog/v1
    
  • 监控组

    https://MANAGEMENT_API_SERVER_ENDPOINT/apis/monitoring.gdc.goog/v1
    
  • 可观测性群组

    https://MANAGEMENT_API_SERVER_ENDPOINT/apis/observability.gdc.goog/v1
    

MANAGEMENT_API_SERVER_ENDPOINT 替换为管理 API 服务器的端点。

发现文档

使用 kubectl proxy --port=8001 命令在本地计算机上打开指向 API 服务器的代理。然后,您可以通过以下网址之一访问发现文档:

  • http://127.0.0.1:8001/apis/logging.gdc.goog/v1
  • http://127.0.0.1:8001/apis/monitoring.gdc.goog/v1
  • http://127.0.0.1:8001/apis/observability.gdc.goog/v1

示例资源

本部分包含使用可观测性 KRM API 的资源示例。

日志记录组

以下是一个 LoggingTarget 自定义资源的示例,用于从 project-1 项目中的特定服务收集日志:

# Configures a log scraping job
apiVersion: logging.gdc.goog/v1
kind: LoggingTarget
metadata:
  # Choose a namespace that matches the namespace of the workload pods
  namespace: project-1
  name: my-service-logging-target
spec:
  # Choose a matching pattern that identifies the pods for this job
  # Optional
  # Relationship between different selectors: 'AND'
  selector:
    # The clusters to collect logs from.
    # The default configuration is to collect logs from all clusters.
    # The relationship between different clusters is an 'OR' relationship.
    # For example, the value '["admin", "system"]' indicates to consider
    # the admin cluster 'OR' the system cluster.
    # Optional
    matchClusters:
    - cluster-1
    - cluster-2

    # The pod name prefixes to collect logs from.
    # The Observability platform scrapes all pods with names
    # that start with the specified prefixes.
    # The values must contain '[a-z0-9-]' characters only.
    # The relationship between different list elements is an 'OR' relationship.
    # Optional
    matchPodNames:
      - pod-1
      - pod-2

    # The container name prefixes to collect logs from.
    # The Observability platform scrapes all containers with names
    # that start with the specified prefixes.
    # The values must contain '[a-z0-9-]' characters only.
    # The relationship between different list elements is an 'OR' relationship.
    # Optional
    matchContainerNames:
      - container-1
      - container-2

  # Choose the predefined parser for log entries.
  # Use parsers to map the log output to labels and extract fields.
  # Specify the log format.
  # Optional
  # Options: klog_text, klog_json, klogr, gdch_json, json
  parser: klog_text

  # Specify an access level for log entries.
  # The default value is 'ao'.
  # Optional
  # Options: ao, pa, io
  logAccessLevel: ao

  # Specify a service name to be applied as a label
  # For user workloads consider this field as a workload name
  # Required
  serviceName: service-name

  # The additional static fields to apply to log entries.
  # The field is a key-value pair, where the field name is the key and
  # the field value is the value.
  # Optional
  additionalFields:
    app: workload2
    key: value

监控组

以下是一个 MonitoringTarget 自定义资源示例,用于从 project-1 项目中的工作负载收集指标:

apiVersion: monitoring.gdc.goog/v1
kind: MonitoringTarget
metadata:
  # Choose the same namespace as the workload pods
  namespace: project-1
  name: string
spec:
  # Choose matching pattern that identifies pods for this job
  # Optional
  # Relationship between different selectors: AND
  selector:
    # Choose clusters to consider for this job
    # Optional
    # List
    # Default: All clusters applicable to this project.
    # Relationship between different list elements: OR
    matchClusters:
      - string

    # Choose pod-labels to consider for this job
    # Optional: Map of key-value pairs.
    # Default: No filtering by label.
    # Relationship between different pairs: AND
    matchLabels:
      key1: value1

    # Choose annotations to consider for this job
    # Optional: Map of key-value pairs
    # Default: No filtering by annotation
    # Relationship between different pairs: AND
    matchAnnotations:
      key1: value1

  # Configure the endpoint exposed for this job
  podMetricsEndpoints:
    # Choose port either via static value or annotation
    # Optional
    # Annotation takes priority
    # Default: static port 80
    port:
      value: integer
      annotation: string

    # Choose path either via static value or annotation
    # Optional
    # Annotation takes priority
    # Default: static path /metrics
    path:
      value: string
      annotation: string

    # Choose scheme either via static value (http or https) or annotation
    # Optional
    # Annotation takes priority
    # Default: static scheme http
    scheme:
      value: string
      annotation: string

    # Choose the frequency to scrape the metrics endpoint defined in podMetricsEndpoints
    # Optional
    # Default: 60s
    scrapeInterval: string

    # Dynamically rewrite the label set of a target before it gets scraped.
    # https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config
    # Optional
    # Default: No filtering by label
    metricsRelabelings:
      - sourceLabels:
          - string
        separator: string
        regex: string
        action: string
        targetLabel: string
        replacement: string

可观测性组

以下是用于更新 platform-obs 项目命名空间中信息中心存储空间大小的 ObservabilityPipeline 自定义资源示例:

# Configure observability pipeline
apiVersion: observability.gdc.goog/v1
kind: ObservabilityPipeline
metadata:
  # Don't change the namespace or name.
  namespace: platform-obs
  name: observability-config
spec:
  ...
  monitoring:
    grafana:
      storageSize: 1Gi # Configure the new storage size for dashboards in the project.
    ...