Skip to content

Conversation

radeksimko
Copy link
Member

@radeksimko radeksimko commented Aug 13, 2025

Description

This introduces two new RPC methods ReadStateByets and WriteStateBytes. It also introduces chunk size negotiation into ConfigureStateStore.

One piece of code I avoided attaching here though is validation of chunk size during ConfigureStateStore as it would be a bit difficult without all the other changes in the other branch impacting the command package.

It's currently part of 6468225 where we can cherry pick it from later if needed.

Target Release

1.14.x

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@radeksimko radeksimko added the no-changelog-needed Add this to your PR if the change does not require a changelog entry label Aug 13, 2025
@radeksimko radeksimko force-pushed the radek/pss-read-write branch 3 times, most recently from f185ebe to 74fd3bc Compare August 14, 2025 12:25
@hashicorp hashicorp deleted a comment Aug 14, 2025
@radeksimko radeksimko force-pushed the radek/pss-read-write branch 6 times, most recently from 85d8bf2 to ac83419 Compare September 25, 2025 16:24
radeksimko and others added 8 commits September 25, 2025 17:25
* Fix nil pointer error

* Add WIP test for ReadStateBytes

* Move test mock to separate testing file

* Update mock to send unexpected EOF when there's a problem returning data and it's not a true EOF

* Add test case for when length != expected length

* Add test for when trying to read state from a store type that doesn't exist

* Change symbol names to lowercase

* Add ability to force a diagnostic to be returned from `mockReadStateBytesClient`'s `Recv` method

* Add test showing error diagnostics raised by the ReadStateBytes client are returned

* Add missing header

* Simplify mock by using an embedded type

* Rename `mockOpts` to `mockReadStateBytesOpts`

* Update existing tests to assert what arguments are passed to the RPC method call

* Add mock WriteStateBytesClient which uses `go.uber.org/mock/gomock` to enable assertions about calls to Send

* Add a test for WriteStateBytes that makes assertions about calls to the Send method

* Update test case to explicitly test writing data smaller than the chunk size

* Implement chunking in WriteStateBytes, add test case to assert expected chunking behaviour

* Add generated mock for Provider_WriteStateBytesClient in protocol v6

* Update tests to use new `MockProvider_WriteStateBytesClient`, remove handwritten mock

* Update code comments in test

* Add tests for diagnostics and errors returned during WriteStateBytes

* Add generated mock for Provider_ReadStateBytesClient in protocol v6, replace old mock

* Add test case for grpc errors in ReadStateBytes, fix how error is returned

* Typo in comment

* Add missing warning test, rename some test cases
* Update Read/WriteStateBytes RPCs to match hashicorp/terraform-plugin-go#531

* Run `make protobuf`

* Run `make generate`

* Update use of `proto.ReadStateBytes_ResponseChunk` in tests

* Fix how diagnostics are handled alongside EOF error, update ReadStateBytes test

* More fixes - test setup was incorrect

I think? I assume that a response would be returned full of zero-values when EOF is encountered.
* Update code to not expect a chunk when EOF encountered

* Return early if any grpc errors are encountered during ReadStateBytes

* Close the stream with CloseSend once everything's read without error. Add test case about handling grpc errors from CloseSend.

* Fix test case about warnings: We would expect to receive a chunk with data alongside the warning and have a normal closing of the stream after EOF

* Add log line, remove unneeded type info
@radeksimko radeksimko marked this pull request as ready for review September 25, 2025 16:45
@radeksimko radeksimko requested a review from a team as a code owner September 25, 2025 16:45
@radeksimko radeksimko changed the title Implement ReadStateBytes + WriteStateBytes PSS: Implement ReadStateBytes + WriteStateBytes Sep 25, 2025
Copy link
Member

@SarahFrench SarahFrench left a comment

Choose a reason for hiding this comment

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

A few comments re: testing and a question about validating chunk size

Copy link
Member

@SarahFrench SarahFrench left a comment

Choose a reason for hiding this comment

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

This looks great to me!

Reviewing this was a bit daunting as I'm quite close to the code and felt I might miss something, but luckily the newly-added tests have taken on the heavy lifting with finding bugs. And we always have the opportunity to iterate a little once we begin implementing features of init using this code.

:shipit:

@radeksimko radeksimko merged commit 51fc4c1 into main Sep 26, 2025
10 of 11 checks passed
@radeksimko radeksimko deleted the radek/pss-read-write branch September 26, 2025 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog-needed Add this to your PR if the change does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants