Skip to content

Commit

Permalink
fix:xds server resource build cache fail (#1331)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun authored Mar 4, 2024
1 parent 68e99fe commit 8ca7997
Show file tree
Hide file tree
Showing 48 changed files with 1,530 additions and 682 deletions.
118 changes: 82 additions & 36 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ run:
- .*~
- test
- "apiserver/nacosserver/v2/pb"
- "apiserver/xdsserverv3/cache"

# Which files to skip: they will be analyzed, but issues from them won't be reported.
# Default value is empty list,
Expand All @@ -54,33 +55,31 @@ run:
- ".*\\.yml$"
- "apiserver/xdsserverv3/cache/linear.go"


# Main linters configurations.
# See https://golangci-lint.run/usage/linters
linters:
# Disable all default enabled linters.
disable-all: true
# Custom enable linters we want to use.
enable:
- errcheck # Errcheck is a program for checking for unchecked errors in go programs.
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted.
- funlen # Tool for detection of long functions
- gci # Gci controls golang package import order and makes it always deterministic.
- goconst # Finds repeated strings that could be replaced by a constant
- gocritic # Provides diagnostics that check for bugs, performance and style issues.
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
- gosimple # Linter for Go source code that specializes in simplifying code
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- misspell # Finds commonly misspelled English words in comments
- nolintlint # Reports ill-formed or insufficient nolint directives
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
- staticcheck # It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary.
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
- errcheck # Errcheck is a program for checking for unchecked errors in go programs.
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted.
- funlen # Tool for detection of long functions
- gci # Gci controls golang package import order and makes it always deterministic.
- goconst # Finds repeated strings that could be replaced by a constant
- gocritic # Provides diagnostics that check for bugs, performance and style issues.
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
- gosimple # Linter for Go source code that specializes in simplifying code
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- misspell # Finds commonly misspelled English words in comments
- nolintlint # Reports ill-formed or insufficient nolint directives
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
- staticcheck # It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary.
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
- usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library.
- lll
#- whitespace # Tool for detection of leading and trailing whitespace


issues:
max-issues-per-linter: 0
max-same-issues: 0
Expand All @@ -100,7 +99,6 @@ issues:
- gocritic
text: "unnecessaryDefer:"


# https://golangci-lint.run/usage/linters
linters-settings:
# https://golangci-lint.run/usage/linters/#misspell
Expand All @@ -117,25 +115,40 @@ linters-settings:
- name: atomic
- name: line-length-limit
severity: error
arguments: [ 480 ]
arguments: [480]
- name: unhandled-error
severity: warning
disabled: true
arguments: [ "fmt.Printf", "myFunction" ]
arguments: ["fmt.Printf", "myFunction"]
- name: var-naming
severity: warning
disabled: true
arguments:
- [ "ID","URL","IP","HTTP","JSON","API","UID","Id","Api","Uid","Http","Json","Ip","Url" ] # AllowList
- [ "VM" ] # DenyList
- [
"ID",
"URL",
"IP",
"HTTP",
"JSON",
"API",
"UID",
"Id",
"Api",
"Uid",
"Http",
"Json",
"Ip",
"Url",
] # AllowList
- ["VM"] # DenyList
- name: string-format
severity: warning
disabled: false
arguments:
- - 'core.WriteError[1].Message'
- '/^([^A-Z]|$)/'
- - "core.WriteError[1].Message"
- "/^([^A-Z]|$)/"
- must not start with a capital letter
- - 'fmt.Errorf[0]'
- - "fmt.Errorf[0]"
- '/(^|[^\.!?])$/'
- must not end in punctuation
- - panic
Expand All @@ -144,27 +157,30 @@ linters-settings:
- name: function-result-limit
severity: warning
disabled: false
arguments: [ 5 ]
arguments: [5]
- name: import-shadowing
severity: warning
disabled: false
arguments: [ "github.com/polarismesh/polaris","namespace" ]
arguments: ["github.com/polarismesh/polaris", "namespace"]
- name: waitgroup-by-value
severity: warning
disabled: false
- name: max-public-structs
severity: warning
disabled: false
arguments: [ 35 ]
arguments: [35]
- name: indent-error-flow
severity: warning
disabled: false
- name: function-length
severity: warning
disabled: false
arguments: [ 80,0 ]
arguments: [80, 0]
- name: file-header
arguments: [ "Tencent is pleased to support the open source community by making Polaris available." ]
arguments:
[
"Tencent is pleased to support the open source community by making Polaris available.",
]
- name: exported
severity: warning
disabled: true
Expand All @@ -185,7 +201,7 @@ linters-settings:
# If lower than 0, disable the check.
# Default: 40
statements: -1

# https://golangci-lint.run/usage/linters/#lll
lll:
# Max line length, lines longer will be reported.
Expand Down Expand Up @@ -244,9 +260,22 @@ linters-settings:
go: "1.15"
# Sxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
# Default: ["*"]
checks: [
"all", "-S1000", "-S1001", "-S1002", "-S1008", "-S1009", "-S1016", "-S1023", "-S1025", "-S1029", "-S1034", "-S1040","-S1019"
]
checks:
[
"all",
"-S1000",
"-S1001",
"-S1002",
"-S1008",
"-S1009",
"-S1016",
"-S1023",
"-S1025",
"-S1029",
"-S1034",
"-S1040",
"-S1019",
]

# https://golangci-lint.run/usage/linters/#govet
govet:
Expand Down Expand Up @@ -335,7 +364,24 @@ linters-settings:
go: "1.15"
# SAxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
# Default: ["*"]
checks: [ "all","-SA1019","-SA4015","-SA1029","-SA1016","-SA9003","-SA4006","-SA6003","-SA1004","-SA4009","-SA6002","-SA4017","-SA4021","-SA1006","-SA4010" ]
checks:
[
"all",
"-SA1019",
"-SA4015",
"-SA1029",
"-SA1016",
"-SA9003",
"-SA4006",
"-SA6003",
"-SA1004",
"-SA4009",
"-SA6002",
"-SA4017",
"-SA4021",
"-SA1006",
"-SA4010",
]

# https://golangci-lint.run/usage/linters/#gofmt
gofmt:
Expand All @@ -345,7 +391,7 @@ linters-settings:
# Apply the rewrite rules to the source before reformatting.
# https://pkg.go.dev/cmd/gofmt
# Default: []
rewrite-rules: [ ]
rewrite-rules: []

# https://golangci-lint.run/usage/linters/#gci
gci:
Expand Down Expand Up @@ -375,4 +421,4 @@ linters-settings:
multi-if: false
# Enforces newlines (or comments) after every multi-line function signature.
# Default: false
multi-func: false
multi-func: false
1 change: 1 addition & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ header: # `header` section is configurations for source codes license header.
- "release"
- "test/data/xds"
- "apiserver/nacosserver/v2/pb"
- "apiserver/xdsserverv3/cache"

# single file
- "LICENSE"
Expand Down
27 changes: 2 additions & 25 deletions apiserver/grpcserver/config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ package config
import (
"context"
"fmt"
"strings"

apiconfig "github.com/polarismesh/specification/source/go/api/v1/config_manage"
"google.golang.org/grpc"

"github.com/polarismesh/polaris/apiserver"
"github.com/polarismesh/polaris/apiserver/grpcserver"
"github.com/polarismesh/polaris/apiserver/grpcserver/utils"
commonlog "github.com/polarismesh/polaris/common/log"
"github.com/polarismesh/polaris/common/model"
"github.com/polarismesh/polaris/config"
Expand Down Expand Up @@ -72,7 +72,7 @@ func (g *ConfigGRPCServer) Run(errCh chan error) {
case "client":
if apiConfig.Enable {
apiconfig.RegisterPolarisConfigGRPCServer(server, g)
openMethod, getErr := GetClientOpenMethod(g.GetProtocol())
openMethod, getErr := utils.GetConfigClientOpenMethod(g.GetProtocol())
if getErr != nil {
return getErr
}
Expand Down Expand Up @@ -125,26 +125,3 @@ func (g *ConfigGRPCServer) enterRateLimit(ip string, method string) uint32 {
func (g *ConfigGRPCServer) allowAccess(method string) bool {
return g.BaseGrpcServer.AllowAccess(method)
}

// GetClientOpenMethod .
func GetClientOpenMethod(protocol string) (map[string]bool, error) {
openMethods := []string{
"GetConfigFile",
"CreateConfigFile",
"UpdateConfigFile",
"PublishConfigFile",
"WatchConfigFiles",
"GetConfigFileMetadataList",
"UpsertAndPublishConfigFile",
"Discover",
}

openMethod := make(map[string]bool)

for _, item := range openMethods {
method := "/v1.PolarisConfig" + strings.ToUpper(protocol) + "/" + item
openMethod[method] = true
}

return openMethod, nil
}
2 changes: 1 addition & 1 deletion apiserver/grpcserver/discover/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (g *GRPCServer) Run(errCh chan error) {
apiservice.RegisterPolarisGRPCServer(server, g.v1server)
apiservice.RegisterPolarisHeartbeatGRPCServer(server, g.v1server)
apiservice.RegisterPolarisServiceContractGRPCServer(server, g.v1server)
openMethod, getErr := utils.GetClientOpenMethod(config.Include, g.GetProtocol())
openMethod, getErr := utils.GetDiscoverClientOpenMethod(config.Include, g.GetProtocol())
if getErr != nil {
return getErr
}
Expand Down
27 changes: 25 additions & 2 deletions apiserver/grpcserver/utils/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,31 @@ import (
"github.com/polarismesh/polaris/common/log"
)

// GetClientOpenMethod 获取客户端openMethod
func GetClientOpenMethod(include []string, protocol string) (map[string]bool, error) {
// GetConfigClientOpenMethod .
func GetConfigClientOpenMethod(protocol string) (map[string]bool, error) {
openMethods := []string{
"GetConfigFile",
"CreateConfigFile",
"UpdateConfigFile",
"PublishConfigFile",
"WatchConfigFiles",
"GetConfigFileMetadataList",
"UpsertAndPublishConfigFile",
"Discover",
}

openMethod := make(map[string]bool)

for _, item := range openMethods {
method := "/v1.PolarisConfig" + strings.ToUpper(protocol) + "/" + item
openMethod[method] = true
}

return openMethod, nil
}

// GetDiscoverClientOpenMethod 获取客户端openMethod
func GetDiscoverClientOpenMethod(include []string, protocol string) (map[string]bool, error) {
clientAccess := make(map[string][]string)
clientAccess[apiserver.DiscoverAccess] = []string{"Discover", "ReportClient", "ReportServiceContract", "GetServiceContract"}
clientAccess[apiserver.RegisterAccess] = []string{"RegisterInstance", "DeregisterInstance"}
Expand Down
6 changes: 3 additions & 3 deletions apiserver/grpcserver/utils/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ func TestGetClientOpenMethod(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := GetClientOpenMethod(tt.args.include, tt.args.protocol)
got, err := GetDiscoverClientOpenMethod(tt.args.include, tt.args.protocol)
if (err != nil) != tt.wantErr {
t.Errorf("GetClientOpenMethod() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("GetDiscoverClientOpenMethod() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetClientOpenMethod() = %v, want %v", got, tt.want)
t.Errorf("GetDiscoverClientOpenMethod() = %v, want %v", got, tt.want)
}
})
}
Expand Down
7 changes: 0 additions & 7 deletions apiserver/nacosserver/model/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,6 @@ func GetGroupName(s string) string {
return ss[0]
}

func DefaultString(s, d string) string {
if len(s) == 0 {
return d
}
return s
}

var ConvertPolarisNamespaceVal = "default"

// ToPolarisNamespace 替换 nacos namespace 为 polaris 的 namespace 信息,主要是针对默认命令空间转为 polaris 的 default
Expand Down
2 changes: 1 addition & 1 deletion apiserver/nacosserver/v1/discover/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (n *DiscoverServer) handleQueryInstances(ctx context.Context, params map[st
if n.pushCenter != nil && udpPort > 0 {
n.pushCenter.AddSubscriber(core.Subscriber{
Key: fmt.Sprintf("%s:%d", clientIP, udpPort),
App: model.DefaultString(params["app"], "unknown"),
App: utils.DefaultString(params["app"], "unknown"),
AddrStr: clientIP,
Ip: clientIP,
Port: int(udpPort),
Expand Down
2 changes: 1 addition & 1 deletion apiserver/nacosserver/v2/discover/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (h *DiscoverServer) handleSubscribeServiceReques(ctx context.Context, req n
Key: remote.ValueConnID(ctx),
AddrStr: meta.ClientIP,
Agent: meta.ClientVersion,
App: nacosmodel.DefaultString(req.GetHeaders()["app"], "unknown"),
App: utils.DefaultString(req.GetHeaders()["app"], "unknown"),
Ip: meta.ClientIP,
NamespaceId: namespace,
Group: group,
Expand Down
Loading

0 comments on commit 8ca7997

Please sign in to comment.