Skip to content

Commit c57d909

Browse files
author
Samuel Archambault
committed
fix data format - still simple json
1 parent b81fbb3 commit c57d909

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

libpod/oci_conmon_common.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,28 +1514,27 @@ func readConmonHealthCheckPipeData(ctr *Container, pipe *os.File) {
15141514
return
15151515
}
15161516

1517-
// Log the raw message received from conmon
1518-
logrus.Debugf("HEALTHCHECK: Raw message received from conmon for container %s: %q", ctr.ID(), string(b))
1519-
logrus.Debugf("HEALTHCHECK: Message length: %d bytes", len(b))
1517+
// Log the raw JSON string received from conmon
1518+
logrus.Debugf("HEALTHCHECK: Raw JSON received from conmon for container %s: %q", ctr.ID(), string(b))
1519+
logrus.Debugf("HEALTHCHECK: JSON length: %d bytes", len(b))
15201520

1521-
// Parse the message as a simple integer (no JSON)
1522-
messageStr := strings.TrimSpace(string(b))
1523-
messageType, err := strconv.Atoi(messageStr)
1524-
if err != nil {
1525-
logrus.Errorf("HEALTHCHECK: Failed to parse message as integer for container %s: %v", ctr.ID(), err)
1521+
// Parse the JSON
1522+
var si syncInfo
1523+
if err := json.Unmarshal(b, &si); err != nil {
1524+
logrus.Errorf("HEALTHCHECK: Failed to parse JSON from conmon for container %s: %v", ctr.ID(), err)
15261525
continue
15271526
}
15281527

1529-
logrus.Debugf("HEALTHCHECK: Parsed message type for container %s: %d", ctr.ID(), messageType)
1528+
logrus.Debugf("HEALTHCHECK: Parsed sync info for container %s: Data=%d, Message=%q", ctr.ID(), si.Data, si.Message)
15301529

15311530
// Handle healthcheck status updates based on your new encoding scheme
15321531
// Base message type is -100, status values are added to it:
15331532
// -100 + 0 (none) = -100
15341533
// -100 + 1 (starting) = -99
15351534
// -100 + 2 (healthy) = -98
15361535
// -100 + 3 (unhealthy) = -97
1537-
if messageType >= HealthCheckMsgStatusUpdate && messageType <= HealthCheckMsgStatusUpdate+HealthCheckStatusUnhealthy {
1538-
statusValue := messageType - HealthCheckMsgStatusUpdate // Convert back to status value
1536+
if si.Data >= HealthCheckMsgStatusUpdate && si.Data <= HealthCheckMsgStatusUpdate+HealthCheckStatusUnhealthy {
1537+
statusValue := si.Data - HealthCheckMsgStatusUpdate // Convert back to status value
15391538
var status string
15401539

15411540
switch statusValue {
@@ -1553,20 +1552,20 @@ func readConmonHealthCheckPipeData(ctr *Container, pipe *os.File) {
15531552
}
15541553

15551554
logrus.Infof("HEALTHCHECK: Received healthcheck status update for container %s: %s (message type: %d, status value: %d)",
1556-
ctr.ID(), status, messageType, statusValue)
1555+
ctr.ID(), status, si.Data, statusValue)
15571556

15581557
// Update the container's healthcheck status
15591558
if err := ctr.updateHealthStatus(status); err != nil {
15601559
logrus.Errorf("HEALTHCHECK: Failed to update healthcheck status for container %s: %v", ctr.ID(), err)
15611560
} else {
15621561
logrus.Infof("HEALTHCHECK: Successfully updated healthcheck status for container %s to %s", ctr.ID(), status)
15631562
}
1564-
} else if messageType < 0 {
1563+
} else if si.Data < 0 {
15651564
// Other negative message types - might be healthcheck related but not recognized
1566-
logrus.Debugf("HEALTHCHECK: Received unrecognized negative message type %d for container %s - might be healthcheck related", messageType, ctr.ID())
1567-
} else if messageType > 0 {
1565+
logrus.Debugf("HEALTHCHECK: Received unrecognized negative message type %d for container %s - might be healthcheck related", si.Data, ctr.ID())
1566+
} else if si.Data > 0 {
15681567
// Positive message types - not healthcheck related
1569-
logrus.Debugf("HEALTHCHECK: Received positive message type %d for container %s - not healthcheck related", messageType, ctr.ID())
1568+
logrus.Debugf("HEALTHCHECK: Received positive message type %d for container %s - not healthcheck related", si.Data, ctr.ID())
15701569
}
15711570
}
15721571
}

0 commit comments

Comments
 (0)