Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

autoscale: meta submission allows multiple resource entrie. #87

Merged
merged 1 commit into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pkg/autoscale/autoscale.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package autoscale

import (
"fmt"
"strconv"

nomad "github.com/hashicorp/nomad/api"
Expand Down Expand Up @@ -188,8 +187,7 @@ func updateResourceTracker(group string, cpu, mem int, tracker map[string]*scala

// updateAutoscaleMeta populates meta with the metrics used to autoscale a job group
func updateAutoscaleMeta(group, metricType string, value, threshold int, meta map[string]string) {
key := fmt.Sprintf("group-%s-metric", group)
meta[key+"-type"] = metricType
key := group + "-" + metricType
meta[key+"-value"] = strconv.Itoa(value)
meta[key+"-threshold"] = strconv.Itoa(threshold)
}
43 changes: 42 additions & 1 deletion pkg/autoscale/autoscale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestAutoScale_updateResourceTracker(t *testing.T) {
func Test_updateResourceTracker(t *testing.T) {
testCases := []struct {
group string
cpu int
Expand Down Expand Up @@ -35,3 +35,44 @@ func TestAutoScale_updateResourceTracker(t *testing.T) {
assert.Equal(t, tc.expected, tc.tracker)
}
}

func Test_updateAutoscaleMeta(t *testing.T) {
testCases := []struct {
inputGroup string
inputMetricType string
inputValue int
inputThreshold int
inputMeta map[string]string
expectedResultMeta map[string]string
name string
}{
{
inputGroup: "test",
inputMetricType: "cpu",
inputValue: 90,
inputThreshold: 89,
inputMeta: make(map[string]string),
expectedResultMeta: map[string]string{"test-cpu-value": "90", "test-cpu-threshold": "89"},
name: "empty input meta",
},
{
inputGroup: "test",
inputMetricType: "memory",
inputValue: 91,
inputThreshold: 89,
inputMeta: map[string]string{"test-cpu-value": "90", "test-cpu-threshold": "89"},
expectedResultMeta: map[string]string{
"test-cpu-value": "90",
"test-cpu-threshold": "89",
"test-memory-value": "91",
"test-memory-threshold": "89",
},
name: "existing input meta",
},
}

for _, tc := range testCases {
updateAutoscaleMeta(tc.inputGroup, tc.inputMetricType, tc.inputValue, tc.inputThreshold, tc.inputMeta)
assert.Equal(t, tc.expectedResultMeta, tc.inputMeta, tc.name)
}
}