Skip to content

fix(fleetcontrol): add missing cursor to getEntitySearchQuery - #1442

Merged
pranav-new-relic merged 1 commit into
mainfrom
fix/fleetcontrol-entity-search-cursor
Aug 24, 2026
Merged

pranav-new-relic merged 1 commit into
mainfrom
fix/fleetcontrol-entity-search-cursor

Conversation

@ShaneLillieNR

Copy link
Copy Markdown
Collaborator

Summary

GetEntitySearch(cursor string, query string) in pkg/fleetcontrol accepted a cursor parameter that was a silent no-op: the generated getEntitySearchQuery GraphQL document only declared $query: String! and called entitySearch(query: $query,) — it never declared $cursor and never passed cursor: $cursor to the entitySearch field. The vars map set "cursor": cursor, but since the query text never referenced $cursor, the value was dropped before the request ever left the client. Every call re-fetched page one regardless of what cursor was passed in.

This is the exact same bug already found and fixed for GetFleetMembers in 93b8a99 ("fix(fleetcontrol): add missing cursor and fix cursor type in getFleetMembersQuery", #1394). That fix added include_arguments: ["cursor"] for the fleetMembers endpoint in .tutone.yml; the equivalent block for entitySearch was missing it.

Changes

  • .tutone.yml: add include_arguments: ["cursor"] to the entitySearch endpoint under the fleetcontrol package's ["actor", "entityManagement"] queries block.
  • pkg/fleetcontrol/fleetcontrol_api.go: getEntitySearchQuery now declares $cursor: String, and passes cursor: $cursor, to entitySearch(...). Applied by hand rather than a full tutone generate — the live NerdGraph schema has drifted substantially since the last full regen, and running it here would have pulled ~16k lines of unrelated changes across 60 files (and even broken an unrelated package due to a type-as-identifier codegen bug in entityrelationship_api.go). The diff here mirrors exactly what 93b8a99 produced for GetFleetMembers.
  • GetEntitySearch/GetEntitySearchWithContext: cursor changed from string to *string, matching the same non-Tutone-covered change 93b8a99 made for GetFleetMembers (the API expects null for "no cursor", not an empty string).
  • pkg/fleetcontrol/fleetcontrol_integration_test.go: updated the 3 existing GetEntitySearch("", ...) call sites to pass nil.
  • pkg/fleetcontrol/entity_search_unit_test.go (new): mocks the NerdGraph endpoint and asserts the actual JSON request body sent over the wire includes the cursor value (and that a nil cursor sends null), verifying the fix at the wire level rather than just via generated code inspection.

No types.go changes were needed — EntityManagementEntitySearchResult already has NextCursor.

Surveyed the rest of fleetcontrol_api.go for other queries with the same dead-cursor bug: GetEntity fetches a single entity by ID and correctly has no cursor; GetEntitySearch and GetFleetMembers are the only two paginated queries in this package, and both are now fixed.

Verification

  • go build ./..., go vet -tags unit ./..., go vet -tags integration ./... all clean.
  • golangci-lint run ./pkg/fleetcontrol/... — 0 issues.
  • go test -tags unit ./pkg/fleetcontrol/... — passes, including the new unit test.
  • Verified against live NerdGraph: called GetEntitySearch(nil, "type = 'FLEET'"), took the returned nextCursor, called again with that cursor — page 2 returned a different set of entities and a new cursor, confirming the cursor now actually advances pagination against real data (not just a mocked assertion).

Context

Discovered while fixing a pagination bug in newrelic-cli's fleetcontrol fleet search command. That CLI-side fix is blocked on this PR merging and a new newrelic-client-go release.

Test plan

  • go build ./...
  • go vet -tags unit ./... / go vet -tags integration ./...
  • golangci-lint run ./pkg/fleetcontrol/...
  • go test -tags unit ./pkg/fleetcontrol/...
  • Live NerdGraph pagination check (ad hoc, not committed)

GetEntitySearch accepted a cursor parameter that was silently dropped:
the generated query only declared $query and never declared $cursor or
passed cursor to the entitySearch field, so every call re-fetched page
one regardless of the cursor passed in. Same bug and fix pattern as
93b8a99 (#1394), which fixed the identical issue in GetFleetMembers.

Verified against live NerdGraph that passing the returned nextCursor
now actually advances the result set.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@codecov-commenter

codecov-commenter commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 32.97%. Comparing base (5ed5d8b) to head (93cb87f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1442      +/-   ##
==========================================
+ Coverage   32.39%   32.97%   +0.57%     
==========================================
  Files         148      148              
  Lines        6939     6939              
==========================================
+ Hits         2248     2288      +40     
+ Misses       4480     4435      -45     
- Partials      211      216       +5     
Flag Coverage Δ
integration 0.21% <ø> (?)
unit 32.75% <ø> (+0.36%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pranav-new-relic

pranav-new-relic commented Aug 19, 2026

Copy link
Copy Markdown
Member

Hey @ShaneLillieNR, thank you for having this fixed, I think this certainly does look good, just that the unit test is a li'l fancy (unlike the unit tests in the rest of the client), but I get why, so I think that's fine (we might want to streamline this later sometime - I'll take a detailed look too) :)

The only double check I'd like you to perform is to test this change with the expected consumer of this change (e.g. the Terraform Provider, or the CLI where you'd like to enable this) so we're sure nothing breaks there. I'm sure there must be a companion PR to enable this (or I'd like you to create one, to fix this as needed) so you might want to test changes in the consumer with this PR and we're sure nothing breaks (it ideally should not :)) and that should give us a 🟢 to merge this.

@ShaneLillieNR

Copy link
Copy Markdown
Collaborator Author

Hey @ShaneLillieNR, thank you for having this fixed, I think this certainly does look good, just that the unit test is a li'l fancy (unlike the unit tests in the rest of the client), but I get why, so I think that's fine (we might want to streamline this later sometime - I'll take a detailed look too) :)

The only double check I'd like you to perform is to test this change with the expected consumer of this change (e.g. the Terraform Provider, or the CLI where you'd like to enable this) so we're sure nothing breaks there. I'm sure there must be a companion PR to enable this (or I'd like you to create one, to fix this as needed) so you might want to test changes in the consumer with this PR and we're sure nothing breaks (it ideally should not :)) and that should give us a 🟢 to merge this.

Hi @pranav-new-relic I think newrelic/newrelic-cli#1874 should cover what you're looking for? We can cover the exactly details on that when we get there but I think it's enough to prove out that the changes here are good?

@ShaneLillieNR

Copy link
Copy Markdown
Collaborator Author

newrelic/terraform-provider-newrelic#3171 is a similar PR but for updating the Terraform provider

@pranav-new-relic
pranav-new-relic merged commit 703c7af into main Aug 24, 2026
15 checks passed
@pranav-new-relic
pranav-new-relic deleted the fix/fleetcontrol-entity-search-cursor branch August 24, 2026 18:55
ShaneLillieNR added a commit to newrelic/terraform-provider-newrelic that referenced this pull request Aug 24, 2026
newrelic/newrelic-client-go#1442 has merged and shipped in v2.93.2, which
carries the GetEntitySearch cursor fix this PR depends on. Point go.mod
at the real release instead of the temporary replace-directive pseudo-version
used during development, and confirm the full build/vet/unit-test suite is
clean with no workarounds needed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
ShaneLillieNR added a commit to newrelic/newrelic-cli that referenced this pull request Aug 24, 2026
newrelic/newrelic-client-go#1442 merged and shipped in v2.93.2, which
carries the GetEntitySearch cursor fix this PR depends on. Drop the
temporary replace directive and point go.mod at the real release.

Re-verified against the same live account/fleets used for the earlier
before/after check - unchanged now that a real released version is in
place.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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