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

fix: 兼容 grpc.MaxCallRecvMsgSize 写法 #372

Merged
merged 11 commits into from
Feb 20, 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
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: 1.21

- name: Build
run: go build -v ./...

- name: Test
run: go test -v -race $(go list ./... | grep -v /examples/ | grep -v github.com/gotomicro/ego/cmd |grep -v github.com/gotomicro/ego/internal/test/errcode) -coverprofile=coverage.txt -covermode=atomic
- name: CodeCov
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.45.2
version: v1.55

# Optional: working directory, useful for monorepos
# working-directory: ./
Expand All @@ -26,7 +30,7 @@ jobs:
args: --timeout=5m --print-issued-lines=true --print-linter-name=true --uniq-by-line=true

# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true
# only-new-issues: true

# Optional: if set to true then the action will use pre-installed Go
# skip-go-installation: true
9 changes: 6 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: goreleaser

on:
pull_request:
push:
branches:
- 'feature/docker-ci'
tags:
- "v**"

jobs:
goreleaser:
Expand All @@ -14,10 +17,10 @@ jobs:
with:
fetch-depth: 0
-
name: Set up Go
name: Set up Go 1.21
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.21
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
Expand Down
4 changes: 4 additions & 0 deletions client/egrpc/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func newComponent(name string, config *Config, logger *elog.Component) *Componen

dialOptions = append(dialOptions, grpc.FailOnNonTempDialError(config.EnableFailOnNonTempDialError))

if config.MaxCallRecvMsgSize != DefaultMaxCallRecvMsgSize {
dialOptions = append(dialOptions, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(config.MaxCallRecvMsgSize)))
}

startTime := time.Now()
cc, err := grpc.DialContext(ctx, config.Addr, dialOptions...)

Expand Down
4 changes: 3 additions & 1 deletion client/egrpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/gotomicro/ego/core/util/xtime"
)

const DefaultMaxCallRecvMsgSize = 1024 * 1024 * 4

// Config ...
type Config struct {
Addr string // 连接地址,直连为127.0.0.1:9001,服务发现为etcd:///appname
Expand Down Expand Up @@ -58,6 +60,6 @@ func DefaultConfig() *Config {
EnableAccessInterceptorRes: false,
EnableServiceConfig: true,
// EnableCPUUsage: true,
MaxCallRecvMsgSize: 1024 * 1024 * 4,
MaxCallRecvMsgSize: DefaultMaxCallRecvMsgSize,
}
}
1 change: 1 addition & 0 deletions client/egrpc/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ func TestDefaultConfig(t *testing.T) {
EnableServiceConfig: true,
keepAlive: nil,
dialOptions: nil,
MaxCallRecvMsgSize: DefaultMaxCallRecvMsgSize,
}, DefaultConfig()))
}
37 changes: 14 additions & 23 deletions client/egrpc/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,34 @@

// Build constructs a specific component from container.
func (c *Container) Build(options ...Option) *Component {
var unaryInterceptors []grpc.UnaryClientInterceptor
var streamInterceptors []grpc.StreamClientInterceptor
// 最先执行trace
if c.config.EnableTraceInterceptor {
options = append(options,
WithDialOption(grpc.WithChainUnaryInterceptor(c.traceUnaryClientInterceptor())),
WithDialOption(grpc.WithChainStreamInterceptor(c.traceStreamClientInterceptor())),
)
unaryInterceptors = append(unaryInterceptors, c.traceUnaryClientInterceptor())
streamInterceptors = append(streamInterceptors, c.traceStreamClientInterceptor())
}

// 其次执行,自定义header头,这样才能赋值到ctx里
// options = append(options, WithDialOption(grpc.WithChainUnaryInterceptor(customHeader(transport.CustomContextKeys()))))

// 默认日志
options = append(options, WithDialOption(grpc.WithChainUnaryInterceptor(c.loggerUnaryClientInterceptor())))

unaryInterceptors = append(unaryInterceptors, c.loggerUnaryClientInterceptor())
if eapp.IsDevelopmentMode() {
options = append(options, WithDialOption(grpc.WithChainUnaryInterceptor(c.debugUnaryClientInterceptor())))
unaryInterceptors = append(unaryInterceptors, c.debugUnaryClientInterceptor())

Check warning on line 55 in client/egrpc/container.go

View check run for this annotation

Codecov / codecov/patch

client/egrpc/container.go#L55

Added line #L55 was not covered by tests
}

if c.config.EnableAppNameInterceptor {
options = append(options, WithDialOption(grpc.WithChainUnaryInterceptor(c.defaultUnaryClientInterceptor())))
options = append(options, WithDialOption(grpc.WithChainStreamInterceptor(c.defaultStreamClientInterceptor())))
unaryInterceptors = append(unaryInterceptors, c.defaultUnaryClientInterceptor())
streamInterceptors = append(streamInterceptors, c.defaultStreamClientInterceptor())
}

if c.config.EnableTimeoutInterceptor {
options = append(options, WithDialOption(grpc.WithChainUnaryInterceptor(c.timeoutUnaryClientInterceptor())))
unaryInterceptors = append(unaryInterceptors, c.timeoutUnaryClientInterceptor())
}

if c.config.EnableMetricInterceptor {
options = append(options,
WithDialOption(grpc.WithChainUnaryInterceptor(c.metricUnaryClientInterceptor())),
)
unaryInterceptors = append(unaryInterceptors, c.metricUnaryClientInterceptor())
}
options = append(options, WithDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(c.config.MaxCallRecvMsgSize))))

for _, option := range options {
option(c)
}

c.config.dialOptions = append(c.config.dialOptions,
grpc.WithChainStreamInterceptor(streamInterceptors...),
grpc.WithChainUnaryInterceptor(unaryInterceptors...),
)
return newComponent(c.name, c.config, c.logger)
}
17 changes: 16 additions & 1 deletion client/egrpc/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"time"

"github.com/BurntSushi/toml"
"github.com/gotomicro/ego/core/econf"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"google.golang.org/grpc/test/bufconn"

"github.com/gotomicro/ego/core/econf"
)

func newCmp(t *testing.T, opt Option) *Component {
Expand Down Expand Up @@ -74,3 +76,16 @@ func TestWithName(t *testing.T) {
cmp := newCmp(t, opt)
assert.Equal(t, "hello", cmp.name)
}

func TestMaxCallRecvMsgSize(t *testing.T) {
opt := WithMaxRecvMsgSize(1024)
cmp := newCmp(t, opt)
assert.Equal(t, 1024, cmp.config.MaxCallRecvMsgSize)
}

func TestMaxCallRecvMsgSizeWithDialOption(t *testing.T) {
var opts []grpc.DialOption
opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(2048)))
cmp := newCmp(t, WithDialOption(opts...))
assert.Equal(t, "grpc", cmp.name)
}
14 changes: 7 additions & 7 deletions client/ehttp/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
// m is a map from scheme to resolver builder.
m = make(map[string]Builder)
// defaultScheme is the default scheme to use.
defaultScheme = "http"
// defaultScheme = "http"
)

// Builder creates a resolver that will be used to watch name resolution updates.
Expand Down Expand Up @@ -99,12 +99,12 @@ func (b *baseBuilder) Scheme() string {
}

type baseResolver struct {
target eregistry.Target // 使用ego的target,因为官方的target后续会不兼容
stop chan struct{}
reg eregistry.Registry
cancel context.CancelFunc
addrSlices []string
nodeInfo map[string]*attributes.Attributes // node节点的属性
target eregistry.Target // 使用ego的target,因为官方的target后续会不兼容
stop chan struct{}
reg eregistry.Registry
cancel context.CancelFunc
// addrSlices []string
nodeInfo map[string]*attributes.Attributes // node节点的属性
}

func (b *baseResolver) GetAddr() string {
Expand Down
1 change: 1 addition & 0 deletions core/eflag/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,5 +297,6 @@ func resetFlagSet() {
flag.Duration("test.timeout", 0, "panic test binary after duration `d` (default 0, timeout disabled)")
flag.String("test.cpu", "", "comma-separated `list` of cpu counts to run each test with")
flag.Int("test.parallel", runtime.GOMAXPROCS(0), "run at most `n` tests in parallel")
flag.String("test.gocoverdir", "", "gocoverdir dir")
SetFlagSet(flagObj)
}
2 changes: 1 addition & 1 deletion core/etrace/otel/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import (
"context"

//lint:ignore SA1019
jaegerv2 "go.opentelemetry.io/otel/exporters/jaeger"

Check failure on line 6 in core/etrace/otel/config.go

View workflow job for this annotation

GitHub Actions / lint

SA1019: "go.opentelemetry.io/otel/exporters/jaeger" is deprecated: This module is no longer supported. OpenTelemetry dropped support for Jaeger exporter in July 2023. Jaeger officially accepts and recommends using OTLP. Use [go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp] or [go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc] instead. (staticcheck)
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/sdk/resource"
Expand Down
5 changes: 3 additions & 2 deletions core/util/xdebug/print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
)

func TestMakeReqAndResError(t *testing.T) {
err := MakeReqAndResError("test", "test", "test", time.Now().Sub(time.Now()), "test", "test")

err := MakeReqAndResError("test", "test", "test", time.Until(time.Now()), "test", "test")
t.Log(err)
}

func TestMakeReqAndResInfo(t *testing.T) {
err := MakeReqAndResInfo("test", "test", "test", time.Now().Sub(time.Now()), "test", "test")
err := MakeReqAndResInfo("test", "test", "test", time.Until(time.Now()), "test", "test")
t.Log(err)
}
Loading
Loading