From f4ecddeca551925afe227a5fd56f26edc5f47b57 Mon Sep 17 00:00:00 2001 From: Mickael Gaillard Date: Wed, 9 Oct 2024 10:44:35 +0200 Subject: [PATCH] Exclude services --- cmd/scaling-instance.go | 1 + go.mod | 2 +- go.sum | 4 ++-- internal/logic/scaling_resource.go | 23 +++++++++++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/cmd/scaling-instance.go b/cmd/scaling-instance.go index 0a52a1c..eafb074 100644 --- a/cmd/scaling-instance.go +++ b/cmd/scaling-instance.go @@ -18,6 +18,7 @@ const ( func init() { flag.StringVarP(&app.ArgsS.Name, "name", "", "", "Apps or Service name") + flag.BoolVarP(&app.ArgsS.IncludeServices, "include_service", "", false, "Autoscale the services") flag.IntVarP(&app.ArgsS.HostCountMin, "min_host_count:", "", 1, "Minimum host count") flag.IntVarP(&app.ArgsS.HostCountMax, "max_host_count", "", 3, "Maximum host count") flag.Float64VarP(&app.ArgsS.CpuUsageMin, "min_cpu_usage_upscale", "", 75.0, "Minimum CPU usage in % (for upscale event only)") diff --git a/go.mod b/go.mod index 74492d0..b92146d 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.6 require ( github.com/spf13/pflag v1.0.5 - github.com/upsun/lib-sun v0.3.11 + github.com/upsun/lib-sun v0.3.12 ) require ( diff --git a/go.sum b/go.sum index 72377e9..fe673b2 100644 --- a/go.sum +++ b/go.sum @@ -16,8 +16,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/upsun/lib-sun v0.3.11 h1:yhlZWWQeIXcm5PLcniV8cbA2Y7kQ/Fkf/0QDPpIi010= -github.com/upsun/lib-sun v0.3.11/go.mod h1:8AtRNv0L+c9qCS/maO/OVFIn2VDi89LTkWwpB7YKTDE= +github.com/upsun/lib-sun v0.3.12 h1:+npDh43Uy2BE450fcUjfBqkzvCeUimLaCpFXi+oKUh0= +github.com/upsun/lib-sun v0.3.12/go.mod h1:8AtRNv0L+c9qCS/maO/OVFIn2VDi89LTkWwpB7YKTDE= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= diff --git a/internal/logic/scaling_resource.go b/internal/logic/scaling_resource.go index c35990e..c6fdbaf 100644 --- a/internal/logic/scaling_resource.go +++ b/internal/logic/scaling_resource.go @@ -104,6 +104,29 @@ func ScalingInstance(projectContext entity.ProjectGlobal) { usages[name] = usage } + if !app.ArgsS.IncludeServices { + // Get Services + log.Println("Dectect available services of project... (to exclude)") + payload = []string{ + "--environment=" + projectContext.DefaultEnv, + "--format=csv", + "--columns=name", + "--no-header", + "--no-interaction", + "--yes", + } + output, err = utils.CallCLIString(projectContext, "service:list", payload...) + if err != nil { + log.Fatalf("command execution failed: %s", err) + } + + // Parse output + srvs := strings.Split(output, "\n") + for _, srv := range srvs[:len(srvs)-1] { + delete(usages, srv) + } + } + // Compute log.Println("Compute trend...")