Skip to content

Commit

Permalink
feat(lb): add ListBackendStats method (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Brosse authored Nov 25, 2019
1 parent 166cf67 commit 3357983
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 17 deletions.
2 changes: 1 addition & 1 deletion api/baremetal/v1alpha1/baremetal_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
_ = namegenerator.GetRandomName
)

// API this API allows to manage your Bare metal server.
// API this API allows to manage your Bare metal server
type API struct {
client *scw.Client
}
Expand Down
4 changes: 2 additions & 2 deletions api/instance/v1/instance_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,7 @@ type CreateServerRequest struct {
//
// Default value: local
BootType BootType `json:"boot_type"`
// Bootscript the bootscript ID to use when `boot_type` is set to `bootscript`.
// Bootscript the bootscript ID to use when `boot_type` is set to `bootscript`
Bootscript *string `json:"bootscript,omitempty"`
// Organization the server organization ID
Organization string `json:"organization,omitempty"`
Expand Down Expand Up @@ -3872,7 +3872,7 @@ type CreateIPRequest struct {
Server *string `json:"server,omitempty"`
}

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

Expand Down
4 changes: 2 additions & 2 deletions api/k8s/v1beta3/k8s_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
_ = namegenerator.GetRandomName
)

// API this API allows you to manage your kapsule clusters.
// API this API allows you to manage your kapsule clusters
type API struct {
client *scw.Client
}
Expand Down Expand Up @@ -506,7 +506,7 @@ type Pool struct {
MinSize uint32 `json:"min_size"`
// MaxSize display upper limit for this pool
MaxSize uint32 `json:"max_size"`
// PlacementGroupID iD of the placement group if any
// PlacementGroupID display ID of the placement group if any
PlacementGroupID *string `json:"placement_group_id"`

CreatedAt time.Time `json:"created_at"`
Expand Down
96 changes: 87 additions & 9 deletions api/lb/v1/lb_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ type Lb struct {

// LbStats lb stats
type LbStats struct {
// BackendServersStats list stats object of your loadbalancer (See the BackendServerStats object description)
// BackendServersStats list stats object of your loadbalancer
BackendServersStats []*BackendServerStats `json:"backend_servers_stats"`
}

Expand All @@ -1105,7 +1105,15 @@ type LbType struct {
type ListACLResponse struct {
// ACLs list of Acl object (see Acl object description)
ACLs []*ACL `json:"acls"`
// TotalCount result count
// TotalCount the total number of items
TotalCount uint32 `json:"total_count"`
}

// ListBackendStatsResponse list backend stats response
type ListBackendStatsResponse struct {
// BackendServersStats list backend stats object of your loadbalancer
BackendServersStats []*BackendServerStats `json:"backend_servers_stats"`
// TotalCount the total number of items
TotalCount uint32 `json:"total_count"`
}

Expand Down Expand Up @@ -1268,7 +1276,7 @@ type CreateLbRequest struct {
Name string `json:"name"`
// Description resource description
Description string `json:"description"`
// 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.
// 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
IPID *string `json:"ip_id"`
// Tags list of keyword
Tags []string `json:"tags"`
Expand Down Expand Up @@ -1443,7 +1451,7 @@ type ListIPsRequest struct {
Region scw.Region `json:"-"`
// Page page number
Page *int32 `json:"-"`
// PageSize set the maximum list size
// PageSize the number of items to return
PageSize *uint32 `json:"-"`
// IPAddress use this to search by IP address
IPAddress *string `json:"-"`
Expand Down Expand Up @@ -1598,7 +1606,7 @@ type ListBackendsRequest struct {
OrderBy ListBackendsRequestOrderBy `json:"-"`
// Page page number
Page *int32 `json:"-"`
// PageSize set the maximum list sizes
// PageSize the number of items to returns
PageSize *uint32 `json:"-"`
}

Expand Down Expand Up @@ -2235,7 +2243,7 @@ type ListFrontendsRequest struct {
OrderBy ListFrontendsRequestOrderBy `json:"-"`
// Page page number
Page *int32 `json:"-"`
// PageSize set the maximum list sizes
// PageSize the number of items to returns
PageSize *uint32 `json:"-"`
}

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

type ListBackendStatsRequest struct {
Region scw.Region `json:"-"`
// LbID load Balancer ID
LbID string `json:"-"`
// Page page number
Page *int32 `json:"-"`
// PageSize the number of items to return
PageSize *uint32 `json:"-"`
}

func (s *API) ListBackendStats(req *ListBackendStatsRequest, opts ...scw.RequestOption) (*ListBackendStatsResponse, error) {
var err error

if req.Region == "" {
defaultRegion, _ := s.client.GetDefaultRegion()
req.Region = defaultRegion
}

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

query := url.Values{}
parameter.AddToQuery(query, "page", req.Page)
parameter.AddToQuery(query, "page_size", req.PageSize)

if fmt.Sprint(req.Region) == "" {
return nil, errors.New("field Region cannot be empty in request")
}

if fmt.Sprint(req.LbID) == "" {
return nil, errors.New("field LbID cannot be empty in request")
}

scwReq := &scw.ScalewayRequest{
Method: "GET",
Path: "/lb/v1/regions/" + fmt.Sprint(req.Region) + "/lbs/" + fmt.Sprint(req.LbID) + "/backend-stats",
Query: query,
Headers: http.Header{},
}

var resp ListBackendStatsResponse

err = s.client.Do(scwReq, &resp, opts...)
if err != nil {
return nil, err
}
return &resp, nil
}

// UnsafeGetTotalCount should not be used
// Internal usage only
func (r *ListBackendStatsResponse) UnsafeGetTotalCount() uint32 {
return r.TotalCount
}

// UnsafeAppend should not be used
// Internal usage only
func (r *ListBackendStatsResponse) UnsafeAppend(res interface{}) (uint32, scw.SdkError) {
results, ok := res.(*ListBackendStatsResponse)
if !ok {
return 0, errors.New("%T type cannot be appended to type %T", res, r)
}

r.BackendServersStats = append(r.BackendServersStats, results.BackendServersStats...)
r.TotalCount += uint32(len(results.BackendServersStats))
return uint32(len(results.BackendServersStats)), nil
}

type ListACLsRequest struct {
Region scw.Region `json:"-"`
// FrontendID iD of your frontend
Expand All @@ -2588,7 +2666,7 @@ type ListACLsRequest struct {
OrderBy ListACLRequestOrderBy `json:"-"`
// Page page number
Page *int32 `json:"-"`
// PageSize set the maximum list size
// PageSize the number of items to return
PageSize *uint32 `json:"-"`
// Name filter acl per name
Name *string `json:"-"`
Expand Down Expand Up @@ -2896,7 +2974,7 @@ type ListCertificatesRequest struct {
OrderBy ListCertificatesRequestOrderBy `json:"-"`
// Page page number
Page *int32 `json:"-"`
// PageSize set the maximum list size
// PageSize the number of items to return
PageSize *uint32 `json:"-"`
// Name use this to search by name
Name *string `json:"-"`
Expand Down Expand Up @@ -3088,7 +3166,7 @@ type ListLbTypesRequest struct {
Region scw.Region `json:"-"`
// Page page number
Page *int32 `json:"-"`
// PageSize set the maximum list size
// PageSize the number of items to return
PageSize *uint32 `json:"-"`
}

Expand Down
2 changes: 1 addition & 1 deletion api/rdb/v1/rdb_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ type RestoreDatabaseBackupRequest struct {
Region scw.Region `json:"-"`
// DatabaseBackupID backup of a logical database
DatabaseBackupID string `json:"-"`
// 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.
// 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
DatabaseName *string `json:"database_name"`
// InstanceID defines the rdb instance where the backup has to be restored
InstanceID string `json:"instance_id"`
Expand Down
4 changes: 3 additions & 1 deletion api/registry/v1/registry_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ type Image struct {
//
// Default value: visibility_unknown
Visibility ImageVisibility `json:"visibility"`
// 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.
// Size image size in bytes, calculated from the size of image layers
//
// 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.
Size uint64 `json:"size"`
// CreatedAt creation date
CreatedAt time.Time `json:"created_at"`
Expand Down
2 changes: 1 addition & 1 deletion api/test/v1/test_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
_ = namegenerator.GetRandomName
)

// API no Auth Service for end-to-end testing.
// API no Auth Service for end-to-end testing
type API struct {
client *scw.Client
}
Expand Down

0 comments on commit 3357983

Please sign in to comment.