Skip to content

Commit 8c67af1

Browse files
CLOUDP-57860: List all available measurements for the given process, C/OM (#87)
1 parent 0972f6a commit 8c67af1

11 files changed

+249
-51
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ require (
1111
github.com/mattn/go-colorable v0.1.4 // indirect
1212
github.com/mattn/go-isatty v0.0.12 // indirect
1313
github.com/mitchellh/go-homedir v1.1.0
14-
github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200402143647-b2e23a196304
15-
github.com/mongodb/go-client-mongodb-ops-manager v0.0.2-0.20200402144858-5160c11d086a
14+
github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200402145105-fa504e988bc4
15+
github.com/mongodb/go-client-mongodb-ops-manager v0.0.2-0.20200403094933-ec3d0be6337f
1616
github.com/mwielbut/pointy v1.1.0
1717
github.com/pelletier/go-toml v1.6.0 // indirect
1818
github.com/spf13/afero v1.2.2

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG
100100
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
101101
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
102102
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
103-
github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200402143647-b2e23a196304 h1:a0DEfd6CnbzNCJMd0MYlGeJtkWhYfK3oKc9hy2zlHtM=
104-
github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200402143647-b2e23a196304/go.mod h1:LS8O0YLkA+sbtOb3fZLF10yY3tJM+1xATXMJ3oU35LU=
105-
github.com/mongodb/go-client-mongodb-ops-manager v0.0.2-0.20200402144858-5160c11d086a h1:wbPx1buq9k8+qUAj8E0AAjQXW3tu5/arkquLS/JkHGk=
106-
github.com/mongodb/go-client-mongodb-ops-manager v0.0.2-0.20200402144858-5160c11d086a/go.mod h1:f1twYK+bhPSmHEGclypJ2IsiNEXIqXwli3EYUc9OUII=
103+
github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200402145105-fa504e988bc4 h1:2moeNJ0DF03xNA3PzOBPUbtv635Cd9CC50OUwl1uVSI=
104+
github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200402145105-fa504e988bc4/go.mod h1:LS8O0YLkA+sbtOb3fZLF10yY3tJM+1xATXMJ3oU35LU=
105+
github.com/mongodb/go-client-mongodb-ops-manager v0.0.2-0.20200403094933-ec3d0be6337f h1:p9DI0e/umHLmrOizpx3SFt32bXyAVnke7VQQPAQeJPg=
106+
github.com/mongodb/go-client-mongodb-ops-manager v0.0.2-0.20200403094933-ec3d0be6337f/go.mod h1:tSyj9LVpQjQciu2gDLSd6GZ3lK5X/tYu8usQga6yslI=
107107
github.com/mwielbut/pointy v1.1.0 h1:U5/YEfoIkaGCHv0St3CgjduqXID4FNRoyZgLM1kY9vg=
108108
github.com/mwielbut/pointy v1.1.0/go.mod h1:MvvO+uMFj9T5DMda33HlvogsFBX7pWWKAkFIn4teYwY=
109109
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=

internal/cli/atlas_measurements_process.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type atlasMeasurementsProcessOpts struct {
3535
start string
3636
end string
3737
measurementType string
38-
store store.ProcessMeasurementLister
38+
store store.AtlasProcessMeasurementLister
3939
}
4040

4141
func (opts *atlasMeasurementsProcessOpts) init() error {
@@ -50,7 +50,7 @@ func (opts *atlasMeasurementsProcessOpts) init() error {
5050

5151
func (opts *atlasMeasurementsProcessOpts) Run() error {
5252
listOpts := opts.newProcessMeasurementListOptions()
53-
result, err := opts.store.ListProcessMeasurements(opts.ProjectID(), opts.host, opts.port, listOpts)
53+
result, err := opts.store.AtlasProcessMeasurements(opts.ProjectID(), opts.host, opts.port, listOpts)
5454

5555
if err != nil {
5656
return err

internal/cli/atlas_measurements_process_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

2424
func TestAtlasMeasurementsProcess_Run(t *testing.T) {
2525
ctrl := gomock.NewController(t)
26-
mockStore := mocks.NewMockProcessMeasurementLister(ctrl)
26+
mockStore := mocks.NewMockAtlasProcessMeasurementLister(ctrl)
2727

2828
defer ctrl.Finish()
2929

@@ -45,7 +45,7 @@ func TestAtlasMeasurementsProcess_Run(t *testing.T) {
4545

4646
opts := listOpts.newProcessMeasurementListOptions()
4747
mockStore.
48-
EXPECT().ListProcessMeasurements(listOpts.projectID, hostName, port, opts).
48+
EXPECT().AtlasProcessMeasurements(listOpts.projectID, hostName, port, opts).
4949
Return(expected, nil).
5050
Times(1)
5151

internal/cli/cloud_manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func CloudManagerBuilder() *cobra.Command {
3434
cmd.AddCommand(OpsManagerSecurityBuilder())
3535
cmd.AddCommand(OpsManagerDBUsersBuilder())
3636
cmd.AddCommand(AtlasEventsBuilder())
37+
cmd.AddCommand(OpsManagerMeasurementsBuilder())
3738

3839
return cmd
3940
}

internal/cli/ops_manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func OpsManagerBuilder() *cobra.Command {
3535
cmd.AddCommand(OpsManagerDBUsersBuilder())
3636
cmd.AddCommand(OpsManagerOwnerBuilder())
3737
cmd.AddCommand(AtlasEventsBuilder())
38+
cmd.AddCommand(OpsManagerMeasurementsBuilder())
3839

3940
return cmd
4041
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2020 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cli
16+
17+
import (
18+
"github.com/mongodb/mongocli/internal/description"
19+
"github.com/spf13/cobra"
20+
)
21+
22+
func OpsManagerMeasurementsBuilder() *cobra.Command {
23+
cmd := &cobra.Command{
24+
Use: "measurements",
25+
Short: description.Measurements,
26+
}
27+
28+
cmd.AddCommand(OpsManagerMeasurementsProcessBuilder())
29+
30+
return cmd
31+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright 2020 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cli
16+
17+
import (
18+
atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas"
19+
"github.com/mongodb/mongocli/internal/description"
20+
"github.com/mongodb/mongocli/internal/flags"
21+
"github.com/mongodb/mongocli/internal/json"
22+
"github.com/mongodb/mongocli/internal/store"
23+
"github.com/mongodb/mongocli/internal/usage"
24+
"github.com/spf13/cobra"
25+
)
26+
27+
type OpsManagerMeasurementsProcessOpts struct {
28+
*globalOpts
29+
pageNum int
30+
itemsPerPage int
31+
hostID string
32+
granularity string
33+
period string
34+
start string
35+
end string
36+
measurementType string
37+
store store.OpsManagerProcessMeasurementLister
38+
}
39+
40+
func (opts *OpsManagerMeasurementsProcessOpts) init() error {
41+
if opts.ProjectID() == "" {
42+
return errMissingProjectID
43+
}
44+
45+
var err error
46+
opts.store, err = store.New()
47+
return err
48+
}
49+
50+
func (opts *OpsManagerMeasurementsProcessOpts) Run() error {
51+
listOpts := opts.newProcessMeasurementListOptions()
52+
result, err := opts.store.OpsManagerProcessMeasurements(opts.ProjectID(), opts.hostID, listOpts)
53+
54+
if err != nil {
55+
return err
56+
}
57+
58+
return json.PrettyPrint(result)
59+
}
60+
61+
func (opts *OpsManagerMeasurementsProcessOpts) newProcessMeasurementListOptions() *atlas.ProcessMeasurementListOptions {
62+
return &atlas.ProcessMeasurementListOptions{
63+
ListOptions: &atlas.ListOptions{
64+
PageNum: opts.pageNum,
65+
ItemsPerPage: opts.itemsPerPage,
66+
},
67+
Granularity: opts.granularity,
68+
Period: opts.period,
69+
Start: opts.start,
70+
End: opts.end,
71+
M: opts.measurementType,
72+
}
73+
}
74+
75+
// mongocli om|cm measurements process(es) hostId [--granularity granularity] [--period period] [--start start] [--end end] [--type type][--projectId projectId]
76+
func OpsManagerMeasurementsProcessBuilder() *cobra.Command {
77+
opts := &OpsManagerMeasurementsProcessOpts{
78+
globalOpts: newGlobalOpts(),
79+
}
80+
cmd := &cobra.Command{
81+
Use: "process",
82+
Short: description.ProcessMeasurements,
83+
Aliases: []string{"processes"},
84+
Args: cobra.ExactArgs(1),
85+
PreRunE: func(cmd *cobra.Command, args []string) error {
86+
return opts.init()
87+
},
88+
RunE: func(cmd *cobra.Command, args []string) error {
89+
opts.hostID = args[0]
90+
return opts.Run()
91+
},
92+
}
93+
94+
cmd.Flags().StringVar(&opts.granularity, flags.Granularity, "", usage.Granularity)
95+
cmd.Flags().StringVar(&opts.period, flags.Period, "", usage.Period)
96+
cmd.Flags().StringVar(&opts.start, flags.Start, "", usage.Start)
97+
cmd.Flags().StringVar(&opts.end, flags.End, "", usage.End)
98+
cmd.Flags().StringVar(&opts.measurementType, flags.MeasurementType, "", usage.MeasurementType)
99+
100+
cmd.Flags().StringVar(&opts.projectID, flags.ProjectID, "", usage.ProjectID)
101+
102+
return cmd
103+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2020 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package cli
15+
16+
import (
17+
"testing"
18+
19+
"github.com/golang/mock/gomock"
20+
"github.com/mongodb/mongocli/internal/fixtures"
21+
"github.com/mongodb/mongocli/internal/mocks"
22+
)
23+
24+
func TestOpsManagerMeasurementsProcess_Run(t *testing.T) {
25+
ctrl := gomock.NewController(t)
26+
mockStore := mocks.NewMockOpsManagerProcessMeasurementLister(ctrl)
27+
28+
defer ctrl.Finish()
29+
30+
expected := fixtures.ProcessMeasurements()
31+
32+
listOpts := &OpsManagerMeasurementsProcessOpts{
33+
globalOpts: newGlobalOpts(),
34+
hostID: "hard-00-00.mongodb.net",
35+
granularity: "PT1M",
36+
period: "PT1M",
37+
store: mockStore,
38+
}
39+
40+
opts := listOpts.newProcessMeasurementListOptions()
41+
mockStore.
42+
EXPECT().OpsManagerProcessMeasurements(listOpts.projectID, listOpts.hostID, opts).
43+
Return(expected, nil).
44+
Times(1)
45+
46+
err := listOpts.Run()
47+
if err != nil {
48+
t.Fatalf("Run() unexpected error: %v", err)
49+
}
50+
}

internal/mocks/mock_process_measurements.go

Lines changed: 35 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)