Skip to content

Commit

Permalink
banner at start
Browse files Browse the repository at this point in the history
Signed-off-by: Jirka Kremser <jiri.kremser@gmail.com>
  • Loading branch information
jkremser committed Oct 10, 2024
1 parent 5771356 commit c64b04f
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 14 deletions.
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.22.2
toolchain go1.22.7

require (
github.com/fatih/color v1.17.0
github.com/go-logr/logr v1.4.2
github.com/kedacore/http-add-on v0.8.0
github.com/kedacore/keda/v2 v2.14.1-0.20240429185716-c55e306af94b
github.com/kelseyhightower/envconfig v1.4.0
go.opentelemetry.io/collector/component v0.110.0
Expand All @@ -22,6 +22,7 @@ require (
golang.org/x/sync v0.8.0
google.golang.org/grpc v1.67.0
google.golang.org/protobuf v1.34.2
k8s.io/apimachinery v0.30.3
k8s.io/code-generator v0.30.3
sigs.k8s.io/controller-runtime v0.18.4
sigs.k8s.io/kustomize/kustomize/v5 v5.4.1
Expand Down Expand Up @@ -61,13 +62,16 @@ require (
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.1.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/mostynb/go-grpc-compression v1.2.3 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/onsi/ginkgo/v2 v2.17.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
Expand Down Expand Up @@ -120,7 +124,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.30.1 // indirect
k8s.io/apiextensions-apiserver v0.30.1 // indirect
k8s.io/apimachinery v0.30.3 // indirect
k8s.io/client-go v0.30.1 // indirect
k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
Expand Down
11 changes: 9 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ github.com/evanphx/json-patch v5.8.1+incompatible h1:2toJaoe7/rNa1zpeQx0UnVEjqk6
github.com/evanphx/json-patch v5.8.1+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
Expand Down Expand Up @@ -69,8 +71,6 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kedacore/http-add-on v0.8.0 h1:CdWFpjfFyWGwuukBxE+PKd7rzGtN4Ux1m0MlY65PcSk=
github.com/kedacore/http-add-on v0.8.0/go.mod h1:OR2f7UmAQSafrBrAFx+Ij7LiexksVkueo9rVfrelhyg=
github.com/kedacore/keda/v2 v2.14.1-0.20240429185716-c55e306af94b h1:FCGepXWVVCrqPDhPFFAuMyeJfgC7bcu1GFgQQsXESVA=
github.com/kedacore/keda/v2 v2.14.1-0.20240429185716-c55e306af94b/go.mod h1:V03Uj1+jxKYAzqa09FSwlEzqj8HfYeXM6yhH4gm4PyA=
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
Expand All @@ -91,6 +91,11 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
Expand Down Expand Up @@ -250,6 +255,8 @@ golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
Expand Down
12 changes: 3 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package main
import (
"context"
"errors"
"flag"
"fmt"
"net"
"os"
Expand All @@ -23,20 +22,18 @@ import (
"go.opentelemetry.io/collector/receiver/otlpreceiver"
"golang.org/x/sync/errgroup"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"github.com/kedify/otel-add-on/build"
"github.com/kedify/otel-add-on/metric"
"github.com/kedify/otel-add-on/receiver"
"github.com/kedify/otel-add-on/scaler"
"github.com/kedify/otel-add-on/types"
"github.com/kedify/otel-add-on/util"

"google.golang.org/grpc"
"google.golang.org/grpc/health"
"google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/reflection"

"github.com/kedacore/http-add-on/pkg/util"
)

var (
Expand All @@ -58,11 +55,8 @@ func main() {

//targetPendingRequests := cfg.TargetPendingRequests

opts := zap.Options{}
opts.BindFlags(flag.CommandLine)
flag.Parse()

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
util.SetupLog(cfg.NoColor)
util.PrintBanner(setupLog, cfg.NoColor)

//k8sCfg, err := ctrl.GetConfig()
_, err := ctrl.GetConfig()
Expand Down
3 changes: 2 additions & 1 deletion scaler/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
)

type Config struct {
OTLPReceiverPort int `envconfig:"OTLP_RECEIVER_PORT" default:"4317"`
OTLPReceiverPort int `envconfig:"OTLP_RECEIVER_PORT" default:"4317"`
NoColor bool `envconfig:"NO_COLOR" default:"false"`
// TargetNamespace is the namespace in which this scaler is running, and the namespace
// that the target interceptors are running in. This scaler and all the interceptors
// must be running in the same namespace
Expand Down
25 changes: 25 additions & 0 deletions util/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package util

import (
"context"
"errors"
"net/http"
)

var (
ignoredErrs = []error{
nil,
context.Canceled,
http.ErrServerClosed,
}
)

func IsIgnoredErr(err error) bool {
for _, ignoredErr := range ignoredErrs {
if errors.Is(err, ignoredErr) {
return true
}
}

return false
}
52 changes: 52 additions & 0 deletions util/welcome.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package util

import (
"flag"
"fmt"

"github.com/fatih/color"
"github.com/go-logr/logr"
"go.uber.org/zap/zapcore"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

const (
fiveSpaces = " "
)

func PrintBanner(logger logr.Logger, noColor bool) {
color.NoColor = noColor
c1, c2, c3, c4 := color.FgBlue, color.FgWhite, color.FgCyan, color.FgHiYellow
pad := fiveSpaces + fiveSpaces
lines := []string{
pad + color.New(c1).Sprintf(" ___ ") + color.New(c4).Sprintf("_____") + color.New(c1).Sprintf(" _____ _ ") + color.New(c3).Sprintf(" _ _"),
pad + color.New(c1).Sprintf(" / _ \\") + color.New(c4).Sprintf("_ _|") + color.New(c1).Sprintf(" ____| | ") + color.New(c3).Sprintf(" __ _ __| | __| | ___ _ __"),
pad + color.New(c1).Sprintf("| | | |") + color.New(c4).Sprintf("| |") + color.New(c1).Sprintf(" | _| | | ") + color.New(c3).Sprintf(" / _` |/ _` |/ _` |") + color.New(c2).Sprintf("___") + color.New(c3).Sprintf(" / _ \\| '_ \\"),
pad + color.New(c1).Sprintf("| |_| |") + color.New(c4).Sprintf("| |") + color.New(c1).Sprintf(" | |___| |___ ") + color.New(c3).Sprintf(" | (_| | (_| | (_| ") + color.New(c2).Sprintf("|___|") + color.New(c3).Sprintf(" (_) | | | |"),
pad + color.New(c1).Sprintf(" \\___/ ") + color.New(c4).Sprintf("|_|") + color.New(c1).Sprintf(" |_____|_____\\ ") + color.New(c3).Sprintf(" \\__,_|\\__,_|\\__,_|") + color.New(c3).Sprintf(" \\___/|_| |_|\n"),
}
for _, line := range lines {
line := line
fmt.Println(line)
}
}

// SetupLog tweak the default log to use custom time format and use colors if supported
func SetupLog(noColor bool) {
var opts zap.Options
zap.UseDevMode(true)(&opts)
zap.ConsoleEncoder(func(c *zapcore.EncoderConfig) {
c.EncodeCaller = func(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder) {
enc.AppendString(caller.TrimmedPath())
}
c.EncodeTime = zapcore.TimeEncoderOfLayout("01-02 15:04:05")
if !noColor {
c.EncodeLevel = zapcore.CapitalColorLevelEncoder
}
})(&opts)

opts.BindFlags(flag.CommandLine)
flag.Parse()
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
}

0 comments on commit c64b04f

Please sign in to comment.