-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add database measurements Endpoint (#80)
- Loading branch information
Showing
5 changed files
with
180 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package mongodbatlas | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
const processDatabaseMeasurementsPath = processesDatabasesPath + "/%s/measurements" | ||
|
||
// ProcessDatabaseMeasurementsService is an interface for interfacing with the process database measurements | ||
// endpoints of the MongoDB Atlas API. | ||
// See more: https://docs.atlas.mongodb.com/reference/api/process-databases-measurements/ | ||
type ProcessDatabaseMeasurementsService interface { | ||
List(context.Context, string, string, int, string, *ProcessMeasurementListOptions) (*ProcessDatabaseMeasurements, *Response, error) | ||
} | ||
|
||
// ProcessDatabaseMeasurementsServiceOp handles communication with the process database measurements related methods of the | ||
// MongoDB Atlas API | ||
type ProcessDatabaseMeasurementsServiceOp struct { | ||
Client RequestDoer | ||
} | ||
|
||
// ProcessDatabaseMeasurements represents a MongoDB process database measurements. | ||
type ProcessDatabaseMeasurements struct { | ||
*ProcessMeasurements | ||
DatabaseName string `json:"databaseName"` | ||
} | ||
|
||
var _ ProcessDatabaseMeasurementsService = &ProcessDatabaseMeasurementsServiceOp{} | ||
|
||
// List list measurements for a specific Atlas MongoDB database. | ||
// See more: https://docs.atlas.mongodb.com/reference/api/process-databases-measurements/ | ||
func (s *ProcessDatabaseMeasurementsServiceOp) List(ctx context.Context, groupID, hostName string, port int, databaseName string, opts *ProcessMeasurementListOptions) (*ProcessDatabaseMeasurements, *Response, error) { | ||
|
||
if groupID == "" { | ||
return nil, nil, NewArgError("groupID", "must be set") | ||
} | ||
|
||
if hostName == "" { | ||
return nil, nil, NewArgError("hostName", "must be set") | ||
} | ||
|
||
if databaseName == "" { | ||
return nil, nil, NewArgError("databaseName", "must be set") | ||
} | ||
|
||
basePath := fmt.Sprintf(processDatabaseMeasurementsPath, groupID, hostName, port, databaseName) | ||
|
||
//Add query params from listOptions | ||
path, err := setListOptions(basePath, opts) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
root := new(ProcessDatabaseMeasurements) | ||
resp, err := s.Client.Do(ctx, req, root) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return root, resp, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package mongodbatlas | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/go-test/deep" | ||
) | ||
|
||
func TestProcessDatabaseMeasurements_List(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|
||
groups := "12345678" | ||
host := "shard-00-00.mongodb.net" | ||
port := 27017 | ||
database := "database" | ||
|
||
mux.HandleFunc(fmt.Sprintf("/groups/%s/processes/%s:%d/databases/%s/measurements", groups, host, port, database), func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, http.MethodGet) | ||
fmt.Fprint(w, `{ | ||
"end" : "2017-08-22T20:31:14Z", | ||
"granularity" : "PT1M", | ||
"groupId" : "12345678", | ||
"hostId" : "shard-00-00.mongodb.net:27017", | ||
"links" : [ { | ||
"href" : "https://cloud.mongodb.com/api/atlas/v1.0/groups/12345678/processes/shard-00-00.mongodb.net:27017/dataabses/database/measurements?granularity=PT1M&period=PT1M", | ||
"rel" : "self" | ||
}, { | ||
"href" : "https://cloud.mongodb.com/api/atlas/v1.0/groups/12345678/processes/shard-00-00.mongodb.net:27017", | ||
"rel" : "http://mms.mongodb.com/host" | ||
} ], | ||
"measurements" : [ { | ||
"dataPoints" : [ { | ||
"timestamp" : "2017-08-22T20:31:12Z", | ||
"value" : null | ||
}, { | ||
"timestamp" : "2017-08-22T20:31:14Z", | ||
"value" : null | ||
} ], | ||
"name" : "DISK_PARTITION_IOPS_READ", | ||
"units" : "SCALAR_PER_SECOND" | ||
}], | ||
"databaseName":"database", | ||
"processId" : "shard-00-00.mongodb.net:27017", | ||
"start" : "2017-08-22T20:30:45Z" | ||
}`) | ||
}) | ||
|
||
opts := &ProcessMeasurementListOptions{ | ||
Granularity: "PT1M", | ||
Period: "PT1M", | ||
} | ||
|
||
measurements, _, err := client.ProcessDatabaseMeasurements.List(ctx, groups, host, port, database, opts) | ||
if err != nil { | ||
t.Fatalf("ProcessDatabaseMeasurements.List returned error: %v", err) | ||
} | ||
|
||
expected := &ProcessDatabaseMeasurements{ | ||
ProcessMeasurements: &ProcessMeasurements{ | ||
End: "2017-08-22T20:31:14Z", | ||
Granularity: "PT1M", | ||
GroupID: "12345678", | ||
HostID: "shard-00-00.mongodb.net:27017", | ||
Links: []*Link{ | ||
{ | ||
Rel: "self", | ||
Href: "https://cloud.mongodb.com/api/atlas/v1.0/groups/12345678/processes/shard-00-00.mongodb.net:27017/dataabses/database/measurements?granularity=PT1M&period=PT1M", | ||
}, | ||
{ | ||
Href: "https://cloud.mongodb.com/api/atlas/v1.0/groups/12345678/processes/shard-00-00.mongodb.net:27017", | ||
Rel: "http://mms.mongodb.com/host", | ||
}, | ||
}, | ||
Measurements: []*Measurements{ | ||
{ | ||
DataPoints: []*DataPoints{ | ||
{ | ||
Timestamp: "2017-08-22T20:31:12Z", | ||
Value: nil, | ||
}, | ||
{ | ||
Timestamp: "2017-08-22T20:31:14Z", | ||
Value: nil, | ||
}, | ||
}, | ||
Name: "DISK_PARTITION_IOPS_READ", | ||
Units: "SCALAR_PER_SECOND", | ||
}, | ||
}, | ||
ProcessID: "shard-00-00.mongodb.net:27017", | ||
Start: "2017-08-22T20:30:45Z", | ||
}, | ||
DatabaseName: "database", | ||
} | ||
|
||
if diff := deep.Equal(measurements, expected); diff != nil { | ||
t.Error(diff) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters