-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Merge branch 'develop' of github.com:darkraiden/sigmund into develop # Conflicts: # .gitignore # go.mod # pkg/autoscaling/execPolicy.go * add salvatore to contributors * add changelog
- Loading branch information
Davide Di Mauro
committed
May 29, 2019
1 parent
bb356d6
commit b0cc6d6
Showing
10 changed files
with
235 additions
and
108 deletions.
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/.vscode | ||
/vendor | ||
.vscode | ||
vendor |
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,9 @@ | ||
## 0.2.0 (May 29, 2019) | ||
|
||
ADDITIONS: | ||
|
||
- checks if either `Memory` or `CPU` are in an `OK` state, rather than just `Low` | ||
|
||
CHANGES: | ||
|
||
- Minor code improvements |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
- [Davide Di Mauro](https://github.com/darkraiden) | ||
- [Salvatore Tards](https://github.com/Stakct) |
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
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 |
---|---|---|
@@ -1,19 +1,65 @@ | ||
package sigmund | ||
|
||
import ( | ||
"fmt" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
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) | ||
// Metric is a type that will be used to serialise the metric types received from SNS | ||
type Metric int | ||
|
||
type dbKey struct { | ||
metric string | ||
value bool | ||
} | ||
|
||
const ( | ||
// LowMemory is a metric that indicates low memory | ||
LowMemory Metric = iota | ||
// LowCPU is a metric that indicates low CPU | ||
LowCPU | ||
// OkMemory is a metric that indicates the absence of memory issues | ||
OkMemory | ||
// OkCPU is a metric that indicates the absence of CPU issues | ||
OkCPU | ||
) | ||
|
||
var stringsToMetrics = map[string]Metric{ | ||
"LowMemory": LowMemory, | ||
"LowCPU": LowCPU, | ||
"OkMemory": OkMemory, | ||
"OkCPU": OkCPU, | ||
} | ||
|
||
func (m Metric) String() string { | ||
metricNames := [...]string{ | ||
"LowMemory", | ||
"LowCPU", | ||
"OkMemory", | ||
"OkCPU", | ||
} | ||
|
||
if m < 0 || m > 3 { | ||
log.WithField("integer", m).Panic("Value cannot be interpreted as a metric") | ||
} | ||
return k, err | ||
|
||
return metricNames[m] | ||
} | ||
|
||
var metricsTodbKey = map[Metric]dbKey{ | ||
LowMemory: { | ||
metric: "isLowMemory", | ||
value: true, | ||
}, | ||
LowCPU: { | ||
metric: "isLowCPU", | ||
value: true, | ||
}, | ||
OkMemory: { | ||
metric: "isLowMemory", | ||
value: false, | ||
}, | ||
OkCPU: { | ||
metric: "isLowCPU", | ||
value: false, | ||
}, | ||
} |
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,28 @@ | ||
package autoscaling | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws/awserr" | ||
"github.com/aws/aws-sdk-go/service/autoscaling" | ||
) | ||
|
||
func checkAutoscalingError(err error) error { | ||
if err != nil { | ||
if aerr, ok := err.(awserr.Error); ok { | ||
switch aerr.Code() { | ||
case autoscaling.ErrCodeScalingActivityInProgressFault: | ||
return fmt.Errorf("%v: %v", autoscaling.ErrCodeScalingActivityInProgressFault, aerr.Error()) | ||
case autoscaling.ErrCodeResourceContentionFault: | ||
return fmt.Errorf("%v: %v", autoscaling.ErrCodeResourceContentionFault, aerr.Error()) | ||
default: | ||
return fmt.Errorf("%v", aerr.Error()) | ||
} | ||
} else { | ||
// Print the error, cast err to awserr.Error to get the Code and | ||
// Message from an error. | ||
return 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
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
Oops, something went wrong.