-
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 ConfigureIndex method #34
Conversation
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.
Nice work, looks pretty good overall. I've got a few comments and some feedback for your consideration.
pinecone/client.go
Outdated
// Example for a pods-based index originally configured with 1 "p1" pod of size "x2" and 1 replica: | ||
// // To scale the size of your pods from "x2" to "x4": | ||
// _, err := pc.ConfigureIndex(ctx, "my-index", "p1.x4", nil) | ||
// if err != nil { | ||
// fmt.Printf("Failed to configure index: %v\n", err) | ||
// } | ||
// | ||
// // To scale the number of replicas: | ||
// _, err := pc.ConfigureIndex(ctx, "my-index", nil, 4) | ||
// if err != nil { | ||
// fmt.Printf("Failed to configure index: %v\n", err) | ||
// } | ||
// | ||
// // To scale both the size of your pods and the number of replicas: | ||
// _, err := pc.ConfigureIndex(ctx, "my-index", "p1.x4", 4) | ||
// if err != nil { | ||
// fmt.Printf("Failed to configure index: %v\n", err) | ||
// } | ||
// |
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.
Did you happen to run gofmt
on this file? Just wondering as the formatting seems a bit off. There should be a blank empty line between the "Example for a pods-based index..." line and the first comment of the code block.
I think gofmt
should also indent the code block further, but I'm not positive.
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.
Ah I didn't -- this was pushed before before our Slack convo about gofmt
. I'll run 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.
Okay done :)
pinecone/client.go
Outdated
@@ -273,6 +273,104 @@ func (c *Client) DeleteIndex(ctx context.Context, idxName string) error { | |||
return nil | |||
} | |||
|
|||
// ConfigureIndex is used to [scale a pods-based index] up or down by changing the size of the pods or the number of | |||
//replicas. |
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 like a space is needed between //
and replicas
.
pinecone/client.go
Outdated
// | ||
// Parameters: | ||
// - name: The name of the index to configure. | ||
// - pods: (Optional) The pod size to scale the index to (e.g. for a "p1" pod type, |
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 like this formatting for (Optional)
. I didn't do the same thing in other areas but we can maybe do another doc comment cleanup pass.
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, sweet!
pinecone/client.go
Outdated
// | ||
// [scale a pods-based index]: https://docs.pinecone.io/guides/indexes/configure-pod-based-indexes | ||
// [app.pinecone.io]: https://app.pinecone.io | ||
func (c *Client) ConfigureIndex(ctx context.Context, name string, pods *string, |
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.
pods
may be a little confusing given that fields means something else when creating an index. Although I'm realizing now we don't provide a pods
value in CreatePodIndexRequest
.
Still, we use PodType
there and I think we should do the same here. I know it's a positional arg, but just for clarity in the code here. I know we then assign things to podType
further down, but initially when I was reading the function I was a bit confused.
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.
Okay, np, I'll change to podType
! (I hate how we call it type
b/c technically it's size
, but yeah best not to confuse ppl who're used to our other SDKs)
pinecone/client.go
Outdated
err := handleErrorResponseBody(req, "failed to configure index: ") | ||
if err != nil { | ||
return nil, err | ||
} |
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 think here you can just do:
err := handleErrorResponseBody(req, "failed to configure index: ") | |
if err != nil { | |
return nil, err | |
} | |
return nil, handleErrorResponseBody(req, "failed to configure index: ") |
We can assume if the StatusCode
is not http.StatusOK
we're returning an error.
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.
oo nice!
pinecone/client.go
Outdated
}, | ||
} | ||
|
||
req, err := c.restClient.ConfigureIndex(ctx, name, request) |
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.
Can we rename req
to res
to make it clearer it's the http.Response
from the function call here?
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.
Sure!
pinecone/client.go
Outdated
return nil, err | ||
} | ||
|
||
defer req.Body.Close() |
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.
nit: In other functions we put this line right after the function call so it's a bit more clear we're actually closing it, so I'd maybe move it up to after the initial function call and error check:
req, err := c.restClient.ConfigureIndex(ctx, name, request)
if err != nil {
log.Fatalf("Failed to configure index %s. Error: %v", name, err)
}
defer req.Body.Close()
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.
okay will do!
pinecone/client_test.go
Outdated
"github.com/google/uuid" | ||
"github.com/pinecone-io/go-pinecone/internal/mocks" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/stretchr/testify/suite" | ||
"io" | ||
"log" | ||
"net/http" | ||
"os" | ||
"reflect" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
"github.com/pinecone-io/go-pinecone/internal/mocks" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/stretchr/testify/suite" |
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.
nit: I think goimports
should split these apart automatically right?
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 thinkkk so. This was also pre-our formatting convo, so I'll push up some changes wrt that soon!
pinecone/client.go
Outdated
} | ||
} | ||
|
||
response, err := control.ParseConfigureIndexResponse(req) // TODO: need this? |
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 don't think we should be using the internals, I don't think we're doing that anywhere else. I'd maybe look at how we're handling things in something like DescribeIndex
. Could you juse use the decodeIndex
function instead?
response, err := control.ParseConfigureIndexResponse(req) // TODO: need this? | |
res, err := c.restClient.ConfigureIndex(ctx, name, request) | |
if err != nil { | |
log.Fatalf("Failed to configure index %s. Error: %v", name, err) | |
} | |
defer res.Body.Close() | |
if req.StatusCode != http.StatusOK { | |
return nil, handleErrorResponseBody(req, "failed to configure index: ") | |
} | |
return decodeIndex(res.Body) |
Ultimately this just returns an IndexModel
, there's not really anything else in ConfigureIndexResponse
, so you'd need to update the return type and maybe doc string here.
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.
Sure yeah good call, I'll do that!
|
||
defer res.Body.Close() | ||
|
||
if res.StatusCode != http.StatusOK { |
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.
Changed this from our usualhttp.StatusCreated
to http.StatusOK
, since configuring an index doesn't give status created or whatnot. Just fyi!
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 good, nice work. Thanks for iterating as well! 🚢
Problem
To have parity with our other clients, we need to include a
ConfigureIndex
method on the Pinecone client.Asana ticket.
Solution
Add a
ConfigureIndex
method. Users can pass a pod size, a # of replicas, or both.Type of Change
Test Plan
New integration tests confirm functionality + pass in CI.