Skip to content

Commit

Permalink
pap: defect fixes - explicit internal-op over autonomy in last 2 minu…
Browse files Browse the repository at this point in the history
…tes, power cap sock file folders creation, and nominal evict service Stop method
  • Loading branch information
h-w-chen committed Nov 25, 2024
1 parent 32a3253 commit d5f1d8f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ func (p ruleBasedPowerStrategy) RecommendAction(actualWatt int,

if ttl <= time.Minute*2 {
// whatever valid alert, power capping should do in short of 2 minutes
return action.PowerAction{Op: spec.InternalOpFreqCap, Arg: desiredWatt}
// this the default behavior unless instructed explicitly by internal op
if spec.InternalOpAuto == internalOp {
return action.PowerAction{Op: spec.InternalOpFreqCap, Arg: desiredWatt}
}
}

op := internalOp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,31 @@ func Test_ruleBasedPowerStrategy_RecommendAction(t *testing.T) {
actualWatt: 99,
desiredWatt: 88,
alert: spec.PowerAlertP1,
internalOp: spec.InternalOpThrottle,
internalOp: spec.InternalOpAuto,
ttl: time.Second * 30,
},
want: action.PowerAction{
Op: spec.InternalOpFreqCap,
Arg: 88,
},
},
{
name: "approaching deadline no freq capping is indicated otherwise only",
fields: fields{
coefficient: exponentialDecay{},
},
args: args{
actualWatt: 99,
desiredWatt: 88,
alert: spec.PowerAlertP1,
internalOp: spec.InternalOpEvict,
ttl: time.Second * 30,
},
want: action.PowerAction{
Op: spec.InternalOpEvict,
Arg: 12,
},
},
{
name: "having a lot of time usually leads to evict a very little portion",
fields: fields{coefficient: exponentialDecay{b: math.E / 2}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net"
"os"
"path/filepath"
"sync"

"github.com/pkg/errors"
Expand Down Expand Up @@ -204,6 +205,10 @@ func newPowerCapServiceSuite(conf *config.Configuration, emitter metrics.MetricE
return nil, nil, errors.Wrap(err, "failed to clean up the residue file")
}

if err := os.MkdirAll(filepath.Dir(socketPath), 0o755); err != nil {
return nil, nil, errors.Wrap(err, "failed to create folders to unix sock file")
}

sock, err := net.Listen("unix", socketPath)
if err != nil {
return nil, nil, fmt.Errorf("%v listen %s failed: %v", powerCapSvc.Name(), socketPath, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,9 @@ func (p *powerPressureEvictServer) Start() error {
}

func (p *powerPressureEvictServer) Stop() error {
p.mutex.Lock()
defer p.mutex.Unlock()

if !p.started {
general.InfofV(6, "pap: power pressure eviction server already stopped")
return nil
}

p.started = false
return p.service.Stop()
// since there is no resource other than the underlying PluginRegistrationWrapper-guarded grpc service,
// which will be cleanup by PluginRegistrationWrapper itself, it has nothing to clean up here
return nil
}

func (p *powerPressureEvictServer) GetToken(ctx context.Context, empty *pluginapi.Empty) (*pluginapi.GetTokenResponse, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ func Test_powerPressureEvictPluginServer_GetEvictPods(t *testing.T) {
p := &powerPressureEvictServer{
evicts: tt.fields.evicts,
}
defer p.Stop()

got, err := p.GetEvictPods(tt.args.ctx, tt.args.request)
if !tt.wantErr(t, err, fmt.Sprintf("GetTopEvictionPods(%v, %v)", tt.args.ctx, tt.args.request)) {
return
Expand Down

0 comments on commit d5f1d8f

Please sign in to comment.