Skip to content

Commit

Permalink
serialize Plan to string & json for better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
duaraghav8 committed Mar 12, 2020
1 parent 2cda219 commit 8183336
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions engine/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package engine

import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/Shuttl-Tech/drone-autoscaler/cluster"
Expand All @@ -20,6 +21,24 @@ type Plan struct {
nodesToDestroy []cluster.NodeId
}

// serialization methods for better representation of Plan in logs
func (p *Plan) String() string {
return fmt.Sprintf(
"action=%v, upscaleCount=%v, nodesToDestroy=%v",
p.action,
p.upscaleCount,
p.nodesToDestroy,
)
}

func (p *Plan) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"action": p.action,
"upscaleCount": p.upscaleCount,
"nodesToDestroy": p.nodesToDestroy,
})
}

// RequiresUpscaling returns true when more agents must be added
func (p *Plan) RequiresUpscaling() bool {
return p.action == actionUpscale
Expand Down

0 comments on commit 8183336

Please sign in to comment.