Skip to content

Commit 70d69ce

Browse files
authored
[Refactor] 配置中心重构+支持配置回滚/撤回发布 (#1187)
1 parent e51daba commit 70d69ce

File tree

166 files changed

+4691
-6970
lines changed

Some content is hidden

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

166 files changed

+4691
-6970
lines changed

.github/workflows/benchmark.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ jobs:
6262
steps:
6363
# Setup the environment.
6464
- name: Setup Go
65-
uses: actions/setup-go@v2
65+
uses: actions/setup-go@v4
6666
with:
67-
go-version: 1.19
67+
go-version: "1.20"
6868
# Checkout latest code
6969
- name: Checkout repo
7070
uses: actions/checkout@v2

.github/workflows/codecov.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ jobs:
5252
steps:
5353
# Setup the environment.
5454
- name: Setup Go
55-
uses: actions/setup-go@v2
55+
uses: actions/setup-go@v4
5656
with:
57-
go-version: 1.19
57+
go-version: "1.20"
5858
# Checkout latest code
5959
- name: Checkout repo
6060
uses: actions/checkout@v2

.github/workflows/docker.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ jobs:
3535
id: get_version
3636
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
3737

38-
- name: Set up Go
39-
uses: actions/setup-go@v2
38+
- name: Setup Go
39+
uses: actions/setup-go@v4
4040
with:
41-
go-version: 1.19
41+
go-version: "1.20"
4242

4343
- name: Set up Docker Buildx
4444
uses: docker/setup-buildx-action@v1

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
golangci:
3030
strategy:
3131
matrix:
32-
go-version: [ 1.19 ]
32+
go-version: [ "1.20" ]
3333
name: golangci-lint
3434
runs-on: ubuntu-latest
3535
steps:

.github/workflows/integration-testing-mysql.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ jobs:
7676
steps:
7777
# Setup the environment.
7878
- name: Setup Go
79-
uses: actions/setup-go@v2
79+
uses: actions/setup-go@v4
8080
with:
81-
go-version: 1.19
81+
go-version: "1.20"
8282
# Checkout latest code
8383
- name: Checkout repo
8484
uses: actions/checkout@v2

.github/workflows/integration-testing.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ jobs:
6262
steps:
6363
# Setup the environment.
6464
- name: Setup Go
65-
uses: actions/setup-go@v2
65+
uses: actions/setup-go@v4
6666
with:
67-
go-version: 1.19
67+
go-version: "1.20"
6868
# Checkout latest code
6969
- name: Checkout repo
7070
uses: actions/checkout@v2

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ jobs:
3636
uses: actions/checkout@v2
3737

3838
- name: Setup Go
39-
uses: actions/setup-go@v2
39+
uses: actions/setup-go@v4
4040
with:
41-
go-version: 1.19
41+
go-version: "1.20"
4242

4343
- name: Get version
4444
id: get_version

.github/workflows/standalone.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ jobs:
4949
ref: ${{ github.event.inputs.server_version }}
5050

5151
- name: Setup Go
52-
uses: actions/setup-go@v2
52+
uses: actions/setup-go@v4
5353
with:
54-
go-version: 1.19
54+
go-version: "1.20"
5555

5656
- name: Build
5757
id: build

admin/config.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,30 @@
1717

1818
package admin
1919

20-
import "github.com/polarismesh/polaris/admin/job"
20+
import (
21+
"github.com/polarismesh/polaris/admin/job"
22+
)
2123

2224
// Config maintain configuration
2325
type Config struct {
2426
Jobs []job.JobConfig `yaml:"jobs"`
2527
}
28+
29+
func DefaultConfig() *Config {
30+
return &Config{
31+
Jobs: []job.JobConfig{
32+
{
33+
Name: "CleanDeletedClients",
34+
Enable: true,
35+
},
36+
{
37+
Name: "CleanDeletedInstances",
38+
Enable: true,
39+
},
40+
{
41+
Name: "CleanConfigReleaseHistory",
42+
Enable: true,
43+
},
44+
},
45+
}
46+
}

admin/job/history_clean.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Tencent is pleased to support the open source community by making Polaris available.
3+
*
4+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-Clause License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://opensource.org/licenses/BSD-3-Clause
11+
*
12+
* Unless required by applicable law or agreed to in writing, software distributed
13+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations under the License.
16+
*/
17+
18+
package job
19+
20+
import (
21+
"time"
22+
23+
"github.com/mitchellh/mapstructure"
24+
25+
"github.com/polarismesh/polaris/store"
26+
)
27+
28+
// 默认保存配置发布天数
29+
const defaultHistoryRetentionDays = 7 * 24 * time.Hour
30+
31+
type CleanConfigFileHistoryJobConfig struct {
32+
RetentionDays time.Duration `mapstructure:"retentionDays"`
33+
BatchSize uint64 `mapstructure:"batchSize"`
34+
}
35+
36+
type cleanConfigFileHistoryJob struct {
37+
cfg *CleanConfigFileHistoryJobConfig
38+
storage store.Store
39+
}
40+
41+
func (job *cleanConfigFileHistoryJob) init(raw map[string]interface{}) error {
42+
cfg := &CleanConfigFileHistoryJobConfig{
43+
RetentionDays: defaultHistoryRetentionDays,
44+
BatchSize: 1000,
45+
}
46+
decodeConfig := &mapstructure.DecoderConfig{
47+
DecodeHook: mapstructure.StringToTimeDurationHookFunc(),
48+
Result: cfg,
49+
}
50+
decoder, err := mapstructure.NewDecoder(decodeConfig)
51+
if err != nil {
52+
log.Errorf("[Maintain][Job][cleanConfigFileHistoryJob] new config decoder err: %v", err)
53+
return err
54+
}
55+
if err = decoder.Decode(raw); err != nil {
56+
log.Errorf("[Maintain][Job][cleanConfigFileHistoryJob] parse config err: %v", err)
57+
return err
58+
}
59+
if cfg.RetentionDays < time.Minute {
60+
cfg.RetentionDays = time.Minute
61+
}
62+
job.cfg = cfg
63+
return nil
64+
}
65+
66+
func (job *cleanConfigFileHistoryJob) execute() {
67+
endTime := time.Now().Add(-1 * job.cfg.RetentionDays)
68+
if err := job.storage.CleanConfigFileReleaseHistory(endTime, job.cfg.BatchSize); err != nil {
69+
log.Errorf("[Maintain][Job][cleanConfigFileHistoryJob] execute err: %v", err)
70+
}
71+
}
72+
73+
func (job *cleanConfigFileHistoryJob) interval() time.Duration {
74+
return time.Minute
75+
}
76+
77+
func (job *cleanConfigFileHistoryJob) clear() {
78+
}

0 commit comments

Comments
 (0)