Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scanner: add more logs #100

Merged
merged 2 commits into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 44 additions & 26 deletions pkg/controller/blockdevice/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func (s *Scanner) collectAllDevices() []*deviceWithAutoProvision {
logrus.Infof("Skip adding non-identifiable block device /dev/%s", disk.Name)
continue
}
logrus.Infof("Adding the disk with block device /dev/%s, id(Name): %s on node %s", disk.Name, bd.Name, s.NodeName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already too late now that the PR has been merged, but this question nevertheless.

Does it not make sense to write this information in one line? The output in the log does not always have to look like in the code. In the meantime in which these output lines are written to the log, other messages can also be written. This can make the output quite confusing. Shouldn't logrus.WithFields be used here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree that.
We will use WithFields after introducing the log format.

I thought we had a similar issue with this (for the whole harvester components).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we had a similar issue with this (for the whole harvester components).

Yes, see here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly this one. I would like to refine all the logs when processing this.

logrus.Infof(" - wwn: %v", bd.Status.DeviceStatus.Details.WWN)
logrus.Infof(" - vendor: %v", bd.Status.DeviceStatus.Details.Vendor)
logrus.Infof(" - model: %v", bd.Status.DeviceStatus.Details.Model)
logrus.Infof(" - SerialNumber: %v", bd.Status.DeviceStatus.Details.SerialNumber)
autoProv := s.ApplyAutoProvisionFiltersForDisk(disk)
allDevices = append(allDevices, &deviceWithAutoProvision{bd: bd, AutoProvisioned: autoProv})

Expand All @@ -118,6 +123,40 @@ func (s *Scanner) collectAllDevices() []*deviceWithAutoProvision {
return allDevices
}

func (s *Scanner) handleExistingDev(oldBd *diskv1.BlockDevice, newBd *diskv1.BlockDevice, autoProvisioned bool) {
if isDevPathChanged(oldBd, newBd) {
logrus.Debugf("Enqueue block device %s for device path change", newBd.Name)
s.Blockdevices.Enqueue(s.Namespace, newBd.Name)
} else if isDevAlreadyProvisioned(newBd) {
logrus.Debugf("Skip the provisioned device: %s", newBd.Name)
} else if s.NeedsAutoProvision(oldBd, autoProvisioned) {
logrus.Debugf("Enqueue block device %s for auto-provisioning", newBd.Name)
s.Blockdevices.Enqueue(s.Namespace, newBd.Name)
} else {
logrus.Debugf("Skip updating device %s", newBd.Name)
}
}

func (s *Scanner) deactivateBlockDevices(oldBds map[string]*diskv1.BlockDevice) error {
for _, oldBd := range oldBds {
if oldBd.Status.State == diskv1.BlockDeviceInactive {
logrus.Debugf("The device %s is already inactive, continue.", oldBd.Name)
continue
}
logrus.Debugf("Change the device %s to inactive.", oldBd.Name)
newBd := oldBd.DeepCopy()
newBd.Status.State = diskv1.BlockDeviceInactive
if !reflect.DeepEqual(oldBd, newBd) {
logrus.Debugf("Update block device %s for new formatting and mount state", oldBd.Name)
if _, err := s.Blockdevices.Update(newBd); err != nil {
logrus.Errorf("Update device %s status error", oldBd.Name)
return err
}
}
}
return nil
}

// scanBlockDevicesOnNode scans block devices on the node, and it will either create or update them.
func (s *Scanner) scanBlockDevicesOnNode() error {
logrus.Debugf("Scan block devices of node: %s", s.NodeName)
Expand All @@ -133,21 +172,13 @@ func (s *Scanner) scanBlockDevicesOnNode() error {
}

oldBds, existingWWNs := convertBlockDeviceListToMap(oldBdList)
logrus.Debugf("The current BdList: %+v", oldBds)
for _, device := range allDevices {
bd := device.bd
autoProvisioned := device.AutoProvisioned
logrus.Debugf("Processing block device %s with wwn: %s", bd.Name, bd.Status.DeviceStatus.Details.WWN)
if oldBd, ok := oldBds[bd.Name]; ok {
if isDevPathChanged(oldBd, bd) {
logrus.Debugf("Enqueue block device %s for device path change", bd.Name)
s.Blockdevices.Enqueue(s.Namespace, bd.Name)
} else if isDevAlreadyProvisioned(bd) {
logrus.Debugf("Skip the provisioned device: %s", bd.Name)
} else if s.NeedsAutoProvision(oldBd, autoProvisioned) {
logrus.Debugf("Enqueue block device %s for auto-provisioning", bd.Name)
s.Blockdevices.Enqueue(s.Namespace, bd.Name)
} else {
logrus.Debugf("Skip updating device %s", bd.Name)
}
s.handleExistingDev(oldBd, bd, autoProvisioned)
// only first time to update the cache
if !CacheDiskTags.Initialized() && oldBd.Spec.Tags != nil && len(oldBd.Spec.Tags) > 0 {
CacheDiskTags.UpdateDiskTags(oldBd.Name, oldBd.Spec.Tags)
Expand Down Expand Up @@ -178,21 +209,8 @@ func (s *Scanner) scanBlockDevicesOnNode() error {

// We do not remove the block device that maybe just temporily not available.
// Set it to inactive and give the chance to recover.
for _, oldBd := range oldBds {
if oldBd.Status.State == diskv1.BlockDeviceInactive {
logrus.Debugf("The device %s is already inactive, continue.", oldBd.Name)
continue
}
logrus.Debugf("Change the device %s to inactive.", oldBd.Name)
newBd := oldBd.DeepCopy()
newBd.Status.State = diskv1.BlockDeviceInactive
if !reflect.DeepEqual(oldBd, newBd) {
logrus.Debugf("Update block device %s for new formatting and mount state", oldBd.Name)
if _, err := s.Blockdevices.Update(newBd); err != nil {
logrus.Errorf("Update device %s status error", oldBd.Name)
return err
}
}
if err := s.deactivateBlockDevices(oldBds); err != nil {
return err
}
return nil
}
Expand Down
Loading