-
Notifications
You must be signed in to change notification settings - Fork 60
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 AWS healthcheck - SQS #187
Open
trishtzy
wants to merge
2
commits into
hellofresh:master
Choose a base branch
from
trishtzy:add-aws-healthcheck
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
* Memcached | ||
* InfluxDB | ||
* Nats | ||
* AWS | ||
|
||
## Usage | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package sqs | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/sqs" | ||
"github.com/aws/aws-sdk-go-v2/service/sqs/types" | ||
) | ||
|
||
// Config is the AWS SQS checker configuration settings. | ||
type Config struct { | ||
// Client is the initialized instance of the AWS SQS client used for making API requests to the AWS SQS service. | ||
Client SqsActions | ||
// QueueUrl is a pointer to the string that contains the URL of the SQS queue to which the client connects. | ||
QueueUrl *string | ||
} | ||
|
||
// SqsActions defines the set of operations used from the SQS client. | ||
type SqsActions interface { | ||
GetQueueAttributes(ctx context.Context, params *sqs.GetQueueAttributesInput, optFns ...func(*sqs.Options)) (*sqs.GetQueueAttributesOutput, error) | ||
} | ||
|
||
// New creates a new AWS SQS health check that verifies if a connection to the queue exists | ||
func New(config Config) func(ctx context.Context) error { | ||
return func(ctx context.Context) error { | ||
arnAttributeName := types.QueueAttributeNameQueueArn | ||
if _, err := config.Client.GetQueueAttributes(ctx, &sqs.GetQueueAttributesInput{ | ||
QueueUrl: config.QueueUrl, | ||
AttributeNames: []types.QueueAttributeName{arnAttributeName}, | ||
}); err != nil { | ||
return fmt.Errorf("unable to get queue ARN: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package sqs | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/sqs" | ||
"github.com/aws/aws-sdk-go-v2/service/sqs/types" | ||
) | ||
|
||
// SimpleMockSQSClient is a manual mock of the SQSAPI interface. | ||
type SimpleMockSQSClient struct { | ||
// Add fields to store mock outputs and any other state | ||
GetQueueAttributesOutput *sqs.GetQueueAttributesOutput | ||
GetQueueAttributesErr error | ||
} | ||
|
||
// GetQueueAttributes is the mock method that mimics the corresponding SQSAPI method. | ||
func (m *SimpleMockSQSClient) GetQueueAttributes(ctx context.Context, params *sqs.GetQueueAttributesInput, optFns ...func(*sqs.Options)) (*sqs.GetQueueAttributesOutput, error) { | ||
// Return the mocked response and error stored in the mock struct | ||
return m.GetQueueAttributesOutput, m.GetQueueAttributesErr | ||
} | ||
|
||
func TestNew(t *testing.T) { | ||
queueURL := "http://example.com/queue" | ||
mockSQSClient := &SimpleMockSQSClient{ | ||
GetQueueAttributesOutput: &sqs.GetQueueAttributesOutput{ | ||
Attributes: map[string]string{ | ||
string(types.QueueAttributeNameQueueArn): "arn:aws:sqs:us-east-1:123456789012:queue1", | ||
}, | ||
}, | ||
GetQueueAttributesErr: nil, | ||
} | ||
|
||
config := Config{ | ||
Client: mockSQSClient, | ||
QueueUrl: &queueURL, | ||
} | ||
|
||
checker := New(config) | ||
|
||
err := checker(context.Background()) | ||
if err != nil { | ||
t.Errorf("Expected no error, but got %v", err) | ||
} | ||
} | ||
|
||
func TestNewError(t *testing.T) { | ||
queueURL := "http://example.com/queue" | ||
mockSQSClient := &SimpleMockSQSClient{ | ||
GetQueueAttributesOutput: &sqs.GetQueueAttributesOutput{ | ||
Attributes: map[string]string{ | ||
string(types.QueueAttributeNameQueueArn): "arn:aws:sqs:us-east-1:123456789012:queue1", | ||
}, | ||
}, | ||
GetQueueAttributesErr: errors.New("failed to get queue attributes"), | ||
} | ||
|
||
config := Config{ | ||
Client: mockSQSClient, | ||
QueueUrl: &queueURL, | ||
} | ||
|
||
checker := New(config) | ||
|
||
err := checker(context.Background()) | ||
if err == nil { | ||
t.Errorf("Expected error, but got none") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.