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

add functions CheckQueueExists CheckBucketExists #183

Merged
merged 2 commits into from
Nov 29, 2024
Merged

Conversation

bpeng
Copy link
Contributor

@bpeng bpeng commented Nov 27, 2024

Proposed Changes

Ticket https://github.com/GeoNet/tickets/issues/13878

Changes proposed in this pull request:

  • add functions to check bucket/queue exist

Production Changes

The following production changes are required to deploy these changes:

  • None

Review

Check the box that applies to this code review. If necessary please seek help with adding a checklist guide for the reviewer.
When assigning the code review please consider the expertise needed to review the changes.

  • This is a content (documentation, web page etc) only change.
  • This is a minor change (meta data, bug fix, improve test coverage etc).
  • This is a larger change (new feature, significant refactoring etc). Please use the code review guidelines to add a checklist below to guide the code reviewer.

Code Review Guide

Insert check list here if needed.

@bpeng bpeng requested a review from CallumNZ November 27, 2024 01:03
Copy link
Contributor

@CallumNZ CallumNZ left a comment

Choose a reason for hiding this comment

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

Some changes.

Please add tests to s3_integration_test.go and sqs_integration_test.go, where it's ensured that it gives an error before the asset is created, and then nil error afterwards.

Will need an equivalent set for SNS too.

If the caller doesn't have permission, that will return an error too? Not sure if our testing infrastructure can test for lack of permissions, so maybe add that behaviour to each function documentation.

aws/s3/s3.go Outdated
@@ -271,6 +271,16 @@ func (s *S3) PutWithMetadata(bucket, key string, object []byte, metadata Meta) e
return err
}

// checks if the given S3 bucket exists.
func (s *S3) CheckBucketExists(bucketName string) error {
// Check if the bucket exists.
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment not needed

aws/s3/s3.go Outdated
@@ -271,6 +271,16 @@ func (s *S3) PutWithMetadata(bucket, key string, object []byte, metadata Meta) e
return err
}

// checks if the given S3 bucket exists.
func (s *S3) CheckBucketExists(bucketName string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

bucket to be consistent with the others.

aws/sqs/sqs.go Outdated
Comment on lines 323 to 333
// checks if the given SQS queue exists.
func (s *SQS) CheckQueueExists(queueName string) error {
// Check if the queue exists.
_, err := s.client.GetQueueUrl(context.TODO(), &sqs.GetQueueUrlInput{
QueueName: aws.String(queueName),
})

return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we usually have the queue URL as an environment variable - is it possible to check from the URL?

@bpeng bpeng force-pushed the health-check branch 3 times, most recently from 0d06f95 to 5ae4175 Compare November 27, 2024 03:58
Comment on lines 190 to 193
client, err := New()

// ASSERT
assert.Nil(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the test isn't focused on whether client creation works, and subsequent client methods will fail if the client creation failed, this is more appropriate:

client, err := New()
require.Nil(t, err, fmt.Sprintf("error creating sqs client: %v", err))

Comment on lines 64 to 68
client, err := New()
ready := client.Ready()
// ASSERT
assert.Nil(t, err)
assert.True(t, ready)
Copy link
Contributor

Choose a reason for hiding this comment

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

client, err := New()
require.Nil(t, err, fmt.Sprintf("error creating sns client: %v", err))

ready := client.Ready()
require.True(t, ready, fmt.Sprint("sns client not ready"))

aws/sqs/sqs.go Outdated
@@ -320,6 +320,18 @@ func (s *SQS) CreateQueue(queueName string, isFifoQueue bool) (string, error) {
return aws.ToString(queue.QueueUrl), err
}

// checks if the given SQS queue exists.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// checks if the given SQS queue exists.
// CheckQueueExists returns an error if the given queue doesn't exist or cannot be accessed.

aws/s3/s3.go Outdated
@@ -271,6 +271,15 @@ func (s *S3) PutWithMetadata(bucket, key string, object []byte, metadata Meta) e
return err
}

// checks if the given S3 bucket exists.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// checks if the given S3 bucket exists.
// CheckBucketExists returns an error if the given bucket doesn't exist or cannot be accessed.

aws/sns/sns.go Outdated
@@ -116,6 +116,14 @@ func (s *SNS) DeleteTopic(topicArn string) error {
return err
}

// checks if an SNS topic exists given its ARN.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// checks if an SNS topic exists given its ARN.
// CheckTopicExists returns an error if the given topic doesn't exist or cannot be accessed.

@CallumNZ
Copy link
Contributor

On second thought, I think dropping Exists from each function name more clearly indicates what the function does, since it can return an error if the bucket exists but the caller doesn't have the right permissions.

Copy link
Contributor

@CallumNZ CallumNZ left a comment

Choose a reason for hiding this comment

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

Just some suggestions to bring inline with Go Docs conventions.

aws/s3/s3.go Outdated
@@ -271,6 +271,15 @@ func (s *S3) PutWithMetadata(bucket, key string, object []byte, metadata Meta) e
return err
}

// checks if the given S3 bucket exists and is accessible.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// checks if the given S3 bucket exists and is accessible.
// CheckBucket checks if the given S3 bucket exists and is accessible.

aws/sns/sns.go Outdated
@@ -116,6 +116,14 @@ func (s *SNS) DeleteTopic(topicArn string) error {
return err
}

// checks if an SNS topic exists and is accessible given its ARN.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// checks if an SNS topic exists and is accessible given its ARN.
// CheckTopic checks if an SNS topic exists and is accessible given its ARN.

aws/sqs/sqs.go Outdated
@@ -320,6 +320,18 @@ func (s *SQS) CreateQueue(queueName string, isFifoQueue bool) (string, error) {
return aws.ToString(queue.QueueUrl), err
}

// checks if the given SQS queue exists and is accessible.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// checks if the given SQS queue exists and is accessible.
// CheckQueue checks if the given SQS queue exists and is accessible.

@sue-h-gns sue-h-gns merged commit 745247c into main Nov 29, 2024
7 checks passed
@sue-h-gns sue-h-gns deleted the health-check branch November 29, 2024 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants