diff --git a/.github/workflows/integration-test-unreleased.yml b/.github/workflows/integration-test-unreleased.yml index 04735fc..c468cbf 100644 --- a/.github/workflows/integration-test-unreleased.yml +++ b/.github/workflows/integration-test-unreleased.yml @@ -20,12 +20,12 @@ jobs: java: [ 11 ] steps: - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@v1 + uses: actions/setup-java@v4 with: java-version: ${{ matrix.java }} - name: Checkout OpenSearch - uses: actions/checkout@v3 + uses: actions/checkout@v6 with: repository: opensearch-project/opensearch ref: ${{ env.OPENSEARCH_VERSION }} @@ -43,12 +43,12 @@ jobs: sleep 90 - name: Set up Go ubuntu-latest - uses: actions/setup-go@v2 + uses: actions/setup-go@v6 with: - go-version: 1.18.2 + go-version: '1.26' - name: Check out source code - uses: actions/checkout@v3 + uses: actions/checkout@v6 - name: Run Integration Tests env: diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index e0e02ca..c3efc94 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -14,36 +14,21 @@ jobs: strategy: matrix: entry: - - { opensearch_version: 1.0.1 } - - { opensearch_version: 1.1.0 } - - { opensearch_version: 1.2.4 } - - { opensearch_version: 1.3.8 } - - { opensearch_version: 2.0.1 } - - { opensearch_version: 2.1.0 } - - { opensearch_version: 2.2.1 } - - { opensearch_version: 2.3.0 } - - { opensearch_version: 2.4.1 } - - { opensearch_version: 2.5.0 } - - { opensearch_version: 2.6.0 } - - { opensearch_version: 2.7.0 } - - { opensearch_version: 2.8.0 } - - { opensearch_version: 2.9.0 } - - { opensearch_version: 2.10.0 } - - { opensearch_version: 2.11.0 } - go-version: [ 1.18.2 ] + - { opensearch_version: 2.19.4 } + - { opensearch_version: 3.6.0 } runs-on: ubuntu-latest steps: - - name: Set up Go ${{ matrix.go-version }} - uses: actions/setup-go@v2 + - name: Set up Go + uses: actions/setup-go@v6 with: - go-version: ${{ matrix.go-version }} + go-version: '1.26' - name: Check out source code - uses: actions/checkout@v3 + uses: actions/checkout@v6 - name: Run Docker Image env: - OPENSEARCH_VERSION: ${{ matrix.opensearch-version }} + OPENSEARCH_VERSION: ${{ matrix.entry.opensearch_version }} run: | make docker.start.components sleep 60 diff --git a/.github/workflows/test-build-workflow.yml b/.github/workflows/test-build-workflow.yml index e661d8c..05e2600 100644 --- a/.github/workflows/test-build-workflow.yml +++ b/.github/workflows/test-build-workflow.yml @@ -14,15 +14,15 @@ jobs: runs-on: ubuntu-latest steps: - name: Set up Go ubuntu-latest - uses: actions/setup-go@v2 + uses: actions/setup-go@v6 with: - go-version: 1.18.2 + go-version: '1.26' - name: Install goimports run: go install golang.org/x/tools/cmd/goimports@latest - name: Check out source code - uses: actions/checkout@v3 + uses: actions/checkout@v6 - name: Format check run: goimports -w . @@ -30,7 +30,7 @@ jobs: - name: Check for modified files id: git-check run: | - echo ::set-output name=modified::$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi) + echo "modified=$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)" >> "$GITHUB_OUTPUT" - name: Display unformated changes and fail if any if: steps.git-check.outputs.modified == 'true' @@ -40,10 +40,9 @@ jobs: exit 1 - name: Lint check - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v9 with: - # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.50.1 + version: v2.11 - name: Run Unit Tests env: @@ -53,7 +52,7 @@ jobs: go tool cover -func=coverage.out - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v5 with: token: ${{secrets.CODECOV_TOKEN}} file: coverage.out @@ -65,18 +64,17 @@ jobs: strategy: matrix: platform: [ ubuntu-latest, macos-latest, windows-latest ] - go-version: [ 1.18.2 ] runs-on: ${{ matrix.platform }} steps: - name: Set up Go ${{ matrix.platform }} - uses: actions/setup-go@v2 + uses: actions/setup-go@v6 with: - go-version: ${{ matrix.go-version }} + go-version: '1.26' - name: Check out source code - uses: actions/checkout@v3 + uses: actions/checkout@v6 - - name: Build for ${{ matrix.platform }}-${{ matrix.go-version }} + - name: Build for ${{ matrix.platform }} env: GOPROXY: "https://proxy.golang.org" - run: go build . \ No newline at end of file + run: go build . diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index ccefc43..a3a7aa7 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -3,8 +3,9 @@ The below matrix shows the compatibility of the [`opensearch-cli`](https://github.com/opensearch-project/opensearch-cli/releases) with versions of [`OpenSearch`](https://opensearch.org/downloads.html#opensearch). -| OpenSearch CLI | OpenSearch | -| ------------- | --------------- | -| 1.0.0 | 1.0.0 | -| 1.1.0 | 1.x | -| 1.1.0 | 2.x | \ No newline at end of file +| OpenSearch CLI | OpenSearch | +|----------------|------------| +| 1.0.0 | 1.0.0 | +| 1.1.0 | 1.x, 2.x | +| 1.2.0 | 2.x | +| 1.3.0 | 2.x, 3.x | diff --git a/Makefile b/Makefile index 80cc61e..b1de396 100644 --- a/Makefile +++ b/Makefile @@ -5,15 +5,15 @@ INTEGRATION_TEST_PATH=./it/... ENV_LOCAL_TEST=\ OPENSEARCH_ENDPOINT="https://localhost:9200" \ OPENSEARCH_USER="admin" \ - OPENSEARCH_PASSWORD="admin" + OPENSEARCH_PASSWORD="MyStr0ngP@ssw0rd!" # this command will start a docker components that we set in docker-compose.yml docker.start.components: - docker-compose up -d; + docker compose up -d; # shutting down docker components docker.stop: - docker-compose down; + docker compose down; # clean up docker docker.clean: diff --git a/client/http.go b/client/http.go index 219c373..b3219b7 100644 --- a/client/http.go +++ b/client/http.go @@ -21,12 +21,12 @@ import ( const defaultTimeout = 10 -//Client is an Abstraction for actual client +// Client is an Abstraction for actual client type Client struct { HTTPClient *retryablehttp.Client } -//NewDefaultClient return new instance of client +// NewDefaultClient return new instance of client func NewDefaultClient(tripper http.RoundTripper) (*Client, error) { client := retryablehttp.NewClient() @@ -38,7 +38,7 @@ func NewDefaultClient(tripper http.RoundTripper) (*Client, error) { }, nil } -//New takes transport and uses accordingly +// New takes transport and uses accordingly func New(tripper http.RoundTripper) (*Client, error) { if tripper == nil { tripper = &http.Transport{ diff --git a/client/mocks/mock_http.go b/client/mocks/mock_http.go index 4142af9..2bfe1f7 100644 --- a/client/mocks/mock_http.go +++ b/client/mocks/mock_http.go @@ -26,7 +26,7 @@ func (f RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) { return f(req), nil } -//NewTestClient returns *http.Client with Transport replaced to avoid making real calls +// NewTestClient returns *http.Client with Transport replaced to avoid making real calls func NewTestClient(fn RoundTripFunc) *client.Client { c, err := client.New(fn) if err != nil { diff --git a/commands/ad.go b/commands/ad.go index 2281298..79097e1 100644 --- a/commands/ad.go +++ b/commands/ad.go @@ -27,7 +27,7 @@ const ( adCommandName = "ad" ) -//adCommand is base command for Anomaly Detection plugin. +// adCommand is base command for Anomaly Detection plugin. var adCommand = &cobra.Command{ Use: adCommandName, Short: "Manage the Anomaly Detection plugin", @@ -39,13 +39,13 @@ func init() { GetRoot().AddCommand(adCommand) } -//GetADCommand returns AD base command, since this will be needed for subcommands -//to add as parent later +// GetADCommand returns AD base command, since this will be needed for subcommands +// to add as parent later func GetADCommand() *cobra.Command { return adCommand } -//GetADHandler returns handler by wiring the dependency manually +// GetADHandler returns handler by wiring the dependency manually func GetADHandler() (*handler.Handler, error) { c, err := client.New(nil) if err != nil { diff --git a/commands/ad_create.go b/commands/ad_create.go index 7ab6d29..91f4297 100644 --- a/commands/ad_create.go +++ b/commands/ad_create.go @@ -23,8 +23,8 @@ const ( generate = "generate-template" ) -//createCmd creates detectors with configuration from input file, if interactive mode is on, -//this command will prompt for confirmation on number of detectors will be created on executions. +// createCmd creates detectors with configuration from input file, if interactive mode is on, +// this command will prompt for confirmation on number of detectors will be created on executions. var createCmd = &cobra.Command{ Use: createDetectorsCommandName + " json-file-path ...", Short: "Create detectors based on JSON files", @@ -46,7 +46,7 @@ var createCmd = &cobra.Command{ }, } -//generateTemplate prints sample detector configuration +// generateTemplate prints sample detector configuration func generateTemplate() { detector, _ := handler.GenerateAnomalyDetector() fmt.Println(string(detector)) @@ -59,7 +59,7 @@ func init() { } -//createDetectors create detectors based on configurations from fileNames +// createDetectors create detectors based on configurations from fileNames func createDetectors(fileNames []string) error { commandHandler, err := GetADHandler() diff --git a/commands/ad_delete.go b/commands/ad_delete.go index 253e2e7..ed12fe7 100644 --- a/commands/ad_delete.go +++ b/commands/ad_delete.go @@ -23,8 +23,8 @@ const ( detectorForceDeletionFlagName = "force" ) -//deleteDetectorsCmd deletes detectors based on id, name or name regex pattern. -//default input is name pattern, one can change this format to be id by passing --id flag +// deleteDetectorsCmd deletes detectors based on id, name or name regex pattern. +// default input is name pattern, one can change this format to be id by passing --id flag var deleteDetectorsCmd = &cobra.Command{ Use: deleteDetectorsCommandName + " detector_name ..." + " [flags] ", Short: "Delete detectors based on a list of IDs, names, or name regex patterns", @@ -51,7 +51,7 @@ func init() { deleteDetectorsCmd.Flags().BoolP("help", "h", false, "Help for "+deleteDetectorsCommandName) } -//deleteDetectors deletes detectors with force by calling delete method provided +// deleteDetectors deletes detectors with force by calling delete method provided func deleteDetectors(detectors []string, force bool, f func(*handler.Handler, string, bool) error) error { commandHandler, err := GetADHandler() if err != nil { diff --git a/commands/ad_get.go b/commands/ad_get.go index d7b7037..2176141 100644 --- a/commands/ad_get.go +++ b/commands/ad_get.go @@ -27,8 +27,8 @@ const ( getDetectorIDFlagName = "id" ) -//getDetectorsCmd prints detectors configuration based on id, name or name regex pattern. -//default input is name pattern, one can change this format to be id by passing --id flag +// getDetectorsCmd prints detectors configuration based on id, name or name regex pattern. +// default input is name pattern, one can change this format to be id by passing --id flag var getDetectorsCmd = &cobra.Command{ Use: getDetectorsCommandName + " detector_name ..." + " [flags] ", Short: "Get detectors based on a list of IDs, names, or name regex patterns", @@ -45,7 +45,7 @@ var getDetectorsCmd = &cobra.Command{ type Display func(*cobra.Command, *entity.DetectorOutput) error -//printDetectors print detectors +// printDetectors print detectors func printDetectors(display Display, cmd *cobra.Command, detectors []string) error { idStatus, _ := cmd.Flags().GetBool(getDetectorIDFlagName) commandHandler, err := GetADHandler() @@ -64,7 +64,7 @@ func printDetectors(display Display, cmd *cobra.Command, detectors []string) err return fprint(cmd, display, results) } -//getDetectors fetch detector from controller +// getDetectors fetch detector from controller func getDetectors( commandHandler *ad.Handler, args []string, get func(*ad.Handler, string) ( []*entity.DetectorOutput, error)) ([]*entity.DetectorOutput, error) { @@ -79,7 +79,7 @@ func getDetectors( return results, nil } -//getDetectorsByID gets detector output based on ID as argument +// getDetectorsByID gets detector output based on ID as argument func getDetectorsByID(commandHandler *ad.Handler, ID string) ([]*entity.DetectorOutput, error) { output, err := ad.GetAnomalyDetectorByID(commandHandler, ID) @@ -89,7 +89,7 @@ func getDetectorsByID(commandHandler *ad.Handler, ID string) ([]*entity.Detector return []*entity.DetectorOutput{output}, nil } -//fprint displays the list of detectors. +// fprint displays the list of detectors. func fprint(cmd *cobra.Command, display Display, results []*entity.DetectorOutput) error { if results == nil { return nil @@ -102,8 +102,8 @@ func fprint(cmd *cobra.Command, display Display, results []*entity.DetectorOutpu return nil } -//FPrint prints detector configuration on writer -//Since this is json format, use indent function to pretty print before printing on writer +// FPrint prints detector configuration on writer +// Since this is json format, use indent function to pretty print before printing on writer func FPrint(writer io.Writer, d *entity.DetectorOutput) error { formattedOutput, err := json.MarshalIndent(d, "", " ") if err != nil { @@ -113,7 +113,7 @@ func FPrint(writer io.Writer, d *entity.DetectorOutput) error { return err } -//Println prints detector configuration on stdout +// Println prints detector configuration on stdout func Println(cmd *cobra.Command, d *entity.DetectorOutput) error { return FPrint(os.Stdout, d) } diff --git a/commands/ad_start_stop.go b/commands/ad_start_stop.go index 56ab92f..f9f77ee 100644 --- a/commands/ad_start_stop.go +++ b/commands/ad_start_stop.go @@ -24,8 +24,8 @@ const ( idFlagName = "id" ) -//startDetectorsCmd start detectors based on id, name or name regex pattern. -//default input is name pattern, one can change this format to be id by passing --id flag +// startDetectorsCmd start detectors based on id, name or name regex pattern. +// default input is name pattern, one can change this format to be id by passing --id flag var startDetectorsCmd = &cobra.Command{ Use: startDetectorsCommandName + " detector_name ..." + " [flags] ", Short: "Start detectors based on a list of IDs, names, or name regex patterns", @@ -44,8 +44,8 @@ var startDetectorsCmd = &cobra.Command{ }, } -//stopDetectorsCmd stops detectors based on id and name pattern. -//default input is name pattern, one can change this format to be id by passing --id flag +// stopDetectorsCmd stops detectors based on id and name pattern. +// default input is name pattern, one can change this format to be id by passing --id flag var stopDetectorsCmd = &cobra.Command{ Use: stopDetectorsCommandName + " detector_name ..." + " [flags] ", Short: "Stop detectors based on a list of IDs, names, or name regex patterns", diff --git a/commands/ad_update.go b/commands/ad_update.go index 43dbf76..fbdbdcf 100644 --- a/commands/ad_update.go +++ b/commands/ad_update.go @@ -23,7 +23,7 @@ const ( startFlagName = "start" ) -//updateDetectorsCmd updates detectors with configuration from input file +// updateDetectorsCmd updates detectors with configuration from input file var updateDetectorsCmd = &cobra.Command{ Use: updateDetectorsCommandName + " json-file-path ... [flags]", Short: "Update detectors based on JSON files", diff --git a/commands/completion.go b/commands/completion.go index 9f43c57..b868f6d 100644 --- a/commands/completion.go +++ b/commands/completion.go @@ -72,7 +72,7 @@ var completionCmd = &cobra.Command{ Long: longText, DisableFlagsInUseLine: true, ValidArgs: []string{BashShell, ZshShell, FishShell, PowerShell}, - Args: cobra.ExactValidArgs(1), + Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), Run: func(cmd *cobra.Command, args []string) { var err error switch args[0] { diff --git a/commands/knn.go b/commands/knn.go index 1834c08..ff0343f 100644 --- a/commands/knn.go +++ b/commands/knn.go @@ -29,14 +29,14 @@ const ( knnStatsNamesFlagName = "stat-names" ) -//knnCommand is base command for k-NN plugin. +// knnCommand is base command for k-NN plugin. var knnCommand = &cobra.Command{ Use: knnCommandName, Short: "Manage the k-NN plugin", Long: "Use the k-NN commands to perform operations like stats, warmup.", } -//knnStatsCommandName provide stats command for k-NN plugin. +// knnStatsCommandName provide stats command for k-NN plugin. var knnStatsCommand = &cobra.Command{ Use: knnStatsCommandName, Short: "Display current status of the k-NN Plugin", @@ -62,7 +62,7 @@ var knnStatsCommand = &cobra.Command{ }, } -//knnWarmupCommand warmups shards +// knnWarmupCommand warmups shards var knnWarmupCommand = &cobra.Command{ Use: knnWarmupCommandName + " index ..." + " [flags] ", Args: cobra.MinimumNArgs(1), @@ -129,7 +129,7 @@ func warmupIndices(h *handler.Handler, index []string) error { return nil } -//GetKNNHandler returns handler by wiring the dependency manually +// GetKNNHandler returns handler by wiring the dependency manually func GetKNNHandler() (*handler.Handler, error) { c, err := client.New(nil) if err != nil { diff --git a/commands/profile.go b/commands/profile.go index 9f506bc..64b633b 100644 --- a/commands/profile.go +++ b/commands/profile.go @@ -44,7 +44,7 @@ const ( FlagProfileHelp = "help" ) -//GetProfileController gets controller based on config file +// GetProfileController gets controller based on config file func GetProfileController() (profile.Controller, error) { cfgFile, err := GetRoot().Flags().GetString(flagConfig) if err != nil { @@ -53,7 +53,7 @@ func GetProfileController() (profile.Controller, error) { return getProfileController(cfgFile) } -//profileCommand is main command for profile operations like list, create and delete +// profileCommand is main command for profile operations like list, create and delete var profileCommand = &cobra.Command{ Use: ProfileCommandName + " sub-command", Short: "Manage a collection of settings and credentials that you can apply to an opensearch-cli command", @@ -64,7 +64,7 @@ var profileCommand = &cobra.Command{ "variable (`" + environment.OPENSEARCH_PROFILE + "`) or create a profile named `default`.", } -//createProfileCmd creates profile interactively by prompting for name (distinct), user, endpoint, password. +// createProfileCmd creates profile interactively by prompting for name (distinct), user, endpoint, password. var createProfileCmd = &cobra.Command{ Use: CreateNewProfileCommandName, Short: "Create profile", @@ -119,7 +119,7 @@ func getProfileName(cmd *cobra.Command, controller profile.Controller) (string, return name, nil } -//deleteProfilesCmd deletes profiles by names +// deleteProfilesCmd deletes profiles by names var deleteProfilesCmd = &cobra.Command{ Use: DeleteProfilesCommandName + " profile_name ...", Short: "Delete profiles by names", @@ -134,7 +134,7 @@ var deleteProfilesCmd = &cobra.Command{ }, } -//listProfileCmd lists profiles by names +// listProfileCmd lists profiles by names var listProfileCmd = &cobra.Command{ Use: ListProfilesCommandName, Short: "List profiles from the config file", @@ -147,7 +147,7 @@ var listProfileCmd = &cobra.Command{ }, } -//deleteProfiles deletes profiles based on names +// deleteProfiles deletes profiles based on names func deleteProfiles(profiles []string) error { profileController, err := GetProfileController() if err != nil { @@ -191,7 +191,7 @@ func init() { GetRoot().AddCommand(profileCommand) } -//getProfileController gets profile controller by wiring config controller with config file +// getProfileController gets profile controller by wiring config controller with config file func getProfileController(cfgFlagValue string) (profile.Controller, error) { configFilePath, err := GetConfigFilePath(cfgFlagValue) if err != nil { @@ -296,7 +296,7 @@ func getUserInputAsMaskedText(isValid func(string) bool) string { return value } -//listProfiles list profiles from the config file +// listProfiles list profiles from the config file func listProfiles(cmd *cobra.Command) error { ok, err := cmd.Flags().GetBool(FlagProfileVerbose) if err != nil { @@ -339,7 +339,7 @@ func displayCompleteProfiles(p profile.Controller) (err error) { return } -//displayProfileNames lists only profile names +// displayProfileNames lists only profile names func displayProfileNames(p profile.Controller) (err error) { var names []string diff --git a/commands/profile_test.go b/commands/profile_test.go index d8144a8..7cf43c2 100644 --- a/commands/profile_test.go +++ b/commands/profile_test.go @@ -19,7 +19,7 @@ import ( "os" "testing" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" diff --git a/commands/root.go b/commands/root.go index 0c662f4..be032b9 100644 --- a/commands/root.go +++ b/commands/root.go @@ -28,7 +28,7 @@ const ( flagProfileName = "profile" ConfigEnvVarName = "OPENSEARCH_CLI_CONFIG" RootCommandName = "opensearch-cli" - version = "1.2.0" + version = "1.3.0" ) func buildVersionString() string { @@ -94,8 +94,8 @@ func GetConfigFilePath(configFlagValue string) (string, error) { return GetDefaultConfigFilePath(), nil } -//isExists check if given path exists or not -//if path is just a name, it will check in current directory +// isExists check if given path exists or not +// if path is just a name, it will check in current directory func isExists(path string) bool { if _, err := os.Stat(path); os.IsNotExist(err) { return false diff --git a/commands/root_test.go b/commands/root_test.go index 9ea750f..7e6a3e8 100644 --- a/commands/root_test.go +++ b/commands/root_test.go @@ -58,7 +58,7 @@ func TestVersionString(t *testing.T) { root.SetArgs([]string{"--version"}) cmd, err := root.ExecuteC() assert.NoError(t, err) - expected := "1.2.0 " + runtime.GOOS + "/" + runtime.GOARCH + expected := "1.3.0 " + runtime.GOOS + "/" + runtime.GOARCH assert.EqualValues(t, expected, cmd.Version) }) } @@ -73,14 +73,14 @@ func createTempConfigFile(testFilePath string) (*os.File, error) { return nil, err } if _, err := tmpfile.Write(content); err != nil { - os.Remove(tmpfile.Name()) // clean up + _ = os.Remove(tmpfile.Name()) // clean up return nil, err } if runtime.GOOS == "windows" { return tmpfile, nil } if err := tmpfile.Chmod(0600); err != nil { - os.Remove(tmpfile.Name()) // clean up + _ = os.Remove(tmpfile.Name()) // clean up return nil, err } return tmpfile, nil @@ -101,7 +101,7 @@ func TestGetProfile(t *testing.T) { assert.NoError(t, err) expectedProfile := entity.Profile{Name: "default", Endpoint: "http://localhost:9200", UserName: "default", Password: "admin"} assert.EqualValues(t, expectedProfile, *actual) - os.Remove(profileFile.Name()) + _ = os.Remove(profileFile.Name()) }) t.Run("test get profile", func(t *testing.T) { root := GetRoot() diff --git a/controller/ad/ad.go b/controller/ad/ad.go index 8dfcb39..ced17e5 100644 --- a/controller/ad/ad.go +++ b/controller/ad/ad.go @@ -28,9 +28,9 @@ import ( "github.com/cheggaaa/pb/v3" ) -//go:generate go run -mod=mod github.com/golang/mock/mockgen -destination=mocks/mock_ad.go -package=mocks . Controller +//go:generate go run -mod=mod go.uber.org/mock/mockgen -destination=mocks/mock_ad.go -package=mocks . Controller -//Controller is an interface for the AD plugin controllers +// Controller is an interface for the AD plugin controllers type Controller interface { StartDetector(context.Context, string) error StopDetector(context.Context, string) error @@ -52,7 +52,7 @@ type controller struct { openSearch platform.Controller } -//New returns new Controller instance +// New returns new Controller instance func New(reader io.Reader, openSearch platform.Controller, gateway ad.Gateway) Controller { return &controller{ reader, @@ -77,7 +77,7 @@ func validateCreateRequest(r entity.CreateDetectorRequest) error { return nil } -//StartDetector start detector based on DetectorID +// StartDetector start detector based on DetectorID func (c controller) StartDetector(ctx context.Context, ID string) error { if len(ID) < 1 { return fmt.Errorf("detector Id: %s cannot be empty", ID) @@ -89,7 +89,7 @@ func (c controller) StartDetector(ctx context.Context, ID string) error { return nil } -//StopDetector stops detector based on DetectorID +// StopDetector stops detector based on DetectorID func (c controller) StopDetector(ctx context.Context, ID string) error { if len(ID) < 1 { return fmt.Errorf("detector Id: %s cannot be empty", ID) @@ -128,7 +128,7 @@ func (c controller) askForConfirmation(message *string) bool { } } -//DeleteDetector deletes detector based on DetectorID, if force is enabled, it stops before deletes +// DeleteDetector deletes detector based on DetectorID, if force is enabled, it stops before deletes func (c controller) DeleteDetector(ctx context.Context, id string, interactive bool, force bool) error { if len(id) < 1 { return fmt.Errorf("detector Id cannot be empty") @@ -164,7 +164,7 @@ func (c controller) DeleteDetector(ctx context.Context, id string, interactive b return nil } -//GetDetector fetch detector based on DetectorID +// GetDetector fetch detector based on DetectorID func (c controller) GetDetector(ctx context.Context, ID string) (*entity.DetectorOutput, error) { if len(ID) < 1 { return nil, fmt.Errorf("detector Id: %s cannot be empty", ID) @@ -194,7 +194,7 @@ func processEntityError(err error) error { return err } -//CreateAnomalyDetector creates detector based on user request +// CreateAnomalyDetector creates detector based on user request func (c controller) CreateAnomalyDetector(ctx context.Context, r entity.CreateDetectorRequest) (*string, error) { if err := validateCreateRequest(r); err != nil { @@ -256,7 +256,7 @@ func getFilterValues(ctx context.Context, request entity.CreateDetectorRequest, return filterValues, nil } -//createProgressBar creates progress bar with suffix as counter and number of action completed, prefix as percentage +// createProgressBar creates progress bar with suffix as counter and number of action completed, prefix as percentage func createProgressBar(total int) *pb.ProgressBar { template := `{{string . "prefix"}}{{percent . }} {{bar . "[" "=" ">" "_" "]" }} {{counters . }}{{string . "suffix"}}` bar := pb.New(total) @@ -290,7 +290,7 @@ func buildCompoundQuery(field string, value interface{}, userFilter json.RawMess return marshal } -//CreateMultiEntityAnomalyDetector creates multiple entity detector based on partition_by field +// CreateMultiEntityAnomalyDetector creates multiple entity detector based on partition_by field func (c controller) CreateMultiEntityAnomalyDetector(ctx context.Context, request entity.CreateDetectorRequest, interactive bool, display bool) ([]string, error) { if request.PartitionField == nil || len(*request.PartitionField) < 1 { result, err := c.CreateAnomalyDetector(ctx, request) @@ -355,7 +355,7 @@ func (c controller) CreateMultiEntityAnomalyDetector(ctx context.Context, reques return detectors, nil } -//SearchDetectorByName searches detector based on name +// SearchDetectorByName searches detector based on name func (c controller) SearchDetectorByName(ctx context.Context, name string) ([]entity.Detector, error) { if len(name) < 1 { return nil, fmt.Errorf("detector name cannot be empty") @@ -378,7 +378,7 @@ func (c controller) SearchDetectorByName(ctx context.Context, name string) ([]en return detectors, nil } -//getDetectors expand pattern to fetch list of matched detectors and return detectors accepted by user +// getDetectors expand pattern to fetch list of matched detectors and return detectors accepted by user // for process func (c controller) getDetectors(ctx context.Context, method string, pattern string, warning bool) ([]entity.Detector, error) { if len(pattern) < 1 { @@ -448,19 +448,19 @@ func (c controller) processDetectorByAction(ctx context.Context, pattern string, return nil } -//StartDetectorByName starts detector based on name pattern. It first calls SearchDetectorByName and then +// StartDetectorByName starts detector based on name pattern. It first calls SearchDetectorByName and then // gets lists of detectorId and call StartDetector to start individual detectors func (c controller) StartDetectorByName(ctx context.Context, pattern string, display bool) error { return c.processDetectorByAction(ctx, pattern, "start", c.StartDetector, display, true) } -//StopDetectorByName stops detector based on name pattern. It first calls SearchDetectorByName and then +// StopDetectorByName stops detector based on name pattern. It first calls SearchDetectorByName and then // gets lists of detectorId and call StopDetector to stop individual detectors func (c controller) StopDetectorByName(ctx context.Context, pattern string, display bool) error { return c.processDetectorByAction(ctx, pattern, "stop", c.StopDetector, display, true) } -//DeleteDetectorByName deletes detector based on name pattern. It first calls SearchDetectorByName and then +// DeleteDetectorByName deletes detector based on name pattern. It first calls SearchDetectorByName and then // gets lists of detectorId and call DeleteDetector to delete individual detectors func (c controller) DeleteDetectorByName(ctx context.Context, name string, force bool, display bool) error { matchedDetectors, err := c.getDetectors(ctx, "delete", name, true) @@ -497,7 +497,7 @@ func (c controller) DeleteDetectorByName(ctx context.Context, name string, force return nil } -//GetDetectorsByName get detector based on name pattern. It first calls SearchDetectorByName and then +// GetDetectorsByName get detector based on name pattern. It first calls SearchDetectorByName and then // gets lists of detectorId and call GetDetector to get individual detector configuration func (c controller) GetDetectorsByName(ctx context.Context, pattern string, display bool) ([]*entity.DetectorOutput, error) { matchedDetectors, err := c.getDetectors(ctx, "fetch", pattern, false) @@ -528,7 +528,7 @@ func (c controller) GetDetectorsByName(ctx context.Context, pattern string, disp return output, nil } -//UpdateDetector updates detector based on DetectorID, if force is enabled, it overrides without checking whether +// UpdateDetector updates detector based on DetectorID, if force is enabled, it overrides without checking whether // user downloaded latest version before updating it, if start is true, detector will be started after update func (c controller) UpdateDetector(ctx context.Context, input entity.UpdateDetectorUserInput, force bool, start bool) error { if len(input.ID) < 1 { diff --git a/controller/ad/ad_test.go b/controller/ad/ad_test.go index 6cd20cc..fb6cbfb 100644 --- a/controller/ad/ad_test.go +++ b/controller/ad/ad_test.go @@ -25,8 +25,8 @@ import ( "path/filepath" "testing" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" ) const mockDetectorID = "m4ccEnIBTXsGi3mvMt9p" diff --git a/controller/ad/mocks/mock_ad.go b/controller/ad/mocks/mock_ad.go index 5c3af15..f27df64 100644 --- a/controller/ad/mocks/mock_ad.go +++ b/controller/ad/mocks/mock_ad.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: opensearch-cli/controller/ad (interfaces: Controller) +// +// Generated by this command: +// +// mockgen -destination=mocks/mock_ad.go -package=mocks . Controller +// // Package mocks is a generated GoMock package. package mocks @@ -9,33 +14,34 @@ import ( ad "opensearch-cli/entity/ad" reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) -// MockController is a mock of Controller interface +// MockController is a mock of Controller interface. type MockController struct { ctrl *gomock.Controller recorder *MockControllerMockRecorder + isgomock struct{} } -// MockControllerMockRecorder is the mock recorder for MockController +// MockControllerMockRecorder is the mock recorder for MockController. type MockControllerMockRecorder struct { mock *MockController } -// NewMockController creates a new mock instance +// NewMockController creates a new mock instance. func NewMockController(ctrl *gomock.Controller) *MockController { mock := &MockController{ctrl: ctrl} mock.recorder = &MockControllerMockRecorder{mock} return mock } -// EXPECT returns an object that allows the caller to indicate expected use +// EXPECT returns an object that allows the caller to indicate expected use. func (m *MockController) EXPECT() *MockControllerMockRecorder { return m.recorder } -// CreateAnomalyDetector mocks base method +// CreateAnomalyDetector mocks base method. func (m *MockController) CreateAnomalyDetector(arg0 context.Context, arg1 ad.CreateDetectorRequest) (*string, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CreateAnomalyDetector", arg0, arg1) @@ -44,28 +50,28 @@ func (m *MockController) CreateAnomalyDetector(arg0 context.Context, arg1 ad.Cre return ret0, ret1 } -// CreateAnomalyDetector indicates an expected call of CreateAnomalyDetector -func (mr *MockControllerMockRecorder) CreateAnomalyDetector(arg0, arg1 interface{}) *gomock.Call { +// CreateAnomalyDetector indicates an expected call of CreateAnomalyDetector. +func (mr *MockControllerMockRecorder) CreateAnomalyDetector(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateAnomalyDetector", reflect.TypeOf((*MockController)(nil).CreateAnomalyDetector), arg0, arg1) } -// CreateMultiEntityAnomalyDetector mocks base method -func (m *MockController) CreateMultiEntityAnomalyDetector(arg0 context.Context, arg1 ad.CreateDetectorRequest, arg2, arg3 bool) ([]string, error) { +// CreateMultiEntityAnomalyDetector mocks base method. +func (m *MockController) CreateMultiEntityAnomalyDetector(ctx context.Context, request ad.CreateDetectorRequest, interactive, display bool) ([]string, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateMultiEntityAnomalyDetector", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "CreateMultiEntityAnomalyDetector", ctx, request, interactive, display) ret0, _ := ret[0].([]string) ret1, _ := ret[1].(error) return ret0, ret1 } -// CreateMultiEntityAnomalyDetector indicates an expected call of CreateMultiEntityAnomalyDetector -func (mr *MockControllerMockRecorder) CreateMultiEntityAnomalyDetector(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +// CreateMultiEntityAnomalyDetector indicates an expected call of CreateMultiEntityAnomalyDetector. +func (mr *MockControllerMockRecorder) CreateMultiEntityAnomalyDetector(ctx, request, interactive, display any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateMultiEntityAnomalyDetector", reflect.TypeOf((*MockController)(nil).CreateMultiEntityAnomalyDetector), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateMultiEntityAnomalyDetector", reflect.TypeOf((*MockController)(nil).CreateMultiEntityAnomalyDetector), ctx, request, interactive, display) } -// DeleteDetector mocks base method +// DeleteDetector mocks base method. func (m *MockController) DeleteDetector(arg0 context.Context, arg1 string, arg2, arg3 bool) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "DeleteDetector", arg0, arg1, arg2, arg3) @@ -73,13 +79,13 @@ func (m *MockController) DeleteDetector(arg0 context.Context, arg1 string, arg2, return ret0 } -// DeleteDetector indicates an expected call of DeleteDetector -func (mr *MockControllerMockRecorder) DeleteDetector(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +// DeleteDetector indicates an expected call of DeleteDetector. +func (mr *MockControllerMockRecorder) DeleteDetector(arg0, arg1, arg2, arg3 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteDetector", reflect.TypeOf((*MockController)(nil).DeleteDetector), arg0, arg1, arg2, arg3) } -// DeleteDetectorByName mocks base method +// DeleteDetectorByName mocks base method. func (m *MockController) DeleteDetectorByName(arg0 context.Context, arg1 string, arg2, arg3 bool) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "DeleteDetectorByName", arg0, arg1, arg2, arg3) @@ -87,13 +93,13 @@ func (m *MockController) DeleteDetectorByName(arg0 context.Context, arg1 string, return ret0 } -// DeleteDetectorByName indicates an expected call of DeleteDetectorByName -func (mr *MockControllerMockRecorder) DeleteDetectorByName(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +// DeleteDetectorByName indicates an expected call of DeleteDetectorByName. +func (mr *MockControllerMockRecorder) DeleteDetectorByName(arg0, arg1, arg2, arg3 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteDetectorByName", reflect.TypeOf((*MockController)(nil).DeleteDetectorByName), arg0, arg1, arg2, arg3) } -// GetDetector mocks base method +// GetDetector mocks base method. func (m *MockController) GetDetector(arg0 context.Context, arg1 string) (*ad.DetectorOutput, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetDetector", arg0, arg1) @@ -102,13 +108,13 @@ func (m *MockController) GetDetector(arg0 context.Context, arg1 string) (*ad.Det return ret0, ret1 } -// GetDetector indicates an expected call of GetDetector -func (mr *MockControllerMockRecorder) GetDetector(arg0, arg1 interface{}) *gomock.Call { +// GetDetector indicates an expected call of GetDetector. +func (mr *MockControllerMockRecorder) GetDetector(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDetector", reflect.TypeOf((*MockController)(nil).GetDetector), arg0, arg1) } -// GetDetectorsByName mocks base method +// GetDetectorsByName mocks base method. func (m *MockController) GetDetectorsByName(arg0 context.Context, arg1 string, arg2 bool) ([]*ad.DetectorOutput, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetDetectorsByName", arg0, arg1, arg2) @@ -117,13 +123,13 @@ func (m *MockController) GetDetectorsByName(arg0 context.Context, arg1 string, a return ret0, ret1 } -// GetDetectorsByName indicates an expected call of GetDetectorsByName -func (mr *MockControllerMockRecorder) GetDetectorsByName(arg0, arg1, arg2 interface{}) *gomock.Call { +// GetDetectorsByName indicates an expected call of GetDetectorsByName. +func (mr *MockControllerMockRecorder) GetDetectorsByName(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDetectorsByName", reflect.TypeOf((*MockController)(nil).GetDetectorsByName), arg0, arg1, arg2) } -// SearchDetectorByName mocks base method +// SearchDetectorByName mocks base method. func (m *MockController) SearchDetectorByName(arg0 context.Context, arg1 string) ([]ad.Detector, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SearchDetectorByName", arg0, arg1) @@ -132,13 +138,13 @@ func (m *MockController) SearchDetectorByName(arg0 context.Context, arg1 string) return ret0, ret1 } -// SearchDetectorByName indicates an expected call of SearchDetectorByName -func (mr *MockControllerMockRecorder) SearchDetectorByName(arg0, arg1 interface{}) *gomock.Call { +// SearchDetectorByName indicates an expected call of SearchDetectorByName. +func (mr *MockControllerMockRecorder) SearchDetectorByName(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SearchDetectorByName", reflect.TypeOf((*MockController)(nil).SearchDetectorByName), arg0, arg1) } -// StartDetector mocks base method +// StartDetector mocks base method. func (m *MockController) StartDetector(arg0 context.Context, arg1 string) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StartDetector", arg0, arg1) @@ -146,13 +152,13 @@ func (m *MockController) StartDetector(arg0 context.Context, arg1 string) error return ret0 } -// StartDetector indicates an expected call of StartDetector -func (mr *MockControllerMockRecorder) StartDetector(arg0, arg1 interface{}) *gomock.Call { +// StartDetector indicates an expected call of StartDetector. +func (mr *MockControllerMockRecorder) StartDetector(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartDetector", reflect.TypeOf((*MockController)(nil).StartDetector), arg0, arg1) } -// StartDetectorByName mocks base method +// StartDetectorByName mocks base method. func (m *MockController) StartDetectorByName(arg0 context.Context, arg1 string, arg2 bool) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StartDetectorByName", arg0, arg1, arg2) @@ -160,13 +166,13 @@ func (m *MockController) StartDetectorByName(arg0 context.Context, arg1 string, return ret0 } -// StartDetectorByName indicates an expected call of StartDetectorByName -func (mr *MockControllerMockRecorder) StartDetectorByName(arg0, arg1, arg2 interface{}) *gomock.Call { +// StartDetectorByName indicates an expected call of StartDetectorByName. +func (mr *MockControllerMockRecorder) StartDetectorByName(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartDetectorByName", reflect.TypeOf((*MockController)(nil).StartDetectorByName), arg0, arg1, arg2) } -// StopDetector mocks base method +// StopDetector mocks base method. func (m *MockController) StopDetector(arg0 context.Context, arg1 string) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StopDetector", arg0, arg1) @@ -174,13 +180,13 @@ func (m *MockController) StopDetector(arg0 context.Context, arg1 string) error { return ret0 } -// StopDetector indicates an expected call of StopDetector -func (mr *MockControllerMockRecorder) StopDetector(arg0, arg1 interface{}) *gomock.Call { +// StopDetector indicates an expected call of StopDetector. +func (mr *MockControllerMockRecorder) StopDetector(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StopDetector", reflect.TypeOf((*MockController)(nil).StopDetector), arg0, arg1) } -// StopDetectorByName mocks base method +// StopDetectorByName mocks base method. func (m *MockController) StopDetectorByName(arg0 context.Context, arg1 string, arg2 bool) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StopDetectorByName", arg0, arg1, arg2) @@ -188,13 +194,13 @@ func (m *MockController) StopDetectorByName(arg0 context.Context, arg1 string, a return ret0 } -// StopDetectorByName indicates an expected call of StopDetectorByName -func (mr *MockControllerMockRecorder) StopDetectorByName(arg0, arg1, arg2 interface{}) *gomock.Call { +// StopDetectorByName indicates an expected call of StopDetectorByName. +func (mr *MockControllerMockRecorder) StopDetectorByName(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StopDetectorByName", reflect.TypeOf((*MockController)(nil).StopDetectorByName), arg0, arg1, arg2) } -// UpdateDetector mocks base method +// UpdateDetector mocks base method. func (m *MockController) UpdateDetector(arg0 context.Context, arg1 ad.UpdateDetectorUserInput, arg2, arg3 bool) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateDetector", arg0, arg1, arg2, arg3) @@ -202,8 +208,8 @@ func (m *MockController) UpdateDetector(arg0 context.Context, arg1 ad.UpdateDete return ret0 } -// UpdateDetector indicates an expected call of UpdateDetector -func (mr *MockControllerMockRecorder) UpdateDetector(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +// UpdateDetector indicates an expected call of UpdateDetector. +func (mr *MockControllerMockRecorder) UpdateDetector(arg0, arg1, arg2, arg3 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateDetector", reflect.TypeOf((*MockController)(nil).UpdateDetector), arg0, arg1, arg2, arg3) } diff --git a/controller/config/config.go b/controller/config/config.go index 54d4c55..0e69e26 100644 --- a/controller/config/config.go +++ b/controller/config/config.go @@ -18,7 +18,7 @@ import ( "gopkg.in/yaml.v3" ) -//go:generate go run -mod=mod github.com/golang/mock/mockgen -destination=mocks/mock_config.go -package=mocks . Controller +//go:generate go run -mod=mod go.uber.org/mock/mockgen -destination=mocks/mock_config.go -package=mocks . Controller type Controller interface { Read() (entity.Config, error) Write(config entity.Config) error diff --git a/controller/config/mocks/mock_config.go b/controller/config/mocks/mock_config.go index 9d23325..09214fb 100644 --- a/controller/config/mocks/mock_config.go +++ b/controller/config/mocks/mock_config.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: opensearch-cli/controller/config (interfaces: Controller) +// +// Generated by this command: +// +// mockgen -destination=mocks/mock_config.go -package=mocks . Controller +// // Package mocks is a generated GoMock package. package mocks @@ -8,33 +13,34 @@ import ( entity "opensearch-cli/entity" reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) -// MockController is a mock of Controller interface +// MockController is a mock of Controller interface. type MockController struct { ctrl *gomock.Controller recorder *MockControllerMockRecorder + isgomock struct{} } -// MockControllerMockRecorder is the mock recorder for MockController +// MockControllerMockRecorder is the mock recorder for MockController. type MockControllerMockRecorder struct { mock *MockController } -// NewMockController creates a new mock instance +// NewMockController creates a new mock instance. func NewMockController(ctrl *gomock.Controller) *MockController { mock := &MockController{ctrl: ctrl} mock.recorder = &MockControllerMockRecorder{mock} return mock } -// EXPECT returns an object that allows the caller to indicate expected use +// EXPECT returns an object that allows the caller to indicate expected use. func (m *MockController) EXPECT() *MockControllerMockRecorder { return m.recorder } -// Read mocks base method +// Read mocks base method. func (m *MockController) Read() (entity.Config, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Read") @@ -43,22 +49,22 @@ func (m *MockController) Read() (entity.Config, error) { return ret0, ret1 } -// Read indicates an expected call of Read +// Read indicates an expected call of Read. func (mr *MockControllerMockRecorder) Read() *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockController)(nil).Read)) } -// Write mocks base method -func (m *MockController) Write(arg0 entity.Config) error { +// Write mocks base method. +func (m *MockController) Write(config entity.Config) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Write", arg0) + ret := m.ctrl.Call(m, "Write", config) ret0, _ := ret[0].(error) return ret0 } -// Write indicates an expected call of Write -func (mr *MockControllerMockRecorder) Write(arg0 interface{}) *gomock.Call { +// Write indicates an expected call of Write. +func (mr *MockControllerMockRecorder) Write(config any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Write", reflect.TypeOf((*MockController)(nil).Write), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Write", reflect.TypeOf((*MockController)(nil).Write), config) } diff --git a/controller/knn/knn.go b/controller/knn/knn.go index 5016847..308c694 100644 --- a/controller/knn/knn.go +++ b/controller/knn/knn.go @@ -19,9 +19,9 @@ import ( "strings" ) -//go:generate go run -mod=mod github.com/golang/mock/mockgen -destination=mocks/mock_knn.go -package=mocks . Controller +//go:generate go run -mod=mod go.uber.org/mock/mockgen -destination=mocks/mock_knn.go -package=mocks . Controller -//Controller is an interface for the k-NN plugin controllers +// Controller is an interface for the k-NN plugin controllers type Controller interface { GetStatistics(context.Context, string, string) ([]byte, error) WarmupIndices(context.Context, []string) (*entity.Shards, error) @@ -31,20 +31,20 @@ type controller struct { gateway gateway.Gateway } -//GetStatistics gets stats data based on nodes and stat names +// GetStatistics gets stats data based on nodes and stat names func (c controller) GetStatistics(ctx context.Context, nodes string, names string) ([]byte, error) { return c.gateway.GetStatistics(ctx, nodes, names) } -//New returns new Controller instance +// New returns new Controller instance func New(gateway gateway.Gateway) Controller { return &controller{ gateway, } } -//WarmupIndices will load all the graphs for all of the shards (primaries and replicas) -//of all the indices specified in the request into native memory +// WarmupIndices will load all the graphs for all of the shards (primaries and replicas) +// of all the indices specified in the request into native memory func (c controller) WarmupIndices(ctx context.Context, index []string) (*entity.Shards, error) { indices := strings.Join(index, ",") response, err := c.gateway.WarmupIndices(ctx, indices) diff --git a/controller/knn/knn_test.go b/controller/knn/knn_test.go index e1694a2..fcc4086 100644 --- a/controller/knn/knn_test.go +++ b/controller/knn/knn_test.go @@ -19,8 +19,8 @@ import ( gateway "opensearch-cli/gateway/knn/mocks" "testing" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" ) func TestControllerGetStatistics(t *testing.T) { diff --git a/controller/knn/mocks/mock_knn.go b/controller/knn/mocks/mock_knn.go index 47c3f71..690b6aa 100644 --- a/controller/knn/mocks/mock_knn.go +++ b/controller/knn/mocks/mock_knn.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: opensearch-cli/controller/knn (interfaces: Controller) +// +// Generated by this command: +// +// mockgen -destination=mocks/mock_knn.go -package=mocks . Controller +// // Package mocks is a generated GoMock package. package mocks @@ -9,33 +14,34 @@ import ( knn "opensearch-cli/entity/knn" reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) -// MockController is a mock of Controller interface +// MockController is a mock of Controller interface. type MockController struct { ctrl *gomock.Controller recorder *MockControllerMockRecorder + isgomock struct{} } -// MockControllerMockRecorder is the mock recorder for MockController +// MockControllerMockRecorder is the mock recorder for MockController. type MockControllerMockRecorder struct { mock *MockController } -// NewMockController creates a new mock instance +// NewMockController creates a new mock instance. func NewMockController(ctrl *gomock.Controller) *MockController { mock := &MockController{ctrl: ctrl} mock.recorder = &MockControllerMockRecorder{mock} return mock } -// EXPECT returns an object that allows the caller to indicate expected use +// EXPECT returns an object that allows the caller to indicate expected use. func (m *MockController) EXPECT() *MockControllerMockRecorder { return m.recorder } -// GetStatistics mocks base method +// GetStatistics mocks base method. func (m *MockController) GetStatistics(arg0 context.Context, arg1, arg2 string) ([]byte, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetStatistics", arg0, arg1, arg2) @@ -44,13 +50,13 @@ func (m *MockController) GetStatistics(arg0 context.Context, arg1, arg2 string) return ret0, ret1 } -// GetStatistics indicates an expected call of GetStatistics -func (mr *MockControllerMockRecorder) GetStatistics(arg0, arg1, arg2 interface{}) *gomock.Call { +// GetStatistics indicates an expected call of GetStatistics. +func (mr *MockControllerMockRecorder) GetStatistics(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStatistics", reflect.TypeOf((*MockController)(nil).GetStatistics), arg0, arg1, arg2) } -// WarmupIndices mocks base method +// WarmupIndices mocks base method. func (m *MockController) WarmupIndices(arg0 context.Context, arg1 []string) (*knn.Shards, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "WarmupIndices", arg0, arg1) @@ -59,8 +65,8 @@ func (m *MockController) WarmupIndices(arg0 context.Context, arg1 []string) (*kn return ret0, ret1 } -// WarmupIndices indicates an expected call of WarmupIndices -func (mr *MockControllerMockRecorder) WarmupIndices(arg0, arg1 interface{}) *gomock.Call { +// WarmupIndices indicates an expected call of WarmupIndices. +func (mr *MockControllerMockRecorder) WarmupIndices(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WarmupIndices", reflect.TypeOf((*MockController)(nil).WarmupIndices), arg0, arg1) } diff --git a/controller/platform/mocks/mock_platform.go b/controller/platform/mocks/mock_platform.go index bab600c..bca3774 100644 --- a/controller/platform/mocks/mock_platform.go +++ b/controller/platform/mocks/mock_platform.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: opensearch-cli/controller/platform (interfaces: Controller) +// +// Generated by this command: +// +// mockgen -destination=mocks/mock_platform.go -package=mocks . Controller +// // Package mocks is a generated GoMock package. package mocks @@ -9,58 +14,59 @@ import ( platform "opensearch-cli/entity/platform" reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) -// MockController is a mock of Controller interface +// MockController is a mock of Controller interface. type MockController struct { ctrl *gomock.Controller recorder *MockControllerMockRecorder + isgomock struct{} } -// MockControllerMockRecorder is the mock recorder for MockController +// MockControllerMockRecorder is the mock recorder for MockController. type MockControllerMockRecorder struct { mock *MockController } -// NewMockController creates a new mock instance +// NewMockController creates a new mock instance. func NewMockController(ctrl *gomock.Controller) *MockController { mock := &MockController{ctrl: ctrl} mock.recorder = &MockControllerMockRecorder{mock} return mock } -// EXPECT returns an object that allows the caller to indicate expected use +// EXPECT returns an object that allows the caller to indicate expected use. func (m *MockController) EXPECT() *MockControllerMockRecorder { return m.recorder } -// Curl mocks base method -func (m *MockController) Curl(arg0 context.Context, arg1 platform.CurlCommandRequest) ([]byte, error) { +// Curl mocks base method. +func (m *MockController) Curl(ctx context.Context, param platform.CurlCommandRequest) ([]byte, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Curl", arg0, arg1) + ret := m.ctrl.Call(m, "Curl", ctx, param) ret0, _ := ret[0].([]byte) ret1, _ := ret[1].(error) return ret0, ret1 } -// Curl indicates an expected call of Curl -func (mr *MockControllerMockRecorder) Curl(arg0, arg1 interface{}) *gomock.Call { +// Curl indicates an expected call of Curl. +func (mr *MockControllerMockRecorder) Curl(ctx, param any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Curl", reflect.TypeOf((*MockController)(nil).Curl), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Curl", reflect.TypeOf((*MockController)(nil).Curl), ctx, param) } -// GetDistinctValues mocks base method -func (m *MockController) GetDistinctValues(arg0 context.Context, arg1, arg2 string) ([]interface{}, error) { +// GetDistinctValues mocks base method. +func (m *MockController) GetDistinctValues(ctx context.Context, index, field string) ([]any, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetDistinctValues", arg0, arg1, arg2) - ret0, _ := ret[0].([]interface{}) + ret := m.ctrl.Call(m, "GetDistinctValues", ctx, index, field) + ret0, _ := ret[0].([]any) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetDistinctValues indicates an expected call of GetDistinctValues -func (mr *MockControllerMockRecorder) GetDistinctValues(arg0, arg1, arg2 interface{}) *gomock.Call { +// GetDistinctValues indicates an expected call of GetDistinctValues. +func (mr *MockControllerMockRecorder) GetDistinctValues(ctx, index, field any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDistinctValues", reflect.TypeOf((*MockController)(nil).GetDistinctValues), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDistinctValues", reflect.TypeOf((*MockController)(nil).GetDistinctValues), ctx, index, field) } diff --git a/controller/platform/platform.go b/controller/platform/platform.go index 5aad689..979290e 100644 --- a/controller/platform/platform.go +++ b/controller/platform/platform.go @@ -21,9 +21,9 @@ import ( "fmt" ) -//go:generate go run -mod=mod github.com/golang/mock/mockgen -destination=mocks/mock_platform.go -package=mocks . Controller +//go:generate go run -mod=mod go.uber.org/mock/mockgen -destination=mocks/mock_platform.go -package=mocks . Controller -//Controller is an interface for OpenSearch +// Controller is an interface for OpenSearch type Controller interface { GetDistinctValues(ctx context.Context, index string, field string) ([]interface{}, error) Curl(ctx context.Context, param platform.CurlCommandRequest) ([]byte, error) @@ -33,14 +33,14 @@ type controller struct { gateway osg.Gateway } -//New returns new instance of Controller +// New returns new instance of Controller func New(gateway osg.Gateway) Controller { return &controller{ gateway, } } -//GetDistinctValues get only unique values for given index, given field name +// GetDistinctValues get only unique values for given index, given field name func (c controller) GetDistinctValues(ctx context.Context, index string, field string) ([]interface{}, error) { if len(index) == 0 || len(field) == 0 { return nil, fmt.Errorf("index and field cannot be empty") @@ -62,7 +62,7 @@ func (c controller) GetDistinctValues(ctx context.Context, index string, field s return values, nil } -//Curl accept user request and convert to format which OpenSearch can understand +// Curl accept user request and convert to format which OpenSearch can understand func (c controller) Curl(ctx context.Context, param platform.CurlCommandRequest) ([]byte, error) { curlRequest, err := mapper.CommandToCurlRequestParameter(param) if err != nil { diff --git a/controller/platform/platform_test.go b/controller/platform/platform_test.go index c23c7f1..1144688 100644 --- a/controller/platform/platform_test.go +++ b/controller/platform/platform_test.go @@ -21,8 +21,8 @@ import ( "path/filepath" "testing" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" ) func helperLoadBytes(t *testing.T, name string) []byte { diff --git a/controller/profile/mocks/mock_profile.go b/controller/profile/mocks/mock_profile.go index 706ec1d..02f13b2 100644 --- a/controller/profile/mocks/mock_profile.go +++ b/controller/profile/mocks/mock_profile.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: opensearch-cli/controller/profile (interfaces: Controller) +// +// Generated by this command: +// +// mockgen -destination=mocks/mock_profile.go -package=mocks . Controller +// // Package mocks is a generated GoMock package. package mocks @@ -8,77 +13,78 @@ import ( entity "opensearch-cli/entity" reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) -// MockController is a mock of Controller interface +// MockController is a mock of Controller interface. type MockController struct { ctrl *gomock.Controller recorder *MockControllerMockRecorder + isgomock struct{} } -// MockControllerMockRecorder is the mock recorder for MockController +// MockControllerMockRecorder is the mock recorder for MockController. type MockControllerMockRecorder struct { mock *MockController } -// NewMockController creates a new mock instance +// NewMockController creates a new mock instance. func NewMockController(ctrl *gomock.Controller) *MockController { mock := &MockController{ctrl: ctrl} mock.recorder = &MockControllerMockRecorder{mock} return mock } -// EXPECT returns an object that allows the caller to indicate expected use +// EXPECT returns an object that allows the caller to indicate expected use. func (m *MockController) EXPECT() *MockControllerMockRecorder { return m.recorder } -// CreateProfile mocks base method -func (m *MockController) CreateProfile(arg0 entity.Profile) error { +// CreateProfile mocks base method. +func (m *MockController) CreateProfile(profile entity.Profile) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateProfile", arg0) + ret := m.ctrl.Call(m, "CreateProfile", profile) ret0, _ := ret[0].(error) return ret0 } -// CreateProfile indicates an expected call of CreateProfile -func (mr *MockControllerMockRecorder) CreateProfile(arg0 interface{}) *gomock.Call { +// CreateProfile indicates an expected call of CreateProfile. +func (mr *MockControllerMockRecorder) CreateProfile(profile any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateProfile", reflect.TypeOf((*MockController)(nil).CreateProfile), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateProfile", reflect.TypeOf((*MockController)(nil).CreateProfile), profile) } -// DeleteProfiles mocks base method -func (m *MockController) DeleteProfiles(arg0 []string) error { +// DeleteProfiles mocks base method. +func (m *MockController) DeleteProfiles(names []string) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DeleteProfiles", arg0) + ret := m.ctrl.Call(m, "DeleteProfiles", names) ret0, _ := ret[0].(error) return ret0 } -// DeleteProfiles indicates an expected call of DeleteProfiles -func (mr *MockControllerMockRecorder) DeleteProfiles(arg0 interface{}) *gomock.Call { +// DeleteProfiles indicates an expected call of DeleteProfiles. +func (mr *MockControllerMockRecorder) DeleteProfiles(names any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteProfiles", reflect.TypeOf((*MockController)(nil).DeleteProfiles), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteProfiles", reflect.TypeOf((*MockController)(nil).DeleteProfiles), names) } -// GetProfileForExecution mocks base method -func (m *MockController) GetProfileForExecution(arg0 string) (entity.Profile, bool, error) { +// GetProfileForExecution mocks base method. +func (m *MockController) GetProfileForExecution(name string) (entity.Profile, bool, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetProfileForExecution", arg0) + ret := m.ctrl.Call(m, "GetProfileForExecution", name) ret0, _ := ret[0].(entity.Profile) ret1, _ := ret[1].(bool) ret2, _ := ret[2].(error) return ret0, ret1, ret2 } -// GetProfileForExecution indicates an expected call of GetProfileForExecution -func (mr *MockControllerMockRecorder) GetProfileForExecution(arg0 interface{}) *gomock.Call { +// GetProfileForExecution indicates an expected call of GetProfileForExecution. +func (mr *MockControllerMockRecorder) GetProfileForExecution(name any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetProfileForExecution", reflect.TypeOf((*MockController)(nil).GetProfileForExecution), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetProfileForExecution", reflect.TypeOf((*MockController)(nil).GetProfileForExecution), name) } -// GetProfileNames mocks base method +// GetProfileNames mocks base method. func (m *MockController) GetProfileNames() ([]string, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetProfileNames") @@ -87,13 +93,13 @@ func (m *MockController) GetProfileNames() ([]string, error) { return ret0, ret1 } -// GetProfileNames indicates an expected call of GetProfileNames +// GetProfileNames indicates an expected call of GetProfileNames. func (mr *MockControllerMockRecorder) GetProfileNames() *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetProfileNames", reflect.TypeOf((*MockController)(nil).GetProfileNames)) } -// GetProfiles mocks base method +// GetProfiles mocks base method. func (m *MockController) GetProfiles() ([]entity.Profile, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetProfiles") @@ -102,13 +108,13 @@ func (m *MockController) GetProfiles() ([]entity.Profile, error) { return ret0, ret1 } -// GetProfiles indicates an expected call of GetProfiles +// GetProfiles indicates an expected call of GetProfiles. func (mr *MockControllerMockRecorder) GetProfiles() *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetProfiles", reflect.TypeOf((*MockController)(nil).GetProfiles)) } -// GetProfilesMap mocks base method +// GetProfilesMap mocks base method. func (m *MockController) GetProfilesMap() (map[string]entity.Profile, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetProfilesMap") @@ -117,7 +123,7 @@ func (m *MockController) GetProfilesMap() (map[string]entity.Profile, error) { return ret0, ret1 } -// GetProfilesMap indicates an expected call of GetProfilesMap +// GetProfilesMap indicates an expected call of GetProfilesMap. func (mr *MockControllerMockRecorder) GetProfilesMap() *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetProfilesMap", reflect.TypeOf((*MockController)(nil).GetProfilesMap)) diff --git a/controller/profile/profile.go b/controller/profile/profile.go index 678be8f..c56339b 100644 --- a/controller/profile/profile.go +++ b/controller/profile/profile.go @@ -24,7 +24,7 @@ const ( DefaultProfileName = "default" ) -//go:generate go run -mod=mod github.com/golang/mock/mockgen -destination=mocks/mock_profile.go -package=mocks . Controller +//go:generate go run -mod=mod go.uber.org/mock/mockgen -destination=mocks/mock_profile.go -package=mocks . Controller type Controller interface { CreateProfile(profile entity.Profile) error DeleteProfiles(names []string) error @@ -38,14 +38,14 @@ type controller struct { configCtrl config.Controller } -//New returns new config controller instance +// New returns new config controller instance func New(c config.Controller) Controller { return &controller{ configCtrl: c, } } -//GetProfiles gets list of profiles fom config file +// GetProfiles gets list of profiles fom config file func (c controller) GetProfiles() ([]entity.Profile, error) { data, err := c.configCtrl.Read() if err != nil { @@ -54,7 +54,7 @@ func (c controller) GetProfiles() ([]entity.Profile, error) { return data.Profiles, nil } -//GetProfileNames gets list of profile names +// GetProfileNames gets list of profile names func (c controller) GetProfileNames() ([]string, error) { profiles, err := c.GetProfiles() if err != nil { @@ -67,7 +67,7 @@ func (c controller) GetProfileNames() ([]string, error) { return names, nil } -//GetProfilesMap returns a map view of the profiles contained in config +// GetProfilesMap returns a map view of the profiles contained in config func (c controller) GetProfilesMap() (map[string]entity.Profile, error) { profiles, err := c.GetProfiles() if err != nil { @@ -80,8 +80,8 @@ func (c controller) GetProfilesMap() (map[string]entity.Profile, error) { return result, nil } -//CreateProfile creates profile by gets list of existing profiles, append new profile to list -//and saves it in config file +// CreateProfile creates profile by gets list of existing profiles, append new profile to list +// and saves it in config file func (c controller) CreateProfile(p entity.Profile) error { data, err := c.configCtrl.Read() if err != nil { @@ -91,7 +91,7 @@ func (c controller) CreateProfile(p entity.Profile) error { return c.configCtrl.Write(data) } -//DeleteProfiles loads all profile, deletes selected profiles, and saves rest in config file +// DeleteProfiles loads all profile, deletes selected profiles, and saves rest in config file func (c controller) DeleteProfiles(names []string) error { profilesMap, err := c.GetProfilesMap() if err != nil { diff --git a/controller/profile/profile_test.go b/controller/profile/profile_test.go index 3643619..48a1f96 100644 --- a/controller/profile/profile_test.go +++ b/controller/profile/profile_test.go @@ -19,8 +19,8 @@ import ( "os" "testing" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" ) func getDefaultConfig() entity.Config { diff --git a/docker-compose.yml b/docker-compose.yml index 33585a7..6a65946 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,5 @@ # Copied from https://github.com/opensearch-project/opensearch-build/blob/main/release/docker/dockercomposefiles/docker-compose.yml # removed node-2 and dashboard since we don't need to create two node cluster for integration test -version: '3' services: test-node1: image: opensearchproject/opensearch:${OPENSEARCH_VERSION:-latest} @@ -12,6 +11,7 @@ services: - cluster.initial_master_nodes=test-node1 - bootstrap.memory_lock=true # along with the memlock settings below, disables swapping - "ES_JAVA_OPTS=-Xms512m -Xmx512m" # minimum and maximum Java heap size, recommend setting both to 50% of system RAM + - OPENSEARCH_INITIAL_ADMIN_PASSWORD=MyStr0ngP@ssw0rd! ulimits: memlock: soft: -1 diff --git a/entity/ad/ad.go b/entity/ad/ad.go index f1b0f4b..8bbfca4 100644 --- a/entity/ad/ad.go +++ b/entity/ad/ad.go @@ -16,25 +16,25 @@ import ( "opensearch-cli/entity" ) -//Feature structure for detector features +// Feature structure for detector features type Feature struct { Name string `json:"feature_name"` Enabled bool `json:"feature_enabled"` AggregationQuery json.RawMessage `json:"aggregation_query"` } -//Period represents time interval +// Period represents time interval type Period struct { Duration int32 `json:"interval"` Unit string `json:"unit"` } -//Interval represent unit of time +// Interval represent unit of time type Interval struct { Period Period `json:"period"` } -//CreateDetector represents Detector creation request +// CreateDetector represents Detector creation request type CreateDetector struct { Name string `json:"name"` Description string `json:"description,omitempty"` @@ -46,14 +46,14 @@ type CreateDetector struct { Delay Interval `json:"window_delay"` } -//FeatureRequest represents feature request +// FeatureRequest represents feature request type FeatureRequest struct { AggregationType []string `json:"aggregation_type"` Enabled bool `json:"enabled"` Field []string `json:"field"` } -//CreateDetectorRequest represents request for AD +// CreateDetectorRequest represents request for AD type CreateDetectorRequest struct { Name string `json:"name"` Description string `json:"description"` @@ -67,71 +67,71 @@ type CreateDetectorRequest struct { PartitionField *string `json:"partition_field"` } -//Bool type for must query +// Bool type for must query type Bool struct { Must []json.RawMessage `json:"must"` } -//Query type to represent query +// Query type to represent query type Query struct { Bool Bool `json:"bool"` } -//Detector type to map name to ID +// Detector type to map name to ID type Detector struct { Name string ID string } -//CreateFailedError structure if create failed +// CreateFailedError structure if create failed type CreateFailedError struct { Type string `json:"type"` Reason string `json:"reason"` } -//CreateError Error type in Create Response +// CreateError Error type in Create Response type CreateError struct { Error CreateFailedError `json:"error"` Status int32 `json:"status"` } -//Configuration represents configuration in config file +// Configuration represents configuration in config file type Configuration struct { Profiles []entity.Profile `mapstructure:"profiles"` } -//Match specifies name +// Match specifies name type Match struct { Name string `json:"name"` } -//SearchQuery contains match names +// SearchQuery contains match names type SearchQuery struct { Match Match `json:"match"` } -//SearchRequest represents structure for search detectors +// SearchRequest represents structure for search detectors type SearchRequest struct { Query SearchQuery `json:"query"` } -//Source contains detectors metadata +// Source contains detectors metadata type Source struct { Name string `json:"name"` } -//Hit contains search results +// Hit contains search results type Hit struct { ID string `json:"_id"` Source Source `json:"_source"` } -//Container represents structure for search response +// Container represents structure for search response type Container struct { Hits []Hit `json:"hits"` } -//SearchResponse represents structure for search response +// SearchResponse represents structure for search response type SearchResponse struct { Hits Container `json:"hits"` } @@ -144,13 +144,13 @@ type AnomalyDetector struct { LastUpdateTime uint64 `json:"last_update_time"` } -//DetectorResponse represents detector's setting +// DetectorResponse represents detector's setting type DetectorResponse struct { ID string `json:"_id"` AnomalyDetector AnomalyDetector `json:"anomaly_detector"` } -//DetectorOutput represents detector's setting displayed to user +// DetectorOutput represents detector's setting displayed to user type DetectorOutput struct { ID string Name string `json:"name"` @@ -165,7 +165,7 @@ type DetectorOutput struct { SchemaVersion int32 `json:"schema_version"` } -//UpdateDetectorUserInput represents user's detector input for update +// UpdateDetectorUserInput represents user's detector input for update type UpdateDetectorUserInput DetectorOutput // UpdateDetector represents detector's settings updated by api diff --git a/entity/config.go b/entity/config.go index 5809b89..6d0601c 100644 --- a/entity/config.go +++ b/entity/config.go @@ -11,7 +11,7 @@ package entity -//Config represents config file structure +// Config represents config file structure type Config struct { Profiles []Profile `yaml:"profiles"` } diff --git a/entity/knn/knn.go b/entity/knn/knn.go index 1ede6d4..ab8b8a8 100644 --- a/entity/knn/knn.go +++ b/entity/knn/knn.go @@ -11,30 +11,30 @@ package knn -//Shards represents number of shards succeeded or failed to warmup +// Shards represents number of shards succeeded or failed to warmup type Shards struct { Total int `json:"total"` Successful int `json:"successful"` Failed int `json:"failed"` } -//WarmupAPIResponse warmup api response structure +// WarmupAPIResponse warmup api response structure type WarmupAPIResponse struct { Shards Shards `json:"_shards"` } -//RootCause gives information about type and reason +// RootCause gives information about type and reason type RootCause struct { Type string `json:"type"` Reason string `json:"reason"` } -//Error contains root cause +// Error contains root cause type Error struct { RootCause []RootCause `json:"root_cause"` } -//ErrorResponse knn request failure error response +// ErrorResponse knn request failure error response type ErrorResponse struct { KNNError Error `json:"error"` Status int `json:"status"` diff --git a/entity/profile.go b/entity/profile.go index 59ff048..34be254 100644 --- a/entity/profile.go +++ b/entity/profile.go @@ -16,7 +16,7 @@ type AWSIAM struct { ServiceName string `yaml:"service"` } -//Trust contains file path for certificate and private key locations +// Trust contains file path for certificate and private key locations type Trust struct { CAFilePath *string ClientCertificateFilePath *string diff --git a/gateway/ad/ad.go b/gateway/ad/ad.go index 8b6dacc..9df5392 100644 --- a/gateway/ad/ad.go +++ b/gateway/ad/ad.go @@ -32,7 +32,7 @@ const ( updateURLTemplate = baseURL + "/%s" ) -//go:generate go run -mod=mod github.com/golang/mock/mockgen -destination=mocks/mock_ad.go -package=mocks . Gateway +//go:generate go run -mod=mod go.uber.org/mock/mockgen -destination=mocks/mock_ad.go -package=mocks . Gateway // Gateway interface to AD Plugin type Gateway interface { @@ -67,56 +67,59 @@ func (g *gateway) buildCreateURL() (*url.URL, error) { return endpoint, nil } -/*CreateDetector Creates an anomaly detector job. +/* +CreateDetector Creates an anomaly detector job. It calls http request: POST _plugins/_anomaly_detection/detectors Sample Input: -{ - "name": "test-detector", - "description": "Test detector", - "time_field": "timestamp", - "indices": [ - "order*" - ], - "feature_attributes": [ - { - "feature_name": "total_order", - "feature_enabled": true, - "aggregation_query": { - "total_order": { - "sum": { - "field": "value" - } - } - } - } - ], - "filter_query": { - "bool": { - "filter": [ - { - "exists": { - "field": "value", - "boost": 1 - } - } - ], - "adjust_pure_negative": true, - "boost": 1 - } - }, - "detection_interval": { - "period": { - "interval": 1, - "unit": "Minutes" - } - }, - "window_delay": { - "period": { - "interval": 1, - "unit": "Minutes" - } - } -}*/ + + { + "name": "test-detector", + "description": "Test detector", + "time_field": "timestamp", + "indices": [ + "order*" + ], + "feature_attributes": [ + { + "feature_name": "total_order", + "feature_enabled": true, + "aggregation_query": { + "total_order": { + "sum": { + "field": "value" + } + } + } + } + ], + "filter_query": { + "bool": { + "filter": [ + { + "exists": { + "field": "value", + "boost": 1 + } + } + ], + "adjust_pure_negative": true, + "boost": 1 + } + }, + "detection_interval": { + "period": { + "interval": 1, + "unit": "Minutes" + } + }, + "window_delay": { + "period": { + "interval": 1, + "unit": "Minutes" + } + } + } +*/ func (g *gateway) CreateDetector(ctx context.Context, payload interface{}) ([]byte, error) { createURL, err := g.buildCreateURL() if err != nil { @@ -196,16 +199,19 @@ func (g *gateway) buildSearchURL() (*url.URL, error) { return endpoint, nil } -/*SearchDetector Returns all anomaly detectors for a search query. +/* +SearchDetector Returns all anomaly detectors for a search query. It calls http request: POST _plugins/_anomaly_detection/detectors/_search sample input Sample Input: -{ - "query": { - "match": { - "name": "test-detector" - } - }*/ + + { + "query": { + "match": { + "name": "test-detector" + } + } +*/ func (g *gateway) SearchDetector(ctx context.Context, payload interface{}) ([]byte, error) { searchURL, err := g.buildSearchURL() if err != nil { @@ -285,56 +291,59 @@ func (g *gateway) buildUpdateURL(ID string) (*url.URL, error) { return endpoint, nil } -/*UpdateDetector Updates a detector with any changes, including the description or adding or removing of features. +/* +UpdateDetector Updates a detector with any changes, including the description or adding or removing of features. It calls http request: PUT _plugins/_anomaly_detection/detectors/ Sample Input: -{ - "name": "test-detector", - "description": "Test detector", - "time_field": "timestamp", - "indices": [ - "order*" - ], - "feature_attributes": [ - { - "feature_name": "total_order", - "feature_enabled": true, - "aggregation_query": { - "total_order": { - "sum": { - "field": "value" - } - } - } - } - ], - "filter_query": { - "bool": { - "filter": [ - { - "exists": { - "field": "value", - "boost": 1 - } - } - ], - "adjust_pure_negative": true, - "boost": 1 - } - }, - "detection_interval": { - "period": { - "interval": 10, - "unit": "Minutes" - } - }, - "window_delay": { - "period": { - "interval": 1, - "unit": "Minutes" - } - } -}*/ + + { + "name": "test-detector", + "description": "Test detector", + "time_field": "timestamp", + "indices": [ + "order*" + ], + "feature_attributes": [ + { + "feature_name": "total_order", + "feature_enabled": true, + "aggregation_query": { + "total_order": { + "sum": { + "field": "value" + } + } + } + } + ], + "filter_query": { + "bool": { + "filter": [ + { + "exists": { + "field": "value", + "boost": 1 + } + } + ], + "adjust_pure_negative": true, + "boost": 1 + } + }, + "detection_interval": { + "period": { + "interval": 10, + "unit": "Minutes" + } + }, + "window_delay": { + "period": { + "interval": 1, + "unit": "Minutes" + } + } + } +*/ func (g *gateway) UpdateDetector(ctx context.Context, ID string, payload interface{}) error { updateURL, err := g.buildUpdateURL(ID) if err != nil { diff --git a/gateway/ad/mocks/mock_ad.go b/gateway/ad/mocks/mock_ad.go index 0acfbda..f44a92d 100644 --- a/gateway/ad/mocks/mock_ad.go +++ b/gateway/ad/mocks/mock_ad.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: opensearch-cli/gateway/ad (interfaces: Gateway) +// +// Generated by this command: +// +// mockgen -destination=mocks/mock_ad.go -package=mocks . Gateway +// // Package mocks is a generated GoMock package. package mocks @@ -8,34 +13,35 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) -// MockGateway is a mock of Gateway interface +// MockGateway is a mock of Gateway interface. type MockGateway struct { ctrl *gomock.Controller recorder *MockGatewayMockRecorder + isgomock struct{} } -// MockGatewayMockRecorder is the mock recorder for MockGateway +// MockGatewayMockRecorder is the mock recorder for MockGateway. type MockGatewayMockRecorder struct { mock *MockGateway } -// NewMockGateway creates a new mock instance +// NewMockGateway creates a new mock instance. func NewMockGateway(ctrl *gomock.Controller) *MockGateway { mock := &MockGateway{ctrl: ctrl} mock.recorder = &MockGatewayMockRecorder{mock} return mock } -// EXPECT returns an object that allows the caller to indicate expected use +// EXPECT returns an object that allows the caller to indicate expected use. func (m *MockGateway) EXPECT() *MockGatewayMockRecorder { return m.recorder } -// CreateDetector mocks base method -func (m *MockGateway) CreateDetector(arg0 context.Context, arg1 interface{}) ([]byte, error) { +// CreateDetector mocks base method. +func (m *MockGateway) CreateDetector(arg0 context.Context, arg1 any) ([]byte, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CreateDetector", arg0, arg1) ret0, _ := ret[0].([]byte) @@ -43,13 +49,13 @@ func (m *MockGateway) CreateDetector(arg0 context.Context, arg1 interface{}) ([] return ret0, ret1 } -// CreateDetector indicates an expected call of CreateDetector -func (mr *MockGatewayMockRecorder) CreateDetector(arg0, arg1 interface{}) *gomock.Call { +// CreateDetector indicates an expected call of CreateDetector. +func (mr *MockGatewayMockRecorder) CreateDetector(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateDetector", reflect.TypeOf((*MockGateway)(nil).CreateDetector), arg0, arg1) } -// DeleteDetector mocks base method +// DeleteDetector mocks base method. func (m *MockGateway) DeleteDetector(arg0 context.Context, arg1 string) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "DeleteDetector", arg0, arg1) @@ -57,13 +63,13 @@ func (m *MockGateway) DeleteDetector(arg0 context.Context, arg1 string) error { return ret0 } -// DeleteDetector indicates an expected call of DeleteDetector -func (mr *MockGatewayMockRecorder) DeleteDetector(arg0, arg1 interface{}) *gomock.Call { +// DeleteDetector indicates an expected call of DeleteDetector. +func (mr *MockGatewayMockRecorder) DeleteDetector(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteDetector", reflect.TypeOf((*MockGateway)(nil).DeleteDetector), arg0, arg1) } -// GetDetector mocks base method +// GetDetector mocks base method. func (m *MockGateway) GetDetector(arg0 context.Context, arg1 string) ([]byte, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetDetector", arg0, arg1) @@ -72,14 +78,14 @@ func (m *MockGateway) GetDetector(arg0 context.Context, arg1 string) ([]byte, er return ret0, ret1 } -// GetDetector indicates an expected call of GetDetector -func (mr *MockGatewayMockRecorder) GetDetector(arg0, arg1 interface{}) *gomock.Call { +// GetDetector indicates an expected call of GetDetector. +func (mr *MockGatewayMockRecorder) GetDetector(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDetector", reflect.TypeOf((*MockGateway)(nil).GetDetector), arg0, arg1) } -// SearchDetector mocks base method -func (m *MockGateway) SearchDetector(arg0 context.Context, arg1 interface{}) ([]byte, error) { +// SearchDetector mocks base method. +func (m *MockGateway) SearchDetector(arg0 context.Context, arg1 any) ([]byte, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SearchDetector", arg0, arg1) ret0, _ := ret[0].([]byte) @@ -87,13 +93,13 @@ func (m *MockGateway) SearchDetector(arg0 context.Context, arg1 interface{}) ([] return ret0, ret1 } -// SearchDetector indicates an expected call of SearchDetector -func (mr *MockGatewayMockRecorder) SearchDetector(arg0, arg1 interface{}) *gomock.Call { +// SearchDetector indicates an expected call of SearchDetector. +func (mr *MockGatewayMockRecorder) SearchDetector(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SearchDetector", reflect.TypeOf((*MockGateway)(nil).SearchDetector), arg0, arg1) } -// StartDetector mocks base method +// StartDetector mocks base method. func (m *MockGateway) StartDetector(arg0 context.Context, arg1 string) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StartDetector", arg0, arg1) @@ -101,13 +107,13 @@ func (m *MockGateway) StartDetector(arg0 context.Context, arg1 string) error { return ret0 } -// StartDetector indicates an expected call of StartDetector -func (mr *MockGatewayMockRecorder) StartDetector(arg0, arg1 interface{}) *gomock.Call { +// StartDetector indicates an expected call of StartDetector. +func (mr *MockGatewayMockRecorder) StartDetector(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartDetector", reflect.TypeOf((*MockGateway)(nil).StartDetector), arg0, arg1) } -// StopDetector mocks base method +// StopDetector mocks base method. func (m *MockGateway) StopDetector(arg0 context.Context, arg1 string) (*string, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StopDetector", arg0, arg1) @@ -116,22 +122,22 @@ func (m *MockGateway) StopDetector(arg0 context.Context, arg1 string) (*string, return ret0, ret1 } -// StopDetector indicates an expected call of StopDetector -func (mr *MockGatewayMockRecorder) StopDetector(arg0, arg1 interface{}) *gomock.Call { +// StopDetector indicates an expected call of StopDetector. +func (mr *MockGatewayMockRecorder) StopDetector(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StopDetector", reflect.TypeOf((*MockGateway)(nil).StopDetector), arg0, arg1) } -// UpdateDetector mocks base method -func (m *MockGateway) UpdateDetector(arg0 context.Context, arg1 string, arg2 interface{}) error { +// UpdateDetector mocks base method. +func (m *MockGateway) UpdateDetector(arg0 context.Context, arg1 string, arg2 any) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateDetector", arg0, arg1, arg2) ret0, _ := ret[0].(error) return ret0 } -// UpdateDetector indicates an expected call of UpdateDetector -func (mr *MockGatewayMockRecorder) UpdateDetector(arg0, arg1, arg2 interface{}) *gomock.Call { +// UpdateDetector indicates an expected call of UpdateDetector. +func (mr *MockGatewayMockRecorder) UpdateDetector(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateDetector", reflect.TypeOf((*MockGateway)(nil).UpdateDetector), arg0, arg1, arg2) } diff --git a/gateway/aws/signer/aws.go b/gateway/aws/signer/aws.go index b286444..581a359 100644 --- a/gateway/aws/signer/aws.go +++ b/gateway/aws/signer/aws.go @@ -17,9 +17,9 @@ import ( "opensearch-cli/entity" "time" - "github.com/aws/aws-sdk-go/aws/credentials" - "github.com/aws/aws-sdk-go/aws/session" - v4 "github.com/aws/aws-sdk-go/aws/signer/v4" + "github.com/aws/aws-sdk-go/aws/credentials" //nolint:staticcheck // TODO: migrate to aws-sdk-go-v2 + "github.com/aws/aws-sdk-go/aws/session" //nolint:staticcheck // TODO: migrate to aws-sdk-go-v2 + v4 "github.com/aws/aws-sdk-go/aws/signer/v4" //nolint:staticcheck // TODO: migrate to aws-sdk-go-v2 "github.com/hashicorp/go-retryablehttp" ) @@ -39,7 +39,7 @@ func sign(req *retryablehttp.Request, region *string, serviceName string, signer return err } -//SignRequest signs the request using SigV4 +// SignRequest signs the request using SigV4 func SignRequest(req *retryablehttp.Request, awsProfile entity.AWSIAM, getSigner func(*credentials.Credentials) *v4.Signer) error { awsSession, err := session.NewSessionWithOptions(session.Options{ Profile: awsProfile.ProfileName, diff --git a/gateway/aws/signer/aws_test.go b/gateway/aws/signer/aws_test.go index 83bed50..b27b45d 100644 --- a/gateway/aws/signer/aws_test.go +++ b/gateway/aws/signer/aws_test.go @@ -17,8 +17,8 @@ import ( "os" "testing" - "github.com/aws/aws-sdk-go/aws/credentials" - v4 "github.com/aws/aws-sdk-go/aws/signer/v4" + "github.com/aws/aws-sdk-go/aws/credentials" //nolint:staticcheck // TODO: migrate to aws-sdk-go-v2 + v4 "github.com/aws/aws-sdk-go/aws/signer/v4" //nolint:staticcheck // TODO: migrate to aws-sdk-go-v2 "github.com/hashicorp/go-retryablehttp" "github.com/stretchr/testify/assert" ) @@ -33,9 +33,9 @@ func TestV4Signer(t *testing.T) { t.Run("sign request success", func(t *testing.T) { req, _ := retryablehttp.NewRequest(http.MethodGet, "https://localhost:9200", nil) region := os.Getenv("AWS_REGION") - os.Setenv("AWS_REGION", "us-west-2") + _ = os.Setenv("AWS_REGION", "us-west-2") defer func() { - os.Setenv("AWS_REGION", region) + _ = os.Setenv("AWS_REGION", region) }() err := SignRequest(req, entity.AWSIAM{ ProfileName: "test1", @@ -51,9 +51,9 @@ func TestV4Signer(t *testing.T) { t.Run("sign request failed due to no region found", func(t *testing.T) { req, _ := retryablehttp.NewRequest(http.MethodGet, "https://localhost:9200", nil) region := os.Getenv("AWS_REGION") - os.Setenv("AWS_REGION", "") + _ = os.Setenv("AWS_REGION", "") defer func() { - os.Setenv("AWS_REGION", region) + _ = os.Setenv("AWS_REGION", region) }() err := SignRequest(req, entity.AWSIAM{ ProfileName: "test1", diff --git a/gateway/gateway.go b/gateway/gateway.go index e3b47b3..63db7ec 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -177,7 +177,7 @@ func (g *HTTPGateway) Call(req *retryablehttp.Request, statusCode int) ([]byte, return nil, err } if r.StatusCode() != statusCode { - return nil, fmt.Errorf(r.GetResponse()) + return nil, fmt.Errorf("%s", r.GetResponse()) } return nil, err @@ -218,13 +218,13 @@ func (g *HTTPGateway) BuildCurlRequest(ctx context.Context, method string, paylo // BuildCurlMultipartFormRequest builds multipart file-upload request based on method and add payload (in byte) func (g *HTTPGateway) BuildCurlMultipartFormRequest(ctx context.Context, method string, filePath string, url string, headers map[string]string) (*retryablehttp.Request, error) { file, _ := os.Open(filePath) - defer file.Close() + defer func() { _ = file.Close() }() body := &bytes.Buffer{} writer := multipart.NewWriter(body) part, _ := writer.CreateFormFile("file", filePath) _, _ = io.Copy(part, file) - writer.Close() + _ = writer.Close() r, err := retryablehttp.NewRequest(method, url, body) diff --git a/gateway/gateway_test.go b/gateway/gateway_test.go index bd2b3d2..a01bb55 100644 --- a/gateway/gateway_test.go +++ b/gateway/gateway_test.go @@ -77,7 +77,7 @@ func TestGatewayRetryVal(t *testing.T) { defer func() { assert.NoError(t, os.Setenv(environment.OPENSEARCH_MAX_RETRY, val)) }() - os.Setenv(environment.OPENSEARCH_MAX_RETRY, "10") + _ = os.Setenv(environment.OPENSEARCH_MAX_RETRY, "10") valAttempt := 2 profile := entity.Profile{ Name: "test1", @@ -120,7 +120,7 @@ func TestGatewayConnectionTimeout(t *testing.T) { defer func() { assert.NoError(t, os.Setenv(environment.OPENSEARCH_TIMEOUT, val)) }() - os.Setenv(environment.OPENSEARCH_TIMEOUT, "5") + _ = os.Setenv(environment.OPENSEARCH_TIMEOUT, "5") timeout := int64(60) profile := entity.Profile{ Name: "test1", diff --git a/gateway/knn/knn.go b/gateway/knn/knn.go index 3b155fa..1ce4b1b 100644 --- a/gateway/knn/knn.go +++ b/gateway/knn/knn.go @@ -31,7 +31,7 @@ const ( warmupIndicesURLTemplate = baseURL + "/warmup/%s" ) -//go:generate go run -mod=mod github.com/golang/mock/mockgen -destination=mocks/mock_knn.go -package=mocks . Gateway +//go:generate go run -mod=mod go.uber.org/mock/mockgen -destination=mocks/mock_knn.go -package=mocks . Gateway // Gateway interface to k-NN Plugin type Gateway interface { @@ -53,7 +53,7 @@ func New(c *client.Client, p *entity.Profile) (Gateway, error) { } -//buildStatsURL to construct url for stats +// buildStatsURL to construct url for stats func (g *gateway) buildStatsURL(nodes string, names string) (*url.URL, error) { endpoint, err := gw.GetValidEndpoint(g.Profile) if err != nil { @@ -68,7 +68,7 @@ func (g *gateway) buildStatsURL(nodes string, names string) (*url.URL, error) { return endpoint, nil } -//buildWarmupURL to construct url for warming up indices +// buildWarmupURL to construct url for warming up indices func (g *gateway) buildWarmupURL(indices string) (*url.URL, error) { endpoint, err := gw.GetValidEndpoint(g.Profile) if err != nil { @@ -78,46 +78,49 @@ func (g *gateway) buildWarmupURL(indices string) (*url.URL, error) { return endpoint, nil } -/*GetStatistics provides information about the current status of the KNN Plugin. +/* +GetStatistics provides information about the current status of the KNN Plugin. GET /_plugins/_knn/stats -{ - "_nodes" : { - "total" : 1, - "successful" : 1, - "failed" : 0 - }, - "cluster_name" : "_run", - "circuit_breaker_triggered" : false, - "nodes" : { - "HYMrXXsBSamUkcAjhjeN0w" : { - "eviction_count" : 0, - "miss_count" : 1, - "graph_memory_usage" : 1, - "graph_memory_usage_percentage" : 3.68, - "graph_index_requests" : 7, - "graph_index_errors" : 1, - "knn_query_requests" : 4, - "graph_query_requests" : 30, - "graph_query_errors" : 15, - "indices_in_cache" : { - "myindex" : { - "graph_memory_usage" : 2, - "graph_memory_usage_percentage" : 3.68, - "graph_count" : 2 - } - }, - "cache_capacity_reached" : false, - "load_exception_count" : 0, - "hit_count" : 0, - "load_success_count" : 1, - "total_load_time" : 2878745, - "script_compilations" : 1, - "script_compilation_errors" : 0, - "script_query_requests" : 534, - "script_query_errors" : 0 - } - } -} + + { + "_nodes" : { + "total" : 1, + "successful" : 1, + "failed" : 0 + }, + "cluster_name" : "_run", + "circuit_breaker_triggered" : false, + "nodes" : { + "HYMrXXsBSamUkcAjhjeN0w" : { + "eviction_count" : 0, + "miss_count" : 1, + "graph_memory_usage" : 1, + "graph_memory_usage_percentage" : 3.68, + "graph_index_requests" : 7, + "graph_index_errors" : 1, + "knn_query_requests" : 4, + "graph_query_requests" : 30, + "graph_query_errors" : 15, + "indices_in_cache" : { + "myindex" : { + "graph_memory_usage" : 2, + "graph_memory_usage_percentage" : 3.68, + "graph_count" : 2 + } + }, + "cache_capacity_reached" : false, + "load_exception_count" : 0, + "hit_count" : 0, + "load_success_count" : 1, + "total_load_time" : 2878745, + "script_compilations" : 1, + "script_compilation_errors" : 0, + "script_query_requests" : 534, + "script_query_errors" : 0 + } + } + } + To filter stats query by nodeID and statName: GET /_plugins/_knn/nodeId1,nodeId2/stats/statName1,statName2 */ @@ -150,15 +153,18 @@ func processKNNError(err error) error { return err } -/* WarmupIndices will perform warmup on given indices +/* + WarmupIndices will perform warmup on given indices + GET /_plugins/_knn/warmup/index1,index2,index3?pretty -{ - "_shards" : { - "total" : 6, - "successful" : 6, - "failed" : 0 + + { + "_shards" : { + "total" : 6, + "successful" : 6, + "failed" : 0 + } } -} */ func (g gateway) WarmupIndices(ctx context.Context, indices string) ([]byte, error) { warmupURL, err := g.buildWarmupURL(indices) diff --git a/gateway/knn/mocks/mock_knn.go b/gateway/knn/mocks/mock_knn.go index a74e43d..b555f08 100644 --- a/gateway/knn/mocks/mock_knn.go +++ b/gateway/knn/mocks/mock_knn.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: opensearch-cli/gateway/knn (interfaces: Gateway) +// +// Generated by this command: +// +// mockgen -destination=mocks/mock_knn.go -package=mocks . Gateway +// // Package mocks is a generated GoMock package. package mocks @@ -8,58 +13,59 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) -// MockGateway is a mock of Gateway interface +// MockGateway is a mock of Gateway interface. type MockGateway struct { ctrl *gomock.Controller recorder *MockGatewayMockRecorder + isgomock struct{} } -// MockGatewayMockRecorder is the mock recorder for MockGateway +// MockGatewayMockRecorder is the mock recorder for MockGateway. type MockGatewayMockRecorder struct { mock *MockGateway } -// NewMockGateway creates a new mock instance +// NewMockGateway creates a new mock instance. func NewMockGateway(ctrl *gomock.Controller) *MockGateway { mock := &MockGateway{ctrl: ctrl} mock.recorder = &MockGatewayMockRecorder{mock} return mock } -// EXPECT returns an object that allows the caller to indicate expected use +// EXPECT returns an object that allows the caller to indicate expected use. func (m *MockGateway) EXPECT() *MockGatewayMockRecorder { return m.recorder } -// GetStatistics mocks base method -func (m *MockGateway) GetStatistics(arg0 context.Context, arg1, arg2 string) ([]byte, error) { +// GetStatistics mocks base method. +func (m *MockGateway) GetStatistics(ctx context.Context, nodes, names string) ([]byte, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetStatistics", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "GetStatistics", ctx, nodes, names) ret0, _ := ret[0].([]byte) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetStatistics indicates an expected call of GetStatistics -func (mr *MockGatewayMockRecorder) GetStatistics(arg0, arg1, arg2 interface{}) *gomock.Call { +// GetStatistics indicates an expected call of GetStatistics. +func (mr *MockGatewayMockRecorder) GetStatistics(ctx, nodes, names any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStatistics", reflect.TypeOf((*MockGateway)(nil).GetStatistics), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStatistics", reflect.TypeOf((*MockGateway)(nil).GetStatistics), ctx, nodes, names) } -// WarmupIndices mocks base method -func (m *MockGateway) WarmupIndices(arg0 context.Context, arg1 string) ([]byte, error) { +// WarmupIndices mocks base method. +func (m *MockGateway) WarmupIndices(ctx context.Context, indices string) ([]byte, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "WarmupIndices", arg0, arg1) + ret := m.ctrl.Call(m, "WarmupIndices", ctx, indices) ret0, _ := ret[0].([]byte) ret1, _ := ret[1].(error) return ret0, ret1 } -// WarmupIndices indicates an expected call of WarmupIndices -func (mr *MockGatewayMockRecorder) WarmupIndices(arg0, arg1 interface{}) *gomock.Call { +// WarmupIndices indicates an expected call of WarmupIndices. +func (mr *MockGatewayMockRecorder) WarmupIndices(ctx, indices any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WarmupIndices", reflect.TypeOf((*MockGateway)(nil).WarmupIndices), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WarmupIndices", reflect.TypeOf((*MockGateway)(nil).WarmupIndices), ctx, indices) } diff --git a/gateway/platform/mocks/mock_platform.go b/gateway/platform/mocks/mock_platform.go index 6a80fd9..23b5aaf 100644 --- a/gateway/platform/mocks/mock_platform.go +++ b/gateway/platform/mocks/mock_platform.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: opensearch-cli/gateway/platform (interfaces: Gateway) +// +// Generated by this command: +// +// mockgen -destination=mocks/mock_platform.go -package=mocks . Gateway +// // Package mocks is a generated GoMock package. package mocks @@ -9,58 +14,59 @@ import ( platform "opensearch-cli/entity/platform" reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) -// MockGateway is a mock of Gateway interface +// MockGateway is a mock of Gateway interface. type MockGateway struct { ctrl *gomock.Controller recorder *MockGatewayMockRecorder + isgomock struct{} } -// MockGatewayMockRecorder is the mock recorder for MockGateway +// MockGatewayMockRecorder is the mock recorder for MockGateway. type MockGatewayMockRecorder struct { mock *MockGateway } -// NewMockGateway creates a new mock instance +// NewMockGateway creates a new mock instance. func NewMockGateway(ctrl *gomock.Controller) *MockGateway { mock := &MockGateway{ctrl: ctrl} mock.recorder = &MockGatewayMockRecorder{mock} return mock } -// EXPECT returns an object that allows the caller to indicate expected use +// EXPECT returns an object that allows the caller to indicate expected use. func (m *MockGateway) EXPECT() *MockGatewayMockRecorder { return m.recorder } -// Curl mocks base method -func (m *MockGateway) Curl(arg0 context.Context, arg1 platform.CurlRequest) ([]byte, error) { +// Curl mocks base method. +func (m *MockGateway) Curl(ctx context.Context, request platform.CurlRequest) ([]byte, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Curl", arg0, arg1) + ret := m.ctrl.Call(m, "Curl", ctx, request) ret0, _ := ret[0].([]byte) ret1, _ := ret[1].(error) return ret0, ret1 } -// Curl indicates an expected call of Curl -func (mr *MockGatewayMockRecorder) Curl(arg0, arg1 interface{}) *gomock.Call { +// Curl indicates an expected call of Curl. +func (mr *MockGatewayMockRecorder) Curl(ctx, request any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Curl", reflect.TypeOf((*MockGateway)(nil).Curl), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Curl", reflect.TypeOf((*MockGateway)(nil).Curl), ctx, request) } -// SearchDistinctValues mocks base method -func (m *MockGateway) SearchDistinctValues(arg0 context.Context, arg1, arg2 string) ([]byte, error) { +// SearchDistinctValues mocks base method. +func (m *MockGateway) SearchDistinctValues(ctx context.Context, index, field string) ([]byte, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SearchDistinctValues", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "SearchDistinctValues", ctx, index, field) ret0, _ := ret[0].([]byte) ret1, _ := ret[1].(error) return ret0, ret1 } -// SearchDistinctValues indicates an expected call of SearchDistinctValues -func (mr *MockGatewayMockRecorder) SearchDistinctValues(arg0, arg1, arg2 interface{}) *gomock.Call { +// SearchDistinctValues indicates an expected call of SearchDistinctValues. +func (mr *MockGatewayMockRecorder) SearchDistinctValues(ctx, index, field any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SearchDistinctValues", reflect.TypeOf((*MockGateway)(nil).SearchDistinctValues), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SearchDistinctValues", reflect.TypeOf((*MockGateway)(nil).SearchDistinctValues), ctx, index, field) } diff --git a/gateway/platform/platform.go b/gateway/platform/platform.go index 1b0c9d7..675adbf 100644 --- a/gateway/platform/platform.go +++ b/gateway/platform/platform.go @@ -26,7 +26,7 @@ import ( const search = "_search" -//go:generate go run -mod=mod github.com/golang/mock/mockgen -destination=mocks/mock_platform.go -package=mocks . Gateway +//go:generate go run -mod=mod go.uber.org/mock/mockgen -destination=mocks/mock_platform.go -package=mocks . Gateway // Gateway interface to call OpenSearch type Gateway interface { diff --git a/go.mod b/go.mod index 26b205d..81ab182 100644 --- a/go.mod +++ b/go.mod @@ -1,32 +1,33 @@ module opensearch-cli -go 1.18 +go 1.26 require ( - github.com/aws/aws-sdk-go v1.37.25 - github.com/cheggaaa/pb/v3 v3.0.5 - github.com/golang/mock v1.4.4 - github.com/hashicorp/go-retryablehttp v0.6.7 - github.com/spf13/cobra v1.5.0 - github.com/stretchr/testify v1.6.1 - golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf - gopkg.in/yaml.v2 v2.4.0 - gopkg.in/yaml.v3 v3.0.0 + github.com/aws/aws-sdk-go v1.55.8 + github.com/cheggaaa/pb/v3 v3.1.7 + github.com/hashicorp/go-retryablehttp v0.7.8 + github.com/spf13/cobra v1.10.2 + github.com/stretchr/testify v1.11.1 + golang.org/x/term v0.41.0 + gopkg.in/yaml.v3 v3.0.1 ) +require github.com/rivo/uniseg v0.4.7 // indirect + require ( - github.com/VividCortex/ewma v1.1.1 // indirect + github.com/VividCortex/ewma v1.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/fatih/color v1.7.0 // indirect - github.com/hashicorp/go-cleanhttp v0.5.1 // indirect - github.com/inconshreveable/mousetrap v1.0.1 // indirect + github.com/fatih/color v1.18.0 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/kr/pretty v0.1.0 // indirect - github.com/mattn/go-colorable v0.1.2 // indirect - github.com/mattn/go-isatty v0.0.12 // indirect - github.com/mattn/go-runewidth v0.0.7 // indirect + github.com/mattn/go-colorable v0.1.14 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-runewidth v0.0.16 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/sys v0.4.0 // indirect + github.com/spf13/pflag v1.0.9 // indirect + go.uber.org/mock v0.6.0 + golang.org/x/sys v0.42.0 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect ) diff --git a/go.sum b/go.sum index 12b07cf..7baebfb 100644 --- a/go.sum +++ b/go.sum @@ -1,26 +1,23 @@ -github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM= -github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA= -github.com/aws/aws-sdk-go v1.37.25 h1:q1C/ILIVusSmqgWG4tFU0uVt3Zm+1I3L2BmNCd2Ug4Q= -github.com/aws/aws-sdk-go v1.37.25/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= -github.com/cheggaaa/pb/v3 v3.0.5 h1:lmZOti7CraK9RSjzExsY53+WWfub9Qv13B5m4ptEoPE= -github.com/cheggaaa/pb/v3 v3.0.5/go.mod h1:X1L61/+36nz9bjIsrDU52qHKOQukUQe2Ge+YvGuquCw= -github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow= +github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4= +github.com/aws/aws-sdk-go v1.55.8 h1:JRmEUbU52aJQZ2AjX4q4Wu7t4uZjOu71uyNmaWlUkJQ= +github.com/aws/aws-sdk-go v1.55.8/go.mod h1:ZkViS9AqA6otK+JBBNH2++sx1sgxrPKcSzPPvQkUtXk= +github.com/cheggaaa/pb/v3 v3.1.7 h1:2FsIW307kt7A/rz/ZI2lvPO+v3wKazzE4K/0LtTWsOI= +github.com/cheggaaa/pb/v3 v3.1.7/go.mod h1:/Ji89zfVPeC/u5j8ukD0MBPHt2bzTYp74lQ7KlgFWTQ= +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc= -github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= -github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= -github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI= -github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= -github.com/hashicorp/go-retryablehttp v0.6.7 h1:8/CAEZt/+F7kR7GevNHulKkUjLht3CPmn7egmhieNKo= -github.com/hashicorp/go-retryablehttp v0.6.7/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= -github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= +github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= +github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= +github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= +github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= +github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= +github.com/hashicorp/go-retryablehttp v0.7.8 h1:ylXZWnqa7Lhqpk0L1P1LzDtGcCR0rPVUrx/c8Unxc48= +github.com/hashicorp/go-retryablehttp v0.7.8/go.mod h1:rjiScheydd+CxvumBsIrFKlx3iS0jrZ7LvzFGFmuKbw= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= @@ -30,51 +27,43 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= -github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54= -github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= +github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU= -github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= +github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= +github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY= +github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= -golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M= -golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= +go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= +golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ= +golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc= +golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw= +golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= +golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/term v0.41.0 h1:QCgPso/Q3RTJx2Th4bDLqML4W6iJiaXFq2/ftQF13YU= +golang.org/x/term v0.41.0/go.mod h1:3pfBgksrReYfZ5lvYM0kSO0LIkAl4Yl2bXOkKP7Ec2A= +golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg= +golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= -gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/handler/ad/ad_test.go b/handler/ad/ad_test.go index d5bd4d7..f1b7651 100644 --- a/handler/ad/ad_test.go +++ b/handler/ad/ad_test.go @@ -20,8 +20,8 @@ import ( "opensearch-cli/mapper" "testing" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" ) func getRawFilter() []byte { @@ -323,14 +323,12 @@ func TestHandlerUpdateDetector(t *testing.T) { } t.Run("update invalid file name", func(t *testing.T) { mockedController := mocks.NewMockController(mockCtrl) - mockedController.EXPECT().UpdateDetector(ctx, input, true, true).Return(errors.New("failed to update")) instance := New(mockedController) err := instance.UpdateDetector("", true, true) assert.EqualError(t, err, "file name cannot be empty") }) t.Run("update invalid file contents", func(t *testing.T) { mockedController := mocks.NewMockController(mockCtrl) - mockedController.EXPECT().UpdateDetector(ctx, input, true, true).Return(errors.New("failed to update")) instance := New(mockedController) err := instance.UpdateDetector("testdata/invalid.txt", true, true) assert.EqualError(t, err, "file testdata/invalid.txt cannot be accepted due to invalid character 'i' looking for beginning of value") diff --git a/handler/knn/knn.go b/handler/knn/knn.go index bc105c1..3279350 100644 --- a/handler/knn/knn.go +++ b/handler/knn/knn.go @@ -18,7 +18,7 @@ import ( entity "opensearch-cli/entity/knn" ) -//Handler is facade for controller +// Handler is facade for controller type Handler struct { knn.Controller } @@ -30,12 +30,12 @@ func New(controller knn.Controller) *Handler { } } -//GetStatistics gets stats data based on nodes and stat names +// GetStatistics gets stats data based on nodes and stat names func GetStatistics(h *Handler, nodes string, names string) ([]byte, error) { return h.GetStatistics(nodes, names) } -//GetStatistics gets stats data based on nodes and stat names +// GetStatistics gets stats data based on nodes and stat names func (h *Handler) GetStatistics(nodes string, names string) ([]byte, error) { ctx := context.Background() response, err := h.Controller.GetStatistics(ctx, nodes, names) @@ -50,12 +50,12 @@ func (h *Handler) GetStatistics(nodes string, names string) ([]byte, error) { return json.MarshalIndent(data, "", " ") } -//WarmupIndices warmups knn index +// WarmupIndices warmups knn index func WarmupIndices(h *Handler, index []string) (*entity.Shards, error) { return h.WarmupIndices(index) } -//WarmupIndices warmups shard based on knn index and returns status of shards +// WarmupIndices warmups shard based on knn index and returns status of shards func (h *Handler) WarmupIndices(index []string) (*entity.Shards, error) { ctx := context.Background() return h.Controller.WarmupIndices(ctx, index) diff --git a/handler/knn/knn_test.go b/handler/knn/knn_test.go index 59d51d7..41db534 100644 --- a/handler/knn/knn_test.go +++ b/handler/knn/knn_test.go @@ -18,8 +18,8 @@ import ( entity "opensearch-cli/entity/knn" "testing" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" ) func TestHandlerGetStatistics(t *testing.T) { diff --git a/handler/platform/platform.go b/handler/platform/platform.go index 8541a13..2ccd47b 100644 --- a/handler/platform/platform.go +++ b/handler/platform/platform.go @@ -17,7 +17,7 @@ import ( entity "opensearch-cli/entity/platform" ) -//Handler is facade for controller +// Handler is facade for controller type Handler struct { platform.Controller } @@ -29,12 +29,12 @@ func New(controller platform.Controller) *Handler { } } -//Curl executes REST API as defined by curl command +// Curl executes REST API as defined by curl command func Curl(h *Handler, request entity.CurlCommandRequest) ([]byte, error) { return h.Curl(request) } -//Curl executes REST API as defined by curl command +// Curl executes REST API as defined by curl command func (h *Handler) Curl(request entity.CurlCommandRequest) ([]byte, error) { ctx := context.Background() return h.Controller.Curl(ctx, request) diff --git a/handler/platform/platform_test.go b/handler/platform/platform_test.go index 4bf7eca..bb295d2 100644 --- a/handler/platform/platform_test.go +++ b/handler/platform/platform_test.go @@ -18,8 +18,8 @@ import ( entity "opensearch-cli/entity/platform" "testing" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" ) func TestHandlerCurl(t *testing.T) { diff --git a/it/ad_test.go b/it/ad_test.go index 5c0e2cc..c4c54e7 100644 --- a/it/ad_test.go +++ b/it/ad_test.go @@ -41,7 +41,7 @@ const ( EcommerceIndexMappingFileName = "ecommerce-mapping" ) -//ADTestSuite suite specific to AD plugin +// ADTestSuite suite specific to AD plugin type ADTestSuite struct { CLISuite DetectorRequest adentity.CreateDetectorRequest @@ -62,7 +62,7 @@ func getRawFeatureAggregation() []byte { }`) } -//SetupSuite runs once for every test suite +// SetupSuite runs once for every test suite func (a *ADTestSuite) SetupSuite() { var err error a.Plugins = append(a.Plugins, "opensearch-anomaly-detection") @@ -144,7 +144,7 @@ func (a *ADTestSuite) AfterTest(suiteName, testName string) { } } -//DeleteDetectorUsingRESTAPI helper to delete detector using rest api +// DeleteDetectorUsingRESTAPI helper to delete detector using rest api func (a *ADTestSuite) DeleteDetectorUsingRESTAPI(t *testing.T, ID string) { indexURL := fmt.Sprintf("%s/_plugins/_anomaly_detection/detectors/%s", a.Profile.Endpoint, ID) _, err := a.callRequest(http.MethodDelete, []byte(""), indexURL) @@ -153,7 +153,7 @@ func (a *ADTestSuite) DeleteDetectorUsingRESTAPI(t *testing.T, ID string) { } } -//StartDetectorUsingRESTAPI helper to start detector using rest api +// StartDetectorUsingRESTAPI helper to start detector using rest api func (a *ADTestSuite) StartDetectorUsingRESTAPI(t *testing.T, ID string) { if ID == "" { t.Fatal("Detector ID cannot be empty") @@ -165,7 +165,7 @@ func (a *ADTestSuite) StartDetectorUsingRESTAPI(t *testing.T, ID string) { } } -//StopDetectorUsingRESTAPI helper to stop detector using rest api +// StopDetectorUsingRESTAPI helper to stop detector using rest api func (a *ADTestSuite) StopDetectorUsingRESTAPI(t *testing.T, ID string) { if ID == "" { t.Fatal("Detector ID cannot be empty") @@ -177,7 +177,7 @@ func (a *ADTestSuite) StopDetectorUsingRESTAPI(t *testing.T, ID string) { } } -//CreateDetectorUsingRESTAPI helper to create detector using rest api +// CreateDetectorUsingRESTAPI helper to create detector using rest api func (a *ADTestSuite) CreateDetectorUsingRESTAPI(t *testing.T) { indexURL := fmt.Sprintf("%s/_plugins/_anomaly_detection/detectors", a.Profile.Endpoint) reqBytes, err := json.Marshal(a.Detector) diff --git a/it/knn_test.go b/it/knn_test.go index 94fc0ff..4736210 100644 --- a/it/knn_test.go +++ b/it/knn_test.go @@ -37,14 +37,14 @@ const ( KnnSampleIndexMappingFileName = "knn-sample-index-mapping" ) -//KNNTestSuite suite specific to k-NN plugin +// KNNTestSuite suite specific to k-NN plugin type KNNTestSuite struct { CLISuite Gateway gateway.Gateway Controller ctrl.Controller } -//SetupSuite runs once for every test suite +// SetupSuite runs once for every test suite func (a *KNNTestSuite) SetupSuite() { var err error a.Client, err = client.New(nil) @@ -71,7 +71,7 @@ func (a *KNNTestSuite) TearDownSuite() { a.DeleteIndex(KNNSampleIndexFileName) } -//GetNodesIDUsingRESTAPI helper to get node id using rest api +// GetNodesIDUsingRESTAPI helper to get node id using rest api func (a *KNNTestSuite) GetNodesIDUsingRESTAPI(t *testing.T) string { indexURL := fmt.Sprintf("%s/_cat/nodes?full_id=true&h=id", a.Profile.Endpoint) response, err := a.callRequest(http.MethodGet, []byte(""), indexURL) diff --git a/it/platform/curl_test.go b/it/platform/curl_test.go index 9e12f43..565a642 100644 --- a/it/platform/curl_test.go +++ b/it/platform/curl_test.go @@ -29,7 +29,7 @@ import ( "strings" "testing" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" @@ -37,7 +37,7 @@ import ( const GetBulkIndexName = "bulk-user-request" -//OpenSearchTestSuite suite tests OpenSearch REST API REQUESTS +// OpenSearchTestSuite suite tests OpenSearch REST API REQUESTS type OpenSearchTestSuite struct { it.CLISuite Gateway gateway.Gateway @@ -48,7 +48,7 @@ type result struct { Source map[string]interface{} `json:"_source"` } -//SetupSuite runs once for every test suite +// SetupSuite runs once for every test suite func (a *OpenSearchTestSuite) SetupSuite() { var err error a.Client, err = client.New(nil) diff --git a/mapper/ad/ad.go b/mapper/ad/ad.go index f2ff55f..79cf998 100644 --- a/mapper/ad/ad.go +++ b/mapper/ad/ad.go @@ -130,7 +130,7 @@ func mapIntervalToStringPtr(request ad.Interval) (*string, error) { return mapper.StringToStringPtr(fmt.Sprintf("%d%s", duration, *unit)), nil } -//MapToCreateDetector maps to CreateDetector +// MapToCreateDetector maps to CreateDetector func MapToCreateDetector(request ad.CreateDetectorRequest) (*ad.CreateDetector, error) { var features []ad.Feature @@ -177,7 +177,7 @@ func validateFeatureLimit(features []ad.FeatureRequest) error { return nil } -//MapToDetectors maps response to detectors +// MapToDetectors maps response to detectors func MapToDetectors(searchResponse []byte, name string) ([]ad.Detector, error) { var data ad.SearchResponse err := json.Unmarshal(searchResponse, &data) diff --git a/release/build.sh b/release/build.sh index 0f02491..16a93af 100755 --- a/release/build.sh +++ b/release/build.sh @@ -21,7 +21,7 @@ cd $GIT_ROOT # We need to start from repository root ##################################################### echo 'setting cli version' -export VERSION="1.2.0" +export VERSION="1.3.0" echo 'Generating artifacts' goreleaser --snapshot --skip-publish --clean