Health Checks

Docker Compose

The simples form of health check is to use the healthcheck directive in the docker-compose.yml file. This is useful if you are deploying Chroma alongside other services that may depend on it.

  1. version: '3.9'
  2. networks:
  3. net:
  4. driver: bridge
  5. services:
  6. server:
  7. image: server
  8. build:
  9. context: .
  10. dockerfile: Dockerfile
  11. volumes:
  12. # Be aware that indexed data are located in "/chroma/chroma/"
  13. # Default configuration for persist_directory in chromadb/config.py
  14. # Read more about deployments: https://docs.trychroma.com/deployment
  15. - chroma-data:/chroma/chroma
  16. command: "--workers 1 --host 0.0.0.0 --port 8000 --proxy-headers --log-config chromadb/log_config.yml --timeout-keep-alive 30"
  17. environment:
  18. - IS_PERSISTENT=TRUE
  19. - CHROMA_SERVER_AUTH_PROVIDER=${CHROMA_SERVER_AUTH_PROVIDER}
  20. - CHROMA_SERVER_AUTH_CREDENTIALS_FILE=${CHROMA_SERVER_AUTH_CREDENTIALS_FILE}
  21. - CHROMA_SERVER_AUTH_CREDENTIALS=${CHROMA_SERVER_AUTH_CREDENTIALS}
  22. - CHROMA_SERVER_AUTH_CREDENTIALS_PROVIDER=${CHROMA_SERVER_AUTH_CREDENTIALS_PROVIDER}
  23. - CHROMA_SERVER_AUTH_TOKEN_TRANSPORT_HEADER=${CHROMA_SERVER_AUTH_TOKEN_TRANSPORT_HEADER}
  24. - PERSIST_DIRECTORY=${PERSIST_DIRECTORY:-/chroma/chroma}
  25. - CHROMA_OTEL_EXPORTER_ENDPOINT=${CHROMA_OTEL_EXPORTER_ENDPOINT}
  26. - CHROMA_OTEL_EXPORTER_HEADERS=${CHROMA_OTEL_EXPORTER_HEADERS}
  27. - CHROMA_OTEL_SERVICE_NAME=${CHROMA_OTEL_SERVICE_NAME}
  28. - CHROMA_OTEL_GRANULARITY=${CHROMA_OTEL_GRANULARITY}
  29. - CHROMA_SERVER_NOFILE=${CHROMA_SERVER_NOFILE}
  30. ports:
  31. - 8000:8000
  32. healthcheck:
  33. test: [ "CMD", "/bin/bash", "-c", "cat < /dev/null > /dev/tcp/localhost/8001" ]
  34. interval: 30s
  35. timeout: 10s
  36. retries: 3
  37. networks:
  38. - net
  39. volumes:
  40. chroma-data:
  41. driver: local

Kubernetes

In kubernetes you can use the livenessProbe and readinessProbe to check the health of the server. This is useful if you are deploying Chroma in a kubernetes cluster.

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: chroma
  5. labels:
  6. app: chroma
  7. spec:
  8. replicas: 1
  9. selector:
  10. matchLabels:
  11. app: chroma
  12. template:
  13. metadata:
  14. labels:
  15. app: chroma
  16. spec:
  17. containers:
  18. - name: chroma
  19. image: <chroma-image>
  20. ports:
  21. - containerPort: 8000
  22. livenessProbe:
  23. httpGet:
  24. path: /api/v1
  25. port: 8000
  26. initialDelaySeconds: 5
  27. periodSeconds: 5
  28. readinessProbe:
  29. httpGet:
  30. path: /api/v1
  31. port: 8000
  32. initialDelaySeconds: 5
  33. periodSeconds: 5
  34. startupProbe:
  35. httpGet:
  36. path: /api/v1
  37. port: 8000
  38. failureThreshold: 3
  39. periodSeconds: 60
  40. initialDelaySeconds: 60

Alternative to the httpGet you can also use tcpSocket:

  1. readinessProbe:
  2. tcpSocket:
  3. port: 8000
  4. failureThreshold: 3
  5. timeoutSeconds: 30
  6. periodSeconds: 60
  7. livenessProbe:
  8. tcpSocket:
  9. port: 8000
  10. failureThreshold: 3
  11. timeoutSeconds: 30
  12. periodSeconds: 60
  13. startupProbe:
  14. tcpSocket:
  15. port: 8000
  16. failureThreshold: 3
  17. periodSeconds: 60
  18. initialDelaySeconds: 60

February 14, 2024