-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
572: Support experimental manager r=Ja7ad a=A7bari # Pull Request ## Related issue Fixes #571 ## What does this PR do? Introduce a new `ExperimentalFeatures` struct and methods to support the experimental features in the Meilisearch client. Users can enable or disable specific experimental features (vector store, logs route, and metrics). ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: polyfloyd <[email protected]> Co-authored-by: Javad <[email protected]> Co-authored-by: Ahbari-M <[email protected]> Co-authored-by: meili-bors[bot] <89034592+meili-bors[bot]@users.noreply.github.com> Co-authored-by: Javad Rajabzadeh <[email protected]>
- Loading branch information
Showing
6 changed files
with
500 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package meilisearch | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
) | ||
|
||
// Type for experimental features with additional client field | ||
type ExperimentalFeatures struct { | ||
client *client | ||
ExperimentalFeaturesBase | ||
} | ||
|
||
func (m *meilisearch) ExperimentalFeatures() *ExperimentalFeatures { | ||
return &ExperimentalFeatures{client: m.client} | ||
} | ||
|
||
func (ef *ExperimentalFeatures) SetVectorStore(vectorStore bool) *ExperimentalFeatures { | ||
ef.VectorStore = &vectorStore | ||
return ef | ||
} | ||
|
||
func (ef *ExperimentalFeatures) SetLogsRoute(logsRoute bool) *ExperimentalFeatures { | ||
ef.LogsRoute = &logsRoute | ||
return ef | ||
} | ||
|
||
func (ef *ExperimentalFeatures) SetMetrics(metrics bool) *ExperimentalFeatures { | ||
ef.Metrics = &metrics | ||
return ef | ||
} | ||
|
||
func (ef *ExperimentalFeatures) SetEditDocumentsByFunction(editDocumentsByFunction bool) *ExperimentalFeatures { | ||
ef.EditDocumentsByFunction = &editDocumentsByFunction | ||
return ef | ||
} | ||
|
||
func (ef *ExperimentalFeatures) SetContainsFilter(containsFilter bool) *ExperimentalFeatures { | ||
ef.ContainsFilter = &containsFilter | ||
return ef | ||
} | ||
|
||
func (ef *ExperimentalFeatures) Get() (*ExperimentalFeaturesResult, error) { | ||
return ef.GetWithContext(context.Background()) | ||
} | ||
|
||
func (ef *ExperimentalFeatures) GetWithContext(ctx context.Context) (*ExperimentalFeaturesResult, error) { | ||
resp := new(ExperimentalFeaturesResult) | ||
req := &internalRequest{ | ||
endpoint: "/experimental-features", | ||
method: http.MethodGet, | ||
withRequest: nil, | ||
withResponse: &resp, | ||
withQueryParams: map[string]string{}, | ||
acceptedStatusCodes: []int{http.StatusOK}, | ||
functionName: "GetExperimentalFeatures", | ||
} | ||
|
||
if err := ef.client.executeRequest(ctx, req); err != nil { | ||
return nil, err | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
func (ef *ExperimentalFeatures) Update() (*ExperimentalFeaturesResult, error) { | ||
return ef.UpdateWithContext(context.Background()) | ||
} | ||
|
||
func (ef *ExperimentalFeatures) UpdateWithContext(ctx context.Context) (*ExperimentalFeaturesResult, error) { | ||
request := ExperimentalFeaturesBase{ | ||
VectorStore: ef.VectorStore, | ||
LogsRoute: ef.LogsRoute, | ||
Metrics: ef.Metrics, | ||
EditDocumentsByFunction: ef.EditDocumentsByFunction, | ||
ContainsFilter: ef.ContainsFilter, | ||
} | ||
resp := new(ExperimentalFeaturesResult) | ||
req := &internalRequest{ | ||
endpoint: "/experimental-features", | ||
method: http.MethodPatch, | ||
contentType: contentTypeJSON, | ||
withRequest: request, | ||
withResponse: resp, | ||
withQueryParams: nil, | ||
acceptedStatusCodes: []int{http.StatusOK}, | ||
functionName: "UpdateExperimentalFeatures", | ||
} | ||
if err := ef.client.executeRequest(ctx, req); err != nil { | ||
return nil, err | ||
} | ||
return resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package meilisearch | ||
|
||
import ( | ||
"crypto/tls" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGet_ExperimentalFeatures(t *testing.T) { | ||
sv := setup(t, "") | ||
customSv := setup(t, "", WithCustomClientWithTLS(&tls.Config{ | ||
InsecureSkipVerify: true, | ||
})) | ||
|
||
tests := []struct { | ||
name string | ||
client ServiceManager | ||
}{ | ||
{ | ||
name: "TestGetStats", | ||
client: sv, | ||
}, | ||
{ | ||
name: "TestGetStatsWithCustomClient", | ||
client: customSv, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ef := tt.client.ExperimentalFeatures() | ||
gotResp, err := ef.Get() | ||
require.NoError(t, err) | ||
require.NotNil(t, gotResp, "ExperimentalFeatures.Get() should not return nil value") | ||
}) | ||
} | ||
} | ||
|
||
func TestUpdate_ExperimentalFeatures(t *testing.T) { | ||
sv := setup(t, "") | ||
customSv := setup(t, "", WithCustomClientWithTLS(&tls.Config{ | ||
InsecureSkipVerify: true, | ||
})) | ||
|
||
tests := []struct { | ||
name string | ||
client ServiceManager | ||
}{ | ||
{ | ||
name: "TestUpdateStats", | ||
client: sv, | ||
}, | ||
{ | ||
name: "TestUpdateStatsWithCustomClient", | ||
client: customSv, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ef := tt.client.ExperimentalFeatures() | ||
ef.SetVectorStore(true) | ||
ef.SetLogsRoute(true) | ||
ef.SetMetrics(true) | ||
ef.SetEditDocumentsByFunction(true) | ||
ef.SetContainsFilter(true) | ||
gotResp, err := ef.Update() | ||
require.NoError(t, err) | ||
require.Equal(t, true, gotResp.VectorStore, "ExperimentalFeatures.Update() should return vectorStore as true") | ||
require.Equal(t, true, gotResp.LogsRoute, "ExperimentalFeatures.Update() should return logsRoute as true") | ||
require.Equal(t, true, gotResp.Metrics, "ExperimentalFeatures.Update() should return metrics as true") | ||
require.Equal(t, true, gotResp.EditDocumentsByFunction, "ExperimentalFeatures.Update() should return editDocumentsByFunction as true") | ||
require.Equal(t, true, gotResp.ContainsFilter, "ExperimentalFeatures.Update() should return containsFilter as true") | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.