Skip to content

Commit

Permalink
修改log配置
Browse files Browse the repository at this point in the history
Signed-off-by: wuyouxia [email protected]
  • Loading branch information
wuyouxia123 committed Oct 10, 2023
1 parent 25c8975 commit 661d3cd
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 40 deletions.
37 changes: 5 additions & 32 deletions cmd/aeraki/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package main

import (
"flag"
"os"
"os/signal"
"strings"

Check failure on line 20 in cmd/aeraki/main.go

View workflow job for this annotation

GitHub Actions / TestPercentageRouting

"strings" imported and not used

Check failure on line 20 in cmd/aeraki/main.go

View workflow job for this annotation

GitHub Actions / redis-e2e-test

"strings" imported and not used

Check failure on line 20 in cmd/aeraki/main.go

View workflow job for this annotation

GitHub Actions / TestVersionRouting

"strings" imported and not used

Check failure on line 20 in cmd/aeraki/main.go

View workflow job for this annotation

GitHub Actions / TestGatewayVersionRouting

"strings" imported and not used

Check failure on line 20 in cmd/aeraki/main.go

View workflow job for this annotation

GitHub Actions / go-lint

"strings" imported and not used (typecheck)

Check failure on line 20 in cmd/aeraki/main.go

View workflow job for this annotation

GitHub Actions / TestAttributeRouting

"strings" imported and not used

Check failure on line 20 in cmd/aeraki/main.go

View workflow job for this annotation

GitHub Actions / TestExportToNS

"strings" imported and not used

Check failure on line 20 in cmd/aeraki/main.go

View workflow job for this annotation

GitHub Actions / TestConsistentHashLb

"strings" imported and not used

Check failure on line 20 in cmd/aeraki/main.go

View workflow job for this annotation

GitHub Actions / TestGlobalRateLimit

"strings" imported and not used

Check failure on line 20 in cmd/aeraki/main.go

View workflow job for this annotation

GitHub Actions / TestHeaderMutation

"strings" imported and not used

Check failure on line 20 in cmd/aeraki/main.go

View workflow job for this annotation

GitHub Actions / TestLocalRateLimit

"strings" imported and not used

Check failure on line 20 in cmd/aeraki/main.go

View workflow job for this annotation

GitHub Actions / TestTrafficMirror

"strings" imported and not used
Expand All @@ -32,20 +31,21 @@ import (
"github.com/aeraki-mesh/aeraki/internal/plugin/metaprotocol"
"github.com/aeraki-mesh/aeraki/internal/plugin/thrift"
"github.com/aeraki-mesh/aeraki/internal/plugin/zookeeper"
flag "github.com/spf13/pflag"
)

const (
defaultIstiodAddr = "istiod.istio-system:15010"
defaultRootNamespace = "istio-system"
defaultElectionID = "aeraki-controller"
defaultLogLevel = "all:info"
defaultConfigStoreSecret = ""
defaultKubernetesDomain = "cluster.local"
defaultMeshConfigMapName = "istio"
)

func main() {
args := bootstrap.NewAerakiArgs()
loggingOptions := log.DefaultOptions()
flag.BoolVar(&args.Master, "master", true, "Run as master")
flag.BoolVar(&args.EnableEnvoyFilterNSScope, "enable-envoy-filter-namespace-scope", false,
"Generate Envoy Filters in the service namespace")
Expand All @@ -59,12 +59,14 @@ func main() {
"The secret to store the Istio kube config store, use the in cluster API server if it's not specified")
flag.StringVar(&args.ElectionID, "election-id", defaultElectionID, "ElectionID to elect master controller")
flag.StringVar(&args.ServerID, "server-id", "", "Aeraki server id")
flag.StringVar(&args.LogLevel, "log-level", defaultLogLevel, "Component log level")
flag.StringVar(&args.KubeDomainSuffix, "domain", defaultKubernetesDomain, "Kubernetes DNS domain suffix")
flag.StringVar(&args.HTTPSAddr, "httpsAddr", ":15017", "validation service HTTPS address")
flag.StringVar(&args.HTTPAddr, "httpAddr", ":8080", "Aeraki readiness service HTTP address")
loggingOptions.AttachFlags(flag.StringArrayVar, flag.StringVar, flag.IntVar, flag.BoolVar)
flag.Parse()

log.Configure(loggingOptions)

flag.VisitAll(func(flag *flag.Flag) {
log.Infof("Aeraki parameter: %s: %v", flag.Name, flag.Value)
})
Expand All @@ -76,7 +78,6 @@ func main() {
initArgsWithEnv(args)
log.Infof("Aeraki bootstrap parameter: %v", args)

setLogLevels(args.LogLevel)
// Create the stop channel for all of the servers.
stopChan := make(chan struct{}, 1)
args.Protocols = initGenerators()
Expand Down Expand Up @@ -123,11 +124,6 @@ func initArgsWithEnv(args *bootstrap.AerakiArgs) {
args.ConfigStoreSecret = secret
}

logLevel := os.Getenv("AERAKI_LOG_LEVEL")
if logLevel != "" {
args.LogLevel = logLevel
}

podName := os.Getenv("POD_NAME")
if podName != "" {
args.PodName = os.Getenv("POD_NAME")
Expand All @@ -144,26 +140,3 @@ func initGenerators() map[protocol.Instance]envoyfilter.Generator {
protocol.MetaProtocol: metaprotocol.NewGenerator(),
}
}

func setLogLevels(level string) {
logOpts := log.DefaultOptions()
levels := strings.Split(level, ",")
for _, l := range levels {
cl := strings.Split(l, ":")
if len(cl) != 2 {
continue
}
logOpts.SetOutputLevel(cl[0], stringToLevel[cl[1]])
}
_ = log.Configure(logOpts)
}

// this is the same as istio.io/pkg/log.stringToLevel
var stringToLevel = map[string]log.Level{
"debug": log.DebugLevel,
"info": log.InfoLevel,
"warn": log.WarnLevel,
"error": log.ErrorLevel,
"fatal": log.FatalLevel,
"none": log.NoneLevel,
}
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ RUN apk update && \
apk add curl

COPY ${AERAKI_ROOT_BIN_DIR}/${ARCH}/${OS}/aeraki /usr/local/bin/
ENTRYPOINT /usr/local/bin/aeraki
ENTRYPOINT ["/usr/local/bin/aeraki"]
1 change: 0 additions & 1 deletion internal/bootstrap/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type AerakiArgs struct {
ConfigStoreSecret string
ElectionID string
ServerID string
LogLevel string
KubeDomainSuffix string
EnableEnvoyFilterNSScope bool
Protocols map[protocol.Instance]envoyfilter.Generator
Expand Down
2 changes: 0 additions & 2 deletions k8s/aeraki.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ spec:
# False(Default): The generated envoyFilters will be placed under Istio root namespace
# True: The generated envoyFilters will be placed under the service namespace
value: "${AERAKI_ENABLE_ENVOY_FILTER_NS_SCOPE}"
- name: AERAKI_LOG_LEVEL
value: "all:debug"
- name: POD_NAME
valueFrom:
fieldRef:
Expand Down
4 changes: 1 addition & 3 deletions manifests/charts/aeraki/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ spec:
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- /usr/local/bin/aeraki
- --master=true
- --enable-envoy-filter-namespace-scope=false
- --log_output_level=all:info
ports:
- containerPort: 8080
protocol: TCP
Expand Down Expand Up @@ -77,8 +77,6 @@ spec:
value: {{ .Values.AERAKI_ENV.AERAKI_XDS_ADDR }}
- name: AERAKI_XDS_PORT
value: { { .Values.AERAKI_ENV.AERAKI_XDS_PORT } }
- name: AERAKI_LOG_LEVEL
value: {{ .Values.AERAKI_ENV.AERAKI_LOG_LEVEL }}
- name: AERAKI_NAMESPACE
valueFrom:
fieldRef:
Expand Down
1 change: 0 additions & 1 deletion manifests/charts/aeraki/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ AERAKI_ENV:
AERAKI_ISTIO_CONFIG_STORE_SECRET:
AERAKI_XDS_ADDR: "aeraki.istio-system"
AERAKI_XDS_PORT: ":15010"
AERAKI_LOG_LEVEL: "all:debug"
AERAKI_ISTIOD_CONFIGMAP_NAME: "istio"

imagePullSecrets: []
Expand Down

0 comments on commit 661d3cd

Please sign in to comment.