Skip to content

refactor: 鉴权插件重构 #1357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6ffbeeb
docs:add error code desc
chuntaojun Sep 25, 2022
67406c5
fix:调整license-checker的触发
chuntaojun Oct 19, 2022
6b2b913
fix:调整license-checker的触发
chuntaojun Oct 19, 2022
c7825aa
hotfix:修复鉴权interceptor遗漏请求来源
chuntaojun Jun 27, 2023
f4d04f9
refactor:store lane rule
chuntaojun Mar 28, 2024
f8ab936
refactor:fix config notify watch client may cause client hangup
chuntaojun Apr 16, 2024
b40aa8c
feat:refactor auth code struct and fix config_center push bug
chuntaojun Apr 30, 2024
cbb248c
feat:support nacos-address server endpoints
chuntaojun May 21, 2024
be1955b
feat:support nacos-address server endpoints
chuntaojun May 23, 2024
7a10f32
feat:support nacos-address server endpoints
chuntaojun May 23, 2024
3de6f56
feat:support nacos-address server endpoints
chuntaojun May 28, 2024
c2c80b6
feat:support nacos-address server endpoints
chuntaojun Jun 10, 2024
f2d9fbd
feat:support nacos-address server endpoints
chuntaojun Jun 13, 2024
f939007
feat:support nacos-address server endpoints
chuntaojun Jun 22, 2024
13dfc0f
feat:support nacos-address server endpoints
chuntaojun Jun 23, 2024
428740b
feat:support nacos-address server endpoints
chuntaojun Jun 23, 2024
f7b2c6a
feat:support nacos-address server endpoints
chuntaojun Jun 23, 2024
45e5bb8
feat:support nacos-address server endpoints
chuntaojun Jun 23, 2024
5bbe29f
feat:support nacos-address server endpoints
chuntaojun Jun 24, 2024
0ec8370
feat:support nacos-address server endpoints
chuntaojun Jun 24, 2024
de378f6
feat:support nacos-address server endpoints
chuntaojun Jun 24, 2024
8d24dd2
feat:support nacos-address server endpoints
chuntaojun Jun 25, 2024
3b041b3
feat:support nacos-address server endpoints
chuntaojun Jun 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 0 additions & 83 deletions admin/job/clean_deleted_client.go

This file was deleted.

82 changes: 0 additions & 82 deletions admin/job/clean_deleted_instance.go

This file was deleted.

198 changes: 198 additions & 0 deletions admin/job/clean_deleted_resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
/**
* Tencent is pleased to support the open source community by making Polaris available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package job

import (
"sync"
"time"

"github.com/mitchellh/mapstructure"

"github.com/polarismesh/polaris/store"
)

var cleanFuncMapping = map[string]func(timeout time.Duration, job *cleanDeletedResourceJob){
"instance": cleanDeletedInstances,
"service": cleanDeletedServices,
"clients": cleanDeletedClients,
"circuitbreaker_rule": func(timeout time.Duration, job *cleanDeletedResourceJob) {
cleanDeletedRules("circuitbreaker_rule", timeout, job)
},
"ratelimit_rule": func(timeout time.Duration, job *cleanDeletedResourceJob) {
cleanDeletedRules("ratelimit_rule", timeout, job)
},
"router_rule": func(timeout time.Duration, job *cleanDeletedResourceJob) {
cleanDeletedRules("router_rule", timeout, job)
},
"faultdetect_rule": func(timeout time.Duration, job *cleanDeletedResourceJob) {
cleanDeletedRules("faultdetect_rule", timeout, job)
},
"lane_rule": func(timeout time.Duration, job *cleanDeletedResourceJob) {
cleanDeletedRules("lane_rule", timeout, job)
},
"config_file_release": cleanDeletedConfigFiles,
}

type CleanDeletedResource struct {
// Resource 记录需要清理的资源类型
Resource string `mapstructure:"resource"`
// Timeout 记录资源的额外超时时间,用户可自定义
Timeout *time.Duration `mapstructure:"timeout"`
// Enable 记录是否开启清理
Enable bool `mapstructure:"enable"`
}

type CleandeletedResourceConf struct {
// ResourceTimeout 记录资源的额外超时时间,用户可自定义
Resources []CleanDeletedResource `json:"resourceTimeout"`
// Timeout 记录清理资源的超时时间,默认20分钟
Timeout time.Duration `mapstructure:"timeout"`
}

type cleanDeletedResourceJob struct {
cfg *CleandeletedResourceConf
storage store.Store
}

func (job *cleanDeletedResourceJob) init(raw map[string]interface{}) error {
cfg := &CleandeletedResourceConf{
Timeout: 20 * time.Minute,
}
decodeConfig := &mapstructure.DecoderConfig{
DecodeHook: mapstructure.StringToTimeDurationHookFunc(),
Result: cfg,
}
decoder, err := mapstructure.NewDecoder(decodeConfig)
if err != nil {
log.Errorf("[Maintain][Job][CleanDeletedClients] new config decoder err: %v", err)
return err
}
if err := decoder.Decode(raw); err != nil {
log.Errorf("[Maintain][Job][CleanDeletedClients] parse config err: %v", err)
return err
}
if cfg.Timeout < 2*time.Minute {
cfg.Timeout = 2 * time.Minute
}
job.cfg = cfg
return nil
}

func (job *cleanDeletedResourceJob) execute() {
wait := &sync.WaitGroup{}
for _, resource := range job.cfg.Resources {
if !resource.Enable {
continue
}
timeout := job.cfg.Timeout
if resource.Timeout != nil {
timeout = *resource.Timeout
}
if cleanFunc, ok := cleanFuncMapping[resource.Resource]; ok {
wait.Add(1)
go func(timeout time.Duration, job *cleanDeletedResourceJob) {
defer wait.Done()
cleanFunc(timeout, job)
}(timeout, job)
}
}
wait.Wait()
}

func (job *cleanDeletedResourceJob) clear() {
}

func (job *cleanDeletedResourceJob) interval() time.Duration {
return time.Minute
}

func cleanDeletedConfigFiles(timeout time.Duration, job *cleanDeletedResourceJob) {
batchSize := uint32(100)
for {
count, err := job.storage.BatchCleanDeletedConfigFiles(timeout, batchSize)
if err != nil {
log.Errorf("[Maintain][Job][CleanDeletedClients] batch clean deleted client, err: %v", err)
break
}
log.Infof("[Maintain][Job][CleanDeletedClients] clean deleted client count %d", count)
if count < batchSize {
break
}
}
}

func cleanDeletedServices(timeout time.Duration, job *cleanDeletedResourceJob) {
batchSize := uint32(100)
for {
count, err := job.storage.BatchCleanDeletedServices(timeout, batchSize)
if err != nil {
log.Errorf("[Maintain][Job][CleanDeletedClients] batch clean deleted client, err: %v", err)
break
}
log.Infof("[Maintain][Job][CleanDeletedClients] clean deleted client count %d", count)
if count < batchSize {
break
}
}
}

func cleanDeletedClients(timeout time.Duration, job *cleanDeletedResourceJob) {
batchSize := uint32(100)
for {
count, err := job.storage.BatchCleanDeletedClients(timeout, batchSize)
if err != nil {
log.Errorf("[Maintain][Job][CleanDeletedClients] batch clean deleted client, err: %v", err)
break
}
log.Infof("[Maintain][Job][CleanDeletedClients] clean deleted client count %d", count)
if count < batchSize {
break
}
}
}

func cleanDeletedInstances(timeout time.Duration, job *cleanDeletedResourceJob) {
batchSize := uint32(100)
for {
count, err := job.storage.BatchCleanDeletedInstances(timeout, batchSize)
if err != nil {
log.Errorf("[Maintain][Job][CleanDeletedInstances] batch clean deleted instance, err: %v", err)
break
}

log.Infof("[Maintain][Job][CleanDeletedInstances] clean deleted instance count %d", count)
if count < batchSize {
break
}
}
}

func cleanDeletedRules(rule string, timeout time.Duration, job *cleanDeletedResourceJob) {
batchSize := uint32(100)
for {
count, err := job.storage.BatchCleanDeletedRules(rule, timeout, batchSize)
if err != nil {
log.Errorf("[Maintain][Job][CleanDeletedClients] batch clean deleted client, err: %v", err)
break
}
log.Infof("[Maintain][Job][CleanDeletedClients] clean deleted client count %d", count)
if count < batchSize {
break
}
}
}
Loading
Loading