Skip to content

refactor: labels support#4118

Merged
borbelyr-kong merged 4 commits intomainfrom
refactor/labels
Apr 10, 2026
Merged

refactor: labels support#4118
borbelyr-kong merged 4 commits intomainfrom
refactor/labels

Conversation

@chrisgacsal
Copy link
Copy Markdown
Collaborator

@chrisgacsal chrisgacsal commented Apr 9, 2026

Overview

Refactor labels support for v3 API.

Summary by CodeRabbit

  • Bug Fixes

    • Conversions from labels to metadata now surface conversion errors and abort create/upsert flows, preventing incomplete resources.
    • Request handlers immediately return conversion errors to avoid proceeding with invalid input.
  • New Features

    • Stricter label validation with reserved-prefix checks to block prohibited keys.
    • Validation now returns richer, actionable errors for invalid label keys/values.

@chrisgacsal chrisgacsal self-assigned this Apr 9, 2026
@chrisgacsal chrisgacsal requested a review from a team as a code owner April 9, 2026 21:07
@chrisgacsal chrisgacsal added the release-note/misc Miscellaneous changes label Apr 9, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 2026

📝 Walkthrough

Walkthrough

This PR centralizes label→metadata conversion via a new ConvertLabelsToMetadata (backed by labels.ToMetadata), makes label conversion error-aware, updates generated and handwritten converters to return/propagate errors, removes local per-file label helpers, and adjusts validation and tests to surface conversion/validation errors.

Changes

Cohort / File(s) Summary
Label core & tests
api/v3/labels/convert.go, api/v3/labels/convert_test.go
Made ToMetadata/ToMetadataAnnotations return errors, added MetadataAnnotations type, aggregate validation errors and updated tests to expect error-aware behavior.
Label validation & tests
api/v3/labels/validate.go, api/v3/labels/validate_test.go
ValidateLabel now returns structured ValidationIssue errors and enforces reserved-prefix checks; removed ErrInvalidLabelKey/Value sentinels; tests adjusted and expanded for reserved prefixes.
Shared converter exports
api/v3/handlers/.../convert.go (billingprofiles, customers, meters, taxcodes, ...)
Exported/added ConvertLabelsToMetadata (wired to labels.ToMetadata) and extended goverter directives so generated converters call the shared function.
Generated converters
api/v3/handlers/*/convert.gen.go (billingprofiles, customers, meters, taxcodes, ...)
Replaced local pV3/v3 label helpers with ConvertLabelsToMetadata(...); many generated converters now return (..., error) and early-return on conversion failure.
Customers handler & generated
api/v3/handlers/customers/convert.go, .../convert.gen.go, create.go, upsert.go
Converter signatures changed to return (..., error); call sites precompute label→metadata and propagate errors; handlers updated to use new returns.
Meters handler & generated
api/v3/handlers/meters/convert.go, .../convert.gen.go, create.go
Create-meter converter now returns (..., error); added ConvertLabelsToMetadata; removed local helpers and simplified request mapping.
Billing, Features, Subscriptions, Taxcodes handlers
api/v3/handlers/billingprofiles/..., features/..., subscriptions/..., taxcodes/...
Precompute metadata via ConvertLabelsToMetadata/labels.ToMetadata, return early on conversion errors, assign converted metadata into inputs/workflows; removed inline helper conversions.
Tests & small handler tweaks
api/v3/handlers/features/convert_test.go, api/v3/handlers/features/convert.go, other handler tests
Updated tests to handle error-aware label conversion; small simplifications at callsites to capture and propagate conversion errors.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Client
participant Handler
participant Converter
participant LabelsPkg
participant DomainModel

Client->>Handler: HTTP Create/Upsert request
Handler->>Converter: ConvertXRequestToInput(body)
Converter->>LabelsPkg: ConvertLabelsToMetadata(body.Labels)
alt conversion success
    LabelsPkg-->>Converter: metadata (nil error)
    Converter-->>DomainModel: return populated input (metadata assigned)
    Converter-->>Handler: input, nil
    Handler-->>Client: proceed (e.g., 201/200)
else conversion fails
    LabelsPkg-->>Converter: error
    Converter-->>Handler: empty input, error
    Handler-->>Client: return error (e.g., 400)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

release-note/feature

Suggested reviewers

  • chrisgacsal
  • tothandras
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: labels support' clearly summarizes the main change—a refactoring of labels handling across the v3 API handlers.

✏️ 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 refactor/labels

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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
api/v3/labels/validate.go (1)

13-16: ⚠️ Potential issue | 🟡 Minor

Remove unused sentinel errors.

ErrInvalidLabelKey and ErrInvalidLabelValue aren't referenced anywhere in the codebase. Since ValidateLabel no longer returns these after the refactor, you can clean them up.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/v3/labels/validate.go` around lines 13 - 16, Remove the unused sentinel
errors ErrInvalidLabelKey and ErrInvalidLabelValue from the file since
ValidateLabel no longer returns them; search for ErrInvalidLabelKey and
ErrInvalidLabelValue to confirm they have no external references, then delete
their declarations from validate.go and run tests to ensure nothing else depends
on those symbols.
🧹 Nitpick comments (3)
api/v3/labels/validate_test.go (1)

129-146: Good coverage of reserved prefix validation, consider adding more prefixes.

The tests cover openmeter_, kong_, and konnect_ reserved prefixes nicely. For completeness, you might want to add test cases for the other reserved prefixes defined in reservedPrefixMatcher (mesh, kic, kuma, insomnia).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/v3/labels/validate_test.go` around lines 129 - 146, Add unit test rows in
api/v3/labels/validate_test.go to cover the remaining reserved prefixes used by
reservedPrefixMatcher: add test cases for "mesh_", "kic_", "kuma_", and
"insomnia_" (each with a key like "mesh_key", "kic_key", "kuma_key",
"insomnia_key", a sample value and wantErr: true) so the test table includes
these prefixes and asserts validation fails for them.
api/v3/labels/convert.go (1)

31-53: Good error aggregation pattern - but annotations branch may be dead code.

The error collection and aggregation via errors.Join + NewNillableGenericValidationError is well-implemented.

However, since ValidateLabel now rejects keys with the openmeter_ prefix (via reservedPrefixMatcher), the annotations branch (lines 38-43) will never execute - any label key starting with openmeter_ fails validation at line 32 and gets skipped. Only non-prefixed keys reach line 38, and they all go to metadata.

This is intentional per the design that clients cannot set openmeter_* labels via API. You could consider removing the dead branch for clarity, or adding a comment explaining it's preserved for symmetry/future use.

♻️ Optional: Remove unreachable annotations branch
 	for k, v := range *labels {
 		if err := ValidateLabel(k, v); err != nil {
 			errs = append(errs, err)
 
 			continue
 		}
 
-		if strings.HasPrefix(k, AnnotationsPrefix) {
-			if annotations == nil {
-				annotations = make(models.Annotations)
-			}
-
-			annotations[strings.TrimPrefix(k, AnnotationsPrefix)] = v
-		} else {
-			if metadata == nil {
-				metadata = make(models.Metadata)
-			}
+		if metadata == nil {
+			metadata = make(models.Metadata)
+		}
 
-			metadata[k] = v
-		}
+		metadata[k] = v
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/v3/labels/convert.go` around lines 31 - 53, The annotations branch in the
loop that builds MetadataAnnotations is unreachable because ValidateLabel (which
uses reservedPrefixMatcher to reject keys starting with the openmeter_ prefix)
will always error for annotation-like keys; update the code in the loop that
iterates over *labels (the block referencing AnnotationsPrefix, annotations, and
metadata) by either removing the annotations branch entirely and returning only
metadata for now, or leaving the branch but adding a clear comment above it
explaining that keys with the AnnotationsPrefix are rejected by ValidateLabel
(via reservedPrefixMatcher) so the branch is retained only for symmetry/future
use; ensure references to AnnotationsPrefix, annotations, metadata,
MetadataAnnotations, and ValidateLabel remain consistent.
api/v3/handlers/customers/convert.go (1)

46-50: Consider returning nil when there's an error.

When labels.ToMetadata fails, the function still returns &m (a pointer to the zero-value metadata) alongside the error. While the generated code does check errors before using the value, returning nil on error is a more defensive pattern that prevents accidental misuse.

💡 Suggested tweak
 func ConvertLabelsToMetadata(l *api.Labels) (*models.Metadata, error) {
 	m, err := labels.ToMetadata(l)
-
-	return &m, err
+	if err != nil {
+		return nil, err
+	}
+	return &m, nil
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/v3/handlers/customers/convert.go` around lines 46 - 50, The
ConvertLabelsToMetadata function currently returns a pointer to m even when
labels.ToMetadata returns an error; update ConvertLabelsToMetadata to return
nil, err when err != nil and only return &m, nil on success. Locate
ConvertLabelsToMetadata and the call to labels.ToMetadata so you return (nil,
err) on failure and (&m, nil) on success to avoid returning a pointer to a
zero-value models.Metadata when an error occurred.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@api/v3/labels/validate.go`:
- Around line 47-55: The validation error created when
reservedPrefixMatcher.MatchString(k) is true uses a misleading message; update
the models.NewValidationIssue call for the "invalid_label_key_prefix" case (the
block that appends to errs) to use a specific message such as "label key uses a
reserved prefix" instead of "label key must be a valid DNS_SUBDOMAIN format" so
the error reflects the reserved-prefix violation while keeping the same error
code, severity, field attribute (models.WithFieldString("labels")), and HTTP
status attribute.

---

Outside diff comments:
In `@api/v3/labels/validate.go`:
- Around line 13-16: Remove the unused sentinel errors ErrInvalidLabelKey and
ErrInvalidLabelValue from the file since ValidateLabel no longer returns them;
search for ErrInvalidLabelKey and ErrInvalidLabelValue to confirm they have no
external references, then delete their declarations from validate.go and run
tests to ensure nothing else depends on those symbols.

---

Nitpick comments:
In `@api/v3/handlers/customers/convert.go`:
- Around line 46-50: The ConvertLabelsToMetadata function currently returns a
pointer to m even when labels.ToMetadata returns an error; update
ConvertLabelsToMetadata to return nil, err when err != nil and only return &m,
nil on success. Locate ConvertLabelsToMetadata and the call to labels.ToMetadata
so you return (nil, err) on failure and (&m, nil) on success to avoid returning
a pointer to a zero-value models.Metadata when an error occurred.

In `@api/v3/labels/convert.go`:
- Around line 31-53: The annotations branch in the loop that builds
MetadataAnnotations is unreachable because ValidateLabel (which uses
reservedPrefixMatcher to reject keys starting with the openmeter_ prefix) will
always error for annotation-like keys; update the code in the loop that iterates
over *labels (the block referencing AnnotationsPrefix, annotations, and
metadata) by either removing the annotations branch entirely and returning only
metadata for now, or leaving the branch but adding a clear comment above it
explaining that keys with the AnnotationsPrefix are rejected by ValidateLabel
(via reservedPrefixMatcher) so the branch is retained only for symmetry/future
use; ensure references to AnnotationsPrefix, annotations, metadata,
MetadataAnnotations, and ValidateLabel remain consistent.

In `@api/v3/labels/validate_test.go`:
- Around line 129-146: Add unit test rows in api/v3/labels/validate_test.go to
cover the remaining reserved prefixes used by reservedPrefixMatcher: add test
cases for "mesh_", "kic_", "kuma_", and "insomnia_" (each with a key like
"mesh_key", "kic_key", "kuma_key", "insomnia_key", a sample value and wantErr:
true) so the test table includes these prefixes and asserts validation fails for
them.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ef7166d0-7dd2-4204-9656-000366288e44

📥 Commits

Reviewing files that changed from the base of the PR and between 3cccdca and 4ca8963.

📒 Files selected for processing (18)
  • api/v3/handlers/billingprofiles/convert.gen.go
  • api/v3/handlers/billingprofiles/convert.go
  • api/v3/handlers/customers/convert.gen.go
  • api/v3/handlers/customers/convert.go
  • api/v3/handlers/customers/create.go
  • api/v3/handlers/customers/upsert.go
  • api/v3/handlers/features/convert.go
  • api/v3/handlers/features/convert_test.go
  • api/v3/handlers/meters/convert.gen.go
  • api/v3/handlers/meters/convert.go
  • api/v3/handlers/meters/create.go
  • api/v3/handlers/subscriptions/convert.go
  • api/v3/handlers/taxcodes/convert.gen.go
  • api/v3/handlers/taxcodes/convert.go
  • api/v3/labels/convert.go
  • api/v3/labels/convert_test.go
  • api/v3/labels/validate.go
  • api/v3/labels/validate_test.go

Comment thread api/v3/labels/validate.go
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

🧹 Nitpick comments (1)
api/v3/labels/validate.go (1)

21-22: Consider updating the regex doc link above reservedPrefixMatcher.

The comment URL looks like the key/value format example, not the reserved-prefix matcher. Updating it would make this block easier to maintain later.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/v3/labels/validate.go` around lines 21 - 22, The comment's regex101 URL
above reservedPrefixMatcher is pointing to a different regex (key/value format)
— update that URL to a regex101 link (or equivalent documentation) that uses the
actual pattern ^(_|kong|konnect|insomnia|mesh|kic|kuma|openmeter) and includes
representative test cases (matching and non-matching prefixes) so the inline doc
reflects reservedPrefixMatcher's intent and is easier to maintain; locate the
variable reservedPrefixMatcher and replace the comment link immediately above it
with the corrected URL.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@api/v3/handlers/features/convert_test.go`:
- Around line 539-550: Add a negative test that calls labels.ToMetadata with an
invalid labels value and asserts it returns a non-nil error and nil (or empty)
metadata: create a new t.Run (e.g., "invalid labels returns error") that passes
a deliberately malformed api.Labels (such as a label with an empty key or
another value that triggers validation in labels.ToMetadata), then assert error
is not nil and meta is nil/empty using assert.Error and assert.Nil/assert.Empty
to cover the failure path introduced by the new (meta, err) signature.

In `@api/v3/labels/validate.go`:
- Around line 49-50: The validation error message for the
"invalid_label_key_prefix" code contains a typo ("nopt" should be "not"); update
the message string in api/v3/labels/validate.go (the entry with
"invalid_label_key_prefix") to read "label key must not have reserved prefix" so
the API returns the correct, professional wording.

---

Nitpick comments:
In `@api/v3/labels/validate.go`:
- Around line 21-22: The comment's regex101 URL above reservedPrefixMatcher is
pointing to a different regex (key/value format) — update that URL to a regex101
link (or equivalent documentation) that uses the actual pattern
^(_|kong|konnect|insomnia|mesh|kic|kuma|openmeter) and includes representative
test cases (matching and non-matching prefixes) so the inline doc reflects
reservedPrefixMatcher's intent and is easier to maintain; locate the variable
reservedPrefixMatcher and replace the comment link immediately above it with the
corrected URL.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0bd0edcb-14c9-4ae1-b601-5bec170e4830

📥 Commits

Reviewing files that changed from the base of the PR and between 4ca8963 and 95673e9.

📒 Files selected for processing (15)
  • api/v3/handlers/billingprofiles/convert.gen.go
  • api/v3/handlers/billingprofiles/convert.go
  • api/v3/handlers/customers/convert.gen.go
  • api/v3/handlers/customers/convert.go
  • api/v3/handlers/customers/create.go
  • api/v3/handlers/customers/upsert.go
  • api/v3/handlers/features/convert.go
  • api/v3/handlers/features/convert_test.go
  • api/v3/handlers/meters/convert.gen.go
  • api/v3/handlers/meters/convert.go
  • api/v3/handlers/meters/create.go
  • api/v3/handlers/subscriptions/convert.go
  • api/v3/handlers/taxcodes/convert.gen.go
  • api/v3/handlers/taxcodes/convert.go
  • api/v3/labels/validate.go
✅ Files skipped from review due to trivial changes (3)
  • api/v3/handlers/meters/create.go
  • api/v3/handlers/customers/create.go
  • api/v3/handlers/billingprofiles/convert.gen.go
🚧 Files skipped from review as they are similar to previous changes (6)
  • api/v3/handlers/features/convert.go
  • api/v3/handlers/subscriptions/convert.go
  • api/v3/handlers/customers/upsert.go
  • api/v3/handlers/taxcodes/convert.go
  • api/v3/handlers/customers/convert.gen.go
  • api/v3/handlers/customers/convert.go

Comment thread api/v3/handlers/features/convert_test.go
Comment thread api/v3/labels/validate.go Outdated
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

♻️ Duplicate comments (1)
api/v3/handlers/features/convert_test.go (1)

539-550: ⚠️ Potential issue | 🟡 Minor

Please add one invalid-label failure-path test here.

Nice update for the new (meta, err) flow, but we still only cover happy/nil paths. Since labels.ToMetadata is now error-aware, add one case with invalid labels and assert error + nil/empty metadata.

Suggested test addition
 func TestConvertMetadataLabels(t *testing.T) {
@@
 	t.Run("nil labels returns nil metadata", func(t *testing.T) {
 		meta, err := labels.ToMetadata(nil)
 		assert.NoError(t, err)
 		assert.Nil(t, meta)
 	})
+
+	t.Run("invalid labels returns error", func(t *testing.T) {
+		l := api.Labels{"bad key": "value"}
+		meta, err := labels.ToMetadata(&l)
+		require.Error(t, err)
+		assert.Nil(t, meta)
+	})
 }

As per coding guidelines: **/*_test.go: "Make sure the tests are comprehensive and cover the changes."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/v3/handlers/features/convert_test.go` around lines 539 - 550, Add a
failing-path unit test for labels.ToMetadata that constructs an invalid
api.Labels value (e.g., a key or value that violates validation rules used by
ToMetadata), calls labels.ToMetadata(&invalidLabels), and asserts that an error
is returned and the returned metadata is nil or empty; place it alongside the
existing tests ("labels to metadata" and "nil labels returns nil metadata") and
name the subtest something like "invalid labels returns error" to verify
ToMetadata's new (meta, err) error-aware behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@api/v3/handlers/billingprofiles/convert.gen.go`:
- Around line 191-195: The create path is still using pV3LabelsToMapStringString
to copy source.Labels directly (allowing invalid labels through), while the
upsert path uses ConvertLabelsToMetadata and validates; update the create
converter to call ConvertLabelsToMetadata(source.Labels) (same as the upsert
flow), propagate and handle the returned error exactly as done where
billingUpdateProfileInput.Metadata is set, replace uses of
pV3LabelsToMapStringString in the create converter, and then regenerate this
file from the Goverter source so both create and upsert use the same validation
helper.

---

Duplicate comments:
In `@api/v3/handlers/features/convert_test.go`:
- Around line 539-550: Add a failing-path unit test for labels.ToMetadata that
constructs an invalid api.Labels value (e.g., a key or value that violates
validation rules used by ToMetadata), calls labels.ToMetadata(&invalidLabels),
and asserts that an error is returned and the returned metadata is nil or empty;
place it alongside the existing tests ("labels to metadata" and "nil labels
returns nil metadata") and name the subtest something like "invalid labels
returns error" to verify ToMetadata's new (meta, err) error-aware behavior.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e81667bd-a772-49ba-9a5a-359113395a75

📥 Commits

Reviewing files that changed from the base of the PR and between 95673e9 and 717a11c.

📒 Files selected for processing (15)
  • api/v3/handlers/billingprofiles/convert.gen.go
  • api/v3/handlers/billingprofiles/convert.go
  • api/v3/handlers/customers/convert.gen.go
  • api/v3/handlers/customers/convert.go
  • api/v3/handlers/customers/create.go
  • api/v3/handlers/customers/upsert.go
  • api/v3/handlers/features/convert.go
  • api/v3/handlers/features/convert_test.go
  • api/v3/handlers/meters/convert.gen.go
  • api/v3/handlers/meters/convert.go
  • api/v3/handlers/meters/create.go
  • api/v3/handlers/subscriptions/convert.go
  • api/v3/handlers/taxcodes/convert.gen.go
  • api/v3/handlers/taxcodes/convert.go
  • api/v3/labels/validate.go
✅ Files skipped from review due to trivial changes (4)
  • api/v3/handlers/customers/create.go
  • api/v3/handlers/customers/upsert.go
  • api/v3/handlers/meters/create.go
  • api/v3/handlers/features/convert.go
🚧 Files skipped from review as they are similar to previous changes (6)
  • api/v3/handlers/subscriptions/convert.go
  • api/v3/handlers/billingprofiles/convert.go
  • api/v3/handlers/meters/convert.gen.go
  • api/v3/labels/validate.go
  • api/v3/handlers/customers/convert.go
  • api/v3/handlers/customers/convert.gen.go

Comment thread api/v3/handlers/billingprofiles/convert.gen.go
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 the current code and only fix it if needed.

Inline comments:
In `@api/v3/labels/validate.go`:
- Around line 23-29: The validation issues currently use a generic "labels"
field which hides which specific label failed; update ValidateLabels to include
the concrete failing key in each NewValidationIssue call (e.g. use
models.WithFieldString(fmt.Sprintf("labels.%s", key)) or similar) so callers can
identify the bad entry—apply the same change for the other NewValidationIssue
invocations referenced (the blocks around lines 33-39 and 43-48) and ensure the
variable used is the actual label key checked in that validation branch.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e2bdb468-58bb-4482-83fc-dc3f30783d96

📥 Commits

Reviewing files that changed from the base of the PR and between 717a11c and e9cff4c.

📒 Files selected for processing (3)
  • api/v3/handlers/billingprofiles/convert.gen.go
  • api/v3/handlers/billingprofiles/convert.go
  • api/v3/labels/validate.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • api/v3/handlers/billingprofiles/convert.gen.go
  • api/v3/handlers/billingprofiles/convert.go

Comment thread api/v3/labels/validate.go
Comment on lines +23 to +29
errs = append(errs, models.NewValidationIssue(
"invalid_label_key_format",
"label key must be in valid format",
models.WithFieldString("labels"),
models.WithCriticalSeverity(),
commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest),
))
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

Keep the failing label key in each validation issue.

Nice cleanup overall, but this now reports every failure against the same "labels" field. Once ValidateLabels joins errors from multiple entries, callers can’t tell which label actually failed. That’s a pretty rough regression for bulk validation. Consider attaching the concrete key (for example labels.<key> or an equivalent attribute) before returning the issue.

Also applies to: 33-39, 43-48

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/v3/labels/validate.go` around lines 23 - 29, The validation issues
currently use a generic "labels" field which hides which specific label failed;
update ValidateLabels to include the concrete failing key in each
NewValidationIssue call (e.g. use
models.WithFieldString(fmt.Sprintf("labels.%s", key)) or similar) so callers can
identify the bad entry—apply the same change for the other NewValidationIssue
invocations referenced (the blocks around lines 33-39 and 43-48) and ensure the
variable used is the actual label key checked in that validation branch.

@borbelyr-kong borbelyr-kong merged commit 5560d74 into main Apr 10, 2026
26 checks passed
@borbelyr-kong borbelyr-kong deleted the refactor/labels branch April 10, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/misc Miscellaneous changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants