Skip to content

Commit

Permalink
Merge branch 'polarismesh:main' into feat.cpu_limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
WTIFS authored Nov 23, 2023
2 parents e4006f2 + ca98b72 commit 94beaf8
Show file tree
Hide file tree
Showing 145 changed files with 8,281 additions and 5,319 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ jobs:
- uses: actions/setup-go@v3
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.3.0
uses: golangci/golangci-lint-action@v3.6.0
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: latest
args: --timeout=30m

21 changes: 21 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,27 @@ type ConfigAPI interface {
PublishConfigFile(namespace, fileGroup, fileName string) error
}

// ConfigGroupAPI .
type ConfigGroupAPI interface {
api.SDKOwner
// GetConfigGroup .
GetConfigGroup(namesapce, group string) (model.ConfigFileGroup, error)
}

type CircuitBreakerAPI interface {
api.SDKOwner
// Check
Check(model.Resource) (*model.CheckResult, error)
// Report
Report(*model.ResourceStat) error
// MakeFunctionDecorator
MakeFunctionDecorator(model.CustomerFunction, *api.RequestContext) model.DecoratorFunction
// MakeInvokeHandler
MakeInvokeHandler(*api.RequestContext) model.InvokeHandler
// Destroy the api is destroyed and cannot be called again
Destroy()
}

// RouterAPI routing api methods
type RouterAPI interface {
api.SDKOwner
Expand Down
87 changes: 87 additions & 0 deletions api/circuitbreaker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* Tencent is pleased to support the open source community by making polaris-go 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 api

import (
"github.com/polarismesh/polaris-go/pkg/config"
"github.com/polarismesh/polaris-go/pkg/model"
)

// CircuitBreakerAPI .
type CircuitBreakerAPI interface {
SDKOwner
// Check
Check(model.Resource) (*model.CheckResult, error)
// Report
Report(*model.ResourceStat) error
// MakeFunctionDecorator
MakeFunctionDecorator(model.CustomerFunction, *RequestContext) model.DecoratorFunction
// MakeInvokeHandler
MakeInvokeHandler(*RequestContext) model.InvokeHandler
}

type ResultToErrorCode interface {
model.ResultToErrorCode
}

type RequestContext struct {
model.RequestContext
}

type ResponseContext struct {
model.ResponseContext
}

var (
// NewConsumerAPI 通过以默认域名为埋点server的默认配置创建 CircuitBreakerAPI
NewCircuitBreakerAPI = newCircuitBreakerAPI
// NewCircuitBreakerByFile 通过配置文件创建SDK CircuitBreakerAPI 对象
NewCircuitBreakerByFile = newCircuitBreakerAPIByFile
// NewCircuitBreakerByConfig 通过配置对象创建SDK CircuitBreakerAPI 对象
NewCircuitBreakerByConfig = newCircuitBreakerAPIByConfig
// NewCircuitBreakerByContext 通过上下文创建SDK CircuitBreakerAPI 对象
NewCircuitBreakerByContext = newCircuitBreakerAPIByContext
)

// 通过以默认域名为埋点server的默认配置创建 CircuitBreakerAPI
func newCircuitBreakerAPI() (CircuitBreakerAPI, error) {
return newCircuitBreakerAPIByConfig(config.NewDefaultConfigurationWithDomain())
}

// newCircuitBreakerAPIByFile 通过配置文件创建SDK CircuitBreakerAPI 对象
func newCircuitBreakerAPIByFile(path string) (CircuitBreakerAPI, error) {
context, err := InitContextByFile(path)
if err != nil {
return nil, err
}
return &circuitBreakerAPI{context}, nil
}

// newCircuitBreakerAPIByConfig 通过配置对象创建SDK CircuitBreakerAPI 对象
func newCircuitBreakerAPIByConfig(cfg config.Configuration) (CircuitBreakerAPI, error) {
context, err := InitContextByConfig(cfg)
if err != nil {
return nil, err
}
return &circuitBreakerAPI{context}, nil
}

// newCircuitBreakerAPIByContext 通过上下文创建SDK CircuitBreakerAPI 对象
func newCircuitBreakerAPIByContext(context SDKContext) CircuitBreakerAPI {
return &circuitBreakerAPI{context}
}
48 changes: 48 additions & 0 deletions api/circuitbreaker_impl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Tencent is pleased to support the open source community by making polaris-go 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 api

import (
"github.com/polarismesh/polaris-go/pkg/model"
_ "github.com/polarismesh/polaris-go/pkg/plugin/register"
)

type circuitBreakerAPI struct {
context SDKContext
}

// SDKContext 获取SDK上下文
func (c *circuitBreakerAPI) SDKContext() SDKContext {
return c.context
}

func (c *circuitBreakerAPI) Check(resource model.Resource) (*model.CheckResult, error) {
return c.context.GetEngine().Check(resource)
}

func (c *circuitBreakerAPI) Report(reportStat *model.ResourceStat) error {
return c.context.GetEngine().Report(reportStat)
}

func (c *circuitBreakerAPI) MakeFunctionDecorator(f model.CustomerFunction, reqCtx *RequestContext) model.DecoratorFunction {
return c.context.GetEngine().MakeFunctionDecorator(f, &reqCtx.RequestContext)
}

func (c *circuitBreakerAPI) MakeInvokeHandler(reqCtx *RequestContext) model.InvokeHandler {
return c.context.GetEngine().MakeInvokeHandler(&reqCtx.RequestContext)
}
15 changes: 15 additions & 0 deletions api/config_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ type ConfigFileAPI interface {
PublishConfigFile(namespace, fileGroup, fileName string) error
}

type ConfigGroupAPI interface {
SDKOwner
// GetConfigGroup 获取配置分组
GetConfigGroup(namespace, group string) (model.ConfigFileGroup, error)
}

var (
// NewConfigFileAPIBySDKContext 通过 SDKContext 创建 ConfigFileAPI
NewConfigFileAPIBySDKContext = newConfigFileAPIBySDKContext
Expand All @@ -41,4 +47,13 @@ var (
NewConfigFileAPIByConfig = newConfigFileAPIByConfig
// NewConfigFileAPIByFile 通过配置文件创建 ConfigFileAPI
NewConfigFileAPIByFile = newConfigFileAPIByFile

// NewConfigGroupAPIBySDKContext 通过 SDKContext 创建 ConfigGroupAPI
NewConfigGroupAPIBySDKContext = newConfigGroupAPIBySDKContext
// NewConfigGroupAPI 通过 polaris.yaml 创建 ConfigGroupAPI
NewConfigGroupAPI = newConfigGroupAPI
// NewConfigGroupAPIByConfig 通过 Configuration 创建 ConfigGroupAPI
NewConfigGroupAPIByConfig = newConfigGroupAPIByConfig
// NewConfigGroupAPIByFile 通过配置文件创建 ConfigGroupAPI
NewConfigGroupAPIByFile = newConfigGroupAPIByFile
)
40 changes: 40 additions & 0 deletions api/config_file_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,43 @@ func (c *configFileAPI) PublishConfigFile(namespace, fileGroup, fileName string)
func (c *configFileAPI) SDKContext() SDKContext {
return c.context
}

type configGroupAPI struct {
context SDKContext
}

func newConfigGroupAPI() (ConfigGroupAPI, error) {
return newConfigGroupAPIByConfig(config.NewDefaultConfigurationWithDomain())
}

func newConfigGroupAPIByConfig(cfg config.Configuration) (ConfigGroupAPI, error) {
context, err := InitContextByConfig(cfg)
if err != nil {
return nil, err
}
return &configGroupAPI{context}, nil
}

func newConfigGroupAPIByFile(path string) (ConfigGroupAPI, error) {
context, err := InitContextByFile(path)
if err != nil {
return nil, err
}
return &configGroupAPI{context}, nil
}

func newConfigGroupAPIBySDKContext(context SDKContext) ConfigGroupAPI {
return &configGroupAPI{
context: context,
}
}

// GetConfigGroup 获取配置分组
func (c *configGroupAPI) GetConfigGroup(namespace, group string) (model.ConfigFileGroup, error) {
return c.context.GetEngine().SyncGetConfigGroup(namespace, group)
}

// SDKContext 获取SDK上下文
func (c *configGroupAPI) SDKContext() SDKContext {
return c.context
}
2 changes: 1 addition & 1 deletion api/provider_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c *providerAPI) RegisterInstance(instance *InstanceRegisterRequest) (*mode
if err := instance.Validate(); err != nil {
return nil, err
}
return c.context.GetEngine().SyncRegisterV2(&instance.InstanceRegisterRequest)
return c.context.GetEngine().SyncRegister(&instance.InstanceRegisterRequest)
}

// Register 同步注册服务,服务注册成功后会填充instance中的InstanceId字段
Expand Down
98 changes: 98 additions & 0 deletions api_circuitbreaker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Tencent is pleased to support the open source community by making polaris-go 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 polaris

import (
"github.com/polarismesh/polaris-go/api"
"github.com/polarismesh/polaris-go/pkg/config"
"github.com/polarismesh/polaris-go/pkg/model"
)

// NewCircuitBreakerAPI 获取 CircuitBreakerAPI
func NewCircuitBreakerAPI() (CircuitBreakerAPI, error) {
rawAPI, err := api.NewCircuitBreakerAPI()
if err != nil {
return nil, err
}
return &circuitBreakerAPI{
rawAPI: rawAPI,
}, nil
}

// NewCircuitBreakerAPIByConfig 通过配置对象获取 CircuitBreakerAPI
func NewCircuitBreakerAPIByConfig(cfg config.Configuration) (CircuitBreakerAPI, error) {
rawAPI, err := api.NewCircuitBreakerByConfig(cfg)
if err != nil {
return nil, err
}
return &circuitBreakerAPI{
rawAPI: rawAPI,
}, nil
}

// NewCircuitBreakerAPIByFile 通过配置文件获取 CircuitBreakerAPI
func NewCircuitBreakerAPIByFile(path string) (CircuitBreakerAPI, error) {
rawAPI, err := api.NewCircuitBreakerByFile(path)
if err != nil {
return nil, err
}
return &circuitBreakerAPI{
rawAPI: rawAPI,
}, nil
}

// NewCircuitBreakerAPIByContext 通过上下文对象获取 CircuitBreakerAPI
func NewCircuitBreakerAPIByContext(context api.SDKContext) CircuitBreakerAPI {
rawAPI := api.NewCircuitBreakerByContext(context)
return &circuitBreakerAPI{
rawAPI: rawAPI,
}
}

type circuitBreakerAPI struct {
rawAPI api.CircuitBreakerAPI
}

// Check
func (c *circuitBreakerAPI) Check(res model.Resource) (*model.CheckResult, error) {
return c.rawAPI.Check(res)
}

// Report
func (c *circuitBreakerAPI) Report(stat *model.ResourceStat) error {
return c.rawAPI.Report(stat)
}

// MakeFunctionDecorator
func (c *circuitBreakerAPI) MakeFunctionDecorator(f model.CustomerFunction, reqCtx *api.RequestContext) model.DecoratorFunction {
return c.rawAPI.MakeFunctionDecorator(f, reqCtx)
}

// MakeInvokeHandler
func (c *circuitBreakerAPI) MakeInvokeHandler(reqCtx *api.RequestContext) model.InvokeHandler {
return c.rawAPI.MakeInvokeHandler(reqCtx)
}

func (c *circuitBreakerAPI) SDKContext() api.SDKContext {
return c.rawAPI.SDKContext()
}

// Destroy the api is destroyed and cannot be called again
func (c *circuitBreakerAPI) Destroy() {
c.rawAPI.SDKContext().Destroy()
}
Loading

0 comments on commit 94beaf8

Please sign in to comment.