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

Downgrade error message from app scaling due to active deployment #542

Merged
merged 3 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

IMPROVEMENTS:
* agent: Dispense `fixed-value`, `pass-through`, and `threshold` strategy plugins by default [[GH-536](https://github.com/hashicorp/nomad-autoscaler/pull/536)]
* plugins/target/nomad: Reduce log level for active deployments error messages [[GH-542](https://github.com/hashicorp/nomad-autoscaler/pull/542)]
* policy: Prevent scaling cluster to zero when using the Nomad APM [[GH-534](https://github.com/hashicorp/nomad-autoscaler/pull/534)]
* scaleutils: Add combined filter to allow filtering by node class and datacenter [[GH-535](https://github.com/hashicorp/nomad-autoscaler/pull/535)]

Expand Down
7 changes: 7 additions & 0 deletions plugins/builtin/target/nomad/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nomad

import (
"fmt"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -135,6 +136,12 @@ func (t *TargetPlugin) Scale(action sdk.ScalingAction, config map[string]string)
&q)

if err != nil {
// Active deployments errors are fairly common and usually not
// impactful to the target's eventual end state, so special case them
// to return a no-op error instead.
if strings.Contains(err.Error(), "job scaling blocked due to active deployment") {
return sdk.NewTargetScalingNoOpError("skipping scaling group %s/%s due to active deployment", config[configKeyJobID], config[configKeyGroup])
}
return fmt.Errorf("failed to scale group %s/%s: %v", config[configKeyJobID], config[configKeyGroup], err)
}
return nil
Expand Down
5 changes: 5 additions & 0 deletions policyeval/base_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ func (w *BaseWorker) handlePolicy(ctx context.Context, eval *sdk.ScalingEvaluati
// handler understand what do to.
err = w.runTargetScale(targetInst, eval.Policy, *winningAction)
if err != nil {
if _, ok := err.(*sdk.TargetScalingNoOpError); ok {
logger.Info("scaling action skipped", "reason", err)
return nil
}

metrics.IncrCounter([]string{"scale", "invoke", "error_count"}, 1)
return fmt.Errorf("failed to scale target: %v", err)
} else {
Expand Down
24 changes: 24 additions & 0 deletions sdk/target.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
package sdk

import (
"fmt"
)

// TargetScalingNoOp is a special error type that can be used by target plugins
// to indicate that a scaling request didn't result in any action, but didn't
// fail either.
// This can be used to avoid post-scaling actions such as placing the policy in
// cooldown.
lgfa29 marked this conversation as resolved.
Show resolved Hide resolved
type TargetScalingNoOpError struct {
Err error
}

// NewTargetScalingNoOpError returns a new target scaling no-op error with the
// provided formatted message.
func NewTargetScalingNoOpError(msg string, args ...interface{}) *TargetScalingNoOpError {
return &TargetScalingNoOpError{Err: fmt.Errorf(msg, args...)}
}

// Error implements the error interface.
func (n *TargetScalingNoOpError) Error() string {
return n.Err.Error()
}

// TargetStatus is the response object when performing the Status call of the
// target plugin interface. The response details key information about the
// current state of the target.
Expand Down