ClickStack использует сборщик OpenTelemetry (OTel) для сбора логов, метрик и событий Kubernetes из кластеров Kubernetes и их перенаправления в ClickStack. Мы поддерживаем родной формат логов OTel и не требуем дополнительной специфичной для вендора конфигурации.
Это руководство охватывает следующее:
- Логи
- Инфраструктурные метрики
примечание
Чтобы отправлять метрики уровня приложения или APM/трассировки, вам также необходимо добавить соответствующую языковую интеграцию в ваше приложение.
Следующее руководство предполагает, что вы развернули сборщик ClickStack OTel в качестве шлюза, защищенного ключом API для приема данных.
Создание конфигурационных файлов Helm chart OTel
Чтобы собирать логи и метрики как с каждого узла, так и с самого кластера, нам нужно развернуть два отдельных сборщика OpenTelemetry. Один будет развернут как DaemonSet для сбора логов и метрик с каждого узла, а другой будет развернут как развертывание для сбора логов и метрик самого кластера.
Создание секрета для ключа API
Создайте новый Kubernetes секрет с ключом API для приема данных из HyperDX. Этот ключ будет использоваться компонентами, установленными ниже, для безопасного приема данных в ваш сборщик ClickStack OTel:
kubectl create secret generic hyperdx-secret \
--from-literal=HYPERDX_API_KEY=<ingestion_api_key> \
Кроме того, создайте конфигурационную карту с расположением вашего сборщика ClickStack OTel:
kubectl create configmap -n=otel-demo otel-config-vars --from-literal=YOUR_OTEL_COLLECTOR_ENDPOINT=<OTEL_COLLECTOR_ENDPOINT>
# e.g. kubectl create configmap -n=otel-demo otel-config-vars --from-literal=YOUR_OTEL_COLLECTOR_ENDPOINT=http://my-hyperdx-hdx-oss-v2-otel-collector:4318
Создание конфигурации DaemonSet
DaemonSet будет собирать логи и метрики с каждого узла в кластере, но не будет собирать события Kubernetes или метрики на уровне кластера.
Скачайте манифест DaemonSet:
curl -O https://raw.githubusercontent.com/ClickHouse/clickhouse-docs/refs/heads/main/docs/use-cases/observability/clickstack/example-datasets/_snippets/k8s_daemonset.yaml
k8s_daemonset.yaml
# daemonset.yaml
mode: daemonset
# Required to use the kubeletstats cpu/memory utilization metrics
clusterRole:
create: true
rules:
- apiGroups:
- ''
resources:
- nodes/proxy
verbs:
- get
presets:
logsCollection:
enabled: true
hostMetrics:
enabled: true
# Configures the Kubernetes Processor to add Kubernetes metadata.
# Adds the k8sattributes processor to all the pipelines and adds the necessary rules to ClusterRole.
# More info: https://opentelemetry.io/docs/kubernetes/collector/components/#kubernetes-attributes-processor
kubernetesAttributes:
enabled: true
# When enabled the processor will extra all labels for an associated pod and add them as resource attributes.
# The label's exact name will be the key.
extractAllPodLabels: true
# When enabled the processor will extra all annotations for an associated pod and add them as resource attributes.
# The annotation's exact name will be the key.
extractAllPodAnnotations: true
# Configures the collector to collect node, pod, and container metrics from the API server on a kubelet..
# Adds the kubeletstats receiver to the metrics pipeline and adds the necessary rules to ClusterRole.
# More Info: https://opentelemetry.io/docs/kubernetes/collector/components/#kubeletstats-receiver
kubeletMetrics:
enabled: true
extraEnvs:
- name: HYPERDX_API_KEY
valueFrom:
secretKeyRef:
name: hyperdx-secret
key: HYPERDX_API_KEY
optional: true
- name: YOUR_OTEL_COLLECTOR_ENDPOINT
valueFrom:
configMapKeyRef:
name: otel-config-vars
key: YOUR_OTEL_COLLECTOR_ENDPOINT
config:
receivers:
# Configures additional kubelet metrics
kubeletstats:
collection_interval: 20s
auth_type: 'serviceAccount'
endpoint: '${env:K8S_NODE_NAME}:10250'
insecure_skip_verify: true
metrics:
k8s.pod.cpu_limit_utilization:
enabled: true
k8s.pod.cpu_request_utilization:
enabled: true
k8s.pod.memory_limit_utilization:
enabled: true
k8s.pod.memory_request_utilization:
enabled: true
k8s.pod.uptime:
enabled: true
k8s.node.uptime:
enabled: true
k8s.container.cpu_limit_utilization:
enabled: true
k8s.container.cpu_request_utilization:
enabled: true
k8s.container.memory_limit_utilization:
enabled: true
k8s.container.memory_request_utilization:
enabled: true
container.uptime:
enabled: true
exporters:
otlphttp:
endpoint: "${env:YOUR_OTEL_COLLECTOR_ENDPOINT}"
headers:
authorization: "${env:HYPERDX_API_KEY}"
compression: gzip
service:
pipelines:
logs:
exporters:
- otlphttp
metrics:
exporters:
- otlphttp
Создание конфигурации развертывания
Чтобы собирать события Kubernetes и метрики на уровне кластера, нам нужно развернуть отдельный сборщик OpenTelemetry как развертывание.
Скачайте манифест развертывания:
curl -O https://raw.githubusercontent.com/ClickHouse/clickhouse-docs/refs/heads/main/docs/use-cases/observability/clickstack/example-datasets/_snippets/k8s_deployment.yaml
k8s_deployment.yaml
# deployment.yaml
mode: deployment
image:
repository: otel/opentelemetry-collector-contrib
tag: 0.123.0
# We only want one of these collectors - any more and we'd produce duplicate data
replicaCount: 1
presets:
kubernetesAttributes:
enabled: true
# When enabled the processor will extra all labels for an associated pod and add them as resource attributes.
# The label's exact name will be the key.
extractAllPodLabels: true
# When enabled the processor will extra all annotations for an associated pod and add them as resource attributes.
# The annotation's exact name will be the key.
extractAllPodAnnotations: true
# Configures the collector to collect kubernetes events.
# Adds the k8sobject receiver to the logs pipeline and collects kubernetes events by default.
# More Info: https://opentelemetry.io/docs/kubernetes/collector/components/#kubernetes-objects-receiver
kubernetesEvents:
enabled: true
# Configures the Kubernetes Cluster Receiver to collect cluster-level metrics.
# Adds the k8s_cluster receiver to the metrics pipeline and adds the necessary rules to ClusteRole.
# More Info: https://opentelemetry.io/docs/kubernetes/collector/components/#kubernetes-cluster-receiver
clusterMetrics:
enabled: true
extraEnvs:
- name: HYPERDX_API_KEY
valueFrom:
secretKeyRef:
name: hyperdx-secret
key: HYPERDX_API_KEY
optional: true
- name: YOUR_OTEL_COLLECTOR_ENDPOINT
valueFrom:
configMapKeyRef:
name: otel-config-vars
key: YOUR_OTEL_COLLECTOR_ENDPOINT
config:
exporters:
otlphttp:
endpoint: "${env:YOUR_OTEL_COLLECTOR_ENDPOINT}"
compression: gzip
headers:
authorization: "${env:HYPERDX_API_KEY}"
service:
pipelines:
logs:
exporters:
- otlphttp
metrics:
exporters:
- otlphttp
Развертывание сборщика OpenTelemetry
Сборщик OpenTelemetry теперь можно развернуть в вашем кластере Kubernetes с помощью
OpenTelemetry Helm Chart.
Добавьте репозиторий OpenTelemetry Helm:
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts # Add OTel Helm repo
Установите chart с вышеуказанной конфигурацией:
helm install my-opentelemetry-collector-deployment open-telemetry/opentelemetry-collector -f k8s_deployment.yaml
helm install my-opentelemetry-collector-daemonset open-telemetry/opentelemetry-collector -f k8s_daemonset.yaml
Теперь метрики, логи и события Kubernetes из вашего кластера Kubernetes должны появиться в HyperDX.
Чтобы сопоставить логи, метрики и трассировки уровня приложения с метаданными Kubernetes (например, имя пода, пространство имен и т. д.), вы захотите перенаправить метаданные Kubernetes в ваше приложение, используя переменную окружения OTEL_RESOURCE_ATTRIBUTES
.
Вот пример развертывания, которое перенаправляет метаданные Kubernetes в приложение с помощью переменных окружения:
# my_app_deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-deployment
spec:
replicas: 1
selector:
matchLabels:
app: app
template:
metadata:
labels:
app: app
# Combined with the Kubernetes Attribute Processor, this will ensure
# the pod's logs and metrics will be associated with a service name.
service.name: <MY_APP_NAME>
spec:
containers:
- name: app-container
image: my-image
env:
# ... other environment variables
# Collect K8s metadata from the downward API to forward to the app
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_UID
valueFrom:
fieldRef:
fieldPath: metadata.uid
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: DEPLOYMENT_NAME
valueFrom:
fieldRef:
fieldPath: metadata.labels['deployment']
# Forward the K8s metadata to the app via OTEL_RESOURCE_ATTRIBUTES
- name: OTEL_RESOURCE_ATTRIBUTES
value: k8s.pod.name=$(POD_NAME),k8s.pod.uid=$(POD_UID),k8s.namespace.name=$(POD_NAMESPACE),k8s.node.name=$(NODE_NAME),k8s.deployment.name=$(DEPLOYMENT_NAME)