Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dmjb committed Jul 16, 2024
1 parent 615ce2e commit c137cec
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
8 changes: 3 additions & 5 deletions internal/engine/eval_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ func (e *executor) createEvalStatusParams(
params := &engif.EvalStatusParams{
Rule: rule,
Profile: profile,
ProfileID: profile.ID,
EntityType: entities.EntityTypeToDB(inf.Type),
RepoID: repoID,
ArtifactID: artID,
PullRequestID: prID,
ProjectID: inf.ProjectID,
ExecutionID: *inf.ExecutionID, // Execution ID is required in the executor.
RuleTypeID: rule.RuleTypeID,
}

// Prepare params for fetching the current rule evaluation from the database
Expand Down Expand Up @@ -89,7 +87,7 @@ func (e *executor) createEvalStatusParams(

// Get the current rule evaluation from the database
evalStatus, err := e.querier.GetRuleEvaluationByProfileIdAndRuleType(ctx,
params.ProfileID,
params.Profile.ID,
entityType,
ruleName,
entityID,
Expand Down Expand Up @@ -135,11 +133,11 @@ func (e *executor) createOrUpdateEvalStatus(
// TODO: once we use the new history table, get rid of RuleTypeID from the params struct
// TODO: replace this table with the evaluation statuses table
evalID, err := e.querier.UpsertRuleEvaluations(ctx, db.UpsertRuleEvaluationsParams{
ProfileID: params.ProfileID,
ProfileID: params.Profile.ID,
RepositoryID: params.RepoID,
ArtifactID: params.ArtifactID,
Entity: params.EntityType,
RuleTypeID: params.RuleTypeID,
RuleTypeID: params.Rule.RuleTypeID,
PullRequestID: params.PullRequestID,
RuleName: params.Rule.Name,
})
Expand Down
1 change: 0 additions & 1 deletion internal/engine/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ func (e *executor) evaluateRule(
if err != nil {
return fmt.Errorf("error creating eval status params: %w", err)
}
evalParams.RuleTypeID = rule.RuleTypeID

// retrieve the rule type engine from the cache
ruleEngine, err := ruleEngineCache.GetRuleEngine(rule.RuleTypeID)
Expand Down
13 changes: 2 additions & 11 deletions internal/engine/interfaces/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ type EvalStatusParams struct {
Result *Result
Profile *models.ProfileAggregate
Rule *models.RuleInstance
ProfileID uuid.UUID
RepoID uuid.NullUUID
ArtifactID uuid.NullUUID
PullRequestID uuid.NullUUID
Expand All @@ -105,7 +104,6 @@ type EvalStatusParams struct {
TaskRunID uuid.UUID
BuildID uuid.UUID
EntityType db.Entities
RuleTypeID uuid.UUID
EvalStatusFromDb *db.ListRuleEvaluationsByProfileIdRow
evalErr error
actionsOnOff map[ActionType]models.ActionOpt
Expand Down Expand Up @@ -176,11 +174,6 @@ func (e *EvalStatusParams) GetRule() *models.RuleInstance {
return e.Rule
}

// GetRuleTypeID returns the rule type ID
func (e *EvalStatusParams) GetRuleTypeID() uuid.UUID {
return e.RuleTypeID
}

// GetEvalStatusFromDb returns the evaluation status from the database
func (e *EvalStatusParams) GetEvalStatusFromDb() *db.ListRuleEvaluationsByProfileIdRow {
return e.EvalStatusFromDb
Expand All @@ -205,11 +198,10 @@ func (e *EvalStatusParams) GetIngestResult() *Result {
func (e *EvalStatusParams) DecorateLogger(l zerolog.Logger) zerolog.Logger {
outl := l.With().
Str("entity_type", string(e.EntityType)).
Str("profile_id", e.ProfileID.String()).
Str("profile_id", e.Profile.ID.String()).
Str("rule_name", e.GetRule().Name).
Str("rule_type_id", e.GetRuleTypeID().String()).
Str("execution_id", e.ExecutionID.String()).
Str("rule_type_id", e.RuleTypeID.String()).
Str("rule_type_id", e.Rule.RuleTypeID.String()).
Logger()
if e.RepoID.Valid {
outl = outl.With().Str("repository_id", e.RepoID.UUID.String()).Logger()
Expand Down Expand Up @@ -244,6 +236,5 @@ type ActionsParams interface {
GetActionsErr() evalerrors.ActionsError
GetEvalErr() error
GetEvalStatusFromDb() *db.ListRuleEvaluationsByProfileIdRow
GetRuleTypeID() uuid.UUID
GetProfile() *models.ProfileAggregate
}
8 changes: 6 additions & 2 deletions internal/logger/telemetry_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func TestTelemetryStore_Record(t *testing.T) {
name: "nil telemetry",
evalParamsFunc: func() *engif.EvalStatusParams {
ep := &engif.EvalStatusParams{}
ep.Rule = &models.RuleInstance{
RuleTypeID: testUUID,
}
ep.Profile = &models.ProfileAggregate{
Name: "artifact_profile",
ID: testUUID,
Expand All @@ -72,12 +75,13 @@ func TestTelemetryStore_Record(t *testing.T) {
telemetry: &logger.TelemetryStore{},
evalParamsFunc: func() *engif.EvalStatusParams {
ep := &engif.EvalStatusParams{}
ep.RuleTypeID = testUUID
ep.Rule = &models.RuleInstance{
RuleTypeID: testUUID,
}
ep.Profile = &models.ProfileAggregate{
Name: "artifact_profile",
ID: testUUID,
}
ep.RuleTypeID = testUUID
ep.SetEvalErr(enginerr.NewErrEvaluationFailed("evaluation failure reason"))
ep.SetActionsOnOff(map[engif.ActionType]models.ActionOpt{
alert.ActionType: models.ActionOptOff,
Expand Down

0 comments on commit c137cec

Please sign in to comment.