Skip to content

Commit 923d69b

Browse files
CLOUDP-60177: Implement Get Measurements of a Disk for a MongoDB Process, Atlas (#78)
1 parent aad5896 commit 923d69b

File tree

3 files changed

+172
-0
lines changed

3 files changed

+172
-0
lines changed

mongodbatlas/mongodbatlas.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type Client struct {
6868
Processes ProcessesService
6969
ProcessMeasurements ProcessMeasurementsService
7070
ProcessDisks ProcessDisksService
71+
ProcessDiskMeasurements ProcessDiskMeasurementsService
7172
ProcessDatabases ProcessDatabasesService
7273

7374
onRequestCompleted RequestCompletionCallback
@@ -190,6 +191,7 @@ func NewClient(httpClient *http.Client) *Client {
190191
c.Processes = &ProcessesServiceOp{Client: c}
191192
c.ProcessMeasurements = &ProcessMeasurementsServiceOp{Client: c}
192193
c.ProcessDisks = &ProcessDisksServiceOp{Client: c}
194+
c.ProcessDiskMeasurements = &ProcessDiskMeasurementsServiceOp{Client: c}
193195
c.ProcessDatabases = &ProcessDatabasesServiceOp{Client: c}
194196

195197
return c
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package mongodbatlas
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/http"
7+
)
8+
9+
const ProcessDiskMeasurementsPath = processesDisksPath + "/%s/measurements"
10+
11+
// ProcessDiskMeasurementsService is an interface for interfacing with the Process Disk Measurements
12+
// endpoints of the MongoDB Atlas API.
13+
// See more: https://docs.atlas.mongodb.com/reference/api/process-disks-measurements/#get-measurements-of-a-disk-for-a-mongodb-process
14+
type ProcessDiskMeasurementsService interface {
15+
List(context.Context, string, string, int, string, *ProcessMeasurementListOptions) (*ProcessDiskMeasurements, *Response, error)
16+
}
17+
18+
// ProcessDiskMeasurementsServiceOp handles communication with the Process Disk Measurements related methods of the
19+
// MongoDB Atlas API
20+
type ProcessDiskMeasurementsServiceOp struct {
21+
Client RequestDoer
22+
}
23+
24+
// ProcessDiskMeasurements represents a MongoDB Process Disk Measurements.
25+
type ProcessDiskMeasurements struct {
26+
*ProcessMeasurements
27+
PartitionName string `json:"partitionName"`
28+
}
29+
30+
var _ ProcessDiskMeasurementsService = &ProcessDiskMeasurementsServiceOp{}
31+
32+
// Get gets measurements for a specific Atlas MongoDB disk.
33+
// See more: https://docs.atlas.mongodb.com/reference/api/process-disks-measurements/#get-measurements-of-a-disk-for-a-mongodb-process
34+
func (s *ProcessDiskMeasurementsServiceOp) List(ctx context.Context, groupID, hostName string, port int, diskName string, opts *ProcessMeasurementListOptions) (*ProcessDiskMeasurements, *Response, error) {
35+
36+
if groupID == "" {
37+
return nil, nil, NewArgError("groupID", "must be set")
38+
}
39+
40+
if hostName == "" {
41+
return nil, nil, NewArgError("hostName", "must be set")
42+
}
43+
44+
if diskName == "" {
45+
return nil, nil, NewArgError("diskName", "must be set")
46+
}
47+
48+
basePath := fmt.Sprintf(ProcessDiskMeasurementsPath, groupID, hostName, port, diskName)
49+
50+
//Add query params from listOptions
51+
path, err := setListOptions(basePath, opts)
52+
if err != nil {
53+
return nil, nil, err
54+
}
55+
56+
req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil)
57+
if err != nil {
58+
return nil, nil, err
59+
}
60+
61+
root := new(ProcessDiskMeasurements)
62+
resp, err := s.Client.Do(ctx, req, root)
63+
if err != nil {
64+
return nil, resp, err
65+
}
66+
67+
return root, resp, err
68+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package mongodbatlas
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"testing"
7+
8+
"github.com/go-test/deep"
9+
)
10+
11+
func TestDiskMeasurements_List(t *testing.T) {
12+
setup()
13+
defer teardown()
14+
15+
groups := "12345678"
16+
host := "shard-00-00.mongodb.net"
17+
port := 27017
18+
disk := "disk"
19+
20+
mux.HandleFunc(fmt.Sprintf("/groups/%s/processes/%s:%d/disks/%s/measurements", groups, host, port, disk), func(w http.ResponseWriter, r *http.Request) {
21+
testMethod(t, r, http.MethodGet)
22+
fmt.Fprint(w, `{
23+
"end" : "2017-08-22T20:31:14Z",
24+
"granularity" : "PT1M",
25+
"groupId" : "12345678",
26+
"hostId" : "shard-00-00.mongodb.net:27017",
27+
"links" : [ {
28+
"href" : "https://cloud.mongodb.com/api/atlas/v1.0/groups/12345678/processes/shard-00-00.mongodb.net:27017/measurements?granularity=PT1M&period=PT1M",
29+
"rel" : "self"
30+
}, {
31+
"href" : "https://cloud.mongodb.com/api/atlas/v1.0/groups/12345678/processes/shard-00-00.mongodb.net:27017",
32+
"rel" : "http://mms.mongodb.com/host"
33+
} ],
34+
"measurements" : [ {
35+
"dataPoints" : [ {
36+
"timestamp" : "2017-08-22T20:31:12Z",
37+
"value" : null
38+
}, {
39+
"timestamp" : "2017-08-22T20:31:14Z",
40+
"value" : null
41+
} ],
42+
"name" : "DISK_PARTITION_IOPS_READ",
43+
"units" : "SCALAR_PER_SECOND"
44+
}],
45+
"partitionName":"xvdb",
46+
"processId" : "shard-00-00.mongodb.net:27017",
47+
"start" : "2017-08-22T20:30:45Z"
48+
}`)
49+
})
50+
51+
opts := &ProcessMeasurementListOptions{
52+
Granularity: "PT1M",
53+
Period: "PT1M",
54+
}
55+
56+
measurements, _, err := client.ProcessDiskMeasurements.List(ctx, groups, host, port, disk, opts)
57+
if err != nil {
58+
t.Fatalf("Teams.Get returned error: %v", err)
59+
}
60+
61+
expected := &ProcessDiskMeasurements{
62+
ProcessMeasurements: &ProcessMeasurements{
63+
End: "2017-08-22T20:31:14Z",
64+
Granularity: "PT1M",
65+
GroupID: "12345678",
66+
HostID: "shard-00-00.mongodb.net:27017",
67+
Links: []*Link{
68+
{
69+
Rel: "self",
70+
Href: "https://cloud.mongodb.com/api/atlas/v1.0/groups/12345678/processes/shard-00-00.mongodb.net:27017/measurements?granularity=PT1M&period=PT1M",
71+
},
72+
{
73+
Href: "https://cloud.mongodb.com/api/atlas/v1.0/groups/12345678/processes/shard-00-00.mongodb.net:27017",
74+
Rel: "http://mms.mongodb.com/host",
75+
},
76+
},
77+
Measurements: []*Measurements{
78+
{
79+
DataPoints: []*DataPoints{
80+
{
81+
Timestamp: "2017-08-22T20:31:12Z",
82+
Value: nil,
83+
},
84+
{
85+
Timestamp: "2017-08-22T20:31:14Z",
86+
Value: nil,
87+
},
88+
},
89+
Name: "DISK_PARTITION_IOPS_READ",
90+
Units: "SCALAR_PER_SECOND",
91+
},
92+
},
93+
ProcessID: "shard-00-00.mongodb.net:27017",
94+
Start: "2017-08-22T20:30:45Z",
95+
},
96+
PartitionName: "xvdb",
97+
}
98+
99+
if diff := deep.Equal(measurements, expected); diff != nil {
100+
t.Error(diff)
101+
}
102+
}

0 commit comments

Comments
 (0)