loki-debug
Skill0 starsChanged 10 months agoMITView on GitHub
Debug Kubernetes pod failures by querying logs from Loki. Use when investigating errors, crashes, or unexpected behavior in pods. Provide a cluster, namespace, and service name to start.
In this repository13 other files it gives its agents.
- AGENTS.mdAGENTS.md
- argocd-opsSkill
- codexSkill
- convergent-reviewSkill
- create-handoffSkill
- create-planSkill
- create-researchSkill
- init-ai-docsSkill
- init-central-docsSkill
- jiraSkill
- pr-statusSkill
- resume-handoffSkill
- tatari-turboliftSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
20 rules. About 0 are common, 14 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈14
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 18
Use this skill when:
- Distinctive: line 27
Ensure these tools are available:
- Distinctive: line 37
Ask the user for:
- Distinctive: line 60
If port-forward fails or is blocked: Ask the user to run the port-forward command manually in a separate terminal:
- Distinctive: line 106
Important: Use single quotes around the query parameter to avoid shell escaping issues with curly braces.
- Distinctive: line 114
Look for error patterns: - Search for "error", "exception", "failed", "panic"
- Distinctive: line 116
Trace request flows: - Follow request IDs or trace IDs
- Distinctive: line 117
Compare pods: - Check if issue affects all pods or specific ones
- Distinctive: line 136
Add more specific pattern filters
- Distinctive: line 138
Check related services or upstream dependencies
- Very specific: line 187
Verify label names with /loki/api/v1/labels
- Distinctive: line 189
Check if the namespace/app labels match exactly
- Very specific: line 193
Ensure port-forward is running: ps aux | grep port-forward
- Distinctive: line 195
Check if port 3100 is already in use
- Distinctive: line 200
Add more specific filters
- Very specific: line 205
If you see parse error near '(' or similar zsh errors:
- Very specific: line 207
Use single quotes around the LogQL query: 'query={...}'
- Distinctive: line 208
Write curl output to a temp file before parsing with jq
- Very specific: line 209
Use arithmetic for time calculations: $(($(date +%s) - 3600))
- Very specific: line 210
Avoid the -v flag with date (use arithmetic instead)
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Loki Log Debugging Skill
Query Kubernetes pod logs stored in Loki to debug failures, errors, and unexpected behavior.
When to Use
Use this skill when:
- Investigating pod failures or crashes
- Debugging application errors in Kubernetes
- Searching for specific log patterns across pods
- Troubleshooting service issues in a cluster
Prerequisites
Ensure these tools are available:
kubectl- configured with cluster contextscurl- for HTTP requestsjq- for JSON parsing
Workflow
Step 1: Gather Information
Ask the user for:
- Cluster - Which cluster to search (test, staging, prod, apps, ops)
- Namespace - Kubernetes namespace (e.g.,
default,payments) - Service/App - Deployment or service name to filter
- Time range - How far back to search (e.g., "last 1 hour", "last 30 minutes")
Step 2: Connect to Loki
Switch kubectl context and set up port-forward:
# Switch to the target cluster
kubectl config use-context <cluster>
# Start port-forward to Loki gateway (run in background)
kubectl port-forward -n loki-system svc/loki-gateway 3100:80 &
LOKI_PF_PID=$!
# Wait for port-forward to establish
sleep 2If port-forward fails or is blocked: Ask the user to run the port-forward command manually in a separate terminal:
kubectl port-forward -n loki-system svc/loki-gateway 3100:80Then continue with the log queries once they confirm it's running.
Step 3: Discover Available Labels
Query Loki for available log labels:
curl -s http://localhost:3100/loki/api/v1/labels | jq '.data[]'Common labels include: namespace, pod, container, app, stream
To see values for a specific label:
curl -s "http://localhost:3100/loki/api/v1/label/<label_name>/values" | jq '.data[]'Step 4: Query Logs
Construct and execute the LogQL query:
# Calculate time range (example: last 1 hour)
# Use arithmetic for shell compatibility (works in bash, zsh, nix shells)
END_SECS=$(date +%s)
START_SECS=$((END_SECS - 3600))
# Query logs and save to temp file (avoids zsh brace parsing issues)
curl -G -s "http://localhost:3100/loki/api/v1/query_range" \
--data-urlencode 'query={namespace="<namespace>", app="<app>"}' \
--data-urlencode "start=${START_SECS}000000000" \
--data-urlencode "end=${END_SECS}000000000" \
--data-urlencode "limit=500" > /tmp/loki_logs.json
# Parse the results
jq -r '.data.result[].values[][1]' /tmp/loki_logs.jsonImportant: Use single quotes around the query parameter to avoid shell escaping issues with curly braces. Write output to a temp file before piping to jq to avoid zsh parsing errors.
Step 5: Analyze Results
When reviewing logs:
- Look for error patterns - Search for "error", "exception", "failed", "panic"
- Check timestamps - Identify when issues started
- Trace request flows - Follow request IDs or trace IDs
- Compare pods - Check if issue affects all pods or specific ones
To filter for errors only:
curl -G -s "http://localhost:3100/loki/api/v1/query_range" \
--data-urlencode 'query={namespace="<namespace>", app="<app>"} |~ "(?i)error|exception|failed"' \
--data-urlencode "start=${START_SECS}000000000" \
--data-urlencode "end=${END_SECS}000000000" \
--data-urlencode "limit=500" > /tmp/loki_logs.json
jq -r '.data.result[].values[][1]' /tmp/loki_logs.jsonStep 6: Iterate and Refine
Based on initial results:
- Narrow time range around the incident
- Add more specific pattern filters
- Query different labels (e.g., specific pod instead of app)
- Check related services or upstream dependencies
Step 7: Cleanup
Kill the port-forward when done:
kill $LOKI_PF_PID 2>/dev/nullCommon LogQL Patterns
# All logs from a namespace
{namespace="payments"}
# Logs from specific app
{namespace="payments", app="checkout-service"}
# Filter by log level
{namespace="payments"} |= "ERROR"
# Case-insensitive error search
{namespace="payments"} |~ "(?i)error"
# Exclude health checks
{namespace="payments"} != "healthcheck" != "/health"
# JSON log parsing
{namespace="payments"} | json | level="error"
# Multiple conditions
{namespace="payments", app="checkout"} |~ "error|exception" != "expected"Troubleshooting
Port-forward fails
# Check if Loki service exists
kubectl get svc -n loki-system
# Check if you can reach the cluster
kubectl cluster-infoNo logs returned
- Verify label names with
/loki/api/v1/labels - Expand time range
- Check if the namespace/app labels match exactly
Connection refused
- Ensure port-forward is running:
ps aux | grep port-forward - Try restarting the port-forward
- Check if port 3100 is already in use
Query timeout
- Reduce time range
- Add more specific filters
- Reduce limit parameter
Shell parsing errors
If you see parse error near '(' or similar zsh errors:
- Use single quotes around the LogQL query:
'query={...}' - Write curl output to a temp file before parsing with jq
- Use arithmetic for time calculations:
$(($(date +%s) - 3600)) - Avoid the
-vflag withdate(use arithmetic instead)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

