Skip to content

Conversation

@jwtty
Copy link
Contributor

@jwtty jwtty commented Oct 21, 2025

Description of your changes

This PR adds the proto and sdk for querying the AttributedBaseRecommendations API.

Tested in standalone env with custom client: fee0b52

And configured with env CAPACITY_ENDPOINT as:

env:
- name: CAPACITY_ENDPOINT
   value: 172.25.67.162:80/fleet # msi-connector svc's clusterIP with /fleet as path prefix

and

env:
- name: CAPACITY_ENDPOINT
  value: msi-connector.msi-connector.svc.cluster.local/fleet # msi-connector svc's domain name with /fleet as path prefix

Both worked:

I1021 03:25:20.130503       1 hubagent/main.go:196] "Capacity client created successfully" endpoint="msi-connector.msi-connector.svc.cluster.local/fleet" client={}
I1021 03:25:20.130868       1 hubagent/main.go:212] "Sending GenerateAttributeBasedRecommendations request" request="subscription_id:\"8ecadfc9-d1a3-4ea4-b844-0d9f87e4d7c8\"  location:\"centraluseuap\"  regular_priority_profile:{target_capacity:4}  resource_properties:{vm_attributes:{allowed_vm_sizes:\"Standard_D2s_v3\"  allowed_vm_sizes:\"Standard_D4s_v3\"}}"
I1021 03:25:23.545086       1 hubagent/main.go:217] "Received recommendations" response="recommended_vm_sizes:{regular_vm_sizes:{family:\"D\"  name:\"Standard_D2s_v3\"  size:\"D2s_v3\"}  regular_vm_sizes:{family:\"D\"  name:\"Standard_D4s_v3\"  size:\"D4s_v3\"}}"

Fixes #

I have:

  • Run make reviewable to ensure this PR is ready for review.

How has this code been tested

Special notes for your reviewer

serverAddress = "http://" + serverAddress
}
// Ensure serverAddress doesn't have trailing slash
serverAddress = strings.TrimSuffix(serverAddress, "/")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this not always localhost?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be http://localhost:<some port>, I prefer the port to be specified from argument instead of hardcoded.

@jwtty jwtty force-pushed the recomm-client branch 2 times, most recently from 8120e8a to fac9f1e Compare October 24, 2025 22:40

// attributeBasedVMSizeRecommenderClient implements the AttributeBasedVMSizeRecommenderClient interface
// for interacting with Azure Attribute-Based VM Size Recommender API.
type attributeBasedVMSizeRecommenderClient struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to make it public as a producer and NewAttributeBasedVMSizeRecommenderClient should return the concrete type.

)

// AttributeBasedVMSizeRecommenderClient is an interface for interacting with the Azure Attribute-Based VM Size Recommender API.
type AttributeBasedVMSizeRecommenderClient interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interface should be defined in the consumer side.

And it may be better to define the interface where we use it and we can have a fake implementation there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a bunch of interfaces defined with the client library itself. I think the point is to provide a self-contained library so users can directly use it: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/client-go/dynamic/dynamicinformer/interface.go#L26

httpClient *http.Client
}

// NewAttributeBasedVMSizeRecommenderClient creates a new attribute-based VM size recommender client.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation is anti-pattern,

// Bad:
package producer

type Thinger interface { Thing() bool }

type defaultThinger struct{ ... }
func (t defaultThinger) Thing() bool { ... }

func NewThinger() Thinger { return defaultThinger{ ... } }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zhiying-lin
zhiying-lin previously approved these changes Oct 28, 2025
Copy link
Contributor

@zhiying-lin zhiying-lin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved to unblock the project progress.

The interface style is also mentioned in https://go.dev/wiki/CodeReviewComments#interfaces.

I'll leave the decision to you, as it's more like a style issue.

@jwtty jwtty merged commit d7d6ab8 into Azure:main Oct 28, 2025
27 of 30 checks passed
@jwtty jwtty deleted the recomm-client branch October 28, 2025 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants