Skip to content

Commit

Permalink
Merge pull request #776 from stacklok/skip
Browse files Browse the repository at this point in the history
engine: Handle skipped rules and silent skips
  • Loading branch information
jhrozek authored Aug 28, 2023
2 parents 9efc4d2 + bd048c5 commit 55f941d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,21 @@ func NewErrEvaluationFailed(sfmt string, args ...any) error {
msg := fmt.Sprintf(sfmt, args...)
return fmt.Errorf("%w: %s", ErrEvaluationFailed, msg)
}

// ErrEvaluationSkipped specifies that the rule was evaluated but skipped.
var ErrEvaluationSkipped = errors.New("evaluation skipped")

// NewErrEvaluationSkipped creates a new evaluation error
func NewErrEvaluationSkipped(sfmt string, args ...any) error {
msg := fmt.Sprintf(sfmt, args...)
return fmt.Errorf("%w: %s", ErrEvaluationSkipped, msg)
}

// ErrEvaluationSkipSilently specifies that the rule was evaluated but skipped silently.
var ErrEvaluationSkipSilently = errors.New("evaluation skipped silently")

// NewErrEvaluationSkipSilently creates a new evaluation error
func NewErrEvaluationSkipSilently(sfmt string, args ...any) error {
msg := fmt.Sprintf(sfmt, args...)
return fmt.Errorf("%w: %s", ErrEvaluationSkipSilently, msg)
}
2 changes: 1 addition & 1 deletion internal/engine/eval/jq/jq.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"fmt"
"reflect"

evalerrors "github.com/stacklok/mediator/internal/engine/eval/errors"
evalerrors "github.com/stacklok/mediator/internal/engine/errors"
"github.com/stacklok/mediator/internal/util"
pb "github.com/stacklok/mediator/pkg/generated/protobuf/go/mediator/v1"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/eval/jq/jq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/stretchr/testify/assert"

evalerrors "github.com/stacklok/mediator/internal/engine/eval/errors"
evalerrors "github.com/stacklok/mediator/internal/engine/errors"
"github.com/stacklok/mediator/internal/engine/eval/jq"
pb "github.com/stacklok/mediator/pkg/generated/protobuf/go/mediator/v1"
)
Expand Down
8 changes: 7 additions & 1 deletion internal/engine/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/go-playground/validator/v10"
"google.golang.org/protobuf/types/known/timestamppb"

evalerrors "github.com/stacklok/mediator/internal/engine/eval/errors"
evalerrors "github.com/stacklok/mediator/internal/engine/errors"
"github.com/stacklok/mediator/internal/events"
"github.com/stacklok/mediator/internal/util"
"github.com/stacklok/mediator/pkg/crypto"
Expand Down Expand Up @@ -576,6 +576,10 @@ func (e *Executor) createOrUpdateEvalStatus(
ruleTypeID int32,
evalErr error,
) error {
if errors.Is(evalErr, evalerrors.ErrEvaluationSkipSilently) {
return nil
}

return e.querier.UpsertRuleEvaluationStatus(ctx, db.UpsertRuleEvaluationStatusParams{
PolicyID: policyID,
RepositoryID: sql.NullInt32{
Expand Down Expand Up @@ -610,6 +614,8 @@ func parseRepoID(repoID any) (int32, error) {
func errorAsEvalStatus(err error) db.EvalStatusTypes {
if errors.Is(err, evalerrors.ErrEvaluationFailed) {
return db.EvalStatusTypesFailure
} else if errors.Is(err, evalerrors.ErrEvaluationSkipped) {
return db.EvalStatusTypesSkipped
} else if err != nil {
return db.EvalStatusTypesError
}
Expand Down

0 comments on commit 55f941d

Please sign in to comment.