Skip to content

Commit

Permalink
Add evaluation_failure_message to ruletypes (#4433)
Browse files Browse the repository at this point in the history
* add: evaluation failure message to ruletypes

* add: unit tests for RuleType WithDefaultEvaluationFailureMessage method

* update: rename to short_failure_message

* update: default message

* update: unit test after msg formatting

* fix: migration file name

* update: service_test with new msg format
  • Loading branch information
teodor-yanev authored Sep 12, 2024
1 parent b2c4521 commit c139b0a
Show file tree
Hide file tree
Showing 14 changed files with 1,719 additions and 1,562 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Copyright 2024 Stacklok, Inc
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

ALTER TABLE rule_type DROP COLUMN short_failure_message;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Copyright 2024 Stacklok, Inc
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

-- Adds a `short_failure_message` column to the `rule_type` table. The failure message
-- is displayed to the user when a rule evaluation fails.
ALTER TABLE rule_type ADD COLUMN short_failure_message TEXT NOT NULL DEFAULT '';
8 changes: 5 additions & 3 deletions database/query/rule_types.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ INSERT INTO rule_type (
severity_value,
subscription_id,
display_name,
release_phase
release_phase,
short_failure_message
) VALUES (
$1,
$2,
Expand All @@ -18,7 +19,8 @@ INSERT INTO rule_type (
sqlc.arg(severity_value),
sqlc.narg(subscription_id),
sqlc.arg(display_name),
sqlc.arg(release_phase)
sqlc.arg(release_phase),
sqlc.arg(short_failure_message)
) RETURNING *;

-- name: ListRuleTypesByProject :many
Expand All @@ -35,7 +37,7 @@ DELETE FROM rule_type WHERE id = $1;

-- name: UpdateRuleType :one
UPDATE rule_type
SET description = $2, definition = sqlc.arg(definition)::jsonb, severity_value = sqlc.arg(severity_value), display_name = sqlc.arg(display_name), release_phase = sqlc.arg(release_phase)
SET description = $2, definition = sqlc.arg(definition)::jsonb, severity_value = sqlc.arg(severity_value), display_name = sqlc.arg(display_name), release_phase = sqlc.arg(release_phase), short_failure_message = sqlc.arg(short_failure_message)
WHERE id = $1
RETURNING *;

Expand Down
1 change: 1 addition & 0 deletions docs/docs/ref/proto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 15 additions & 14 deletions internal/db/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 36 additions & 24 deletions internal/db/rule_types.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 19 additions & 17 deletions internal/ruletypes/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,18 @@ func (_ *ruleTypeService) CreateRuleType(
return nil, err
}

ruleType = ruleType.WithDefaultDisplayName()
ruleType = ruleType.WithDefaultDisplayName().WithDefaultShortFailureMessage()
newDBRecord, err := qtx.CreateRuleType(ctx, db.CreateRuleTypeParams{
Name: ruleTypeName,
DisplayName: ruleType.GetDisplayName(),
ProjectID: projectID,
Description: ruleType.GetDescription(),
Definition: serializedRule,
Guidance: ruleType.GetGuidance(),
SeverityValue: *severity,
SubscriptionID: uuid.NullUUID{UUID: subscriptionID, Valid: subscriptionID != uuid.Nil},
ReleasePhase: *releasePhase,
Name: ruleTypeName,
DisplayName: ruleType.GetDisplayName(),
ShortFailureMessage: ruleType.GetShortFailureMessage(),
ProjectID: projectID,
Description: ruleType.GetDescription(),
Definition: serializedRule,
Guidance: ruleType.GetGuidance(),
SeverityValue: *severity,
SubscriptionID: uuid.NullUUID{UUID: subscriptionID, Valid: subscriptionID != uuid.Nil},
ReleasePhase: *releasePhase,
})
if err != nil {
return nil, fmt.Errorf("failed to create rule type: %w", err)
Expand Down Expand Up @@ -225,14 +226,15 @@ func (_ *ruleTypeService) UpdateRuleType(
return nil, err
}

ruleType = ruleType.WithDefaultDisplayName()
ruleType = ruleType.WithDefaultDisplayName().WithDefaultShortFailureMessage()
updatedRuleType, err := qtx.UpdateRuleType(ctx, db.UpdateRuleTypeParams{
ID: oldRuleType.ID,
Description: ruleType.GetDescription(),
Definition: serializedRule,
SeverityValue: *severity,
DisplayName: ruleType.GetDisplayName(),
ReleasePhase: *releasePhase,
ID: oldRuleType.ID,
Description: ruleType.GetDescription(),
Definition: serializedRule,
SeverityValue: *severity,
DisplayName: ruleType.GetDisplayName(),
ShortFailureMessage: ruleType.GetShortFailureMessage(),
ReleasePhase: *releasePhase,
})
if err != nil {
return nil, fmt.Errorf("failed to update rule type: %w", err)
Expand Down
Loading

0 comments on commit c139b0a

Please sign in to comment.