Repository navigation
fix(k8s-statefulset/daemonset-healthcheck): tasks that end with no report output - #783
Open
answersamir wants to merge 3 commits into
Open
answersamir wants to merge 3 commits into
answersamir wants to merge 3 commits into
Conversation
…tput Four tasks in this bundle produced no task output on healthy StatefulSets: - Check for Container Restarts: container_restarts.sh printed plain text when nothing restarted, and narrative lines before the JSON when something did; the runbook json.loads()-ed stdout and failed either way. The script now writes the narrative to stderr and always prints a JSON array; the runbook parses it defensively, raises an issue when it cannot, defines issue_timestamp on the script-failure path, and always adds a summary to the report. - Inspect StatefulSet Replicas: the healthy path added nothing to the report. It now always reports the replica counts, and raises an issue when kubectl | jq returns nothing (no pipefail, so a failed get exits 0). - Analyze Application Log Patterns: LOG_PATTERN_CATEGORIES_STR was never made a suite variable, so the summary line failed after issues were raised. - Detect Log Anomalies: RW.K8sLog returns next_steps as a string; the runbook expanded it as a list and failed whenever an anomaly was found.
…il on unreadable pods - GNU date rejects "10m ago" / "3h ago", so THRESHOLD_TIME was empty and the restart window was ignored: any restart in the pod's lifetime counted. Expand the m/h suffix the same way k8s-deployment-healthcheck does. - A failed kubectl get statefulset / get pods (e.g. Forbidden) produced "[]", which read as "no restarts". Exit non-zero instead so the runbook raises "Container Restart Analysis Failed".
… fixes k8s-daemonset-healthcheck is a copy of the StatefulSet bundle and fails the same way: Check for Container Restarts json.loads() plain text, Analyze Application Log Patterns hits the missing LOG_PATTERN_CATEGORIES_STR suite variable, and Detect Log Anomalies expands the next_steps string as a list. Port both StatefulSet commits (stdout is a JSON array, narrative on stderr, defensive parsing, restart-age unit expansion, kubectl rc checks). Inspect DaemonSet Status already reports on the healthy path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On the lazarus ring, four default
k8s-statefulset-healthchecktasks record no output on healthy StatefulSets. Skill Builder batchae8711cb7ea5scored 11 plan steps as data gaps because of it. Across the batch's 15 run sessions (12 StatefulSet SLXs):json.loads(r'''No containers with restarts found for StatefulSet … in the last 10m.''')→JSONDecodeErrorVariable '${LOG_PATTERN_CATEGORIES_STR}' not foundValue of variable '@{issue["next_steps"]}' is not list or list-likeAdd Pre To Report)RBAC, the kubeconfig and the runner upload all work: other tasks in the same run requests uploaded output.
Causes and fixes
Check for Container Restarts
container_restarts.shprints plain text when nothing restarted, and narrative lines before the JSON when something did. The runbook runsjson.loads()on stdout, so the task fails in both cases. It never raises a real restart issue.${issue_timestamp}on the script-failure path, where it was undefined.Inspect StatefulSet Replicas
kubectl … | jqreturns nothing. There is no pipefail, so a Forbiddengetused to exit 0 and pass silently.Analyze Application Log Patterns
Set Suite Variable ${LOG_PATTERN_CATEGORIES_STR}, which is whatk8s-deployment-healthcheckalready does.Detect Log Anomalies
RW.K8sLog.Analyze Log Anomaliesreturnsnext_stepsas a newline-joined string.Restart script, second commit
date -d "10m ago"is invalid, soTHRESHOLD_TIMEwas empty andCONTAINER_RESTART_AGEwas ignored. Any restart in a pod's lifetime counted.m/hsuffix the wayk8s-deployment-healthcheckdoes. A failedkubectl get statefulsetorget podsnow exits 1, so the runbook raises "Container Restart Analysis Failed" instead of reading[]as "no restarts".k8s-daemonset-healthcheck, third commit
Testing
I ran
runbook.robotin a Debian container with rw-core-keywords in production mode, so it writesreport.jsonlandissues.jsonl. A stubkubectlreplayed the realrw-lazarus-vaultStatefulSet and pod JSON captured from lazarus, plus synthetic logs and restart variants.json.loadson narrative + JSON)CONTAINER_RESTART_AGE=10mCONTAINER_RESTART_AGE=2dget/logsForbiddenNot changed (pre-existing, RBAC-only):
Fetch Workload Logsraises.Inspect DaemonSet StatusreportsReady=0/0without an issue.