diff --git a/.azure/templates/install-dependencies.yml b/.azure/templates/install-dependencies.yml index 8c9f82f2..1c0134c4 100644 --- a/.azure/templates/install-dependencies.yml +++ b/.azure/templates/install-dependencies.yml @@ -52,9 +52,8 @@ steps: path: $(Build.ArtifactStagingDirectory)/download artifact: ${{ parameters.commonLibArtifact }} patterns: | - target/debs/trixie/libyang_1.0*.deb - target/debs/trixie/libyang-*_1.0*.deb target/debs/trixie/libyang3_*.deb + target/debs/trixie/libyang-dev_3*.deb target/debs/trixie/libpcre3_*.deb target/debs/trixie/libpcre3-dev_*.deb target/debs/trixie/libpcre16-3_*.deb diff --git a/patches/gnmi_get.patch b/patches/gnmi_get.patch index cf451f3c..a92dc43f 100644 --- a/patches/gnmi_get.patch +++ b/patches/gnmi_get.patch @@ -1,14 +1,16 @@ --- ./github.com/google/gnxi/gnmi_get/gnmi_get.go 2019-11-26 15:44:07.303598063 -0800 +++ ./github.com/google/gnxi/gnmi_get/gnmi_get.go 2019-12-19 19:56:11.364223008 -0800 -@@ -21,6 +21,7 @@ +@@ -21,6 +21,9 @@ "fmt" "strings" "time" + "io/ioutil" ++ "os" ++ "strconv" log "github.com/golang/glog" "github.com/golang/protobuf/proto" -@@ -30,7 +31,7 @@ +@@ -30,7 +33,7 @@ "github.com/google/gnxi/utils" "github.com/google/gnxi/utils/credentials" "github.com/google/gnxi/utils/xpath" @@ -17,7 +19,7 @@ pb "github.com/openconfig/gnmi/proto/gnmi" ) -@@ -63,16 +64,20 @@ +@@ -63,19 +66,36 @@ xPathFlags arrayFlags pbPathFlags arrayFlags pbModelDataFlags arrayFlags @@ -28,8 +30,20 @@ timeOut = flag.Duration("time_out", 10*time.Second, "Timeout for the Get request, 10 seconds by default") encodingName = flag.String("encoding", "JSON_IETF", "value encoding format to be used") + jwtToken = flag.String("jwt_token", "", "JWT Token if required") ++ maxRecvMsgSize = flag.Int("max_recv_msg_size", getEnvAsInt("gRPC_MAX_RECEIVE_MSG_SIZE", 4*1024*1024), "Maximum receive message size in bytes") ) - + ++// getEnvAsInt reads an environment variable and returns its integer value. ++// Falls back to defaultVal if the variable is unset or not a valid integer. ++func getEnvAsInt(envVar string, defaultVal int) int { ++ if val, ok := os.LookupEnv(envVar); ok { ++ if intVal, err := strconv.Atoi(val); err == nil { ++ return intVal ++ } ++ } ++ return defaultVal ++} ++ func main() { flag.Var(&xPathFlags, "xpath", "xpath of the config node to be fetched") flag.Var(&pbPathFlags, "pbpath", "protobuf format path of the config node to be fetched") @@ -38,7 +52,11 @@ flag.Parse() opts := credentials.ClientCredentials(*targetName) -@@ -87,6 +92,10 @@ ++ opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(*maxRecvMsgSize))) + conn, err := grpc.Dial(*targetAddr, opts...) + if err != nil { + log.Exitf("Dialing to %q failed: %v", *targetAddr, err) +@@ -87,6 +108,10 @@ ctx, cancel := context.WithTimeout(context.Background(), *timeOut) defer cancel() @@ -49,7 +67,7 @@ encoding, ok := pb.Encoding_value[*encodingName] if !ok { var gnmiEncodingList []string -@@ -96,12 +105,14 @@ +@@ -96,12 +121,14 @@ log.Exitf("Supported encodings: %s", strings.Join(gnmiEncodingList, ", ")) } @@ -65,7 +83,7 @@ } pbPathList = append(pbPathList, pbPath) } -@@ -120,6 +131,7 @@ +@@ -120,6 +133,7 @@ } getRequest := &pb.GetRequest{ @@ -73,7 +91,7 @@ Encoding: pb.Encoding(encoding), Path: pbPathList, UseModels: pbModelDataList, -@@ -135,4 +147,20 @@ +@@ -135,4 +149,20 @@ fmt.Println("== getResponse:") utils.PrintProto(getResponse) diff --git a/telemetry/telemetry.go b/telemetry/telemetry.go index 3b3c85da..9f1ea4ee 100644 --- a/telemetry/telemetry.go +++ b/telemetry/telemetry.go @@ -12,6 +12,7 @@ import ( "os" "os/signal" "path/filepath" + "strconv" "strings" "sync" "sync/atomic" @@ -129,6 +130,17 @@ func runTelemetry(args []string) error { return nil } +// getEnvAsInt reads an environment variable and returns its integer value. +// Falls back to defaultVal if the variable is unset or not a valid integer. +func getEnvAsInt(envVar string, defaultVal int) int { + if val, ok := os.LookupEnv(envVar); ok { + if intVal, err := strconv.Atoi(val); err == nil { + return intVal + } + } + return defaultVal +} + func getGlogFlagsMap() map[string]bool { // glog flags: https://pkg.go.dev/github.com/golang/glog return map[string]bool{ @@ -206,8 +218,8 @@ func setupFlags(fs *flag.FlagSet) (*TelemetryConfig, *gnmi.Config, error) { AuthPolicyEnabled: fs.Bool("authz_policy_enabled", false, "Enable authz policy. Require insecure flag to be false."), AuthzPolicyFile: fs.String("authorization_policy_file", "/keys/authorization_policy.json", "Full path name of the JSON authorization policy file."), EnableStreamMultiplexing: fs.Bool("enable_stream_multiplexing", false, "Allow multiple Subscribe RPCs on a single TCP connection via HTTP/2 stream multiplexing"), - MaxRecvMsgSize: fs.Int("max_recv_msg_size", 4*1024*1024, "Maximum message size in bytes that the server can receive"), - MaxSendMsgSize: fs.Int("max_send_msg_size", 4*1024*1024, "Maximum message size in bytes that the server can send"), + MaxRecvMsgSize: fs.Int("max_recv_msg_size", getEnvAsInt("gRPC_MAX_RECEIVE_MSG_SIZE", 4*1024*1024), "Maximum message size in bytes that the server can receive"), + MaxSendMsgSize: fs.Int("max_send_msg_size", getEnvAsInt("gRPC_MAX_SEND_MSG_SIZE", 4*1024*1024), "Maximum message size in bytes that the server can send"), } fs.Var(&telemetryCfg.UserAuth, "client_auth", "Client auth mode(s) - none,cert,password") diff --git a/telemetry/telemetry_test.go b/telemetry/telemetry_test.go index 657ef606..687c4e0e 100644 --- a/telemetry/telemetry_test.go +++ b/telemetry/telemetry_test.go @@ -1472,6 +1472,80 @@ func TestCertAuthDisabledWhenNoCaCert(t *testing.T) { } } +func TestMaxMsgSizeFromEnv(t *testing.T) { + originalArgs := os.Args + defer func() { os.Args = originalArgs }() + + os.Setenv("gRPC_MAX_SEND_MSG_SIZE", "8388608") + os.Setenv("gRPC_MAX_RECEIVE_MSG_SIZE", "8388608") + defer os.Unsetenv("gRPC_MAX_SEND_MSG_SIZE") + defer os.Unsetenv("gRPC_MAX_RECEIVE_MSG_SIZE") + + fs := flag.NewFlagSet("testMaxMsgEnv", flag.ContinueOnError) + os.Args = []string{"cmd", "-port", "8080", "-noTLS"} + + config, _, err := setupFlags(fs) + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + + if *config.MaxSendMsgSize != 8388608 { + t.Errorf("Expected MaxSendMsgSize=8388608, got %d", *config.MaxSendMsgSize) + } + if *config.MaxRecvMsgSize != 8388608 { + t.Errorf("Expected MaxRecvMsgSize=8388608, got %d", *config.MaxRecvMsgSize) + } +} + +func TestMaxMsgSizeDefault(t *testing.T) { + originalArgs := os.Args + defer func() { os.Args = originalArgs }() + + os.Unsetenv("gRPC_MAX_SEND_MSG_SIZE") + os.Unsetenv("gRPC_MAX_RECEIVE_MSG_SIZE") + + fs := flag.NewFlagSet("testMaxMsgDefault", flag.ContinueOnError) + os.Args = []string{"cmd", "-port", "8080", "-noTLS"} + + config, _, err := setupFlags(fs) + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + + expected := 4 * 1024 * 1024 + if *config.MaxSendMsgSize != expected { + t.Errorf("Expected MaxSendMsgSize=%d, got %d", expected, *config.MaxSendMsgSize) + } + if *config.MaxRecvMsgSize != expected { + t.Errorf("Expected MaxRecvMsgSize=%d, got %d", expected, *config.MaxRecvMsgSize) + } +} + +func TestMaxMsgSizeCliOverridesEnv(t *testing.T) { + originalArgs := os.Args + defer func() { os.Args = originalArgs }() + + os.Setenv("gRPC_MAX_SEND_MSG_SIZE", "8388608") + os.Setenv("gRPC_MAX_RECEIVE_MSG_SIZE", "8388608") + defer os.Unsetenv("gRPC_MAX_SEND_MSG_SIZE") + defer os.Unsetenv("gRPC_MAX_RECEIVE_MSG_SIZE") + + fs := flag.NewFlagSet("testMaxMsgCliOverride", flag.ContinueOnError) + os.Args = []string{"cmd", "-port", "8080", "-noTLS", "-max_send_msg_size", "16777216", "-max_recv_msg_size", "16777216"} + + config, _, err := setupFlags(fs) + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + + if *config.MaxSendMsgSize != 16777216 { + t.Errorf("Expected CLI override MaxSendMsgSize=16777216, got %d", *config.MaxSendMsgSize) + } + if *config.MaxRecvMsgSize != 16777216 { + t.Errorf("Expected CLI override MaxRecvMsgSize=16777216, got %d", *config.MaxRecvMsgSize) + } +} + func TestMain(m *testing.M) { defer test_utils.MemLeakCheck() m.Run()