wip: added .PreviousCount to api.ScalingEvent and structs.ScalingEvent, with developmental tests
This commit is contained in:
parent
78f91f5637
commit
aeb3ed449e
|
@ -1776,10 +1776,11 @@ func TestJobs_ScaleAction(t *testing.T) {
|
|||
job := testJobWithScalingPolicy()
|
||||
job.ID = &id
|
||||
groupName := *job.TaskGroups[0].Name
|
||||
groupCount := *job.TaskGroups[0].Count
|
||||
origCount := *job.TaskGroups[0].Count
|
||||
newCount := origCount + 1
|
||||
|
||||
// Trying to scale against a target before it exists returns an error
|
||||
_, _, err := jobs.Scale(id, "missing", intToPtr(groupCount+1), "this won't work",
|
||||
_, _, err := jobs.Scale(id, "missing", intToPtr(newCount), "this won't work",
|
||||
false, nil, nil)
|
||||
require.Error(err)
|
||||
require.Contains(err.Error(), "not found")
|
||||
|
@ -1790,7 +1791,6 @@ func TestJobs_ScaleAction(t *testing.T) {
|
|||
assertWriteMeta(t, wm)
|
||||
|
||||
// Perform scaling action
|
||||
newCount := groupCount + 1
|
||||
scalingResp, wm, err := jobs.Scale(id, groupName,
|
||||
intToPtr(newCount), "need more instances", false,
|
||||
map[string]interface{}{
|
||||
|
@ -1822,6 +1822,7 @@ func TestJobs_ScaleAction(t *testing.T) {
|
|||
require.Greater(scalingEvent.Time, uint64(0))
|
||||
require.NotNil(scalingEvent.EvalID)
|
||||
require.Equal(scalingResp.EvalID, *scalingEvent.EvalID)
|
||||
require.Equal(int64(origCount), scalingEvent.PreviousCount)
|
||||
}
|
||||
|
||||
func TestJobs_ScaleAction_Error(t *testing.T) {
|
||||
|
|
|
@ -92,11 +92,12 @@ type TaskGroupScaleStatus struct {
|
|||
}
|
||||
|
||||
type ScalingEvent struct {
|
||||
Count *int64
|
||||
Error bool
|
||||
Message string
|
||||
Meta map[string]interface{}
|
||||
EvalID *string
|
||||
Time uint64
|
||||
CreateIndex uint64
|
||||
Count *int64
|
||||
PreviousCount int64
|
||||
Error bool
|
||||
Message string
|
||||
Meta map[string]interface{}
|
||||
EvalID *string
|
||||
Time uint64
|
||||
CreateIndex uint64
|
||||
}
|
||||
|
|
|
@ -5458,16 +5458,17 @@ func TestJobEndpoint_Scale(t *testing.T) {
|
|||
state := s1.fsm.State()
|
||||
|
||||
job := mock.Job()
|
||||
count := job.TaskGroups[0].Count
|
||||
originalCount := job.TaskGroups[0].Count
|
||||
err := state.UpsertJob(1000, job)
|
||||
require.Nil(err)
|
||||
|
||||
groupName := job.TaskGroups[0].Name
|
||||
scale := &structs.JobScaleRequest{
|
||||
JobID: job.ID,
|
||||
Target: map[string]string{
|
||||
structs.ScalingTargetGroup: job.TaskGroups[0].Name,
|
||||
structs.ScalingTargetGroup: groupName,
|
||||
},
|
||||
Count: helper.Int64ToPtr(int64(count + 1)),
|
||||
Count: helper.Int64ToPtr(int64(originalCount + 1)),
|
||||
Message: "because of the load",
|
||||
Meta: map[string]interface{}{
|
||||
"metrics": map[string]string{
|
||||
|
@ -5487,6 +5488,10 @@ func TestJobEndpoint_Scale(t *testing.T) {
|
|||
require.NoError(err)
|
||||
require.NotEmpty(resp.EvalID)
|
||||
require.Greater(resp.EvalCreateIndex, resp.JobModifyIndex)
|
||||
|
||||
events, _, _ := state.ScalingEventsByJob(nil, job.Namespace, job.ID)
|
||||
require.Equal(1, len(events[groupName]))
|
||||
require.Equal(int64(originalCount), events[groupName][0].PreviousCount)
|
||||
}
|
||||
|
||||
func TestJobEndpoint_Scale_ACL(t *testing.T) {
|
||||
|
@ -5637,6 +5642,7 @@ func TestJobEndpoint_Scale_NoEval(t *testing.T) {
|
|||
|
||||
job := mock.Job()
|
||||
groupName := job.TaskGroups[0].Name
|
||||
originalCount := job.TaskGroups[0].Count
|
||||
var resp structs.JobRegisterResponse
|
||||
err := msgpackrpc.CallWithCodec(codec, "Job.Register", &structs.JobRegisterRequest{
|
||||
Job: job,
|
||||
|
@ -5683,6 +5689,10 @@ func TestJobEndpoint_Scale_NoEval(t *testing.T) {
|
|||
event := groupEvents[0]
|
||||
require.Nil(event.EvalID)
|
||||
require.Greater(eventsIndex, jobCreateIndex)
|
||||
|
||||
events, _, _ := state.ScalingEventsByJob(nil, job.Namespace, job.ID)
|
||||
require.Equal(1, len(events[groupName]))
|
||||
require.Equal(int64(originalCount), events[groupName][0].PreviousCount)
|
||||
}
|
||||
|
||||
func TestJobEndpoint_InvalidCount(t *testing.T) {
|
||||
|
|
|
@ -4701,6 +4701,9 @@ type ScalingEvent struct {
|
|||
// Count is the new scaling count, if provided
|
||||
Count *int64
|
||||
|
||||
// PreviousCount is the count at the time of the scaling event
|
||||
PreviousCount int64
|
||||
|
||||
// Message is the message describing a scaling event
|
||||
Message string
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ require (
|
|||
github.com/hashicorp/go-bindata v3.0.8-0.20180209072458-bf7910af8997+incompatible
|
||||
github.com/hashicorp/go-msgpack v1.1.5
|
||||
github.com/hashicorp/hcl/v2 v2.5.1
|
||||
github.com/jteeuwen/go-bindata v3.0.7+incompatible // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||
github.com/onsi/ginkgo v1.12.0 // indirect
|
||||
|
|
|
@ -38,8 +38,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.1-0.20200509193318-234c15e7648f h1:AwZUiMWfYSmIiHdFJIubTSs8BFIFoMmUFbeuwBzHIPs=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.1-0.20200509193318-234c15e7648f/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
|
||||
github.com/fatih/color v1.6.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
|
@ -143,8 +141,6 @@ github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3/go.m
|
|||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||
github.com/hashicorp/go-bindata v3.0.7+incompatible h1:tnw1ukCrIsFR0IyN3C+ABwePoiAqEVjR9BFiGauTo1M=
|
||||
github.com/hashicorp/go-bindata v3.0.7+incompatible/go.mod h1:+IrDq36jUYG0q6TsDY9uO2p77C8f8S5y+RbYHr2UI+U=
|
||||
github.com/hashicorp/go-bindata v3.0.8-0.20180209072458-bf7910af8997+incompatible h1:EDTAuh27kAIhxuyK8ef3iHQARA+8NQaXyTeDEiG3Q6o=
|
||||
github.com/hashicorp/go-bindata v3.0.8-0.20180209072458-bf7910af8997+incompatible/go.mod h1:+IrDq36jUYG0q6TsDY9uO2p77C8f8S5y+RbYHr2UI+U=
|
||||
github.com/hashicorp/go-msgpack v1.1.5 h1:9byZdVjKTe5mce63pRVNP1L7UAmdHOTEMGehn6KvJWs=
|
||||
|
@ -164,8 +160,6 @@ github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3/go.mod
|
|||
github.com/jmoiron/sqlx v1.2.1-0.20190826204134-d7d95172beb5/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
|
||||
github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo=
|
||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||
github.com/jteeuwen/go-bindata v3.0.7+incompatible h1:91Uy4d9SYVr1kyTJ15wJsog+esAZZl7JmEfTkwmhJts=
|
||||
github.com/jteeuwen/go-bindata v3.0.7+incompatible/go.mod h1:JVvhzYOiGBnFSYRyV00iY8q7/0PThjIYav1p9h5dmKs=
|
||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
|
|
Loading…
Reference in New Issue