Skip to content

Commit

Permalink
udev: Use structured logging in ActionHandler
Browse files Browse the repository at this point in the history
With this we now see messages like:

```
time="2024-07-17T01:37:24Z" level=debug msg="Prepare to handle udev action" udevAction=add udevEnv="map[..big chunk of stuff here..]"

time="2024-07-17T01:37:24Z" level=info msg="udev action triggering scanner wake" device=/dev/sda kind=BlockDevice name=b3270eab097d4515bac2d595665ac618 namespace=longhorn-system udevAction=add

time="2024-07-17T01:44:23Z" level=info msg="udev action triggering scanner wake" device=/dev/sda kind=BlockDevice name=b3270eab097d4515bac2d595665ac618 namespace=longhorn-system udevAction=remove
```

And in the case of an unidentifiable device:

```
time="2024-07-17T01:44:39Z" level=info msg="Skip adding non-identifiable block device" device=/dev/sda
```

Signed-off-by: Tim Serong <[email protected]>
(cherry picked from commit 61e0f7d)
  • Loading branch information
tserong authored and Vicente-Cheng committed Jul 17, 2024
1 parent 3360c30 commit 823d096
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions pkg/udev/uevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ func (u *Udev) ActionHandler(uevent netlink.UEvent) {
if !udevDevice.IsDisk() && !udevDevice.IsPartition() {
return
}
logrus.Debugf("Prepare to handle event: %s, env: %+v", uevent.Action, uevent.Env)
logrus.WithFields(logrus.Fields{
"udevAction": uevent.Action,
"udevEnv": fmt.Sprintf("%+v", uevent.Env),
}).Debug("Prepare to handle udev action")

devPath := udevDevice.GetDevName()
var disk *block.Disk
Expand Down Expand Up @@ -135,7 +138,10 @@ func (u *Udev) ActionHandler(uevent netlink.UEvent) {
} else {
parentPath, err := block.GetParentDevName(devPath)
if err != nil {
logrus.Errorf("failed to get parent dev name, %s", err.Error())
logrus.WithFields(logrus.Fields{
"device": devPath,
"err": err.Error(),
}).Error("Failed to get parent device name")
}
part = u.scanner.BlockInfo.GetPartitionByDevPath(parentPath, devPath)
disk = part.Disk
Expand All @@ -151,7 +157,9 @@ func (u *Udev) ActionHandler(uevent netlink.UEvent) {
}

if bd.Name == "" {
logrus.Infof("Skip adding non-identifiable block device %s", bd.Spec.DevPath)
logrus.WithFields(logrus.Fields{
"device": bd.Spec.DevPath,
}).Info("Skip adding non-identifiable block device")
return
}

Expand All @@ -161,7 +169,13 @@ func (u *Udev) ActionHandler(uevent netlink.UEvent) {

func (u *Udev) wakeUpScanner(uevent netlink.UEvent, bd *v1beta1.BlockDevice) {
utils.CallerWithCondLock(u.scanner.Cond, func() any {
logrus.Infof("Wake up scanner with %s operation with blockdevice: %s, device: %s", uevent.Action, bd.Name, bd.Spec.DevPath)
logrus.WithFields(logrus.Fields{
"namespace": bd.Namespace,
"name": bd.Name,
"kind": "BlockDevice",
"udevAction": uevent.Action,
"device": bd.Spec.DevPath,
}).Info("udev action triggering scanner wake")
u.scanner.Cond.Signal()
return nil
})
Expand Down

0 comments on commit 823d096

Please sign in to comment.