Skip to content

Commit b4bfe22

Browse files
committed
improve: improve instance handler logging
Signed-off-by: Shuo Wu <shuo.wu@suse.com>
1 parent e72e927 commit b4bfe22

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

controller/instance_handler.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewInstanceHandler(ds *datastore.DataStore, instanceManagerHandler Instance
4949
}
5050
}
5151

52-
func (h *InstanceHandler) syncStatusWithInstanceManager(im *longhorn.InstanceManager, instanceName string, spec *longhorn.InstanceSpec, status *longhorn.InstanceStatus, instances map[string]longhorn.InstanceProcess) {
52+
func (h *InstanceHandler) syncStatusWithInstanceManager(log *logrus.Entry, im *longhorn.InstanceManager, instanceName string, spec *longhorn.InstanceSpec, status *longhorn.InstanceStatus, instances map[string]longhorn.InstanceProcess) {
5353
defer func() {
5454
if status.CurrentState == longhorn.InstanceStateStopped {
5555
status.InstanceManagerName = ""
@@ -64,7 +64,7 @@ func (h *InstanceHandler) syncStatusWithInstanceManager(im *longhorn.InstanceMan
6464
if im == nil || im.Status.CurrentState == longhorn.InstanceManagerStateUnknown || isDelinquent {
6565
if status.Started {
6666
if status.CurrentState != longhorn.InstanceStateUnknown {
67-
logrus.Warnf("Marking the instance as state UNKNOWN since the related node %v of instance %v is down or deleted", spec.NodeID, instanceName)
67+
log.Warnf("Marking the instance as state UNKNOWN since the related node %v of instance %v is down or deleted", spec.NodeID, instanceName)
6868
}
6969
status.CurrentState = longhorn.InstanceStateUnknown
7070
} else {
@@ -122,7 +122,7 @@ func (h *InstanceHandler) syncStatusWithInstanceManager(im *longhorn.InstanceMan
122122
if !exists {
123123
if status.Started {
124124
if status.CurrentState != longhorn.InstanceStateError {
125-
logrus.Warnf("Marking the instance as state ERROR since failed to find the instance status in instance manager %v for the running instance %v", im.Name, instanceName)
125+
log.Warnf("Marking the instance as state ERROR since failed to find the instance status in instance manager %v for the running instance %v", im.Name, instanceName)
126126
}
127127
status.CurrentState = longhorn.InstanceStateError
128128
} else {
@@ -139,7 +139,7 @@ func (h *InstanceHandler) syncStatusWithInstanceManager(im *longhorn.InstanceMan
139139
}
140140

141141
if status.InstanceManagerName != "" && status.InstanceManagerName != im.Name {
142-
logrus.Errorf("The related process of instance %v is found in the instance manager %v, but the instance manager name in the instance status is %v. "+
142+
log.Errorf("The related process of instance %v is found in the instance manager %v, but the instance manager name in the instance status is %v. "+
143143
"The instance manager name shouldn't change except for cleanup",
144144
instanceName, im.Name, status.InstanceManagerName)
145145
}
@@ -164,28 +164,28 @@ func (h *InstanceHandler) syncStatusWithInstanceManager(im *longhorn.InstanceMan
164164

165165
imPod, err := h.ds.GetPodRO(im.Namespace, im.Name)
166166
if err != nil {
167-
logrus.WithError(err).Errorf("Failed to get instance manager pod from %v", im.Name)
167+
log.WithError(err).Errorf("Failed to get instance manager pod from %v", im.Name)
168168
return
169169
}
170170

171171
if imPod == nil {
172-
logrus.Warnf("Instance manager pod from %v not exist in datastore", im.Name)
172+
log.Warnf("Instance manager pod from %v not exist in datastore", im.Name)
173173
return
174174
}
175175

176176
storageIP := h.ds.GetStorageIPFromPod(imPod)
177177
if status.StorageIP != storageIP {
178+
log.Warnf("Instance %v is state running in instance manager %s, but its recorded Storage IP %s does not match the instance manager pod Storage IP %s", instanceName, im.Name, status.StorageIP, storageIP)
178179
status.StorageIP = storageIP
179-
logrus.Warnf("Instance %v starts running, Storage IP %v", instanceName, status.StorageIP)
180180
}
181181

182182
if status.IP != im.Status.IP {
183+
log.Warnf("Instance %v is state running in instance manager %s, but its recorded IP %s does not match the instance manager recorded IP %s", instanceName, im.Name, status.IP, im.Status.IP)
183184
status.IP = im.Status.IP
184-
logrus.Warnf("Instance %v starts running, IP %v", instanceName, status.IP)
185185
}
186186
if status.Port != int(instance.Status.PortStart) {
187+
log.Warnf("Instance %v is state running in instance manager %s, but its recorded Port %d does not match the instance manager recorded Port %d", instanceName, im.Name, status.Port, instance.Status.PortStart)
187188
status.Port = int(instance.Status.PortStart)
188-
logrus.Warnf("Instance %v starts running, Port %d", instanceName, status.Port)
189189
}
190190
if status.UblkID != instance.Status.UblkID {
191191
status.UblkID = instance.Status.UblkID
@@ -278,7 +278,7 @@ func (h *InstanceHandler) ReconcileInstanceState(obj interface{}, spec *longhorn
278278
return err
279279
}
280280

281-
log := logrus.WithField("instance", instanceName)
281+
log := logrus.WithFields(logrus.Fields{"instance": instanceName, "volumeName": spec.VolumeName, "dataEngine": spec.DataEngine, "specNodeID": spec.NodeID})
282282

283283
var im *longhorn.InstanceManager
284284
if status.InstanceManagerName != "" {
@@ -310,6 +310,9 @@ func (h *InstanceHandler) ReconcileInstanceState(obj interface{}, spec *longhorn
310310
}
311311
}
312312
}
313+
if im != nil {
314+
log = log.WithFields(logrus.Fields{"instanceManager": im.Name})
315+
}
313316

314317
if spec.LogRequested {
315318
if !status.LogFetched {
@@ -388,7 +391,7 @@ func (h *InstanceHandler) ReconcileInstanceState(obj interface{}, spec *longhorn
388391
return fmt.Errorf("unknown instance desire state: desire %v", spec.DesireState)
389392
}
390393

391-
h.syncStatusWithInstanceManager(im, instanceName, spec, status, instances)
394+
h.syncStatusWithInstanceManager(log, im, instanceName, spec, status, instances)
392395

393396
switch status.CurrentState {
394397
case longhorn.InstanceStateRunning:
@@ -417,10 +420,10 @@ func (h *InstanceHandler) ReconcileInstanceState(obj interface{}, spec *longhorn
417420
}
418421

419422
if types.IsDataEngineV1(instance.Spec.DataEngine) {
420-
logrus.Warnf("Instance %v crashed on Instance Manager %v at %v, getting log",
423+
log.Warnf("Instance %v crashed on Instance Manager %v at %v, getting log",
421424
instanceName, im.Name, im.Spec.NodeID)
422425
if err := h.printInstanceLogs(instanceName, runtimeObj); err != nil {
423-
logrus.WithError(err).Warnf("failed to get crash log for instance %v on Instance Manager %v at %v",
426+
log.WithError(err).Warnf("failed to get crash log for instance %v on Instance Manager %v at %v",
424427
instanceName, im.Name, im.Spec.NodeID)
425428
}
426429
}

0 commit comments

Comments
 (0)