Skip to content
Open
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: 1 addition & 2 deletions .azure/templates/install-dependencies.yml
Comment thread
Sreevanich16 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 26 additions & 8 deletions patches/gnmi_get.patch
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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()

Expand All @@ -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, ", "))
}

Expand All @@ -65,15 +83,15 @@
}
pbPathList = append(pbPathList, pbPath)
}
@@ -120,6 +131,7 @@
@@ -120,6 +133,7 @@
}

getRequest := &pb.GetRequest{
+ Prefix: &prefix,
Encoding: pb.Encoding(encoding),
Path: pbPathList,
UseModels: pbModelDataList,
@@ -135,4 +147,20 @@
@@ -135,4 +149,20 @@

fmt.Println("== getResponse:")
utils.PrintProto(getResponse)
Expand Down
16 changes: 14 additions & 2 deletions telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"os/signal"
"path/filepath"
"strconv"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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")
Expand Down
74 changes: 74 additions & 0 deletions telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading