-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add codegen/build-clients.sh
script, update codegen/apis
submodule
#49
Conversation
…d-clients.sh script for handling building control and data plane clients using a specific version of the API spec, update client.go to match generated internals
[submodule "codegen/apis"] | ||
path = codegen/apis | ||
url = [email protected]:pinecone-io/apis.git |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving to new submodule location, and swapping the underlying repo.
@@ -0,0 +1,70 @@ | |||
#!/bin/bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was modeling this after the work @jhamon had done in other repos, but this diverges a bit in that I'm not using a docker image, and we're doing both OAS and proto files in here.
Let me know if this doesn't make sense - or any other feedback. I didn't want to make too many changes to the dependencies we were using to generate code.
echo "Verifying spec version has been provided: $version" | ||
if [ -z "$version" ]; then | ||
echo "Version is required" | ||
exit 1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should maybe do some actual checking against the folder names under /apis/_build/
maybe. 🤔
|
||
oapi-codegen --package=control \ | ||
--generate types,client \ | ||
"${oas_file}" > "${control_destination}/control_plane.oas.go" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a version
in the proto / data plane output, maybe should have that here too.
@@ -3,7 +3,6 @@ module github.com/pinecone-io/go-pinecone | |||
go 1.21 | |||
|
|||
require ( | |||
github.com/golang/protobuf v1.5.4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran go mod tidy
locally and this was removed... I think the google.golang.org/protobuf v1.34.1
below covers it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we should prefer google.golang.org according to https://protobuf.dev/reference/go/faq/.
justfile
Outdated
go install golang.org/x/tools/cmd/godoc@latest | ||
gen: | ||
protoc --experimental_allow_proto3_optional --proto_path=apis/proto --go_opt=module="github.com/pinecone-io/go-pinecone" --go-grpc_opt=module="github.com/pinecone-io/go-pinecone" --go_out=. --go-grpc_out=. apis/proto/pinecone/data/v1/vector_service.proto | ||
oapi-codegen --package=control --generate types,client apis/openapi/control/v1/control_v1.yaml > internal/gen/control/control_plane.oas.go | ||
./codegen/build-clients.sh "2024-07" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling the script with version from here, we could set a global "API_VERSION" constant somewhere and use that here and elsewhere maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just
can also have variables: https://just.systems/man/en/chapter_29.html
Shards *control.PodSpecShards `json:"shards,omitempty"` | ||
SourceCollection *string `json:"source_collection,omitempty"` | ||
}{ | ||
req.Spec = control.IndexSpec{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generated anonymous type cleaned up a bit, which is nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice. The previous impl was unsightly.
@@ -19,11 +19,10 @@ test-unit: | |||
bootstrap: | |||
go install google.golang.org/protobuf/cmd/[email protected] | |||
go install google.golang.org/grpc/cmd/[email protected] | |||
go install github.com/oapi-codegen/oapi-codegen/v2/cmd/[email protected] | |||
go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest | |||
go install golang.org/x/tools/cmd/godoc@latest | |||
gen: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just gen
now requires just bootstrap
so the script has the right dependencies to call... should it call bootstrap
itself or is unexpectedly installing dependencies weird?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that would be weird. bootstrap
shouldn't be a requirement for just gen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me, assuming tests are passing with the newly built output. Is the version being set in X-Pinecone-Api-Version
header for control plane actions? For some other languages, I had to augment the generated code by writing the version number somewhere (see python and ts) and then setting up that custom header. The generated java included the version number, but still required some effort to hook it up into headers properly. So it's worth double checking that is being done correctly after this refactoring.
Good question, I was going to implement the header in a follow up PR, but given what you mentioned I should probably just do it here. Thanks for the heads up, I had wrongly assumed the version number was written in as part of the spec build process and wasn't considering it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments. Looks good!
.gitignore
Outdated
@@ -120,3 +120,4 @@ modules.xml | |||
|
|||
go.work* | |||
.env | |||
.DS_Store |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably just add this to your dev machine as a global gitignore (similar to .idea, .swp files, etc)
@@ -3,7 +3,6 @@ module github.com/pinecone-io/go-pinecone | |||
go 1.21 | |||
|
|||
require ( | |||
github.com/golang/protobuf v1.5.4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we should prefer google.golang.org according to https://protobuf.dev/reference/go/faq/.
@@ -19,11 +19,10 @@ test-unit: | |||
bootstrap: | |||
go install google.golang.org/protobuf/cmd/[email protected] | |||
go install google.golang.org/grpc/cmd/[email protected] | |||
go install github.com/oapi-codegen/oapi-codegen/v2/cmd/[email protected] | |||
go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest | |||
go install golang.org/x/tools/cmd/godoc@latest | |||
gen: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that would be weird. bootstrap
shouldn't be a requirement for just gen
@@ -19,11 +19,10 @@ test-unit: | |||
bootstrap: | |||
go install google.golang.org/protobuf/cmd/[email protected] | |||
go install google.golang.org/grpc/cmd/[email protected] | |||
go install github.com/oapi-codegen/oapi-codegen/v2/cmd/[email protected] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We pinned this to a version to avoid unnecessary codegen updates. It's fine to update but maybe a specific version instead of latest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the catch, I mean to pin to v2.3.0
which is the version they swapped to the new github.com
location.
justfile
Outdated
go install golang.org/x/tools/cmd/godoc@latest | ||
gen: | ||
protoc --experimental_allow_proto3_optional --proto_path=apis/proto --go_opt=module="github.com/pinecone-io/go-pinecone" --go-grpc_opt=module="github.com/pinecone-io/go-pinecone" --go_out=. --go-grpc_out=. apis/proto/pinecone/data/v1/vector_service.proto | ||
oapi-codegen --package=control --generate types,client apis/openapi/control/v1/control_v1.yaml > internal/gen/control/control_plane.oas.go | ||
./codegen/build-clients.sh "2024-07" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just
can also have variables: https://just.systems/man/en/chapter_29.html
pinecone/client.go
Outdated
x := minOne(req.Replicas) | ||
return &x | ||
return x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is assignment and explicit return necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, lemme clean this up - I ran through here too quick fixing the initial build.
Shards *control.PodSpecShards `json:"shards,omitempty"` | ||
SourceCollection *string `json:"source_collection,omitempty"` | ||
}{ | ||
req.Spec = control.IndexSpec{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice. The previous impl was unsightly.
…in oapi-codegen to v2.3.0
…enting the API version as a constant, use that as a header for both control and data plane operations
…eaders on the client
Added a |
Problem
We're getting ready to release
v1.0.0
of the Go SDK. Before we do that, we need to make sure we're generating our control and data plane client code from the proper specifications. When thego-pinecone
repo was originally set up, theapis
submodule was created and points to a private, Go-specific cut of the OpenAPI and proto files from about 4 months ago.Since then we're made changes to how we approach client generation, and where our upstream spec files live.
Solution
codegen/
folder to hold both theapis
submodule and thebuild-clients.sh
script..gitmodules
to moveapis
->codegen/apis
.build-clients.sh
script. Originally,just gen
called a few shell commands for generating from OpenAPI and protos. The new script handles generation in a fashion similar to our other repos, and allows specifying a specific API version.client.go
/client_test.go
to handle some changes to underlying types.My approach was based on the work @jhamon has done in other repos to align our code generation pipelines.
Type of Change
Test Plan
There weren't changes needed to the actual SDK interface. Make sure CI runs and our unit & integration tests are passing as expected.