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

Add ConfigureIndex method #34

Merged
merged 20 commits into from
Jul 12, 2024
Merged

Add ConfigureIndex method #34

merged 20 commits into from
Jul 12, 2024

Conversation

aulorbe
Copy link
Contributor

@aulorbe aulorbe commented Jul 1, 2024

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Infrastructure change (CI configs, etc)
  • Non-code change (docs, etc)
  • None of the above: (explain here)

Test Plan

New integration tests confirm functionality + pass in CI.

pinecone/client_test.go Outdated Show resolved Hide resolved
@aulorbe aulorbe requested a review from austin-denoble July 8, 2024 22:40
@aulorbe aulorbe marked this pull request as ready for review July 8, 2024 22:40
Copy link
Contributor

@austin-denoble austin-denoble left a 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.

Comment on lines 294 to 312
// 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)
// }
//
Copy link
Contributor

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.

Copy link
Contributor Author

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay done :)

@@ -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.
Copy link
Contributor

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.

//
// 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,
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, sweet!

//
// [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,
Copy link
Contributor

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.

Copy link
Contributor Author

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)

Comment on lines 357 to 360
err := handleErrorResponseBody(req, "failed to configure index: ")
if err != nil {
return nil, err
}
Copy link
Contributor

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:

Suggested change
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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oo nice!

},
}

req, err := c.restClient.ConfigureIndex(ctx, name, request)
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!

return nil, err
}

defer req.Body.Close()
Copy link
Contributor

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()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay will do!

Comment on lines 6 to 17
"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"
Copy link
Contributor

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?

Copy link
Contributor Author

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!

}
}

response, err := control.ParseConfigureIndexResponse(req) // TODO: need this?
Copy link
Contributor

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?

Suggested change
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.

Copy link
Contributor Author

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!

@aulorbe aulorbe requested a review from austin-denoble July 12, 2024 15:52

defer res.Body.Close()

if res.StatusCode != http.StatusOK {
Copy link
Contributor Author

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!

Copy link
Contributor

@austin-denoble austin-denoble left a 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! 🚢

@aulorbe aulorbe merged commit cef7a46 into main Jul 12, 2024
3 checks passed
@aulorbe aulorbe deleted the Audrey/configure-index branch July 12, 2024 17:01
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.

2 participants