Skip to content

Commit 9318008

Browse files
authored
INTMDB-802: Add Data Federation Query Limit (#475)
1 parent 2453b15 commit 9318008

File tree

2 files changed

+272
-1
lines changed

2 files changed

+272
-1
lines changed

mongodbatlas/data_federation.go

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import (
2121
)
2222

2323
const (
24-
dataFederationBasePath = "api/atlas/v1.0/groups/%s/dataFederation"
24+
dataFederationBasePath = "api/atlas/v1.0/groups/%s/dataFederation"
25+
dataFederationQueryLimitBasePath = "api/atlas/v1.0/groups/%s/dataFederation/%s/limits"
2526
)
2627

2728
// DataFederationService is an interface for interfacing with the Data Federation endpoints of the MongoDB Atlas API.
@@ -33,6 +34,10 @@ type DataFederationService interface {
3334
Create(context.Context, string, *DataFederationInstance) (*DataFederationInstance, *Response, error)
3435
Update(context.Context, string, string, *DataFederationInstance, *DataFederationUpdateOptions) (*DataFederationInstance, *Response, error)
3536
Delete(context.Context, string, string) (*Response, error)
37+
ListQueryLimits(context.Context, string, string) ([]*DataFederationQueryLimit, *Response, error)
38+
GetQueryLimit(context.Context, string, string, string) (*DataFederationQueryLimit, *Response, error)
39+
ConfigureQueryLimit(context.Context, string, string, string, *DataFederationQueryLimit) (*DataFederationQueryLimit, *Response, error)
40+
DeleteQueryLimit(context.Context, string, string, string) (*Response, error)
3641
}
3742

3843
// DataFederationServiceOp handles communication with the DataFederationService related methods of the
@@ -133,6 +138,18 @@ type DataFederationUpdateOptions struct {
133138
SkipRoleValidation bool `url:"skipRoleValidation"`
134139
}
135140

141+
// DataFederationQueryLimit Details of a tenant-level query limit for Data Federation.
142+
type DataFederationQueryLimit struct {
143+
CurrentUsage int64 `json:"currentUsage,omitempty"`
144+
DefaultLimit int64 `json:"defaultLimit,omitempty"`
145+
LastModifiedDate string `json:"lastModifiedDate,omitempty"`
146+
MaximumLimit int64 `json:"maximumLimit,omitempty"`
147+
Name string `json:"name,omitempty"`
148+
OverrunPolicy string `json:"overrunPolicy,omitempty"`
149+
TenantName string `json:"tenantName,omitempty"`
150+
Value int64 `json:"value,omitempty"`
151+
}
152+
136153
// List gets the details of all federated database instances in the specified project.
137154
//
138155
// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Data-Federation/operation/listFederatedDatabases
@@ -276,3 +293,112 @@ func (s *DataFederationServiceOp) Delete(ctx context.Context, groupID, name stri
276293

277294
return resp, err
278295
}
296+
297+
// ConfigureQueryLimit Creates or updates one query limit for one federated database instance.
298+
//
299+
// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Data-Federation/operation/createOneDataFederationQueryLimit
300+
func (s *DataFederationServiceOp) ConfigureQueryLimit(ctx context.Context, groupID, name, limitName string, queryLimit *DataFederationQueryLimit) (*DataFederationQueryLimit, *Response, error) {
301+
if groupID == "" {
302+
return nil, nil, NewArgError("groupID", "must be set")
303+
}
304+
if name == "" {
305+
return nil, nil, NewArgError("name", "must be set")
306+
}
307+
if limitName == "" {
308+
return nil, nil, NewArgError("limitName", "must be set")
309+
}
310+
if queryLimit == nil {
311+
return nil, nil, NewArgError("queryLimit", "must be set")
312+
}
313+
314+
basePath := fmt.Sprintf(dataFederationQueryLimitBasePath, groupID, name)
315+
path := fmt.Sprintf("%s/%s", basePath, limitName)
316+
req, err := s.Client.NewRequest(ctx, http.MethodPatch, path, queryLimit)
317+
if err != nil {
318+
return nil, nil, err
319+
}
320+
321+
root := new(DataFederationQueryLimit)
322+
resp, err := s.Client.Do(ctx, req, &root)
323+
if err != nil {
324+
return nil, resp, err
325+
}
326+
327+
return root, resp, err
328+
}
329+
330+
func (s *DataFederationServiceOp) DeleteQueryLimit(ctx context.Context, groupID, name, limitName string) (*Response, error) {
331+
if groupID == "" {
332+
return nil, NewArgError("groupId", "must be set")
333+
}
334+
if name == "" {
335+
return nil, NewArgError("name", "must be set")
336+
}
337+
if limitName == "" {
338+
return nil, NewArgError("limitName", "must be set")
339+
}
340+
341+
basePath := fmt.Sprintf(dataFederationQueryLimitBasePath, groupID, name)
342+
path := fmt.Sprintf("%s/%s", basePath, limitName)
343+
344+
req, err := s.Client.NewRequest(ctx, http.MethodDelete, path, nil)
345+
if err != nil {
346+
return nil, err
347+
}
348+
349+
resp, err := s.Client.Do(ctx, req, nil)
350+
351+
return resp, err
352+
}
353+
354+
func (s *DataFederationServiceOp) GetQueryLimit(ctx context.Context, groupID, name, limitName string) (*DataFederationQueryLimit, *Response, error) {
355+
if groupID == "" {
356+
return nil, nil, NewArgError("groupID", "must be set")
357+
}
358+
if name == "" {
359+
return nil, nil, NewArgError("name", "must be set")
360+
}
361+
if limitName == "" {
362+
return nil, nil, NewArgError("limitName", "must be set")
363+
}
364+
365+
basePath := fmt.Sprintf(dataFederationQueryLimitBasePath, groupID, name)
366+
path := fmt.Sprintf("%s/%s", basePath, limitName)
367+
368+
req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil)
369+
if err != nil {
370+
return nil, nil, err
371+
}
372+
373+
root := new(DataFederationQueryLimit)
374+
resp, err := s.Client.Do(ctx, req, &root)
375+
if err != nil {
376+
return nil, resp, err
377+
}
378+
379+
return root, resp, err
380+
}
381+
382+
func (s *DataFederationServiceOp) ListQueryLimits(ctx context.Context, groupID, name string) ([]*DataFederationQueryLimit, *Response, error) {
383+
if groupID == "" {
384+
return nil, nil, NewArgError("groupID", "must be set")
385+
}
386+
if name == "" {
387+
return nil, nil, NewArgError("name", "must be set")
388+
}
389+
390+
path := fmt.Sprintf(dataFederationQueryLimitBasePath, groupID, name)
391+
392+
req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil)
393+
if err != nil {
394+
return nil, nil, err
395+
}
396+
397+
var root []*DataFederationQueryLimit
398+
resp, err := s.Client.Do(ctx, req, &root)
399+
if err != nil {
400+
return nil, resp, err
401+
}
402+
403+
return root, resp, err
404+
}

mongodbatlas/data_federation_test.go

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,3 +767,148 @@ func TestDataFederation_Delete(t *testing.T) {
767767
t.Fatalf("DataFederation.Delete returned error: %v", err)
768768
}
769769
}
770+
771+
func TestDataFederationQueryLimit_List(t *testing.T) {
772+
client, mux, teardown := setup()
773+
defer teardown()
774+
775+
groupID := "6c7498dg87d9e6526801572b"
776+
tenantName := "TestInstance"
777+
778+
path := fmt.Sprintf("/api/atlas/v1.0/groups/%s/dataFederation/%s/limits", groupID, tenantName)
779+
780+
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
781+
testMethod(t, r, http.MethodGet)
782+
fmt.Fprint(w, `[{
783+
"currentUsage": 0,
784+
"lastModifiedDate": "2023-05-12T10:41:03Z",
785+
"name": "bytesProcessed.daily",
786+
"overrunPolicy": "BLOCK",
787+
"tenantName": "TestInstance",
788+
"value": 2147483648
789+
}]`)
790+
})
791+
792+
dataFederationQueryLimits, _, err := client.DataFederation.ListQueryLimits(ctx, groupID, tenantName)
793+
if err != nil {
794+
t.Fatalf("DataFederation.ListQueryLimit returned error: %v", err)
795+
}
796+
797+
expected := []*DataFederationQueryLimit{
798+
{
799+
CurrentUsage: 0,
800+
LastModifiedDate: "2023-05-12T10:41:03Z",
801+
Name: "bytesProcessed.daily",
802+
OverrunPolicy: "BLOCK",
803+
TenantName: "TestInstance",
804+
Value: 2147483648,
805+
},
806+
}
807+
808+
if diff := deep.Equal(dataFederationQueryLimits, expected); diff != nil {
809+
t.Error(diff)
810+
}
811+
}
812+
813+
func TestDataFederationQueryLimit_Get(t *testing.T) {
814+
client, mux, teardown := setup()
815+
defer teardown()
816+
817+
groupID := "6c7498dg87d9e6526801572b"
818+
tenantName := "TestInstance"
819+
limitName := "bytesProcessed.daily"
820+
821+
path := fmt.Sprintf("/api/atlas/v1.0/groups/%s/dataFederation/%s/limits/%s", groupID, tenantName, limitName)
822+
823+
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
824+
testMethod(t, r, http.MethodGet)
825+
fmt.Fprint(w, `{
826+
"currentUsage": 0,
827+
"lastModifiedDate": "2023-05-12T10:41:03Z",
828+
"name": "bytesProcessed.daily",
829+
"overrunPolicy": "BLOCK",
830+
"tenantName": "TestInstance",
831+
"value": 2147483648
832+
}`)
833+
})
834+
835+
dataFederationQueryLimits, _, err := client.DataFederation.GetQueryLimit(ctx, groupID, tenantName, limitName)
836+
if err != nil {
837+
t.Fatalf("DataFederation.GetQueryLimit returned error: %v", err)
838+
}
839+
840+
expected := DataFederationQueryLimit{
841+
CurrentUsage: 0,
842+
LastModifiedDate: "2023-05-12T10:41:03Z",
843+
Name: "bytesProcessed.daily",
844+
OverrunPolicy: "BLOCK",
845+
TenantName: "TestInstance",
846+
Value: 2147483648,
847+
}
848+
849+
if diff := deep.Equal(*dataFederationQueryLimits, expected); diff != nil {
850+
t.Error(diff)
851+
}
852+
}
853+
854+
func TestDataFederation_Configure(t *testing.T) {
855+
client, mux, teardown := setup()
856+
defer teardown()
857+
858+
groupID := "6c7498dg87d9e6526801572b"
859+
tenantName := "TestInstance"
860+
limitName := "bytesProcessed.daily"
861+
862+
path := fmt.Sprintf("/api/atlas/v1.0/groups/%s/dataFederation/%s/limits/%s", groupID, tenantName, limitName)
863+
864+
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
865+
testMethod(t, r, http.MethodPatch)
866+
fmt.Fprint(w, `{
867+
"currentUsage": 0,
868+
"lastModifiedDate": "2023-05-12T10:41:03Z",
869+
"name": "bytesProcessed.daily",
870+
"overrunPolicy": "BLOCK",
871+
"tenantName": "TestInstance",
872+
"value": 2147483648
873+
}`)
874+
})
875+
876+
requestBody := &DataFederationQueryLimit{OverrunPolicy: "BLOCK", Value: 2147483648}
877+
dataFederationQueryLimit, _, err := client.DataFederation.ConfigureQueryLimit(ctx, groupID, tenantName, limitName, requestBody)
878+
if err != nil {
879+
t.Fatalf("DataFederation.ConfigureQueryLimit returned error: %v", err)
880+
}
881+
882+
expected := DataFederationQueryLimit{
883+
CurrentUsage: 0,
884+
LastModifiedDate: "2023-05-12T10:41:03Z",
885+
Name: "bytesProcessed.daily",
886+
OverrunPolicy: "BLOCK",
887+
TenantName: "TestInstance",
888+
Value: 2147483648,
889+
}
890+
891+
if diff := deep.Equal(*dataFederationQueryLimit, expected); diff != nil {
892+
t.Error(diff)
893+
}
894+
}
895+
896+
func TestDataFederationQueryLimit_Delete(t *testing.T) {
897+
client, mux, teardown := setup()
898+
defer teardown()
899+
900+
groupID := "6c7498dg87d9e6526801572b"
901+
tenantName := "TestInstance"
902+
limitName := "bytesProcessed.daily"
903+
904+
path := fmt.Sprintf("/api/atlas/v1.0/groups/%s/dataFederation/%s/limits/%s", groupID, tenantName, limitName)
905+
906+
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
907+
testMethod(t, r, http.MethodDelete)
908+
})
909+
910+
_, err := client.DataFederation.DeleteQueryLimit(ctx, groupID, tenantName, limitName)
911+
if err != nil {
912+
t.Fatalf("DataFederation.DeleteQueryLimit returned error: %v", err)
913+
}
914+
}

0 commit comments

Comments
 (0)