Skip to content

Commit

Permalink
Merge pull request #1596 from pb82/always-return-all-sizes-enterprise
Browse files Browse the repository at this point in the history
feat: return all sizes regardless of capacity for enterprise
  • Loading branch information
machi1990 authored Feb 27, 2023
2 parents 258f9fe + 49a35f7 commit 1122f01
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 17 deletions.
12 changes: 12 additions & 0 deletions internal/kafka/internal/handlers/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,18 @@ func Test_GetEnterpriseCluster(t *testing.T) {
Id: "x1",
CapacityConsumed: 1,
},
{
Id: "x2",
CapacityConsumed: 2,
},
{
Id: "x3",
CapacityConsumed: 3,
},
{
Id: "x4",
CapacityConsumed: 4,
},
},
SupportedBillingModels: []public.SupportedKafkaBillingModel{
{
Expand Down
15 changes: 3 additions & 12 deletions internal/kafka/internal/presenters/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/pkg/api"
"github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/pkg/errors"
"github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/pkg/logger"
"github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/pkg/shared/utils/arrays"
)

func PresentEnterpriseClusterListItem(cluster api.Cluster) public.EnterpriseClusterListItem {
Expand Down Expand Up @@ -75,7 +74,7 @@ func PresentEnterpriseCluster(cluster api.Cluster, consumedStreamingUnitsInTheCl
storedCapacityInfo, ok := cluster.RetrieveDynamicCapacityInfo()[types.STANDARD.String()]
if ok {
presentedCluster.CapacityInformation = presentEnterpriseClusterCapacityInfo(consumedStreamingUnitsInTheCluster, storedCapacityInfo)
supportedInstanceTypes, err := presentEnterpriseClusterSupportedInstanceTypes(presentedCluster.CapacityInformation.RemainingKafkaStreamingUnits, kafkaConfig)
supportedInstanceTypes, err := presentEnterpriseClusterSupportedInstanceTypes(kafkaConfig)
if err != nil {
return public.EnterpriseCluster{}, err
}
Expand All @@ -99,7 +98,7 @@ func presentEnterpriseClusterCapacityInfo(consumedStreamingUnitsInTheCluster int
}
}

func presentEnterpriseClusterSupportedInstanceTypes(remainingCapacity int32, kafkaConfig *config.KafkaConfig) (public.SupportedKafkaInstanceTypesList, error) {
func presentEnterpriseClusterSupportedInstanceTypes(kafkaConfig *config.KafkaConfig) (public.SupportedKafkaInstanceTypesList, error) {
// enterprise clusters only supports standard instance type for now. It is safe to hardcode this.
standardInstanceType, err := kafkaConfig.SupportedInstanceTypes.Configuration.GetKafkaInstanceTypeByID(types.STANDARD.String())
if err != nil { // this should never happen, lets log an error in case it happens.
Expand All @@ -118,15 +117,7 @@ func presentEnterpriseClusterSupportedInstanceTypes(remainingCapacity int32, kaf
}, err
}

availableSizes := arrays.Filter(standardInstanceType.Sizes, func(size config.KafkaInstanceSize) bool {
return int32(size.CapacityConsumed) <= remainingCapacity
})

presentedSizes := []public.SupportedKafkaSize{}

if len(availableSizes) > 0 {
presentedSizes = GetSupportedSizes(&config.KafkaInstanceType{Sizes: availableSizes})
}
presentedSizes := GetSupportedSizes(&config.KafkaInstanceType{Sizes: standardInstanceType.Sizes})

return public.SupportedKafkaInstanceTypesList{
InstanceTypes: []public.SupportedKafkaInstanceType{
Expand Down
37 changes: 33 additions & 4 deletions internal/kafka/internal/presenters/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func Test_PresentEnterpriseCluster(t *testing.T) {
CloudProvider: "azure",
Region: "af-east",
MultiAZ: true,
DynamicCapacityInfo: api.JSON([]byte(`{"standard":{"max_nodes":15,"max_units":5,"remaining_units":3}}`)),
DynamicCapacityInfo: api.JSON(`{"standard":{"max_nodes":15,"max_units":5,"remaining_units":3}}`),
},
kafkaConfig: validKafkaConfig,
},
Expand Down Expand Up @@ -254,6 +254,14 @@ func Test_PresentEnterpriseCluster(t *testing.T) {
Id: "x3",
CapacityConsumed: 3,
},
{
Id: "x4",
CapacityConsumed: 4,
},
{
Id: "x5",
CapacityConsumed: 5,
},
},
SupportedBillingModels: []public.SupportedKafkaBillingModel{
{
Expand All @@ -267,7 +275,7 @@ func Test_PresentEnterpriseCluster(t *testing.T) {
},
},
{
name: "should successfully convert api.Cluster to EnterpriseCluster with capacity information and supported types that has an empty list of sizes when there is not capacity left",
name: "should successfully convert api.Cluster to EnterpriseCluster with capacity information and a full list of supported sizes",
args: args{
cluster: api.Cluster{
ClusterID: clusterId,
Expand Down Expand Up @@ -298,8 +306,29 @@ func Test_PresentEnterpriseCluster(t *testing.T) {
SupportedInstanceTypes: public.SupportedKafkaInstanceTypesList{
InstanceTypes: []public.SupportedKafkaInstanceType{
{
Id: types.STANDARD.String(),
Sizes: []public.SupportedKafkaSize{},
Id: types.STANDARD.String(),
Sizes: []public.SupportedKafkaSize{
{
Id: "x1",
CapacityConsumed: 1,
},
{
Id: "x2",
CapacityConsumed: 2,
},
{
Id: "x3",
CapacityConsumed: 3,
},
{
Id: "x4",
CapacityConsumed: 4,
},
{
Id: "x5",
CapacityConsumed: 5,
},
},
SupportedBillingModels: []public.SupportedKafkaBillingModel{
{
Id: constants.BillingModelEnterprise.String(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,10 @@ func TestEnterpriseClusterGet(t *testing.T) {
g.Expect(standardInstanceType.Id).To(gomega.Equal(types.STANDARD.String()))
g.Expect(standardInstanceType.SupportedBillingModels).To(gomega.HaveLen(1))
g.Expect(standardInstanceType.SupportedBillingModels[0].Id).To(gomega.Equal(constants.BillingModelEnterprise.String()))
g.Expect(standardInstanceType.Sizes).To(gomega.HaveLen(1))
g.Expect(standardInstanceType.Sizes).To(gomega.HaveLen(2))
g.Expect(standardInstanceType.Sizes[0].Id).To(gomega.Equal("x1"))
g.Expect(standardInstanceType.Sizes[1].Id).To(gomega.Equal("x2"))

// get cluster addons parameters
clusterWithAddonParameters, resp11, err := client.EnterpriseDataplaneClustersApi.GetEnterpriseClusterWithAddonParameters(adminCtx, entCluster.ClusterID)
g.Expect(err).ToNot(gomega.HaveOccurred())
Expand Down

0 comments on commit 1122f01

Please sign in to comment.