From df505695bf632ac658e3badfb7a7de4e60485528 Mon Sep 17 00:00:00 2001 From: Paul Norton Date: Mon, 25 Dec 2023 13:32:20 -0500 Subject: [PATCH] collapse evaluators into goals package --- policy/evaluators/evaluators.go | 23 ----------------------- policy/{evaluators => goals}/differ.go | 8 +++----- policy/goals/types.go | 6 ++++++ policy/policy_handler/handler.go | 7 +++---- 4 files changed, 12 insertions(+), 32 deletions(-) delete mode 100644 policy/evaluators/evaluators.go rename policy/{evaluators => goals}/differ.go (85%) diff --git a/policy/evaluators/evaluators.go b/policy/evaluators/evaluators.go deleted file mode 100644 index 75fc1ba..0000000 --- a/policy/evaluators/evaluators.go +++ /dev/null @@ -1,23 +0,0 @@ -package evaluators - -import ( - "context" - - "github.com/atomist-skills/go-skill/policy/goals" - "github.com/atomist-skills/go-skill/policy/query" - - "github.com/atomist-skills/go-skill" - "olympos.io/encoding/edn" -) - -type EvaluatorFlags uint8 - -const ( - EVAL_SKIP_LOCAL EvaluatorFlags = 1 << iota - OPT_DIGEST -) - -type GoalEvaluator interface { - GetFlags() EvaluatorFlags - EvaluateGoal(ctx context.Context, req skill.RequestContext, commonData query.CommonSubscriptionQueryResult, subscriptionResults [][]edn.RawMessage) ([]goals.GoalEvaluationQueryResult, error) -} diff --git a/policy/evaluators/differ.go b/policy/goals/differ.go similarity index 85% rename from policy/evaluators/differ.go rename to policy/goals/differ.go index 85a3e47..dc331e3 100644 --- a/policy/evaluators/differ.go +++ b/policy/goals/differ.go @@ -1,17 +1,15 @@ -package evaluators +package goals import ( "fmt" - "github.com/atomist-skills/go-skill/policy/goals" - "github.com/atomist-skills/go-skill" "github.com/mitchellh/hashstructure/v2" ) // GoalResultsDiffer checks if the current query results differ from the previous ones. // It returns the storage id for the current query results. -func GoalResultsDiffer(log skill.Logger, queryResults []goals.GoalEvaluationQueryResult, digest string, goal goals.Goal, previousStorageId string) (bool, string, error) { +func GoalResultsDiffer(log skill.Logger, queryResults []GoalEvaluationQueryResult, digest string, goal Goal, previousStorageId string) (bool, string, error) { log.Infof("Generating storage id for goal %s, image %s", goal.Definition, digest) hash, err := hashstructure.Hash(queryResults, hashstructure.FormatV2, nil) if err != nil { @@ -43,7 +41,7 @@ func isRelevantParam(str string) bool { } // Returns the config hash for the current skill config -func GoalConfigsDiffer(log skill.Logger, config skill.Configuration, digest string, goal goals.Goal, previousConfigHash string) (bool, string, error) { +func GoalConfigsDiffer(log skill.Logger, config skill.Configuration, digest string, goal Goal, previousConfigHash string) (bool, string, error) { log.Debugf("Generating config hash for goal %s, image %s", goal.Definition, digest) params := config.Parameters diff --git a/policy/goals/types.go b/policy/goals/types.go index f89a967..721acf3 100644 --- a/policy/goals/types.go +++ b/policy/goals/types.go @@ -17,6 +17,8 @@ package goals import ( + "context" + "github.com/atomist-skills/go-skill/policy/query" "time" "github.com/atomist-skills/go-skill" @@ -48,3 +50,7 @@ type GoalEvaluationResultEntity struct { ConfigHash string `edn:"goal.result/config-hash"` CreatedAt time.Time `edn:"goal.result/created-at"` } + +type GoalEvaluator interface { + EvaluateGoal(ctx context.Context, req skill.RequestContext, commonData query.CommonSubscriptionQueryResult, subscriptionResults [][]edn.RawMessage) ([]GoalEvaluationQueryResult, error) +} diff --git a/policy/policy_handler/handler.go b/policy/policy_handler/handler.go index 0cba6ed..cb325b4 100644 --- a/policy/policy_handler/handler.go +++ b/policy/policy_handler/handler.go @@ -7,7 +7,6 @@ import ( "github.com/atomist-skills/go-skill" "github.com/atomist-skills/go-skill/policy/data" - "github.com/atomist-skills/go-skill/policy/evaluators" "github.com/atomist-skills/go-skill/policy/goals" "github.com/atomist-skills/go-skill/policy/query" "github.com/atomist-skills/go-skill/policy/storage" @@ -16,7 +15,7 @@ import ( ) type ( - EvaluatorSelector func(ctx context.Context, req skill.RequestContext, goal goals.Goal, dataSource data.DataSource) (evaluators.GoalEvaluator, error) + EvaluatorSelector func(ctx context.Context, req skill.RequestContext, goal goals.Goal, dataSource data.DataSource) (goals.GoalEvaluator, error) Handler interface { Start() @@ -185,14 +184,14 @@ func transact( return skill.NewFailedStatus(fmt.Sprintf("Failed to create evaluation storage: %s", err.Error())) } - configDiffer, configHash, err := evaluators.GoalConfigsDiffer(req.Log, configuration, digest, goal, configHash) + configDiffer, configHash, err := goals.GoalConfigsDiffer(req.Log, configuration, digest, goal, configHash) if err != nil { req.Log.Errorf("Failed to check if config hash changed for digest: %s", digest, err) req.Log.Warnf("Will continue with the evaluation nonetheless") configDiffer = true } - differ, storageId, err := evaluators.GoalResultsDiffer(req.Log, goalResults, digest, goal, storageId) + differ, storageId, err := goals.GoalResultsDiffer(req.Log, goalResults, digest, goal, storageId) if err != nil { req.Log.Errorf("Failed to check if goal results changed for digest: %s", digest, err) req.Log.Warnf("Will continue with the evaluation nonetheless")