Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configure page_size as an optional parameter #50

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Config struct {
RequestAggregationDelay time.Duration `yaml:"request_aggregation_delay"`
Provider string `yaml:"provider,omitempty"`
Engine string `yaml:"engine,omitempty"`
PageSize int `yaml:"page_size,omitempty"`
PageSize *int `yaml:"page_size,omitempty"`
SSL *SSL `yaml:"ssl,omitempty"`
CredsPath *string `yaml:"credentials_path,omitempty"`
FwdSvcURL *string `yaml:"forward_service_url,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"
"time"

"github.com/agrea/ptr"
"github.com/stretchr/testify/require"
)

Expand All @@ -36,6 +37,7 @@ http:
port: 49021
ssl: true
request_aggregation_delay: 15s
page_size: 50
ssl:
cert: %s
key: %s
Expand Down Expand Up @@ -89,6 +91,7 @@ func TestConfig(t *testing.T) {
SSL: true,
},
RequestAggregationDelay: 15 * time.Second,
PageSize: ptr.Int(50),
SSL: &SSL{
Cert: cert.Name(),
Key: key.Name(),
Expand Down
18 changes: 14 additions & 4 deletions pkg/providers/aws/instance_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,21 @@ import (

var defaultPageSize int32 = 100

func (p *Provider) generateInstanceTopology(ctx context.Context, pageSize int32, cis []topology.ComputeInstances) ([]types.InstanceTopology, error) {
var err error
topology := []types.InstanceTopology{}
func (p *Provider) generateInstanceTopology(ctx context.Context, pageSize *int, cis []topology.ComputeInstances) ([]types.InstanceTopology, error) {
var (
err error
topology []types.InstanceTopology
limit int32
)

if pageSize != nil {
limit = int32(*pageSize)
} else {
limit = defaultPageSize
}

for _, ci := range cis {
if topology, err = p.generateInstanceTopologyForRegionInstances(ctx, pageSize, &ci, topology); err != nil {
if topology, err = p.generateInstanceTopologyForRegionInstances(ctx, limit, &ci, topology); err != nil {
return nil, err
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/providers/aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ func New(clientFactory ClientFactory, imdsClient IDMSClient) *Provider {
}
}

func (p *Provider) GenerateTopologyConfig(ctx context.Context, pageSize int, instances []topology.ComputeInstances) (*topology.Vertex, error) {
topology, err := p.generateInstanceTopology(ctx, int32(pageSize), instances)
func (p *Provider) GenerateTopologyConfig(ctx context.Context, pageSize *int, instances []topology.ComputeInstances) (*topology.Vertex, error) {
topology, err := p.generateInstanceTopology(ctx, pageSize, instances)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/baremetal/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func New() (*Provider, error) {
return &Provider{}, nil
}

func (p *Provider) GenerateTopologyConfig(ctx context.Context, _ int, instances []topology.ComputeInstances) (*topology.Vertex, error) {
func (p *Provider) GenerateTopologyConfig(ctx context.Context, _ *int, instances []topology.ComputeInstances) (*topology.Vertex, error) {
if len(instances) > 1 {
return nil, ErrMultiRegionNotSupported
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/cw/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func New() (*Provider, error) {
return &Provider{}, nil
}

func (p *Provider) GenerateTopologyConfig(ctx context.Context, _ int, instances []topology.ComputeInstances) (*topology.Vertex, error) {
func (p *Provider) GenerateTopologyConfig(ctx context.Context, _ *int, instances []topology.ComputeInstances) (*topology.Vertex, error) {
if len(instances) > 1 {
return nil, fmt.Errorf("CW does not support mult-region topology requests")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/gcp/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func New(clientFactory ClientFactory) (*Provider, error) {
}, nil
}

func (p *Provider) GenerateTopologyConfig(ctx context.Context, _ int, instances []topology.ComputeInstances) (*topology.Vertex, error) {
func (p *Provider) GenerateTopologyConfig(ctx context.Context, _ *int, instances []topology.ComputeInstances) (*topology.Vertex, error) {
if len(instances) > 1 {
return nil, fmt.Errorf("GCP does not support mult-region topology requests")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/oci/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func New(ociClientFactory ClientFactory) *Provider {
}
}

func (p *Provider) GenerateTopologyConfig(ctx context.Context, _ int, instances []topology.ComputeInstances) (*topology.Vertex, error) {
func (p *Provider) GenerateTopologyConfig(ctx context.Context, _ *int, instances []topology.ComputeInstances) (*topology.Vertex, error) {
cfg, err := GenerateInstanceTopology(ctx, p.clientFactory, instances)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

type Provider interface {
GenerateTopologyConfig(ctx context.Context, pageSize int, instances []topology.ComputeInstances) (*topology.Vertex, error)
GenerateTopologyConfig(ctx context.Context, pageSize *int, instances []topology.ComputeInstances) (*topology.Vertex, error)
}

type Config struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ func (p *Provider) GetComputeInstances(_ context.Context) ([]topology.ComputeIns
}, nil
}

func (p *Provider) GenerateTopologyConfig(_ context.Context, _ int, _ []topology.ComputeInstances) (*topology.Vertex, error) {
func (p *Provider) GenerateTopologyConfig(_ context.Context, _ *int, _ []topology.ComputeInstances) (*topology.Vertex, error) {
return p.tree, nil
}
Loading