Skip to content

Commit

Permalink
allow grpc's MaxMsgRecvSize to be set via a config (#291)
Browse files Browse the repository at this point in the history
* add ability to set MaxRecvMsgSize via config, #2305

Signed-off-by: sriv <[email protected]>

* bump version -> 4.2.0

Signed-off-by: sriv <[email protected]>

* update gh actions and go versions

Signed-off-by: sriv <[email protected]>

Signed-off-by: sriv <[email protected]>
  • Loading branch information
sriv authored Nov 21, 2022
1 parent 9e75689 commit 4859e42
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
steps:
- uses: actions/checkout@v1

- name: Setup go 1.16
uses: actions/setup-go@v1
- name: Setup go 1.19
uses: actions/setup-go@v3
with:
go-version: 1.16
go-version: '>=1.19.0'

- name: build
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
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: latest
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:

steps:

- uses: actions/checkout@v1
- uses: actions/checkout@v3

- name: Setup go 1.16
uses: actions/setup-go@v1
- name: Setup go 1.19
uses: actions/setup-go@v3
with:
go-version: 1.16
go-version: '>=1.19.0'

- name: Download packages
run: |
Expand Down
10 changes: 10 additions & 0 deletions env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
SaveExecutionResult = "save_execution_result"
pluginKillTimeout = "plugin_kill_timeout"
gaugeMinifyReports = "gauge_minify_reports"
gaugeMaxMessageSize = "gauge_max_message_size"
)

func GetCurrentExecutableDir() (string, string) {
Expand Down Expand Up @@ -100,6 +101,15 @@ func isEnvSet(envName string) bool {
return strings.ToLower(envValue) == "true"
}

func GetMaxMessageSize() int {
m := os.Getenv(gaugeMaxMessageSize)
r, err := strconv.Atoi(m)
if err != nil {
return 1024
}
return r
}

// PluginKillTimeout returns the plugin_kill_timeout in seconds
var PluginKillTimeout = func() int {
e := os.Getenv(pluginKillTimeout)
Expand Down
29 changes: 29 additions & 0 deletions env/env_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package env

import "testing"

func TestMaxRecvMsgSize(t *testing.T) {
t.Run("empty value should return default", func(t *testing.T) {
t.Setenv(gaugeMaxMessageSize, "")
v := GetMaxMessageSize()
if v != 1024 {
t.Errorf("Expected 1024, got %d", v)
}
})

t.Run("non-numeric should return default", func(t *testing.T) {
t.Setenv(gaugeMaxMessageSize, "abcd")
v := GetMaxMessageSize()
if v != 1024 {
t.Errorf("Expected 1024, got %d", v)
}
})

t.Run("numeric should return set value", func(t *testing.T) {
t.Setenv(gaugeMaxMessageSize, "2048")
v := GetMaxMessageSize()
if v != 2048 {
t.Errorf("Expected 2048, got %d", v)
}
})
}
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ func main() {
if err != nil {
logger.Fatalf("failed to start server.")
}
server := grpc.NewServer(grpc.MaxRecvMsgSize(1024 * 1024 * 1024))
mSize := env.GetMaxMessageSize()
logger.Debugf("Setting MaxRecvMsgSize = %d MB", mSize)
server := grpc.NewServer(grpc.MaxRecvMsgSize(mSize * 1024 * 1024))
h := &handler{server: server}
gauge_messages.RegisterReporterServer(server, h)
logger.Infof("Listening on port:%d", l.Addr().(*net.TCPAddr).Port)
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
"scope": [
"Execution"
],
"version": "4.1.5"
"version": "4.2.0"
}

0 comments on commit 4859e42

Please sign in to comment.