Skip to content

Commit d4d7a8f

Browse files
authored
Fix/console (#1397)
* fix: create tag rule bug * refactor: config refactor; fix: fix console bugs * fix: instance disable traffic * fix: CI promblems * fix: typo
1 parent 7af9308 commit d4d7a8f

250 files changed

Lines changed: 827 additions & 5332 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ jobs:
5252
if: github.repository == 'apache/dubbo-admin'
5353
steps:
5454
- uses: actions/checkout@v4
55+
- name: Setup Node.js
56+
uses: actions/setup-node@v4
57+
with:
58+
node-version: '18'
59+
cache: 'yarn'
60+
cache-dependency-path: ui-vue3/yarn.lock
61+
- name: Build Frontend (Vue3)
62+
working-directory: ui-vue3
63+
run: |
64+
yarn install --frozen-lockfile
65+
yarn build
66+
- name: Copy Dist Directory
67+
run: cp -r ui-vue3/dist/ app/dubbo-ui/
5568
- name: Setup Go ${{ matrix.go_version }}
5669
uses: actions/setup-go@v5
5770
with:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ bin/
4545
build/
4646
vendor/
4747

48-
48+
app/dubbo-ui/dist/

Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Build the manager binary
17+
FROM docker.io/golang:1.24 AS builder
18+
ARG TARGETOS
19+
ARG TARGETARCH
20+
21+
WORKDIR /app
22+
23+
COPY go.mod go.mod
24+
COPY go.sum go.sum
25+
26+
ENV GOPROXY=https://goproxy.cn,direct
27+
28+
# cache deps before building and copying source so that we don't need to re-download as much
29+
# and so that source changes don't invalidate our downloaded layer
30+
RUN go env && go mod download
31+
32+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o dubbo-admin ./app/dubbo-admin/main.go
33+
34+
# Use distroless as minimal base image to package the manager binary
35+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
36+
FROM gcr.io/distroless/static:nonroot
37+
WORKDIR /
38+
COPY --from=builder /app/dubbo-admin .
39+
USER 65532:65532
40+
41+
ENTRYPOINT ["./dubbo-admin","run"]

app/dubbo-admin/cmd/root.go

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,68 +18,24 @@
1818
package cmd
1919

2020
import (
21-
"fmt"
2221
"os"
23-
"path/filepath"
2422

2523
"github.com/spf13/cobra"
2624

27-
dubbolog "github.com/apache/dubbo-admin/pkg/common/log"
28-
"github.com/apache/dubbo-admin/pkg/core"
29-
cmd2 "github.com/apache/dubbo-admin/pkg/core/cmd"
3025
"github.com/apache/dubbo-admin/pkg/core/cmd/version"
3126
)
3227

3328
// newRootCmd represents the base command when called without any subcommands.
3429
func newRootCmd() *cobra.Command {
35-
args := struct {
36-
logLevel string
37-
outputPath string
38-
maxSize int
39-
maxBackups int
40-
maxAge int
41-
}{}
4230
cmd := &cobra.Command{
4331
Use: "dubbo-admin",
4432
Short: "Universal Admin for Dubbo Application",
4533
Long: `Universal Admin for Dubbo Application`,
46-
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
47-
level, err := dubbolog.ParseLogLevel(args.logLevel)
48-
if err != nil {
49-
return err
50-
}
51-
52-
if args.outputPath != "" {
53-
output, err := filepath.Abs(args.outputPath)
54-
if err != nil {
55-
return err
56-
}
57-
58-
fmt.Printf("%s: logs will be stored in %q\n", "dubbo-cp", output)
59-
core.SetLogger(core.NewLoggerWithRotation(level, output, args.maxSize, args.maxBackups, args.maxAge))
60-
} else {
61-
core.SetLogger(core.NewLogger(level))
62-
}
63-
64-
// once command line flags have been parsed,
65-
// avoid printing usage instructions
66-
cmd.SilenceUsage = true
67-
68-
return nil
69-
},
7034
}
7135

7236
cmd.SetOut(os.Stdout)
73-
74-
// root flags
75-
cmd.PersistentFlags().StringVar(&args.logLevel, "log-level", dubbolog.InfoLevel.String(), cmd2.UsageOptions("log level", dubbolog.OffLevel, dubbolog.InfoLevel, dubbolog.DebugLevel))
76-
cmd.PersistentFlags().StringVar(&args.outputPath, "log-output-path", args.outputPath, "path to the file that will be filled with logs. Example: if we set it to /tmp/dubbo.log then after the file is rotated we will have /tmp/dubbo-2021-06-07T09-15-18.265.log")
77-
cmd.PersistentFlags().IntVar(&args.maxBackups, "log-max-retained-files", 1000, "maximum number of the old log files to retain")
78-
cmd.PersistentFlags().IntVar(&args.maxSize, "log-max-size", 100, "maximum size in megabytes of a log file before it gets rotated")
79-
cmd.PersistentFlags().IntVar(&args.maxAge, "log-max-age", 30, "maximum number of days to retain old log files based on the timestamp encoded in their filename")
80-
8137
// sub-commands
82-
cmd.AddCommand(newRunCmdWithOpts(cmd2.DefaultRunCmdOpts))
38+
cmd.AddCommand(newRunCmdWithOpts())
8339
cmd.AddCommand(version.NewVersionCmd())
8440

8541
return cmd

app/dubbo-admin/cmd/run.go

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,24 @@
1818
package cmd
1919

2020
import (
21+
"context"
22+
"os"
23+
"os/signal"
24+
"syscall"
2125
"time"
2226

2327
"github.com/spf13/cobra"
2428

2529
"github.com/apache/dubbo-admin/pkg/config"
2630
"github.com/apache/dubbo-admin/pkg/config/app"
2731
"github.com/apache/dubbo-admin/pkg/core/bootstrap"
28-
dubbocmd "github.com/apache/dubbo-admin/pkg/core/cmd"
2932
"github.com/apache/dubbo-admin/pkg/core/logger"
3033
dubboversion "github.com/apache/dubbo-admin/pkg/version"
3134
)
3235

3336
const gracefullyShutdownDuration = 3 * time.Second
3437

35-
// This is the open file limit below which the control plane may not
36-
// reasonably have enough descriptors to accept all its clients.
37-
const minOpenFileLimit = 4096
38-
39-
func newRunCmdWithOpts(opts dubbocmd.RunCmdOpts) *cobra.Command {
38+
func newRunCmdWithOpts() *cobra.Command {
4039
args := struct {
4140
configPath string
4241
}{}
@@ -49,10 +48,10 @@ func newRunCmdWithOpts(opts dubbocmd.RunCmdOpts) *cobra.Command {
4948
cfg := app.DefaultAdminConfig()
5049
err := config.Load(args.configPath, &cfg)
5150
if err != nil {
52-
logger.Errorf("could not load the configuration, cause: %s", err.Error())
5351
return err
54-
5552
}
53+
// 2. configure logger
54+
logger.Init(cfg.Log)
5655
cfgForDisplay, err := config.ConfigForDisplay(&cfg)
5756
if err != nil {
5857
logger.Errorf("unable to prepare config for display, cause: %s", err.Error())
@@ -63,11 +62,10 @@ func newRunCmdWithOpts(opts dubbocmd.RunCmdOpts) *cobra.Command {
6362
logger.Errorf("unable to convert config to json, cause: %s", err.Error())
6463
return err
6564
}
66-
logger.Infof("Current config %s", cfgBytes)
67-
logger.Infof("Running in mode `%s`", cfg.Mode)
65+
logger.Infof("current config:\n %s", cfgBytes)
6866

6967
// 2. build components
70-
gracefulCtx, ctx := opts.SetupSignalHandler()
68+
gracefulCtx, ctx := setupSignalHandler()
7169
rt, err := bootstrap.Bootstrap(gracefulCtx, cfg)
7270
if err != nil {
7371
logger.Errorf("unable to bootstrap, cause: %s", err.Error())
@@ -91,6 +89,25 @@ func newRunCmdWithOpts(opts dubbocmd.RunCmdOpts) *cobra.Command {
9189
},
9290
}
9391
// flags
94-
cmd.PersistentFlags().StringVarP(&args.configPath, "config-file", "c", "", "configuration file")
92+
cmd.PersistentFlags().StringVarP(&args.configPath, "config-file", "c", "./dubbo-admin.yaml", "configuration file")
9593
return cmd
9694
}
95+
96+
func setupSignalHandler() (context.Context, context.Context) {
97+
gracefulCtx, gracefulCancel := context.WithCancel(context.Background())
98+
ctx, cancel := context.WithCancel(context.Background())
99+
c := make(chan os.Signal, 3)
100+
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
101+
go func() {
102+
s := <-c
103+
logger.Warnf("received signal %s, stopping instance gracefully", s.String())
104+
gracefulCancel()
105+
s = <-c
106+
logger.Warnf("received second signal %s, stopping instance", s.String())
107+
cancel()
108+
s = <-c
109+
logger.Warnf("received third signal %s, force exit", s.String())
110+
os.Exit(1)
111+
}()
112+
return gracefulCtx, ctx
113+
}

app/dubbo-admin/dubbo-admin-legacy.yaml

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)