Skip to content
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

Codecov/1.18.0 #1316

Merged
merged 10 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions apiserver/grpcserver/discover/v1/client_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ func (g *DiscoverServer) Discover(server apiservice.PolarisGRPC_DiscoverServer)
case apiservice.DiscoverRequest_FAULT_DETECTOR:
action = metrics.ActionDiscoverFaultDetect
out = g.namingServer.GetFaultDetectWithCache(ctx, in.Service)
case apiservice.DiscoverRequest_SERVICE_CONTRACT:
action = metrics.ActionDiscoverServiceContract
out = g.namingServer.GetServiceContractWithCache(ctx, in.ServiceContract)
default:
out = api.NewDiscoverRoutingResponse(apimodel.Code_InvalidDiscoverResource, in.Service)
}
Expand Down
16 changes: 8 additions & 8 deletions apiserver/xdsserverv3/resource/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func BuildRateLimitDescriptors(rule *traffic_manage.Rule) ([]*route.RateLimit_Ac
Value: arg.GetValue().GetValue().GetValue(),
})
case apitraffic.MatchArgument_QUERY:
queryParameterValueMatch := BuildRateLimitActionQueryParameterValueMatch(descriptorKey, arg.Value)
queryParameterValueMatch := BuildRateLimitActionQueryParameterValueMatch(descriptorKey, arg)
actions = append(actions, &route.RateLimit_Action{
ActionSpecifier: &route.RateLimit_Action_QueryParameterValueMatch_{
QueryParameterValueMatch: queryParameterValueMatch,
Expand Down Expand Up @@ -425,22 +425,22 @@ func BuildRateLimitDescriptors(rule *traffic_manage.Rule) ([]*route.RateLimit_Ac
}

func BuildRateLimitActionQueryParameterValueMatch(key string,
value *apimodel.MatchString) *route.RateLimit_Action_QueryParameterValueMatch {
arg *apitraffic.MatchArgument) *route.RateLimit_Action_QueryParameterValueMatch {
queryParameterValueMatch := &route.RateLimit_Action_QueryParameterValueMatch{
DescriptorKey: key,
DescriptorValue: value.GetValue().GetValue(),
DescriptorValue: arg.GetValue().GetValue().GetValue(),
ExpectMatch: wrapperspb.Bool(true),
QueryParameters: []*route.QueryParameterMatcher{},
}
switch value.GetType() {
switch arg.GetValue().GetType() {
case apimodel.MatchString_EXACT:
queryParameterValueMatch.QueryParameters = []*route.QueryParameterMatcher{
{
Name: key,
Name: arg.GetKey(),
QueryParameterMatchSpecifier: &route.QueryParameterMatcher_StringMatch{
StringMatch: &v32.StringMatcher{
MatchPattern: &v32.StringMatcher_Exact{
Exact: value.GetValue().GetValue(),
Exact: arg.GetValue().GetValue().GetValue(),
},
},
},
Expand All @@ -449,13 +449,13 @@ func BuildRateLimitActionQueryParameterValueMatch(key string,
case apimodel.MatchString_REGEX:
queryParameterValueMatch.QueryParameters = []*route.QueryParameterMatcher{
{
Name: key,
Name: arg.GetKey(),
QueryParameterMatchSpecifier: &route.QueryParameterMatcher_StringMatch{
StringMatch: &v32.StringMatcher{
MatchPattern: &v32.StringMatcher_SafeRegex{
SafeRegex: &v32.RegexMatcher{
EngineType: &v32.RegexMatcher_GoogleRe2{},
Regex: value.GetValue().GetValue(),
Regex: arg.GetValue().GetValue().GetValue(),
},
},
},
Expand Down
21 changes: 11 additions & 10 deletions common/metrics/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,17 @@ func ResourceOfConfigFile(group, name string) string {
}

const (
ActionGetConfigFile = "GET_CONFIG_FILE"
ActionListConfigFiles = "LIST_CONFIG_FILES"
ActionListConfigGroups = "LIST_CONFIG_GROUPS"
ActionPublishConfigFile = "PUBLISH_CONFIG_FILE"
ActionDiscoverInstance = "DISCOVER_INSTANCE"
ActionDiscoverServices = "DISCOVER_SERVICES"
ActionDiscoverRouterRule = "DISCOVER_ROUTER_RULE"
ActionDiscoverRateLimit = "DISCOVER_RATE_LIMIT"
ActionDiscoverCircuitBreaker = "DISCOVER_CIRCUIT_BREAKER"
ActionDiscoverFaultDetect = "DISCOVER_FAULT_DETECT"
ActionGetConfigFile = "GET_CONFIG_FILE"
ActionListConfigFiles = "LIST_CONFIG_FILES"
ActionListConfigGroups = "LIST_CONFIG_GROUPS"
ActionPublishConfigFile = "PUBLISH_CONFIG_FILE"
ActionDiscoverInstance = "DISCOVER_INSTANCE"
ActionDiscoverServices = "DISCOVER_SERVICES"
ActionDiscoverRouterRule = "DISCOVER_ROUTER_RULE"
ActionDiscoverRateLimit = "DISCOVER_RATE_LIMIT"
ActionDiscoverCircuitBreaker = "DISCOVER_CIRCUIT_BREAKER"
ActionDiscoverFaultDetect = "DISCOVER_FAULT_DETECT"
ActionDiscoverServiceContract = "DISCOVER_SERVICE_CONTRACT"
)

type ClientDiscoverMetric struct {
Expand Down
36 changes: 30 additions & 6 deletions common/model/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"time"

apiservice "github.com/polarismesh/specification/source/go/api/v1/service_manage"

commontime "github.com/polarismesh/polaris/common/time"
)

type ServiceContract struct {
Expand Down Expand Up @@ -89,12 +91,34 @@ func (e *EnrichServiceContract) Format() {
}
}

type ServiceContractView struct {
*ServiceContract
// 接口描述信息
Interfaces []*InterfaceDescriptor
ClientInterfaces map[string]*InterfaceDescriptor
ManualInterfaces map[string]*InterfaceDescriptor
func (e *EnrichServiceContract) ToSpec() *apiservice.ServiceContract {
interfaces := make([]*apiservice.InterfaceDescriptor, 0, len(e.Interfaces))
for i := range e.Interfaces {
item := e.Interfaces[i]
interfaces = append(interfaces, &apiservice.InterfaceDescriptor{
Id: item.ID,
Path: item.Path,
Method: item.Method,
Source: item.Source,
Content: item.Content,
Revision: item.Revision,
Ctime: commontime.Time2String(item.CreateTime),
Mtime: commontime.Time2String(item.ModifyTime),
})
}
return &apiservice.ServiceContract{
Id: e.ID,
Name: e.Name,
Namespace: e.Namespace,
Service: e.Service,
Protocol: e.Protocol,
Version: e.Version,
Revision: e.Revision,
Content: e.Content,
Ctime: commontime.Time2String(e.CreateTime),
Mtime: commontime.Time2String(e.ModifyTime),
Interfaces: interfaces,
}
}

func (s *ServiceContract) GetResourceName() string {
Expand Down
2 changes: 1 addition & 1 deletion config/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ func TestServer_GetConfigGroupsWithCache(t *testing.T) {
// 同一个 revision 查询
rsp = testSuit.ConfigServer().GetConfigGroupsWithCache(testSuit.DefaultCtx, &apiconfig.ClientConfigFileInfo{
Namespace: wrapperspb.String("ns-0"),
Md5: wrapperspb.String(rsp.GetRevision()),
Md5: wrapperspb.String(rsp.GetRevision()),
})
assert.Equal(t, uint32(apimodel.Code_DataNoChange), rsp.Code, rsp.Info)

Expand Down
37 changes: 25 additions & 12 deletions config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,40 +89,53 @@ type Server struct {
// Initialize 初始化配置中心模块
func Initialize(ctx context.Context, config Config, s store.Store, cacheMgr cachetypes.CacheManager,
namespaceOperator namespace.NamespaceOperateServer) error {
if !config.Open {
originServer.initialized = true
if originServer.initialized {
return nil
}
proxySvr, originSvr, err := doInitialize(ctx, config, s, cacheMgr, namespaceOperator)
if err != nil {
return err
}
originServer = originSvr
server = proxySvr
return nil
}

if originServer.initialized {
return nil
func doInitialize(ctx context.Context, config Config, s store.Store, cacheMgr cachetypes.CacheManager,
namespaceOperator namespace.NamespaceOperateServer) (ConfigCenterServer, *Server, error) {
if !config.Open {
originServer.initialized = true
return nil, nil, nil
}

var proxySvr ConfigCenterServer
originSvr := &Server{}

if err := cacheMgr.OpenResourceCache(configCacheEntries...); err != nil {
return err
return nil, nil, err
}
err := originServer.initialize(ctx, config, s, namespaceOperator, cacheMgr)
if err != nil {
return err
return nil, nil, err
}

// 需要返回包装代理的 DiscoverServer
order := config.Interceptors
for i := range order {
factory, exist := serverProxyFactories[order[i]]
if !exist {
return fmt.Errorf("name(%s) not exist in serverProxyFactories", order[i])
return nil, nil, fmt.Errorf("name(%s) not exist in serverProxyFactories", order[i])
}

proxySvr, err := factory(originServer, server)
tmpSvr, err := factory(originServer, server)
if err != nil {
return err
return nil, nil, err
}
server = proxySvr
proxySvr = tmpSvr
}

originServer.initialized = true
return nil
originSvr.initialized = true
return proxySvr, originSvr, nil
}

func (s *Server) initialize(ctx context.Context, config Config, ss store.Store,
Expand Down
14 changes: 7 additions & 7 deletions config/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

mockcache "github.com/polarismesh/polaris/cache/mock"
"github.com/polarismesh/polaris/common/eventhub"
mockstore "github.com/polarismesh/polaris/store/mock"
"github.com/stretchr/testify/assert"
)

func Test_Initialize(t *testing.T) {
Expand All @@ -37,20 +38,19 @@ func Test_Initialize(t *testing.T) {

t.Cleanup(func() {
ctrl.Finish()
originServer.watchCenter.Close()
originServer.initialized = false
originServer = nil
server = nil
})

cacheMgr.EXPECT().OpenResourceCache(gomock.Any()).Return(nil).AnyTimes()
cacheMgr.EXPECT().ConfigFile().Return(nil).AnyTimes()
cacheMgr.EXPECT().Gray().Return(nil).AnyTimes()
cacheMgr.EXPECT().ConfigGroup().Return(nil).AnyTimes()

err := Initialize(context.Background(), Config{
proxySvr, originSvr, err := doInitialize(context.Background(), Config{
Open: true,
}, mockStore, cacheMgr, nil)
assert.NoError(t, err)
assert.NotNil(t, originServer)
assert.NotNil(t, originSvr)
assert.NotNil(t, proxySvr)

originSvr.watchCenter.Close()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ require (

require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/polarismesh/specification v1.4.2-alpha.6
github.com/polarismesh/specification v1.4.2-alpha.7
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polarismesh/go-restful-openapi/v2 v2.0.0-20220928152401-083908d10219 h1:XnFyNUWnciM6zgXaz6tm+Egs35rhoD0KGMmKh4gCdi0=
github.com/polarismesh/go-restful-openapi/v2 v2.0.0-20220928152401-083908d10219/go.mod h1:4WhwBysTom9Eoy0hQ4W69I0FmO+T0EpjEW9/5sgHoUk=
github.com/polarismesh/specification v1.4.2-alpha.6 h1:EUhATwFjb4lGIrI/UEoaVdyLWpjZrOuDTQn4S12QE10=
github.com/polarismesh/specification v1.4.2-alpha.6/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/polarismesh/specification v1.4.2-alpha.7 h1:4BhlGD/xJ/092cuu/T5BgwAMwlPFg8vIMfBNMRyEtak=
github.com/polarismesh/specification v1.4.2-alpha.7/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
Expand Down
2 changes: 2 additions & 0 deletions service/api_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ type ClientServer interface {
GetCircuitBreakerWithCache(ctx context.Context, req *apiservice.Service) *apiservice.DiscoverResponse
// GetFaultDetectWithCache User Client Get FaultDetect Rule Information
GetFaultDetectWithCache(ctx context.Context, req *apiservice.Service) *apiservice.DiscoverResponse
// GetServiceContractWithCache User Client Get ServiceContract Rule Information
GetServiceContractWithCache(ctx context.Context, req *apiservice.ServiceContract) *apiservice.DiscoverResponse
// UpdateInstance update one instance by client
UpdateInstance(ctx context.Context, req *apiservice.Instance) *apiservice.Response
// ReportServiceContract client report service_contract
Expand Down
Loading
Loading