Skip to content

CLOUDP-57861: Describe available measurements for partition of the given process, OM #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ gen-mocks: ## Generate mocks
mockgen -source=internal/store/hosts.go -destination=internal/mocks/mock_hosts.go -package=mocks
mockgen -source=internal/store/host_databases.go -destination=internal/mocks/mock_host_databases.go -package=mocks
mockgen -source=internal/store/host_disks.go -destination=internal/mocks/mock_host_disks.go -package=mocks
mockgen -source=internal/store/host_disk_measurements.go -destination=internal/mocks/mock_host_disk_measurements.go -package=mocks

.PHONY: build
build: ## Generate a binary in ./bin
Expand Down
1 change: 1 addition & 0 deletions internal/cli/ops_manager_measurements_disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func OpsManagerMeasurementsDisksBuilder() *cobra.Command {
}

cmd.AddCommand(OpsManagerMeasurementsDisksListBuilder())
cmd.AddCommand(OpsManagerMeasurementsDisksDescribeBuilder())

return cmd
}
87 changes: 87 additions & 0 deletions internal/cli/ops_manager_measurements_disks_describe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2020 MongoDB Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cli

import (
"github.com/mongodb/mongocli/internal/description"
"github.com/mongodb/mongocli/internal/flags"
"github.com/mongodb/mongocli/internal/json"
"github.com/mongodb/mongocli/internal/store"
"github.com/mongodb/mongocli/internal/usage"
"github.com/spf13/cobra"
)

type opsManagerMeasurementsDisksDescribeOpts struct {
globalOpts
measurementsOpts
hostID string
name string
store store.HostDiskMeasurementsLister
}

func (opts *opsManagerMeasurementsDisksDescribeOpts) init() error {
if opts.ProjectID() == "" {
return errMissingProjectID
}

var err error
opts.store, err = store.New()
return err
}

func (opts *opsManagerMeasurementsDisksDescribeOpts) Run() error {
listOpts := opts.newProcessMeasurementListOptions()
result, err := opts.store.HostDiskMeasurements(opts.ProjectID(), opts.hostID, opts.name, listOpts)

if err != nil {
return err
}

return json.PrettyPrint(result)
}

// mcli om measurements disk(s) describe [host:port] [name] --granularity g --period p --start start --end end [--type type] [--projectId projectId]
func OpsManagerMeasurementsDisksDescribeBuilder() *cobra.Command {
opts := &opsManagerMeasurementsDisksDescribeOpts{}
cmd := &cobra.Command{
Use: "describe [hostId] [name]",
Short: description.ListDisks,
Args: cobra.ExactArgs(2),
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.init()
},
RunE: func(cmd *cobra.Command, args []string) error {
opts.hostID = args[0]
opts.name = args[1]

return opts.Run()
},
}

cmd.Flags().IntVar(&opts.pageNum, flags.Page, 0, usage.Page)
cmd.Flags().IntVar(&opts.itemsPerPage, flags.Limit, 0, usage.Limit)

cmd.Flags().StringVar(&opts.granularity, flags.Granularity, "", usage.Granularity)
cmd.Flags().StringVar(&opts.period, flags.Period, "", usage.Period)
cmd.Flags().StringVar(&opts.start, flags.Start, "", usage.Start)
cmd.Flags().StringVar(&opts.end, flags.End, "", usage.End)
cmd.Flags().StringVar(&opts.measurementType, flags.MeasurementType, "", usage.MeasurementType)

cmd.Flags().StringVar(&opts.projectID, flags.ProjectID, "", usage.ProjectID)

_ = cmd.MarkFlagRequired(flags.Granularity)

return cmd
}
48 changes: 48 additions & 0 deletions internal/cli/ops_manager_measurements_disks_describe_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2020 MongoDB Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cli

import (
"testing"

"github.com/golang/mock/gomock"
"github.com/mongodb/mongocli/internal/fixtures"
"github.com/mongodb/mongocli/internal/mocks"
)

func TestOpsManagerMeasurementsDisksDescribeOpts_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockHostDiskMeasurementsLister(ctrl)

defer ctrl.Finish()

expected := fixtures.DiskMeasurements()

listOpts := &opsManagerMeasurementsDisksDescribeOpts{
hostID: "1",
name: "test",
store: mockStore,
}

opts := listOpts.newProcessMeasurementListOptions()
mockStore.
EXPECT().HostDiskMeasurements(listOpts.projectID, listOpts.hostID, listOpts.name, opts).
Return(expected, nil).
Times(1)

err := listOpts.Run()
if err != nil {
t.Fatalf("Run() unexpected error: %v", err)
}
}
49 changes: 49 additions & 0 deletions internal/mocks/mock_host_disk_measurements.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions internal/store/host_disk_measurements.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2020 MongoDB Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package store

import (
"context"
"fmt"

atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas"
om "github.com/mongodb/go-client-mongodb-ops-manager/opsmngr"
"github.com/mongodb/mongocli/internal/config"
)

type HostDiskMeasurementsLister interface {
HostDiskMeasurements(string, string, string, *atlas.ProcessMeasurementListOptions) (*atlas.ProcessDiskMeasurements, error)
}

// HostDiskMeasurements encapsulate the logic to manage different cloud providers
func (s *Store) HostDiskMeasurements(groupID, hostID string, partitionName string, opts *atlas.ProcessMeasurementListOptions) (*atlas.ProcessDiskMeasurements, error) {
switch s.service {
case config.OpsManagerService, config.CloudManagerService:
result, _, err := s.client.(*om.Client).HostDiskMeasurements.List(context.Background(), groupID, hostID, partitionName, opts)
return result, err
default:
return nil, fmt.Errorf("unsupported service: %s", s.service)
}
}