cakd observe
Overview
Section titled “Overview”The cakd observe command uses AI to analyze metrics and logs for a project namespace and return a concise diagnosis and remediation steps.
cakd observe <project-name> [flags]Environment Variables
Section titled “Environment Variables”| Env Var | Short | Type | Default | Description |
|---|---|---|---|---|
GEMINI_API_KEY | string | "" | Your Google Gemini API key. Required for AI diagnosis. | |
GEMINI_MODEL | string | "gemini-flash-latest" | The Gemini model to use for AI diagnosis. |
How It Works
Section titled “How It Works”- Accepts a single argument: the
project(Kubernetes namespace). - Reads the
GEMINI_API_KEYenvironment variable. If unset, the command exits with an error. - Initializes clients for Prometheus (metrics), Loki (logs), and Gemini (AI). The Gemini client uses the
GEMINI_MODELenvironment variable, defaulting togemini-flash-latestif not specified. - Fetches container restart metrics for the specified
projectfrom Prometheus. This is done by querying the Prometheus service directly if running in-cluster (detected by theKUBERNETES_SERVICE_HOSTenvironment variable) or by usingkubectl get --rawto proxy the request if running out-of-cluster. If fetching fails, a warning is printed, and “No metrics available” is used in the prompt. - Fetches the 50 most recent logs for the specified
projectfrom Loki. This is done by querying the Loki service directly if running in-cluster (detected by theKUBERNETES_SERVICE_HOSTenvironment variable) or by usingkubectl get --rawto proxy the request if running out-of-cluster. If fetching fails, a warning is printed, and “No logs available” is used in the prompt. - Constructs a detailed diagnostic prompt for the AI, including the fetched metrics and logs, and instructions to act as an expert DevOps engineer. The prompt explicitly requests the AI to “Answer in Vietnamese.”
- Sends the prompt to the Gemini AI model for analysis.
- Prints the AI-generated diagnosis, including identification of crashing pods, root cause analysis, and actionable solutions, to standard output.
Examples
Section titled “Examples”Basic usage
Section titled “Basic usage”export GEMINI_API_KEY="your_api_key"cakd observe my-appSpecifying a Gemini model
Section titled “Specifying a Gemini model”export GEMINI_API_KEY="your_api_key"export GEMINI_MODEL="gemini-pro"cakd observe my-app