gianarb / orbiter

Orbiter is an opensource docker swarm autoscaler
Apache License 2.0
501 stars 54 forks source link

Optimize by querying by ID #57

Open bjwschaap opened 6 years ago

bjwschaap commented 6 years ago

You don't need to fetch and loop through all services in the Swarm @ https://github.com/gianarb/orbiter/blob/e8753183828181303209d4152319717be22927a9/autoscaler/autoscaler.go#L56

Instead you can add a filter, and fetch the required service directly. E.g.:

serviceFilter := filters.NewArgs()
serviceFilter.Add("id", serviceId)
services, err := dockerClient.ServiceList(ctx, types.ServiceListOptions{Filters: serviceFilter})

Also see: https://docs.docker.com/engine/reference/commandline/service_ls/#filtering

gianarb commented 6 years ago

This is a good catch @bjwschaap thanks!