Skip to content

Conversation

@esebesto
Copy link
Contributor

@esebesto esebesto commented Oct 1, 2025

This PR fixes a bug where the JSONLPersistentDiskGenerator produced an inconsistent structure for the 'labels' field compared to other generators.

The issue was caused by the attribute override logic running after the default labels were set, causing correctly formatted labels to be overwritten. This change reorders the operations to match the logic in the ComputeEngine generator, ensuring a consistent key-value pair format for labels across all generated data. This resolves JSON parsing errors in BigQuery.

== Assisted by Gemini ==

Summary by Sourcery

Reorder label determination in JSONLPersistentDiskGenerator to fix inconsistent labels and align with ComputeEngine logic

Bug Fixes:

  • Fix incorrect labels structure by applying attribute overrides before determining default labels, preventing overwrites and resolving BigQuery JSON parsing errors

Enhancements:

  • Align label assignment order with ComputeEngine generator for consistency across GCP generators

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 1, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Reorder labels assignment in JSONLPersistentDiskGenerator to occur after attribute overrides, aligning with ComputeEngine logic and preventing incorrect label structures in BigQuery.

Class diagram for updated labels assignment in JSONLPersistentDiskGenerator

classDiagram
    class JSONLPersistentDiskGenerator {
        +_update_data(row)
        +generate_data(report_type=None)
        +determine_labels(LABELS)
        attributes
        LABELS
        column_labels
        _resource_name
        _resource_global_name
        _currency
    }
    JSONLPersistentDiskGenerator : _update_data(row) now assigns labels after attribute overrides
Loading

Flow diagram for labels assignment order in _update_data

flowchart TD
    A[Start _update_data]
    B[Set invoice, resource, currency]
    C[Override attributes in row]
    D[Assign labels using determine_labels]
    E[Return row]
    A --> B --> C --> D --> E
Loading

File-Level Changes

Change Details Files
Reorder labels assignment to occur after attribute processing
  • Removed initial row["labels"] assignment before attribute loop
  • Inserted row["labels"] assignment immediately after applying attribute overrides
nise/generators/gcp/disk_generator.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Oct 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.5%. Comparing base (14b3f53) to head (7ad82d2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #584   +/-   ##
=====================================
  Coverage   93.5%   93.5%           
=====================================
  Files         56      56           
  Lines       4677    4677           
  Branches     651     651           
=====================================
+ Hits        4372    4373    +1     
+ Misses       164     163    -1     
  Partials     141     141           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@esebesto esebesto changed the title Fix incorrect labels structure in GCP JSONLPersistentDiskGenerator Fix incorrect labels' structure in GCP JSONLPersistentDiskGenerator Oct 1, 2025
@esebesto esebesto changed the title Fix incorrect labels' structure in GCP JSONLPersistentDiskGenerator [COST-6067] Fix incorrect labels' structure in GCP JSONLPersistentDiskGenerator Oct 1, 2025
@esebesto esebesto merged commit 6e2b027 into main Oct 1, 2025
5 checks passed
@esebesto esebesto deleted the esebesto/fix_gcp_pd_labels branch October 1, 2025 12:51
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.

3 participants