Add Count RPC to EndDevice registry#7909
Open
happyRip wants to merge 1 commit into
Open
Conversation
5f30b37 to
6f138b1
Compare
6f138b1 to
202f100
Compare
Member
Author
|
Imre is on leave (Stack Reviewers 1) |
Member
johanstokking
left a comment
There was a problem hiding this comment.
API and implementation look good but this is missing tests.
nicholaspcr
reviewed
May 11, 2026
Contributor
nicholaspcr
left a comment
There was a problem hiding this comment.
A few points:
- There should be a CHANGELOG entry
- Is it worth considering filters to this new endpoint?
- created_since or other fields associated with IS device fields.
| } | ||
|
|
||
| message CountEndDevicesResponse { | ||
| uint32 count = 1; |
Contributor
There was a problem hiding this comment.
Why uint32 instead of uint64, considering that:
- The store implementation returns uint64
- The value we set in the total header (on any List requests) is derived from the uint64.
Comment on lines
+336
to
+356
| func (is *IdentityServer) countEndDevices( | ||
| ctx context.Context, req *ttnpb.CountEndDevicesRequest, | ||
| ) (*ttnpb.CountEndDevicesResponse, error) { | ||
| if err := rights.RequireApplication( | ||
| ctx, req.GetApplicationIds(), ttnpb.Right_RIGHT_APPLICATION_DEVICES_READ, | ||
| ); err != nil { | ||
| return nil, err | ||
| } | ||
| var count uint64 | ||
| err := is.store.Transact(ctx, func(ctx context.Context, st store.Store) (err error) { | ||
| count, err = st.CountEndDevices(ctx, req.GetApplicationIds()) | ||
| return err | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return &ttnpb.CountEndDevicesResponse{ | ||
| Count: uint32(min(count, math.MaxUint32)), // #nosec G115 -- bounded by min | ||
| }, nil | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
Add a unit test for this in the end_device_registry_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
References https://github.com/TheThingsIndustries/lorawan-stack/issues/4802
Changes
CountRPC toEndDeviceRegistrywith REST endpointGET /applications/{id}/devices/count.CountEndDevicesstore method; requiresRIGHT_APPLICATION_DEVICES_READ.Testing
Steps
GET /applications/{app_id}/devices/countwith valid auth. Verify response{"count": N}.RIGHT_APPLICATION_DEVICES_READand verify permission denied.Results
Read device count
returns
Use an API key with no read permission
returns
Regressions
Existing
ListandDeletedevice endpoints are unchanged. Store layerCountEndDeviceswas already tested.Notes for Reviewers
The store interface and bunstore implementation for
CountEndDevicesalready existed (used bydeleteApplication/purgeApplication). This PR only adds the proto definition and gRPC handler to expose it as a public API.Checklist
README.mdfor the chosen target branch.CHANGELOG.md.CONTRIBUTING.md, there are no fixup commits left.