Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Di Mauro Davide committed Feb 8, 2019
0 parents commit 4424758
Show file tree
Hide file tree
Showing 21 changed files with 941 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.vscode
/vendor
76 changes: 76 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributing

When contributing to this repository, please first discuss the change you wish to make via issue,
email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

## Pull Request Process

1. Ensure any install or build dependencies are removed before the end of the layer when doing a build.
2. Update the README.md with details of changes to the interface, this includes new environment variables, exposed ports, useful file locations and container parameters.
3. Increase the version numbers in any examples files and the README.md to the new version that this Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/).
4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you.

## Code of Conduct

### Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

### Our Standards

Examples of behavior that contributes to creating a positive environment
include:

- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

- The use of sexualized language or imagery and unwelcome sexual attention or
advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting

### Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

### Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

### Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
81 changes: 81 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "github.com/aws/aws-sdk-go"
version = "1.15.89"

[prune]
go-tests = true
unused-packages = true
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2018 Davide Di Mauro

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Sigmund

<img id="gopher" src="https://storage.googleapis.com/gopherizeme.appspot.com/gophers/7da7cd5ba32fae25e03301f30ba3a1296b47ca2e.png" alt="Sigmund Go" height=200px>

A Go lang tool designed to `shrink` AWS Autoscaling Clusters based on `CPU` and `Memory` Cloudwatch Alarm Metrics.

This tool is meant to be for people who want to scale their instances back in whenever **both** `CPU` **AND** `Memory` conditions are met.

## Prerequisites

- A DynamoDB table
- AWS credentials with the following permissions:
- DynamoDB Table Read/Write access
- Ability to Execute Autoscaling Policies

### DyanamoDB Table structure

In order to work, your DynamoDB table should look like the one that follows:

| ID | isLowCPU | isLowMemory |
| :-: | :------: | :---------: |
| 0 | false | false |

**NB** it is important that the table is pre-populated with the values showed above, most importantly you must make sure that the `ID` = 0 - that value will never change.

## Installing

You can directly use the `go` tool to download and install the `sigmund` package into your `GOPATH`:

```bash
$ go get github.com/darkraiden/sigmund.go
```

You can also clone the repository yourself:

```bash
$ mkdir -p $GOPATH/src/github.com/darkraiden/
$ cd $GOPATH/src/github.com/darkraiden/
$ git clone git@gihub.com:darkraiden/sigmund
```

Note: This project uses dep so you'll need to run `dep ensure` to grab all the dependencies.

## How to use it

First things first, initialise a `Sigmund` from your application:

```go
// Get a Sigmund
s, err := sigmund.New("eu-west-1", "anASGName", "anASGPolicyName", "aDynamoTableName", "cpu") // cpu can be replaced by memory, depending on which metric changed on your Cloudwatch Alerts
if err != nil {
panic(err)
}
```

Now that you have your `Sigmund`, you're ready to update the DB _and eventually_ execute the autoscaling group policy:

```go
err := s.Shrink()
if err != nil {
panic(err)
}
```

## Running the tests

Every Package of this project comes with some unit tests which use the Go `testing` package. Run the tests, from the package folder, by typing:

```bash
$ go test -v ./...
```

## Contributing

Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.

## Versioning

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/darkraiden/sigmund/tags).

## Authors

- [Davide Di Mauro](https://github.com/darkraiden)

See also the list of [contributors](contributors.md) who participated in this project.

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
1 change: 1 addition & 0 deletions contributors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- [Davide Di Mauro](https://github.com/darkraiden)
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module github.com/darkraiden/sigmund

require (
github.com/aws/aws-lambda-go v1.8.0
github.com/aws/aws-sdk-go v1.15.89
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/aws/aws-lambda-go v1.8.0 h1:YMCzi9FP7MNVVj9AkGpYyaqh/mvFOjhqiDtnNlWtKTg=
github.com/aws/aws-lambda-go v1.8.0/go.mod h1:zUsUQhAUjYzR8AuduJPCfhBuKWUaDbQiPOG+ouzmE1A=
github.com/aws/aws-sdk-go v1.15.89 h1:T5xLl6ePbLhTdKWoeRhwIV58OfXPSLu2s4GMNDpRLu0=
github.com/aws/aws-sdk-go v1.15.89/go.mod h1:es1KtYUFs7le0xQ3rOihkuoVD90z7D0fR2Qm4S00/gU=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 h1:12VvqtR6Aowv3l/EQUlocDHW2Cp4G9WJVH7uyH8QFJE=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
19 changes: 19 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package sigmund

import (
"fmt"
)

func identifyMetric(m string) (string, error) {
var k string
var err error
switch {
case m == "memory":
k = "isLowMemory"
case m == "cpu":
k = "isLowCPU"
default:
err = fmt.Errorf("%v is an invalid parameter. Please provide either 'memory' or 'cpu' keys", m)
}
return k, err
}
40 changes: 40 additions & 0 deletions pkg/autoscaling/asg_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package autoscaling

import "testing"

type config struct {
autoscalingGroupName string
policyName string
region string
expected error
}

var configs = []config{
{
autoscalingGroupName: "test1",
policyName: "policy1",
region: "us-east-1",
expected: nil,
},
{
autoscalingGroupName: "test2",
policyName: "policy2",
region: "us-east-1",
expected: nil,
},
{
autoscalingGroupName: "test3",
policyName: "policy3",
region: "us-east-1",
expected: nil,
},
}

func TestNew(t *testing.T) {
for _, conf := range configs {
_, err := checkConfig(conf.autoscalingGroupName, conf.policyName, conf.region)
if err != nil {
t.Errorf("Error message was incorrect, expected: %v, got: %v", conf.expected, err)
}
}
}
Loading

0 comments on commit 4424758

Please sign in to comment.