Skip to content

Commit 94beaf8

Browse files
authored
Merge branch 'polarismesh:main' into feat.cpu_limiter
2 parents e4006f2 + ca98b72 commit 94beaf8

File tree

145 files changed

+8281
-5319
lines changed

Some content is hidden

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

145 files changed

+8281
-5319
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ jobs:
3737
- uses: actions/setup-go@v3
3838
- uses: actions/checkout@v3
3939
- name: golangci-lint
40-
uses: golangci/golangci-lint-action@v3.3.0
40+
uses: golangci/golangci-lint-action@v3.6.0
4141
with:
4242
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
4343
version: latest
44+
args: --timeout=30m
45+

api.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,27 @@ type ConfigAPI interface {
147147
PublishConfigFile(namespace, fileGroup, fileName string) error
148148
}
149149

150+
// ConfigGroupAPI .
151+
type ConfigGroupAPI interface {
152+
api.SDKOwner
153+
// GetConfigGroup .
154+
GetConfigGroup(namesapce, group string) (model.ConfigFileGroup, error)
155+
}
156+
157+
type CircuitBreakerAPI interface {
158+
api.SDKOwner
159+
// Check
160+
Check(model.Resource) (*model.CheckResult, error)
161+
// Report
162+
Report(*model.ResourceStat) error
163+
// MakeFunctionDecorator
164+
MakeFunctionDecorator(model.CustomerFunction, *api.RequestContext) model.DecoratorFunction
165+
// MakeInvokeHandler
166+
MakeInvokeHandler(*api.RequestContext) model.InvokeHandler
167+
// Destroy the api is destroyed and cannot be called again
168+
Destroy()
169+
}
170+
150171
// RouterAPI routing api methods
151172
type RouterAPI interface {
152173
api.SDKOwner

api/circuitbreaker.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* Tencent is pleased to support the open source community by making polaris-go 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 api
19+
20+
import (
21+
"github.com/polarismesh/polaris-go/pkg/config"
22+
"github.com/polarismesh/polaris-go/pkg/model"
23+
)
24+
25+
// CircuitBreakerAPI .
26+
type CircuitBreakerAPI interface {
27+
SDKOwner
28+
// Check
29+
Check(model.Resource) (*model.CheckResult, error)
30+
// Report
31+
Report(*model.ResourceStat) error
32+
// MakeFunctionDecorator
33+
MakeFunctionDecorator(model.CustomerFunction, *RequestContext) model.DecoratorFunction
34+
// MakeInvokeHandler
35+
MakeInvokeHandler(*RequestContext) model.InvokeHandler
36+
}
37+
38+
type ResultToErrorCode interface {
39+
model.ResultToErrorCode
40+
}
41+
42+
type RequestContext struct {
43+
model.RequestContext
44+
}
45+
46+
type ResponseContext struct {
47+
model.ResponseContext
48+
}
49+
50+
var (
51+
// NewConsumerAPI 通过以默认域名为埋点server的默认配置创建 CircuitBreakerAPI
52+
NewCircuitBreakerAPI = newCircuitBreakerAPI
53+
// NewCircuitBreakerByFile 通过配置文件创建SDK CircuitBreakerAPI 对象
54+
NewCircuitBreakerByFile = newCircuitBreakerAPIByFile
55+
// NewCircuitBreakerByConfig 通过配置对象创建SDK CircuitBreakerAPI 对象
56+
NewCircuitBreakerByConfig = newCircuitBreakerAPIByConfig
57+
// NewCircuitBreakerByContext 通过上下文创建SDK CircuitBreakerAPI 对象
58+
NewCircuitBreakerByContext = newCircuitBreakerAPIByContext
59+
)
60+
61+
// 通过以默认域名为埋点server的默认配置创建 CircuitBreakerAPI
62+
func newCircuitBreakerAPI() (CircuitBreakerAPI, error) {
63+
return newCircuitBreakerAPIByConfig(config.NewDefaultConfigurationWithDomain())
64+
}
65+
66+
// newCircuitBreakerAPIByFile 通过配置文件创建SDK CircuitBreakerAPI 对象
67+
func newCircuitBreakerAPIByFile(path string) (CircuitBreakerAPI, error) {
68+
context, err := InitContextByFile(path)
69+
if err != nil {
70+
return nil, err
71+
}
72+
return &circuitBreakerAPI{context}, nil
73+
}
74+
75+
// newCircuitBreakerAPIByConfig 通过配置对象创建SDK CircuitBreakerAPI 对象
76+
func newCircuitBreakerAPIByConfig(cfg config.Configuration) (CircuitBreakerAPI, error) {
77+
context, err := InitContextByConfig(cfg)
78+
if err != nil {
79+
return nil, err
80+
}
81+
return &circuitBreakerAPI{context}, nil
82+
}
83+
84+
// newCircuitBreakerAPIByContext 通过上下文创建SDK CircuitBreakerAPI 对象
85+
func newCircuitBreakerAPIByContext(context SDKContext) CircuitBreakerAPI {
86+
return &circuitBreakerAPI{context}
87+
}

api/circuitbreaker_impl.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Tencent is pleased to support the open source community by making polaris-go 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 api
19+
20+
import (
21+
"github.com/polarismesh/polaris-go/pkg/model"
22+
_ "github.com/polarismesh/polaris-go/pkg/plugin/register"
23+
)
24+
25+
type circuitBreakerAPI struct {
26+
context SDKContext
27+
}
28+
29+
// SDKContext 获取SDK上下文
30+
func (c *circuitBreakerAPI) SDKContext() SDKContext {
31+
return c.context
32+
}
33+
34+
func (c *circuitBreakerAPI) Check(resource model.Resource) (*model.CheckResult, error) {
35+
return c.context.GetEngine().Check(resource)
36+
}
37+
38+
func (c *circuitBreakerAPI) Report(reportStat *model.ResourceStat) error {
39+
return c.context.GetEngine().Report(reportStat)
40+
}
41+
42+
func (c *circuitBreakerAPI) MakeFunctionDecorator(f model.CustomerFunction, reqCtx *RequestContext) model.DecoratorFunction {
43+
return c.context.GetEngine().MakeFunctionDecorator(f, &reqCtx.RequestContext)
44+
}
45+
46+
func (c *circuitBreakerAPI) MakeInvokeHandler(reqCtx *RequestContext) model.InvokeHandler {
47+
return c.context.GetEngine().MakeInvokeHandler(&reqCtx.RequestContext)
48+
}

api/config_file.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ type ConfigFileAPI interface {
3232
PublishConfigFile(namespace, fileGroup, fileName string) error
3333
}
3434

35+
type ConfigGroupAPI interface {
36+
SDKOwner
37+
// GetConfigGroup 获取配置分组
38+
GetConfigGroup(namespace, group string) (model.ConfigFileGroup, error)
39+
}
40+
3541
var (
3642
// NewConfigFileAPIBySDKContext 通过 SDKContext 创建 ConfigFileAPI
3743
NewConfigFileAPIBySDKContext = newConfigFileAPIBySDKContext
@@ -41,4 +47,13 @@ var (
4147
NewConfigFileAPIByConfig = newConfigFileAPIByConfig
4248
// NewConfigFileAPIByFile 通过配置文件创建 ConfigFileAPI
4349
NewConfigFileAPIByFile = newConfigFileAPIByFile
50+
51+
// NewConfigGroupAPIBySDKContext 通过 SDKContext 创建 ConfigGroupAPI
52+
NewConfigGroupAPIBySDKContext = newConfigGroupAPIBySDKContext
53+
// NewConfigGroupAPI 通过 polaris.yaml 创建 ConfigGroupAPI
54+
NewConfigGroupAPI = newConfigGroupAPI
55+
// NewConfigGroupAPIByConfig 通过 Configuration 创建 ConfigGroupAPI
56+
NewConfigGroupAPIByConfig = newConfigGroupAPIByConfig
57+
// NewConfigGroupAPIByFile 通过配置文件创建 ConfigGroupAPI
58+
NewConfigGroupAPIByFile = newConfigGroupAPIByFile
4459
)

api/config_file_impl.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,43 @@ func (c *configFileAPI) PublishConfigFile(namespace, fileGroup, fileName string)
7676
func (c *configFileAPI) SDKContext() SDKContext {
7777
return c.context
7878
}
79+
80+
type configGroupAPI struct {
81+
context SDKContext
82+
}
83+
84+
func newConfigGroupAPI() (ConfigGroupAPI, error) {
85+
return newConfigGroupAPIByConfig(config.NewDefaultConfigurationWithDomain())
86+
}
87+
88+
func newConfigGroupAPIByConfig(cfg config.Configuration) (ConfigGroupAPI, error) {
89+
context, err := InitContextByConfig(cfg)
90+
if err != nil {
91+
return nil, err
92+
}
93+
return &configGroupAPI{context}, nil
94+
}
95+
96+
func newConfigGroupAPIByFile(path string) (ConfigGroupAPI, error) {
97+
context, err := InitContextByFile(path)
98+
if err != nil {
99+
return nil, err
100+
}
101+
return &configGroupAPI{context}, nil
102+
}
103+
104+
func newConfigGroupAPIBySDKContext(context SDKContext) ConfigGroupAPI {
105+
return &configGroupAPI{
106+
context: context,
107+
}
108+
}
109+
110+
// GetConfigGroup 获取配置分组
111+
func (c *configGroupAPI) GetConfigGroup(namespace, group string) (model.ConfigFileGroup, error) {
112+
return c.context.GetEngine().SyncGetConfigGroup(namespace, group)
113+
}
114+
115+
// SDKContext 获取SDK上下文
116+
func (c *configGroupAPI) SDKContext() SDKContext {
117+
return c.context
118+
}

api/provider_impl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (c *providerAPI) RegisterInstance(instance *InstanceRegisterRequest) (*mode
3838
if err := instance.Validate(); err != nil {
3939
return nil, err
4040
}
41-
return c.context.GetEngine().SyncRegisterV2(&instance.InstanceRegisterRequest)
41+
return c.context.GetEngine().SyncRegister(&instance.InstanceRegisterRequest)
4242
}
4343

4444
// Register 同步注册服务,服务注册成功后会填充instance中的InstanceId字段

api_circuitbreaker.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* Tencent is pleased to support the open source community by making polaris-go 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 polaris
19+
20+
import (
21+
"github.com/polarismesh/polaris-go/api"
22+
"github.com/polarismesh/polaris-go/pkg/config"
23+
"github.com/polarismesh/polaris-go/pkg/model"
24+
)
25+
26+
// NewCircuitBreakerAPI 获取 CircuitBreakerAPI
27+
func NewCircuitBreakerAPI() (CircuitBreakerAPI, error) {
28+
rawAPI, err := api.NewCircuitBreakerAPI()
29+
if err != nil {
30+
return nil, err
31+
}
32+
return &circuitBreakerAPI{
33+
rawAPI: rawAPI,
34+
}, nil
35+
}
36+
37+
// NewCircuitBreakerAPIByConfig 通过配置对象获取 CircuitBreakerAPI
38+
func NewCircuitBreakerAPIByConfig(cfg config.Configuration) (CircuitBreakerAPI, error) {
39+
rawAPI, err := api.NewCircuitBreakerByConfig(cfg)
40+
if err != nil {
41+
return nil, err
42+
}
43+
return &circuitBreakerAPI{
44+
rawAPI: rawAPI,
45+
}, nil
46+
}
47+
48+
// NewCircuitBreakerAPIByFile 通过配置文件获取 CircuitBreakerAPI
49+
func NewCircuitBreakerAPIByFile(path string) (CircuitBreakerAPI, error) {
50+
rawAPI, err := api.NewCircuitBreakerByFile(path)
51+
if err != nil {
52+
return nil, err
53+
}
54+
return &circuitBreakerAPI{
55+
rawAPI: rawAPI,
56+
}, nil
57+
}
58+
59+
// NewCircuitBreakerAPIByContext 通过上下文对象获取 CircuitBreakerAPI
60+
func NewCircuitBreakerAPIByContext(context api.SDKContext) CircuitBreakerAPI {
61+
rawAPI := api.NewCircuitBreakerByContext(context)
62+
return &circuitBreakerAPI{
63+
rawAPI: rawAPI,
64+
}
65+
}
66+
67+
type circuitBreakerAPI struct {
68+
rawAPI api.CircuitBreakerAPI
69+
}
70+
71+
// Check
72+
func (c *circuitBreakerAPI) Check(res model.Resource) (*model.CheckResult, error) {
73+
return c.rawAPI.Check(res)
74+
}
75+
76+
// Report
77+
func (c *circuitBreakerAPI) Report(stat *model.ResourceStat) error {
78+
return c.rawAPI.Report(stat)
79+
}
80+
81+
// MakeFunctionDecorator
82+
func (c *circuitBreakerAPI) MakeFunctionDecorator(f model.CustomerFunction, reqCtx *api.RequestContext) model.DecoratorFunction {
83+
return c.rawAPI.MakeFunctionDecorator(f, reqCtx)
84+
}
85+
86+
// MakeInvokeHandler
87+
func (c *circuitBreakerAPI) MakeInvokeHandler(reqCtx *api.RequestContext) model.InvokeHandler {
88+
return c.rawAPI.MakeInvokeHandler(reqCtx)
89+
}
90+
91+
func (c *circuitBreakerAPI) SDKContext() api.SDKContext {
92+
return c.rawAPI.SDKContext()
93+
}
94+
95+
// Destroy the api is destroyed and cannot be called again
96+
func (c *circuitBreakerAPI) Destroy() {
97+
c.rawAPI.SDKContext().Destroy()
98+
}

0 commit comments

Comments
 (0)