Skip to content

Commit 623df05

Browse files
committed
debug logs and correlation id
Signed-off-by: Ujjwal Kumar <[email protected]>
1 parent cabd99d commit 623df05

15 files changed

+193
-85
lines changed

builder/ibmcloud/vpc/client.go

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,11 @@ func (client IBMCloudClient) isResourceDown(resourceID string, resourceType stri
211211
instance, response, err := vpcService.GetInstance(options)
212212
if err != nil {
213213
xRequestId := response.Headers["X-Request-Id"][0]
214-
xCorrelationId := response.Headers["X-Correlation-Id"][0]
215-
err := fmt.Errorf("[ERROR] Failed retrieving resource information. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s", err, xRequestId, xCorrelationId)
214+
xCorrelationId := ""
215+
if len(response.Headers["X-Correlation-Id"]) != 0 {
216+
xCorrelationId = fmt.Sprintf("\n X-Correlation-Id : %s", response.Headers["X-Correlation-Id"][0])
217+
}
218+
err := fmt.Errorf("[ERROR] Failed retrieving resource information. Error: %s \n X-Request-Id : %s %s", err, xRequestId, xCorrelationId)
216219
ui.Error(err.Error())
217220
log.Println(err.Error())
218221
return false, err
@@ -241,8 +244,11 @@ func (client IBMCloudClient) manageInstance(resourceID string, action string, st
241244
response, res, err := vpcService.CreateInstanceAction(options)
242245
if err != nil {
243246
xRequestId := res.Headers["X-Request-Id"][0]
244-
xCorrelationId := res.Headers["X-Correlation-Id"][0]
245-
err := fmt.Errorf("[ERROR] Failed to perform %s action over instance. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s", action, err, xRequestId, xCorrelationId)
247+
xCorrelationId := ""
248+
if len(res.Headers["X-Correlation-Id"]) != 0 {
249+
xCorrelationId = fmt.Sprintf("\n X-Correlation-Id : %s", res.Headers["X-Correlation-Id"][0])
250+
}
251+
err := fmt.Errorf("[ERROR] Failed to perform %s action over instance. Error: %s \n X-Request-Id : %s %s", action, err, xRequestId, xCorrelationId)
246252
ui.Error(err.Error())
247253
log.Println(err.Error())
248254
return "", err
@@ -267,8 +273,11 @@ func (client IBMCloudClient) retrieveResource(resourceID string, state multistep
267273

268274
if err != nil {
269275
xRequestId := response.Headers["X-Request-Id"][0]
270-
xCorrelationId := response.Headers["X-Correlation-Id"][0]
271-
err := fmt.Errorf("[ERROR] Failed retrieving resource information. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s", err, xRequestId, xCorrelationId)
276+
xCorrelationId := ""
277+
if len(response.Headers["X-Correlation-Id"]) != 0 {
278+
xCorrelationId = fmt.Sprintf("\n X-Correlation-Id : %s", response.Headers["X-Correlation-Id"][0])
279+
}
280+
err := fmt.Errorf("[ERROR] Failed retrieving resource information. Error: %s \n X-Request-Id : %s %s", err, xRequestId, xCorrelationId)
272281
ui.Error(err.Error())
273282
log.Println(err.Error())
274283
return nil, err
@@ -306,8 +315,11 @@ func (client IBMCloudClient) createFloatingIP(state multistep.StateBag) (*vpcv1.
306315
floatingIP, response, err := vpcService.CreateFloatingIP(options)
307316
if err != nil {
308317
xRequestId := response.Headers["X-Request-Id"][0]
309-
xCorrelationId := response.Headers["X-Correlation-Id"][0]
310-
err := fmt.Errorf("[ERROR] Failed creating Floating IP Request. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s", err, xRequestId, xCorrelationId)
318+
xCorrelationId := ""
319+
if len(response.Headers["X-Correlation-Id"]) != 0 {
320+
xCorrelationId = fmt.Sprintf("\n X-Correlation-Id : %s", response.Headers["X-Correlation-Id"][0])
321+
}
322+
err := fmt.Errorf("[ERROR] Failed creating Floating IP Request. Error: %s \n X-Request-Id : %s %s", err, xRequestId, xCorrelationId)
311323
ui.Error(err.Error())
312324
log.Println(err.Error())
313325
return nil, err
@@ -327,8 +339,11 @@ func (client IBMCloudClient) GrabCredentials(instanceID string, state multistep.
327339
instanceCredentials, response, err := vpcService.GetInstanceInitialization(options)
328340
if err != nil {
329341
xRequestId := response.Headers["X-Request-Id"][0]
330-
xCorrelationId := response.Headers["X-Correlation-Id"][0]
331-
err := fmt.Errorf("[ERROR] Failed getting instance initialization data. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s", err, xRequestId, xCorrelationId)
342+
xCorrelationId := ""
343+
if len(response.Headers["X-Correlation-Id"]) != 0 {
344+
xCorrelationId = fmt.Sprintf("\n X-Correlation-Id : %s", response.Headers["X-Correlation-Id"][0])
345+
}
346+
err := fmt.Errorf("[ERROR] Failed getting instance initialization data. Error: %s \n X-Request-Id : %s %s", err, xRequestId, xCorrelationId)
332347
ui.Error(err.Error())
333348
log.Println(err.Error())
334349
return "", "", err
@@ -413,8 +428,11 @@ func (client IBMCloudClient) createSSHKeyVPC(state multistep.StateBag) (*vpcv1.K
413428
key, response, err := vpcService.CreateKey(options)
414429
if err != nil {
415430
xRequestId := response.Headers["X-Request-Id"][0]
416-
xCorrelationId := response.Headers["X-Correlation-Id"][0]
417-
err := fmt.Errorf("[ERROR] Error sending the HTTP request that creates the SSH Key for VPC. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s", err, xRequestId, xCorrelationId)
431+
xCorrelationId := ""
432+
if len(response.Headers["X-Correlation-Id"]) != 0 {
433+
xCorrelationId = fmt.Sprintf("\n X-Correlation-Id : %s", response.Headers["X-Correlation-Id"][0])
434+
}
435+
err := fmt.Errorf("[ERROR] Error sending the HTTP request that creates the SSH Key for VPC. Error: %s \n X-Request-Id : %s %s", err, xRequestId, xCorrelationId)
418436
ui.Error(err.Error())
419437
log.Println(err.Error())
420438
return nil, err
@@ -432,8 +450,11 @@ func (client IBMCloudClient) getSecurityGroup(state multistep.StateBag, security
432450
securityGroup, response, err := vpcService.GetSecurityGroup(&securityGroupData)
433451
if err != nil {
434452
xRequestId := response.Headers["X-Request-Id"][0]
435-
xCorrelationId := response.Headers["X-Correlation-Id"][0]
436-
err := fmt.Errorf("[ERROR] Error getting the Security Group. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s", err, xRequestId, xCorrelationId)
453+
xCorrelationId := ""
454+
if len(response.Headers["X-Correlation-Id"]) != 0 {
455+
xCorrelationId = fmt.Sprintf("\n X-Correlation-Id : %s", response.Headers["X-Correlation-Id"][0])
456+
}
457+
err := fmt.Errorf("[ERROR] Error getting the Security Group. Error: %s \n X-Request-Id : %s %s", err, xRequestId, xCorrelationId)
437458
ui.Error(err.Error())
438459
log.Println(err.Error())
439460
return nil, err
@@ -451,8 +472,11 @@ func (client IBMCloudClient) createSecurityGroup(state multistep.StateBag, secur
451472
securityGroup, response, err := vpcService.CreateSecurityGroup(&securityGroupData)
452473
if err != nil {
453474
xRequestId := response.Headers["X-Request-Id"][0]
454-
xCorrelationId := response.Headers["X-Correlation-Id"][0]
455-
err := fmt.Errorf("[ERROR] Error creating the Security Group. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s", err, xRequestId, xCorrelationId)
475+
xCorrelationId := ""
476+
if len(response.Headers["X-Correlation-Id"]) != 0 {
477+
xCorrelationId = fmt.Sprintf("\n X-Correlation-Id : %s", response.Headers["X-Correlation-Id"][0])
478+
}
479+
err := fmt.Errorf("[ERROR] Error creating the Security Group. Error: %s \n X-Request-Id : %s %s", err, xRequestId, xCorrelationId)
456480
ui.Error(err.Error())
457481
log.Println(err.Error())
458482
return nil, err
@@ -473,8 +497,11 @@ func (client IBMCloudClient) createRule(rule vpcv1.CreateSecurityGroupRuleOption
473497

474498
if err != nil {
475499
xRequestId := response.Headers["X-Request-Id"][0]
476-
xCorrelationId := response.Headers["X-Correlation-Id"][0]
477-
err := fmt.Errorf("[ERROR] Error sending the HTTP request that creates a Security Group's rule. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s", err, xRequestId, xCorrelationId)
500+
xCorrelationId := ""
501+
if len(response.Headers["X-Correlation-Id"]) != 0 {
502+
xCorrelationId = fmt.Sprintf("\n X-Correlation-Id : %s", response.Headers["X-Correlation-Id"][0])
503+
}
504+
err := fmt.Errorf("[ERROR] Error sending the HTTP request that creates a Security Group's rule. Error: %s \n X-Request-Id : %s %s", err, xRequestId, xCorrelationId)
478505
ui.Error(err.Error())
479506
log.Println(err.Error())
480507
return nil, err
@@ -495,8 +522,11 @@ func (client IBMCloudClient) addNetworkInterfaceToSecurityGroup(securityGroupID
495522
securityGroupTargetReferenceIntf, response, err := vpcService.CreateSecurityGroupTargetBinding(options)
496523
if err != nil {
497524
xRequestId := response.Headers["X-Request-Id"][0]
498-
xCorrelationId := response.Headers["X-Correlation-Id"][0]
499-
err := fmt.Errorf("[ERROR] Error sending the HTTP request that Add the VSI's network interface to the Security Group. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s", err, xRequestId, xCorrelationId)
525+
xCorrelationId := ""
526+
if len(response.Headers["X-Correlation-Id"]) != 0 {
527+
xCorrelationId = fmt.Sprintf("\n X-Correlation-Id : %s", response.Headers["X-Correlation-Id"][0])
528+
}
529+
err := fmt.Errorf("[ERROR] Error sending the HTTP request that Add the VSI's network interface to the Security Group. Error: %s \n X-Request-Id : %s %s", err, xRequestId, xCorrelationId)
500530
ui.Error(err.Error())
501531
log.Println(err.Error())
502532
return nil, err

builder/ibmcloud/vpc/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Config struct {
4444
VSIInterface string `mapstructure:"vsi_interface"`
4545
VSIUserDataFile string `mapstructure:"vsi_user_data_file"`
4646
VSIUserDataString string `mapstructure:"vsi_user_data"`
47+
VPCDebugLogs string `mapstructure:"vpc_log"`
4748

4849
ImageName string `mapstructure:"image_name"`
4950
ImageTags []string `mapstructure:"tags"`

builder/ibmcloud/vpc/config.hcl2spec.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builder/ibmcloud/vpc/step_capture_image.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,23 @@ func (s *stepCaptureImage) Run(_ context.Context, state multistep.StateBag) mult
9292

9393
if err != nil {
9494
xRequestId := response.Headers["X-Request-Id"][0]
95-
xCorrelationId := response.Headers["X-Correlation-Id"][0]
96-
err := fmt.Errorf("[ERROR] Error sending the HTTP request that creates the image. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s", err, xRequestId, xCorrelationId)
95+
xCorrelationId := ""
96+
if len(response.Headers["X-Correlation-Id"]) != 0 {
97+
xCorrelationId = fmt.Sprintf("\n X-Correlation-Id : %s", response.Headers["X-Correlation-Id"][0])
98+
}
99+
err := fmt.Errorf("[ERROR] Error sending the HTTP request that creates the image. Error: %s \n X-Request-Id : %s %s", err, xRequestId, xCorrelationId)
97100
ui.Error(err.Error())
98101
log.Println(err.Error())
99102
return multistep.ActionHalt
100103
}
101104

102105
if err != nil {
103106
xRequestId := response.Headers["X-Request-Id"][0]
104-
xCorrelationId := response.Headers["X-Correlation-Id"][0]
105-
err := fmt.Errorf("[ERROR] Error creating the Image: %s \n X-Request-Id : %s \n X-Correlation-Id : %s", err, xRequestId, xCorrelationId)
107+
xCorrelationId := ""
108+
if len(response.Headers["X-Correlation-Id"]) != 0 {
109+
xCorrelationId = fmt.Sprintf("\n X-Correlation-Id : %s", response.Headers["X-Correlation-Id"][0])
110+
}
111+
err := fmt.Errorf("[ERROR] Error creating the Image: %s \n X-Request-Id : %s %s", err, xRequestId, xCorrelationId)
106112
state.Put("error", err)
107113
ui.Error(err.Error())
108114
// log.Fatalf(err.Error())

0 commit comments

Comments
 (0)