Skip to content

Conversation

@maxxkia
Copy link

@maxxkia maxxkia commented Jan 18, 2025

These changes introduce two new features for FreezingRule default store

  • Raise error when a freezing rule has zero violations. This can be enabled by setting the property default.warnEmptyRuleViolation=true. For backward compatibility it is disabled by default.
  • Skip rule violation file creation or delete if it already exists, when there are zero violations. This can be enabled by setting the property default.deleteEmptyRuleViolation=true, it is disabled by default.

Signed-off-by: Masoud Kiaeeha [email protected]

Resolves #1264

@maxxkia maxxkia force-pushed the extension-for-empty-frozen-rule branch 5 times, most recently from a833065 to 90c5338 Compare January 19, 2025 11:24
@maxxkia maxxkia marked this pull request as ready for review January 19, 2025 11:34
private static final String ALLOW_STORE_UPDATE_PROPERTY_NAME = "default.allowStoreUpdate";
private static final String ALLOW_STORE_UPDATE_DEFAULT = "true";
private static final String DELETE_EMPTY_RULE_VIOLATION_PROPERTY_NAME = "default.deleteEmptyRuleViolation";
private static final String DELETE_EMPTY_RULE_VIOLATION_DEFAULT = "false";
Copy link
Author

@maxxkia maxxkia Jan 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can discuss the above default value. I would prefer to have default true here, but I'd like to first hear the opinions from the maintainers.

@Override
public void save(ArchRule rule, List<String> violations) {
log.trace("Storing evaluated rule '{}' with {} violations: {}", rule.getDescription(), violations.size(), violations);
if (violations.isEmpty() && warnEmptyRuleViolation) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check has to be placed here at the top, because for empty frozen rule violations you don't necessarily need to update the store. By seeing such warning the developer could change the test to non-freezing rather than decide to update the store.

@maxxkia maxxkia changed the title raise error for empty violation store raise error for empty violation store and delete empty rule file Jan 19, 2025
@maxxkia maxxkia force-pushed the extension-for-empty-frozen-rule branch from 90c5338 to 60de7ab Compare January 19, 2025 14:03
throw new StoreEmptyException(String.format("Saving empty violations for freezing rule is disabled (enable by configuration %s.%s=true)",
ViolationStoreFactory.FREEZE_STORE_PROPERTY_NAME, WARN_EMPTY_RULE_VIOLATION_PROPERTY_NAME));
}
if (violations.isEmpty() && deleteEmptyRule && !contains(rule)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another way to write this check would be

Suggested change
if (violations.isEmpty() && deleteEmptyRule && !contains(rule)) {
if (violations.isEmpty() && (deleteEmptyRule || skipEmptyRule) && !contains(rule)) {

where skipEmptyRule condition is only used for skipping creation of empty rule file. To keep the configuration simple, I decided to use deleteEmptyRule for both skipping file creation and deleting the empty file.

These changes introduce two new features for FreezingRule default store
* Raise error when a freezing rule has zero violations. This can be enabled by setting the property `default.warnEmptyRuleViolation=true`. For backward compatibility it is disabled by default.
* Skip rule violation file creation or delete if it already exists, when there are zero violations. This can be enabled by setting the property `default.deleteEmptyRuleViolation=true`, it is disabled by default.

Signed-off-by: Masoud Kiaeeha <[email protected]>

Resolves TNG#1264
@maxxkia maxxkia force-pushed the extension-for-empty-frozen-rule branch from 60de7ab to 4952aae Compare January 30, 2025 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature suggestion: Freeze files and stored.rules validation / sanity check

1 participant