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

Many functions are calling the machine listing to retrieve a single machine, overloading the MAAS regions #239

Open
r00ta opened this issue Oct 25, 2024 · 3 comments

Comments

@r00ta
Copy link
Contributor

r00ta commented Oct 25, 2024

I found out that in TF there are many calls to

func getMachine(client *client.Client, identifier string) (*entity.Machine, error) {
	machines, err := client.Machines.Get(&entity.MachinesParams{})
	if err != nil {
		return nil, err
	}
	for _, m := range machines {
		if m.SystemID == identifier || m.Hostname == identifier || m.FQDN == identifier || m.BootInterface.MACAddress == identifier {
			return &m, nil
		}
	}
	return nil, fmt.Errorf("machine (%s) not found", identifier)
}

which means that in order to get a single machine the machine listing is called. The machine listing is the most expensive operation and for this reason it should be avoided as much as possible.

Instead, these functions should specify the identifiers in the machine listing so to perform the lookup on the server and improve a lot the server performances. If some identifiers are not supported by the current API, we should improve the API so to make it possible.

@sempervictus
Copy link

can we cache the machines list from the first call for the duration of the run?

@sempervictus
Copy link

sempervictus commented Oct 25, 2024

the "short circuit" approach for the >40 calls across the provider for that would be something like

diff --git i/maas/resource_maas_machine.go w/maas/resource_maas_machine.go
index fff14e0..da5c63f 100644
--- i/maas/resource_maas_machine.go
+++ w/maas/resource_maas_machine.go
@@ -351,6 +351,10 @@ func waitForMachineStatus(ctx context.Context, client *client.Client, systemID s
 }
 
 func getMachine(client *client.Client, identifier string) (*entity.Machine, error) {
+       machine, err := client.Machine.Get(identifier)
+       if err == nil {
+               return machine, nil
+       }
        machines, err := client.Machines.Get(&entity.MachinesParams{})
        if err != nil {
                return nil, err

which should help those lookups a lot if the subordinate resources pass the system.ID to that call (what the gomaas client expects for client.Machine.Get vs Machines.Get)

@sempervictus

This comment has been minimized.

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

No branches or pull requests

2 participants