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

Feat daily cost notification template #69

Merged
merged 6 commits into from
Feb 21, 2024
Merged

Feat daily cost notification template #69

merged 6 commits into from
Feb 21, 2024

Conversation

nao1215
Copy link
Owner

@nao1215 nao1215 commented Feb 21, 2024

Summary by CodeRabbit

  • New Features

    • Introduced Daily Cost Notification feature for monitoring AWS costs via email.
    • Added support for AWS Cost Explorer API to retrieve cost data.
    • Implemented functionality to publish notifications using AWS Simple Notification Service (SNS).
  • Documentation

    • Provided comprehensive documentation for the Daily Cost Notification feature, including setup and usage instructions.
    • Added a workflow diagram to illustrate the system architecture for Daily Cost Notifications.
  • Tests

    • Implemented test suites for cost retrieval and SNS publishing functionalities, ensuring reliability and error handling.
  • Chores

    • Updated CloudFormation scripts to include deployment steps for the Daily Cost Notification feature.
  • Refactor

    • Introduced interfaces and mock implementations for cost retrieval and SNS publishing to enhance modularity and testability.

Copy link
Contributor

coderabbitai bot commented Feb 21, 2024

Warning

Rate Limit Exceeded

@nao1215 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 24 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 8323dec and 1f38658.

Walkthrough

The recent update introduces a comprehensive Daily Cost Notification feature across the application. It leverages AWS services like Cost Explorer, SNS, and Lambda to provide users with daily updates on their AWS spending. The implementation covers various aspects, from domain logic to external service interactions and cloud infrastructure deployment, ensuring thorough documentation and testing.

Changes

File Path Change Summary
README.md Added a new feature for Daily Cost Notification with complete documentation coverage.
app/domain/service/... Introduced CostGetter interface for cost information retrieval.
Introduced SNSPublisher interface for publishing messages to an SNS topic.
app/external/... Added functionality for interacting with AWS Cost Explorer API and SNS.
Introduced mock implementations for CostGetter and SNSPublisher interfaces.
app/interactor/..., app/usecase/... Implemented logic for cost retrieval and SNS message publishing.
cloudformation/... Updated Makefile and added CloudFormation setup for Daily Cost Notification.

Related issues

  • nao1215/rainbow#64: The issue requests a Daily Cost Notification feature using Lambda, SNS, and Cost Explorer, aligning with the objectives of this PR.

Poem

In the digital realm, where data flows wide,
A rabbit hopped in, with a stride full of pride.
"Beware of your spending," it softly advised,
Through emails each day, your costs summarized.
🐰💼✉️
With AWS magic, in the cloud so vast,
Your budget's now safe, as long as it lasts.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@@ -0,0 +1,15 @@
package mock

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
ST1000: at least one file in a package should have a package comment (stylecheck)

// GetCost gets the cost.
func (c *CostGetter) GetCost(ctx context.Context, input *usecase.CostGetterInput) (*usecase.CostGetterOutput, error) {
if input.End.Before(input.Start) {
return nil, errors.New("End date is before the start date")

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
ST1005: error strings should not be capitalized (stylecheck)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d5de19e and 3696053.
Files ignored due to path filters (6)
  • cloudformation/daily-cost-notification/daily-cost-email.png is excluded by: !**/*.png
  • cloudformation/daily-cost-notification/daily-cost-notification.png is excluded by: !**/*.png
  • cloudformation/daily-cost-notification/subscription-confirm.png is excluded by: !**/*.png
  • cloudformation/daily-cost-notification/template.yml is excluded by: !**/*.yml
  • go.mod is excluded by: !**/*.mod
  • go.sum is excluded by: !**/*.sum
Files selected for processing (19)
  • README.md (1 hunks)
  • app/domain/service/cost_explorer.go (1 hunks)
  • app/domain/service/sns.go (1 hunks)
  • app/external/cost_explorer.go (1 hunks)
  • app/external/mock/cost_explorer.go (1 hunks)
  • app/external/mock/sns.go (1 hunks)
  • app/external/sns.go (1 hunks)
  • app/interactor/cost_explorer.go (1 hunks)
  • app/interactor/cost_explorer_test.go (1 hunks)
  • app/interactor/sns.go (1 hunks)
  • app/interactor/sns_test.go (1 hunks)
  • app/usecase/cost_explorer.go (1 hunks)
  • app/usecase/sns.go (1 hunks)
  • cloudformation/Makefile (1 hunks)
  • cloudformation/daily-cost-notification/.gitignore (1 hunks)
  • cloudformation/daily-cost-notification/Makefile (1 hunks)
  • cloudformation/daily-cost-notification/README.md (1 hunks)
  • cloudformation/daily-cost-notification/daily-cost-notification.drawio (1 hunks)
  • cloudformation/daily-cost-notification/main.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • cloudformation/daily-cost-notification/.gitignore
Additional comments: 5
app/external/mock/cost_explorer.go (1)
  • 1-15: The mock implementation of CostGetter is correctly defined and follows best practices for mocking in Go. It allows for flexible testing scenarios by using a function type.
app/external/mock/sns.go (1)
  • 1-15: The mock implementation of SNSPublisher is correctly defined and follows the established pattern for mocking in Go, ensuring consistency and flexibility in testing.
app/domain/service/sns.go (1)
  • 1-19: The SNSPublisher interface and its associated types are well-defined, following best practices for interface design in Go. The use of context and clear method signatures ensures a good foundation for implementing SNS publishing functionality.
README.md (1)
  • 50-50: The addition of the "Daily Cost Notification" feature to the Template List is clear and concise, effectively informing users about the new feature's availability and its documentation. This update integrates well with the existing structure of the README.md file, maintaining consistency in presentation and formatting.
cloudformation/daily-cost-notification/daily-cost-notification.drawio (1)
  • 1-69: The diagram provided in daily-cost-notification.drawio effectively illustrates the workflow of the "Daily Cost Notification" feature, using clear and accurate representations of AWS services and the interactions between them. The logical flow from scheduled execution through EventBridge, processing by a Lambda function, logging via CloudWatch, and finally publishing a notification through SNS to send an email is well depicted. This diagram will be valuable for users and developers to understand the feature's architecture and operational dynamics.

Comment on lines +1 to +19
package usecase

import "context"

// SNSPublisherInput is the input of the Publish method.
type SNSPublisherInput struct {
// TopicArn is the ARN of the topic.
TopicArn string
// Message is the message that you want to publish.
Message string
}

// SNSPublisherOutput is the output of the Publish method.
type SNSPublisherOutput struct{}

// SNSPublisher is the interface that wraps the basic Publish method.
type SNSPublisher interface {
PublishSNS(ctx context.Context, input *SNSPublisherInput) (*SNSPublisherOutput, error)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The SNSPublisher interface and its associated types are duplicated here and in app/domain/service/sns.go. To maintain clarity and reduce redundancy, it's recommended to remove these duplicate definitions and rely on the ones in the domain layer.

- // SNSPublisherInput is the input of the Publish method.
- type SNSPublisherInput struct {
-   // TopicArn is the ARN of the topic.
-   TopicArn string
-   // Message is the message that you want to publish.
-   Message string
- }
- 
- // SNSPublisherOutput is the output of the Publish method.
- type SNSPublisherOutput struct{}
- 
- // SNSPublisher is the interface that wraps the basic Publish method.
- type SNSPublisher interface {
-   PublishSNS(ctx context.Context, input *SNSPublisherInput) (*SNSPublisherOutput, error)
- }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
package usecase
import "context"
// SNSPublisherInput is the input of the Publish method.
type SNSPublisherInput struct {
// TopicArn is the ARN of the topic.
TopicArn string
// Message is the message that you want to publish.
Message string
}
// SNSPublisherOutput is the output of the Publish method.
type SNSPublisherOutput struct{}
// SNSPublisher is the interface that wraps the basic Publish method.
type SNSPublisher interface {
PublishSNS(ctx context.Context, input *SNSPublisherInput) (*SNSPublisherOutput, error)
}
package usecase
import "context"

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3696053 and 8323dec.
Files ignored due to path filters (2)
  • go.mod is excluded by: !**/*.mod
  • go.sum is excluded by: !**/*.sum
Files selected for processing (4)
  • .github/workflows/cfn-guard.yml (1 hunks)
  • .github/workflows/cloudformation.yml (1 hunks)
  • app/external/mock/cost_explorer.go (1 hunks)
  • app/interactor/cost_explorer.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • app/external/mock/cost_explorer.go
  • app/interactor/cost_explorer.go

@@ -4,6 +4,7 @@ on:
push:
paths:
- 'cloudformation/**'
- 'cloudformation/**/**'
Copy link
Contributor

Choose a reason for hiding this comment

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

The path pattern 'cloudformation/**/**' is redundant because the glob pattern 'cloudformation/**' already matches files in all directories and subdirectories under 'cloudformation'. Consider removing the redundant pattern to simplify the workflow configuration.

-      - 'cloudformation/**/**'

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- 'cloudformation/**/**'

This comment has been minimized.

Copy link

HOTTEST report

PASS FAIL SKIP TOTAL DURATION
289 0 7 296 3.615410753s

Reported by hottest

Copy link

Code Metrics Report

main (d5de19e) #69 (70927ad) +/-
Coverage 22.3% 22.2% -0.0%
Test Execution Time 43s 11s -32s
Details
  |                     | main (d5de19e) | #69 (70927ad) |  +/-  |
  |---------------------|----------------|---------------|-------|
- | Coverage            |          22.3% |         22.2% | -0.0% |
  |   Files             |             53 |            60 |    +7 |
  |   Lines             |           1835 |          1893 |   +58 |
+ |   Covered           |            409 |           421 |   +12 |
+ | Test Execution Time |            43s |           11s |  -32s |

Code coverage of files in pull request scope (0.0% → 20.7%)

Files Coverage +/-
app/external/cost_explorer.go 0.0% 0.0%
app/external/mock/cost_explorer.go 100.0% +100.0%
app/external/mock/sns.go 100.0% +100.0%
app/external/sns.go 0.0% 0.0%
app/interactor/cost_explorer.go 85.7% +85.7%
app/interactor/sns.go 100.0% +100.0%
cloudformation/daily-cost-notification/main.go 0.0% 0.0%

Reported by octocov

@nao1215 nao1215 merged commit 1a38708 into main Feb 21, 2024
9 checks passed
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.

1 participant