From 25cb3dc2532c8eeaff74c4459914035fabe64769 Mon Sep 17 00:00:00 2001 From: viv-ng Date: Mon, 25 Nov 2024 13:09:33 -0800 Subject: [PATCH 1/5] Update awssqs.go with logging before calling AWS getQueueUrl() & sendMessage(). Added more logging to see what input we are calling AWS methods with. Signed-off-by: Vivien Ng --- pkg/services/awssqs.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/services/awssqs.go b/pkg/services/awssqs.go index 026f9e2e..aa5af81b 100644 --- a/pkg/services/awssqs.go +++ b/pkg/services/awssqs.go @@ -49,12 +49,15 @@ func (s awsSqsService) Send(notif Notification, dest Destination) error { client := sqs.NewFromConfig(cfg) + // 'client' provides credential, region, endpointUrl + // 'getQueueInput()' provides queueName, accountId queueUrl, err := GetQueueURL(context.TODO(), client, s.getQueueInput(dest)) if err != nil { log.Error("Got an error getting the queue URL: ", err) return err } + // 'sendMessageInput()' provides queueUrl, message sendMessage, err := SendMsg(context.TODO(), client, s.sendMessageInput(queueUrl.QueueUrl, notif)) if err != nil { log.Error("Got an error sending the message: ", err) @@ -189,9 +192,11 @@ type SQSSendMessageAPI interface { } var GetQueueURL = func(c context.Context, api SQSSendMessageAPI, input *sqs.GetQueueUrlInput) (*sqs.GetQueueUrlOutput, error) { + log.Info("[GetQueueUrl] queue_name: %s, account_id: %s", input.QueueName, input.QueueOwnerAWSAccountId) return api.GetQueueUrl(c, input) } var SendMsg = func(c context.Context, api SQSSendMessageAPI, input *sqs.SendMessageInput) (*sqs.SendMessageOutput, error) { + log.Info("[SendMsg] queue_url: %s, message_body: %s", input.QueueUrl, input.MessageBody) return api.SendMessage(c, input) } From f01924b91fc7c4891f8c6c713afdf8f2b31c480e Mon Sep 17 00:00:00 2001 From: Vivien Ng Date: Mon, 25 Nov 2024 13:41:14 -0800 Subject: [PATCH 2/5] fixed syntax error Signed-off-by: Vivien Ng --- pkg/services/awssqs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/services/awssqs.go b/pkg/services/awssqs.go index aa5af81b..c3312873 100644 --- a/pkg/services/awssqs.go +++ b/pkg/services/awssqs.go @@ -192,11 +192,11 @@ type SQSSendMessageAPI interface { } var GetQueueURL = func(c context.Context, api SQSSendMessageAPI, input *sqs.GetQueueUrlInput) (*sqs.GetQueueUrlOutput, error) { - log.Info("[GetQueueUrl] queue_name: %s, account_id: %s", input.QueueName, input.QueueOwnerAWSAccountId) + log.Infof("[GetQueueUrl] queue_name: %s, account_id: %s", input.QueueName, input.QueueOwnerAWSAccountId) return api.GetQueueUrl(c, input) } var SendMsg = func(c context.Context, api SQSSendMessageAPI, input *sqs.SendMessageInput) (*sqs.SendMessageOutput, error) { - log.Info("[SendMsg] queue_url: %s, message_body: %s", input.QueueUrl, input.MessageBody) + log.Infof("[SendMsg] queue_url: %s, message_body: %s", input.QueueUrl, input.MessageBody) return api.SendMessage(c, input) } From 256494f83dd35849f73ef74caca07fec29d8fd5f Mon Sep 17 00:00:00 2001 From: Vivien Ng Date: Mon, 25 Nov 2024 15:29:30 -0800 Subject: [PATCH 3/5] fixing log statement syntax Signed-off-by: Vivien Ng --- pkg/services/awssqs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/services/awssqs.go b/pkg/services/awssqs.go index c3312873..4ac3d996 100644 --- a/pkg/services/awssqs.go +++ b/pkg/services/awssqs.go @@ -192,11 +192,11 @@ type SQSSendMessageAPI interface { } var GetQueueURL = func(c context.Context, api SQSSendMessageAPI, input *sqs.GetQueueUrlInput) (*sqs.GetQueueUrlOutput, error) { - log.Infof("[GetQueueUrl] queue_name: %s, account_id: %s", input.QueueName, input.QueueOwnerAWSAccountId) + log.Infof("[GetQueueUrl] queue_name: %s, account_id: %s", *input.QueueName, *input.QueueOwnerAWSAccountId) return api.GetQueueUrl(c, input) } var SendMsg = func(c context.Context, api SQSSendMessageAPI, input *sqs.SendMessageInput) (*sqs.SendMessageOutput, error) { - log.Infof("[SendMsg] queue_url: %s, message_body: %s", input.QueueUrl, input.MessageBody) + log.Infof("[SendMsg] queue_url: %s, message_body: %s", *input.QueueUrl, *input.MessageBody) return api.SendMessage(c, input) } From 8beb552a764b0b2047405436ddec3698d198b42d Mon Sep 17 00:00:00 2001 From: Vivien Ng Date: Tue, 26 Nov 2024 23:28:01 -0800 Subject: [PATCH 4/5] fixed NPE for fetching an optional field in GetQueueUrlInput Signed-off-by: Vivien Ng --- pkg/services/awssqs.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/services/awssqs.go b/pkg/services/awssqs.go index 4ac3d996..a0eb8356 100644 --- a/pkg/services/awssqs.go +++ b/pkg/services/awssqs.go @@ -192,11 +192,17 @@ type SQSSendMessageAPI interface { } var GetQueueURL = func(c context.Context, api SQSSendMessageAPI, input *sqs.GetQueueUrlInput) (*sqs.GetQueueUrlOutput, error) { - log.Infof("[GetQueueUrl] queue_name: %s, account_id: %s", *input.QueueName, *input.QueueOwnerAWSAccountId) + // QueueName is required, QueueOwnerAWSAccountId is optional + accountIdStr := "" + if input.QueueOwnerAWSAccountId != nil { + accountIdStr = ", account_id: " + *input.QueueOwnerAWSAccountId + } + log.Infof("[GetQueueUrl] queue_name: %s%s", *input.QueueName, accountIdStr) return api.GetQueueUrl(c, input) } var SendMsg = func(c context.Context, api SQSSendMessageAPI, input *sqs.SendMessageInput) (*sqs.SendMessageOutput, error) { + // QueueUrl & MessageBody are required fields. log.Infof("[SendMsg] queue_url: %s, message_body: %s", *input.QueueUrl, *input.MessageBody) return api.SendMessage(c, input) } From 3cc7c0e76f2c08b3775349aca40901e36c6844d5 Mon Sep 17 00:00:00 2001 From: Vivien Ng Date: Tue, 26 Nov 2024 23:35:45 -0800 Subject: [PATCH 5/5] fix formatting error Signed-off-by: Vivien Ng --- pkg/services/awssqs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/services/awssqs.go b/pkg/services/awssqs.go index a0eb8356..4261a6b4 100644 --- a/pkg/services/awssqs.go +++ b/pkg/services/awssqs.go @@ -197,7 +197,7 @@ var GetQueueURL = func(c context.Context, api SQSSendMessageAPI, input *sqs.GetQ if input.QueueOwnerAWSAccountId != nil { accountIdStr = ", account_id: " + *input.QueueOwnerAWSAccountId } - log.Infof("[GetQueueUrl] queue_name: %s%s", *input.QueueName, accountIdStr) + log.Infof("[GetQueueUrl] queue_name: %s%s", *input.QueueName, accountIdStr) return api.GetQueueUrl(c, input) }