Skip to content

Commit 3357983

Browse files
author
Quentin Brosse
authored
feat(lb): add ListBackendStats method (#252)
1 parent 166cf67 commit 3357983

File tree

7 files changed

+97
-17
lines changed

7 files changed

+97
-17
lines changed

api/baremetal/v1alpha1/baremetal_sdk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var (
3737
_ = namegenerator.GetRandomName
3838
)
3939

40-
// API this API allows to manage your Bare metal server.
40+
// API this API allows to manage your Bare metal server
4141
type API struct {
4242
client *scw.Client
4343
}

api/instance/v1/instance_sdk.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ type CreateServerRequest struct {
14691469
//
14701470
// Default value: local
14711471
BootType BootType `json:"boot_type"`
1472-
// Bootscript the bootscript ID to use when `boot_type` is set to `bootscript`.
1472+
// Bootscript the bootscript ID to use when `boot_type` is set to `bootscript`
14731473
Bootscript *string `json:"bootscript,omitempty"`
14741474
// Organization the server organization ID
14751475
Organization string `json:"organization,omitempty"`
@@ -3872,7 +3872,7 @@ type CreateIPRequest struct {
38723872
Server *string `json:"server,omitempty"`
38733873
}
38743874

3875-
// CreateIP reseve an IP
3875+
// CreateIP reserve an IP
38763876
func (s *API) CreateIP(req *CreateIPRequest, opts ...scw.RequestOption) (*CreateIPResponse, error) {
38773877
var err error
38783878

api/k8s/v1beta3/k8s_sdk.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var (
3737
_ = namegenerator.GetRandomName
3838
)
3939

40-
// API this API allows you to manage your kapsule clusters.
40+
// API this API allows you to manage your kapsule clusters
4141
type API struct {
4242
client *scw.Client
4343
}
@@ -506,7 +506,7 @@ type Pool struct {
506506
MinSize uint32 `json:"min_size"`
507507
// MaxSize display upper limit for this pool
508508
MaxSize uint32 `json:"max_size"`
509-
// PlacementGroupID iD of the placement group if any
509+
// PlacementGroupID display ID of the placement group if any
510510
PlacementGroupID *string `json:"placement_group_id"`
511511

512512
CreatedAt time.Time `json:"created_at"`

api/lb/v1/lb_sdk.go

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ type Lb struct {
10851085

10861086
// LbStats lb stats
10871087
type LbStats struct {
1088-
// BackendServersStats list stats object of your loadbalancer (See the BackendServerStats object description)
1088+
// BackendServersStats list stats object of your loadbalancer
10891089
BackendServersStats []*BackendServerStats `json:"backend_servers_stats"`
10901090
}
10911091

@@ -1105,7 +1105,15 @@ type LbType struct {
11051105
type ListACLResponse struct {
11061106
// ACLs list of Acl object (see Acl object description)
11071107
ACLs []*ACL `json:"acls"`
1108-
// TotalCount result count
1108+
// TotalCount the total number of items
1109+
TotalCount uint32 `json:"total_count"`
1110+
}
1111+
1112+
// ListBackendStatsResponse list backend stats response
1113+
type ListBackendStatsResponse struct {
1114+
// BackendServersStats list backend stats object of your loadbalancer
1115+
BackendServersStats []*BackendServerStats `json:"backend_servers_stats"`
1116+
// TotalCount the total number of items
11091117
TotalCount uint32 `json:"total_count"`
11101118
}
11111119

@@ -1268,7 +1276,7 @@ type CreateLbRequest struct {
12681276
Name string `json:"name"`
12691277
// Description resource description
12701278
Description string `json:"description"`
1271-
// IPID just like for compute instances, when you destroy a Load Balancer, you can keep its highly available IP address and reuse it for another Load Balancer later.
1279+
// IPID just like for compute instances, when you destroy a Load Balancer, you can keep its highly available IP address and reuse it for another Load Balancer later
12721280
IPID *string `json:"ip_id"`
12731281
// Tags list of keyword
12741282
Tags []string `json:"tags"`
@@ -1443,7 +1451,7 @@ type ListIPsRequest struct {
14431451
Region scw.Region `json:"-"`
14441452
// Page page number
14451453
Page *int32 `json:"-"`
1446-
// PageSize set the maximum list size
1454+
// PageSize the number of items to return
14471455
PageSize *uint32 `json:"-"`
14481456
// IPAddress use this to search by IP address
14491457
IPAddress *string `json:"-"`
@@ -1598,7 +1606,7 @@ type ListBackendsRequest struct {
15981606
OrderBy ListBackendsRequestOrderBy `json:"-"`
15991607
// Page page number
16001608
Page *int32 `json:"-"`
1601-
// PageSize set the maximum list sizes
1609+
// PageSize the number of items to returns
16021610
PageSize *uint32 `json:"-"`
16031611
}
16041612

@@ -2235,7 +2243,7 @@ type ListFrontendsRequest struct {
22352243
OrderBy ListFrontendsRequestOrderBy `json:"-"`
22362244
// Page page number
22372245
Page *int32 `json:"-"`
2238-
// PageSize set the maximum list sizes
2246+
// PageSize the number of items to returns
22392247
PageSize *uint32 `json:"-"`
22402248
}
22412249

@@ -2578,6 +2586,76 @@ func (s *API) GetLbStats(req *GetLbStatsRequest, opts ...scw.RequestOption) (*Lb
25782586
return &resp, nil
25792587
}
25802588

2589+
type ListBackendStatsRequest struct {
2590+
Region scw.Region `json:"-"`
2591+
// LbID load Balancer ID
2592+
LbID string `json:"-"`
2593+
// Page page number
2594+
Page *int32 `json:"-"`
2595+
// PageSize the number of items to return
2596+
PageSize *uint32 `json:"-"`
2597+
}
2598+
2599+
func (s *API) ListBackendStats(req *ListBackendStatsRequest, opts ...scw.RequestOption) (*ListBackendStatsResponse, error) {
2600+
var err error
2601+
2602+
if req.Region == "" {
2603+
defaultRegion, _ := s.client.GetDefaultRegion()
2604+
req.Region = defaultRegion
2605+
}
2606+
2607+
defaultPageSize, exist := s.client.GetDefaultPageSize()
2608+
if (req.PageSize == nil || *req.PageSize == 0) && exist {
2609+
req.PageSize = &defaultPageSize
2610+
}
2611+
2612+
query := url.Values{}
2613+
parameter.AddToQuery(query, "page", req.Page)
2614+
parameter.AddToQuery(query, "page_size", req.PageSize)
2615+
2616+
if fmt.Sprint(req.Region) == "" {
2617+
return nil, errors.New("field Region cannot be empty in request")
2618+
}
2619+
2620+
if fmt.Sprint(req.LbID) == "" {
2621+
return nil, errors.New("field LbID cannot be empty in request")
2622+
}
2623+
2624+
scwReq := &scw.ScalewayRequest{
2625+
Method: "GET",
2626+
Path: "/lb/v1/regions/" + fmt.Sprint(req.Region) + "/lbs/" + fmt.Sprint(req.LbID) + "/backend-stats",
2627+
Query: query,
2628+
Headers: http.Header{},
2629+
}
2630+
2631+
var resp ListBackendStatsResponse
2632+
2633+
err = s.client.Do(scwReq, &resp, opts...)
2634+
if err != nil {
2635+
return nil, err
2636+
}
2637+
return &resp, nil
2638+
}
2639+
2640+
// UnsafeGetTotalCount should not be used
2641+
// Internal usage only
2642+
func (r *ListBackendStatsResponse) UnsafeGetTotalCount() uint32 {
2643+
return r.TotalCount
2644+
}
2645+
2646+
// UnsafeAppend should not be used
2647+
// Internal usage only
2648+
func (r *ListBackendStatsResponse) UnsafeAppend(res interface{}) (uint32, scw.SdkError) {
2649+
results, ok := res.(*ListBackendStatsResponse)
2650+
if !ok {
2651+
return 0, errors.New("%T type cannot be appended to type %T", res, r)
2652+
}
2653+
2654+
r.BackendServersStats = append(r.BackendServersStats, results.BackendServersStats...)
2655+
r.TotalCount += uint32(len(results.BackendServersStats))
2656+
return uint32(len(results.BackendServersStats)), nil
2657+
}
2658+
25812659
type ListACLsRequest struct {
25822660
Region scw.Region `json:"-"`
25832661
// FrontendID iD of your frontend
@@ -2588,7 +2666,7 @@ type ListACLsRequest struct {
25882666
OrderBy ListACLRequestOrderBy `json:"-"`
25892667
// Page page number
25902668
Page *int32 `json:"-"`
2591-
// PageSize set the maximum list size
2669+
// PageSize the number of items to return
25922670
PageSize *uint32 `json:"-"`
25932671
// Name filter acl per name
25942672
Name *string `json:"-"`
@@ -2896,7 +2974,7 @@ type ListCertificatesRequest struct {
28962974
OrderBy ListCertificatesRequestOrderBy `json:"-"`
28972975
// Page page number
28982976
Page *int32 `json:"-"`
2899-
// PageSize set the maximum list size
2977+
// PageSize the number of items to return
29002978
PageSize *uint32 `json:"-"`
29012979
// Name use this to search by name
29022980
Name *string `json:"-"`
@@ -3088,7 +3166,7 @@ type ListLbTypesRequest struct {
30883166
Region scw.Region `json:"-"`
30893167
// Page page number
30903168
Page *int32 `json:"-"`
3091-
// PageSize set the maximum list size
3169+
// PageSize the number of items to return
30923170
PageSize *uint32 `json:"-"`
30933171
}
30943172

api/rdb/v1/rdb_sdk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ type RestoreDatabaseBackupRequest struct {
12531253
Region scw.Region `json:"-"`
12541254
// DatabaseBackupID backup of a logical database
12551255
DatabaseBackupID string `json:"-"`
1256-
// DatabaseName defines the destination database in order to restore into a specified database, the default destination is set to the origin database of the backup.
1256+
// DatabaseName defines the destination database in order to restore into a specified database, the default destination is set to the origin database of the backup
12571257
DatabaseName *string `json:"database_name"`
12581258
// InstanceID defines the rdb instance where the backup has to be restored
12591259
InstanceID string `json:"instance_id"`

api/registry/v1/registry_sdk.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,9 @@ type Image struct {
329329
//
330330
// Default value: visibility_unknown
331331
Visibility ImageVisibility `json:"visibility"`
332-
// Size image size in bytes, calculated from the size of image layers. One layer used in two tags of the same image is counted once but one layer used in two images is counted twice.
332+
// Size image size in bytes, calculated from the size of image layers
333+
//
334+
// Image size in bytes, calculated from the size of image layers. One layer used in two tags of the same image is counted once but one layer used in two images is counted twice.
333335
Size uint64 `json:"size"`
334336
// CreatedAt creation date
335337
CreatedAt time.Time `json:"created_at"`

api/test/v1/test_sdk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var (
3737
_ = namegenerator.GetRandomName
3838
)
3939

40-
// API no Auth Service for end-to-end testing.
40+
// API no Auth Service for end-to-end testing
4141
type API struct {
4242
client *scw.Client
4343
}

0 commit comments

Comments
 (0)