Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - v2alpha1 atxs stream #5566

Closed
wants to merge 29 commits into from

Conversation

kacpersaw
Copy link
Contributor

@kacpersaw kacpersaw commented Feb 13, 2024

This PR is based on #5233

api: spacemeshos/api#305

  • watch support. subscribe to atxs emitted after validating and saving database
  • encode the rest of the fields
  • add support for limit and offset and make use of it in List api. public services should not expose Stream, as it is much harder to track resources for streams
  • extract into separate service that has access only for to db pointer, in order to enable readonly replicas
  • always order by epoch asc, id
  • matcher for watcher based on request parameters
  • extract query builder into separate module
  • test coverage
  • activations count

streaming full atxs

stream all atxs before and including publish epoch 2:

grpcurl -plaintext -d '{"end_epoch": 2}' 127.0.0.1:9093 spacemesh.v2alpha1.ActivationStreamService.Stream

stream all atxs that belong to the specific smesher

grpcurl -plaintext -d '{"node_id": "MaAcOOLRj0pffyWO8gfuuWiBszQG2ueq/SNbbMnHHoU="}' 127.0.0.1:9093 spacemesh.v2alpha1.ActivationStreamService

the same as above, but also continue waiting for atxs from same smesher

grpcurl -plaintext -d '{"node_id": "MaAcOOLRj0pffyWO8gfuuWiBszQG2ueq/SNbbMnHHoU=", "watch": true}' 127.0.0.1:9093 spacemesh.v2alpha1.ActivationStreamService.Stream

listing atxs

streaming if more convenient to use (less memory footprint, can read whole collection from same stream), however
it is harder to enforce fair distribution of resources for multiple concurrent users. for public api it is better to use req/resp pattern
with strict limits and no ability to continuously watch collections.

list full atxs

grpcurl -plaintext -d '{"start_epoch": 2, "limit": 100, "offset": 100}' 127.0.0.1:9092 spacemesh.v2alpha1.ActivationService.List

note that limit and offset are effective only for specific query, so that if you started iteration with start_epoch: 2, you can't just bump start_epoch to 3 and continue using same offset and limit if you care about getting correct results.

activations count per epoch

grpcurl -plaintext -d '{"epoch": 2}' 127.0.0.1:9092 spacemesh.v2alpha1.ActivationService.ActivationsCount

versioning

data in spacemesh is mostly static and not expected to change constantly. for the case when it does change, object can be bumped to the next version. all responses return protobuf oneof version type.

Copy link

codecov bot commented Feb 13, 2024

Codecov Report

Attention: 76 lines in your changes are missing coverage. Please review.

Comparison is base (e8af701) 79.7% compared to head (d87b0e8) 79.7%.

Files Patch % Lines
api/grpcserver/v2alpha1/activation.go 70.0% 42 Missing and 20 partials ⚠️
common/fixture/atxs.go 88.7% 4 Missing and 4 partials ⚠️
sql/atxs/atxs.go 81.8% 3 Missing and 1 partial ⚠️
sql/builder/builder.go 90.4% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           develop   #5566     +/-   ##
=========================================
- Coverage     79.7%   79.7%   -0.1%     
=========================================
  Files          267     270      +3     
  Lines        26857   27186    +329     
=========================================
+ Hits         21416   21669    +253     
- Misses        3920    3970     +50     
- Partials      1521    1547     +26     

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

@kacpersaw kacpersaw marked this pull request as ready for review February 15, 2024 11:52
api/grpcserver/config.go Show resolved Hide resolved
api/grpcserver/v2alpha1/activation.go Outdated Show resolved Hide resolved
api/grpcserver/v2alpha1/activation.go Outdated Show resolved Hide resolved
node/node.go Outdated Show resolved Hide resolved
api/grpcserver/v2alpha1/activation.go Outdated Show resolved Hide resolved
common/fixture/atxs.go Outdated Show resolved Hide resolved
common/fixture/atxs.go Outdated Show resolved Hide resolved
api/grpcserver/v2alpha1/activation_test.go Outdated Show resolved Hide resolved
api/grpcserver/v2alpha1/activation_test.go Outdated Show resolved Hide resolved
api/grpcserver/v2alpha1/activation_test.go Outdated Show resolved Hide resolved
@kacpersaw kacpersaw requested a review from poszu February 16, 2024 13:00
@kacpersaw
Copy link
Contributor Author

bors merge

spacemesh-bors bot pushed a commit that referenced this pull request Feb 16, 2024
This PR is based on #5233

api: spacemeshos/api#305

- [x] watch support. subscribe to atxs emitted after validating and saving database
- [x] encode the rest of the fields
- [x] add support for limit and offset and make use of it in List api. public services should not expose Stream, as it is much harder to track resources for streams
- [x] extract into separate service that has access only for to db pointer, in order to enable readonly replicas
- [x] always order by epoch asc, id
- [x] matcher for watcher based on request parameters
- [x] extract query builder into separate module
- [x] test coverage
- [x] activations count

--- 

### streaming full atxs

stream all atxs before and including publish epoch 2:

> grpcurl -plaintext -d '{"end_epoch": 2}' 127.0.0.1:9093 spacemesh.v2.ActivationStreamService.Stream

stream all atxs that belong to the specific smesher 

> grpcurl -plaintext -d '{"node_id": "MaAcOOLRj0pffyWO8gfuuWiBszQG2ueq/SNbbMnHHoU="}' 127.0.0.1:9093 spacemesh.v2.ActivationStreamService 

the same as above, but also continue waiting for atxs from same smesher

> grpcurl -plaintext -d '{"node_id": "MaAcOOLRj0pffyWO8gfuuWiBszQG2ueq/SNbbMnHHoU=", "watch": true}' 127.0.0.1:9093 spacemesh.v2.ActivationStreamService.Stream

### listing atxs

streaming if more convenient to use (less memory footprint, can read whole collection from same stream), however
it is harder to enforce fair distribution of resources for multiple concurrent users. for public api it is better to use req/resp pattern
with strict limits and no ability to continuously watch collections.

list full atxs

> grpcurl -plaintext -d '{"start_epoch": 2, "limit": 100, "offset": 100}' 127.0.0.1:9092 spacemesh.v2.ActivationService.List

note that limit and offset are effective only for specific query, so that if you started iteration with start_epoch: 2, you can't just bump start_epoch to 3 and continue using same offset and limit if you care about getting correct results.

### activations count per epoch

> grpcurl -plaintext -d '{"epoch": 2}' 127.0.0.1:9092 spacemesh.v2alpha1.ActivationService.ActivationsCount

### versioning

data in spacemesh is mostly static and not expected to change constantly. for the case when it does change, object can be bumped to the next version. all responses return protobuf oneof version type.

Co-authored-by: Dmitry <[email protected]>
@spacemesh-bors
Copy link

Pull request successfully merged into develop.

Build succeeded:

@spacemesh-bors spacemesh-bors bot changed the title v2alpha1 atxs stream [Merged by Bors] - v2alpha1 atxs stream Feb 16, 2024
@spacemesh-bors spacemesh-bors bot closed this Feb 16, 2024
@@ -36,7 +36,7 @@ require (
github.com/quic-go/quic-go v0.41.0
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
github.com/seehuhn/mt19937 v1.0.0
github.com/spacemeshos/api/release/go v1.28.0
github.com/spacemeshos/api/release/go v1.28.1-0.20240215101325-80fe2752264b
Copy link
Member

Choose a reason for hiding this comment

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

@kacpersaw could you update this to the released version (v1.29.0)?

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.

4 participants