Skip to content

feat:[PEA-31] Tagging rule changes and scripts for Tagging summary#2393

Merged
arunpaladin merged 3 commits into
masterfrom
feat/resource_tag_validation
May 26, 2026
Merged

feat:[PEA-31] Tagging rule changes and scripts for Tagging summary#2393
arunpaladin merged 3 commits into
masterfrom
feat/resource_tag_validation

Conversation

@nkeerthana111
Copy link
Copy Markdown
Contributor

@nkeerthana111 nkeerthana111 commented May 14, 2026

Description

Please include a summary of the changes and the related issues. Please also include relevant motivation and context. List
any dependencies that are required for this change.

Problem

Solution

Fixes # (issue if any)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Chore (no code changes)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also
list any relevant details for your test configuration

  • Test A
  • Test B

Checklist:

  • My code follows the style guidelines of this project
  • My commit message/PR follows the contribution guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Other Information:

List any documentation updates that are needed for the Wiki

Summary by CodeRabbit

  • New Features

    • Enhanced tag validation: supports separate configurable case-sensitive and case-insensitive mandatory tag lists and reports combined missing tags in failure annotations.
  • Bug Fixes

    • For EC2 resources, tag checks are skipped when instance state is undefined/null to avoid incorrect failures.

Review Change Stack

@nkeerthana111 nkeerthana111 requested a review from arunpaladin May 14, 2026 06:03
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 14, 2026

Walkthrough

Adds dual-mode mandatory tag validation to EC2 TaggingRule: new rule parameters for case-sensitive and case-insensitive tag lists, a case-aware PacmanUtils helper to compute missing tags, fallback to configured tags when parameters are absent, and a state null guard for EC2 resources.

Changes

EC2 Instance Tagging Rule with Case-Sensitive/Insensitive Tag Support

Layer / File(s) Summary
Rule parameter constants
jobs/pacman-awsrules/src/main/java/com/tmobile/cloud/constants/PacmanRuleConstants.java
Two new public constants define rule parameter names (MANDATORY_TAGS and MANDATORY_TAGS_IGNORE_CASE) for customizing tag validation per rule.
Case-aware tag validation utility
jobs/pacman-awsrules/src/main/java/com/tmobile/cloud/awsrules/utils/PacmanUtils.java
New getMissingTagsfromResourceAttributeWithCase() detects missing tags with both exact (case-sensitive) and lowercase-normalized (case-insensitive) checks; getTagKey() helper centralizes "tags."+tag construction.
TaggingRule execution with dual tag support
jobs/pacman-awsrules/src/main/java/com/tmobile/cloud/awsrules/ec2/TaggingRule.java
execute() reads optional MANDATORY_TAGS and MANDATORY_TAGS_IGNORE_CASE, falls back to config when absent, delegates missing-tag detection to the new utility, builds combined annotation payload, adds EC2 STATE_NAME null guard, and consolidated java.util imports.

Sequence Diagram(s)

sequenceDiagram
  participant TaggingRule
  participant Config
  participant PacmanUtils
  Note over TaggingRule: Evaluate EC2 resource
  TaggingRule->>Config: read TAGGING_MANDATORY_TAGS (fallback)
  TaggingRule->>PacmanUtils: getMissingTagsfromResourceAttributeWithCase(caseSensitiveList, caseInsensitiveList, attributes)
  PacmanUtils-->>TaggingRule: Set of missing tags
  Note over TaggingRule: build annotation payload using combined mandatory tags
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • kevin-paladin

Poem

🐰 I hop through code with a twitchy nose,
Case-strict checks and soft-lower prose.
Constants in paw, utilities bright,
I sniff missing tags in day or night.
A little hop for rules done right.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete; it contains only the template structure with all required sections empty (no problem statement, solution details, issue references, selected change type, test details, or checklist confirmations). Fill in all required template sections: provide a clear problem statement, describe the solution with motivation/context, link related issues, select applicable change type, document test procedures, and confirm all checklist items.
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title mentions PEA-31 and tagging rule changes, which aligns with the changeset's focus on enhancing TaggingRule with case-sensitive and case-insensitive mandatory tag support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/resource_tag_validation

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.42.2)
jobs/pacman-awsrules/src/main/java/com/tmobile/cloud/awsrules/utils/PacmanUtils.java

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@jobs/pacman-awsrules/src/main/java/com/tmobile/cloud/awsrules/ec2/TaggingRule.java`:
- Around line 83-112: Ensure shared required inputs (tagsSplitter, targetType
and any other required config) are validated before computing hasCustomTags and
entering the custom-tag branch: check that tagsSplitter and targetType are
non-null/non-empty and call PacmanUtils.doesAllHaveValue or throw
InvalidInputException early. Also make state checks null-safe: verify
resourceAttributes is non-null and that
resourceAttributes.get(PacmanRuleConstants.STATE_NAME) != null before calling
equalsIgnoreCase (use a local String state = resourceAttributes.get(...); if
(state != null && state.equalsIgnoreCase(...))). Update references in this block
(hasCustomTags, caseSensitiveTagsFromParam, caseInsensitiveTagsFromParam,
tagsSplitter, targetType, resourceAttributes, PacmanRuleConstants.STATE_NAME)
accordingly.

In
`@jobs/pacman-awsrules/src/main/java/com/tmobile/cloud/awsrules/utils/PacmanUtils.java`:
- Around line 153-163: When normalizing tag keys in PacmanUtils, the current
loop that builds lowerCaseAttributes overwrites case-variant entries and can
replace a populated value with a blank one; change the population logic in the
loop that constructs lowerCaseAttributes so it only replaces an existing entry
when the existing value is null or blank and the new value is non-blank (i.e.,
compute lowerKey = entry.getKey().toLowerCase(), existing =
lowerCaseAttributes.get(lowerKey); if existing==null or
(existing.trim().isEmpty() && !entry.getValue().trim().isEmpty()) then put the
new value). This uses the existing lowerCaseAttributes map, the entry from
attributes, and getTagKey/caseInsensitiveTags to preserve non-blank values when
normalizing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b78f7b22-1ab9-4bf4-945f-4c175aabe32c

📥 Commits

Reviewing files that changed from the base of the PR and between 41ca869 and c52e59c.

📒 Files selected for processing (4)
  • installer/resources/pacbot_app/files/DB_Policy.sql
  • jobs/pacman-awsrules/src/main/java/com/tmobile/cloud/awsrules/ec2/TaggingRule.java
  • jobs/pacman-awsrules/src/main/java/com/tmobile/cloud/awsrules/utils/PacmanUtils.java
  • jobs/pacman-awsrules/src/main/java/com/tmobile/cloud/constants/PacmanRuleConstants.java

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@jobs/pacman-awsrules/src/main/java/com/tmobile/cloud/awsrules/utils/PacmanUtils.java`:
- Line 156: The toLowerCase() call used to normalize tag keys (e.g., where
lowerKey is assigned via entry.getKey().toLowerCase()) is locale-sensitive;
change it to entry.getKey().toLowerCase(Locale.ROOT) (and any other
toLowerCase() occurrences in the same method/area such as the one around line
163) to ensure locale-safe normalization, and add the import java.util.Locale if
it's not already present.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 010747ac-0e2b-419e-b5ab-c56618e89a3a

📥 Commits

Reviewing files that changed from the base of the PR and between b227abc and dd58a64.

📒 Files selected for processing (1)
  • jobs/pacman-awsrules/src/main/java/com/tmobile/cloud/awsrules/utils/PacmanUtils.java

Map<String, String> lowerCaseAttributes = new HashMap<>();

for (Map.Entry<String, String> entry : attributes.entrySet()) {
String lowerKey = entry.getKey().toLowerCase();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Specify Locale.ROOT in toLowerCase() calls to prevent locale-specific bugs.

The case normalization uses toLowerCase() without specifying a locale. In Turkish and some other locales, this produces incorrect results (e.g., "I".toLowerCase() yields "ı" instead of "i"), which will cause tag keys to be mismatched and tags incorrectly reported as missing.

The past review comment on lines 153–165 explicitly suggested toLowerCase(Locale.ROOT) to avoid this issue, but that change was not applied.

🔧 Apply the locale-safe normalization
 for (Map.Entry<String, String> entry : attributes.entrySet()) {
-    String lowerKey = entry.getKey().toLowerCase();
+    String lowerKey = entry.getKey().toLowerCase(Locale.ROOT);
     String existingValue = lowerCaseAttributes.get(lowerKey);
     if (existingValue == null || existingValue.trim().isEmpty()) {
         lowerCaseAttributes.put(lowerKey, entry.getValue());
     }
 }
 for (String tag : caseInsensitiveTags) {
-    String expectedKey = getTagKey(tag).toLowerCase();
+    String expectedKey = getTagKey(tag).toLowerCase(Locale.ROOT);
     String value = lowerCaseAttributes.get(expectedKey);

Also applies to: 163-163

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@jobs/pacman-awsrules/src/main/java/com/tmobile/cloud/awsrules/utils/PacmanUtils.java`
at line 156, The toLowerCase() call used to normalize tag keys (e.g., where
lowerKey is assigned via entry.getKey().toLowerCase()) is locale-sensitive;
change it to entry.getKey().toLowerCase(Locale.ROOT) (and any other
toLowerCase() occurrences in the same method/area such as the one around line
163) to ensure locale-safe normalization, and add the import java.util.Locale if
it's not already present.

@arunpaladin arunpaladin merged commit 230e84c into master May 26, 2026
62 checks passed
@arunpaladin arunpaladin deleted the feat/resource_tag_validation branch May 26, 2026 06:26
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.

2 participants