Skip to content

Commit

Permalink
Merge branch 'master' into gnoi_reboot
Browse files Browse the repository at this point in the history
  • Loading branch information
ndas7 authored Dec 12, 2024
2 parents d2bcd6c + 6eade51 commit 4ab6795
Show file tree
Hide file tree
Showing 20 changed files with 1,178 additions and 81 deletions.
24 changes: 20 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
# Build directory
build/

# Debian packaging files
debian/.debhelper/
debian/files
debian/sonic-telemetry.debhelper.log
debian/sonic-telemetry.substvars
debian/sonic-telemetry/
vendor
src
cvl
translib
debian/sonic-gnmi.debhelper.log
debian/sonic-gnmi.substvars
debian/sonic-gnmi/

# Vendor directory
vendor/

# Source directories
src/
cvl/
translib/

# SWSS common generated files
swsscommon/swsscommon.go
swsscommon/swsscommon.i
swsscommon/swsscommon_wrap.cxx
swsscommon/swsscommon_wrap.h
47 changes: 36 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ go.mod:

$(GO_DEPS): go.mod $(PATCHES) swsscommon_wrap
$(GO) mod vendor
$(GO) mod download golang.org/x/[email protected]
$(GO) mod download github.com/jipanyang/[email protected]
cp -r $(GOPATH)/pkg/mod/golang.org/x/[email protected]/* vendor/golang.org/x/crypto/
cp -r $(GOPATH)/pkg/mod/github.com/jipanyang/[email protected]/* vendor/github.com/jipanyang/gnxi/

# Apply patch from sonic-mgmt-common, ignore glog.patch because glog version changed
sed -i 's/patch -d $${DEST_DIR}\/github.com\/golang\/glog/\#patch -d $${DEST_DIR}\/github.com\/golang\/glog/g' $(MGMT_COMMON_DIR)/patches/apply.sh
$(MGMT_COMMON_DIR)/patches/apply.sh vendor
sed -i 's/#patch -d $${DEST_DIR}\/github.com\/golang\/glog/patch -d $${DEST_DIR}\/github.com\/golang\/glog/g' $(MGMT_COMMON_DIR)/patches/apply.sh

chmod -R u+w vendor
patch -d vendor -p0 < patches/gnmi_cli.all.patch
patch -d vendor -p0 < patches/gnmi_set.patch
patch -d vendor -p0 < patches/gnmi_get.patch
patch -d vendor -p0 < patches/gnmi_path.patch
patch -d vendor -p0 < patches/gnmi_xpath.patch
git apply patches/0001-Updated-to-filter-and-write-to-file.patch

touch $@

go-deps: $(GO_DEPS)
Expand All @@ -69,28 +69,53 @@ go-deps-clean:
$(RM) -r vendor

sonic-gnmi: $(GO_DEPS)
# advancetls 1.0.0 release need following patch to build by go-1.19
patch -d vendor -p0 < patches/0002-Fix-advance-tls-build-with-go-119.patch
# build service first which depends on advancetls
ifeq ($(CROSS_BUILD_ENVIRON),y)
$(GO) build -o ${GOBIN}/telemetry -mod=vendor $(BLD_FLAGS) github.com/sonic-net/sonic-gnmi/telemetry
ifneq ($(ENABLE_DIALOUT_VALUE),0)
$(GO) build -o ${GOBIN}/dialout_client_cli -mod=vendor $(BLD_FLAGS) github.com/sonic-net/sonic-gnmi/dialout/dialout_client_cli
endif
$(GO) build -o ${GOBIN}/gnmi_get -mod=vendor github.com/jipanyang/gnxi/gnmi_get
$(GO) build -o ${GOBIN}/gnmi_set -mod=vendor github.com/jipanyang/gnxi/gnmi_set
$(GO) build -o ${GOBIN}/gnmi_cli -mod=vendor github.com/openconfig/gnmi/cmd/gnmi_cli
$(GO) build -o ${GOBIN}/gnoi_client -mod=vendor github.com/sonic-net/sonic-gnmi/gnoi_client
$(GO) build -o ${GOBIN}/gnmi_dump -mod=vendor github.com/sonic-net/sonic-gnmi/gnmi_dump
else
$(GO) install -mod=vendor $(BLD_FLAGS) github.com/sonic-net/sonic-gnmi/telemetry
ifneq ($(ENABLE_DIALOUT_VALUE),0)
$(GO) install -mod=vendor $(BLD_FLAGS) github.com/sonic-net/sonic-gnmi/dialout/dialout_client_cli
endif
$(GO) install -mod=vendor github.com/sonic-net/sonic-gnmi/gnoi_client
$(GO) install -mod=vendor github.com/sonic-net/sonic-gnmi/gnmi_dump
endif

# download and apply patch for gnmi client, which will break advancetls
# backup crypto and gnxi
mkdir backup_crypto
cp -r vendor/golang.org/x/crypto/* backup_crypto/

# download and patch crypto and gnxi
$(GO) mod download golang.org/x/[email protected]
cp -r $(GOPATH)/pkg/mod/golang.org/x/[email protected]/* vendor/golang.org/x/crypto/
chmod -R u+w vendor
patch -d vendor -p0 < patches/gnmi_cli.all.patch
patch -d vendor -p0 < patches/gnmi_set.patch
patch -d vendor -p0 < patches/gnmi_get.patch
git apply patches/0001-Updated-to-filter-and-write-to-file.patch

ifeq ($(CROSS_BUILD_ENVIRON),y)
$(GO) build -o ${GOBIN}/gnmi_get -mod=vendor github.com/jipanyang/gnxi/gnmi_get
$(GO) build -o ${GOBIN}/gnmi_set -mod=vendor github.com/jipanyang/gnxi/gnmi_set
$(GO) build -o ${GOBIN}/gnmi_cli -mod=vendor github.com/openconfig/gnmi/cmd/gnmi_cli
else
$(GO) install -mod=vendor github.com/jipanyang/gnxi/gnmi_get
$(GO) install -mod=vendor github.com/jipanyang/gnxi/gnmi_set
$(GO) install -mod=vendor github.com/openconfig/gnmi/cmd/gnmi_cli
$(GO) install -mod=vendor github.com/sonic-net/sonic-gnmi/gnoi_client
$(GO) install -mod=vendor github.com/sonic-net/sonic-gnmi/gnmi_dump
endif

# restore old version
rm -rf vendor/golang.org/x/crypto/
mv backup_crypto/ vendor/golang.org/x/crypto/

swsscommon_wrap:
make -C swsscommon

Expand Down
15 changes: 11 additions & 4 deletions common_utils/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (
"sync/atomic"
)


// AuthInfo holds data about the authenticated user
type AuthInfo struct {
// Username
User string
User string
AuthEnabled bool
// Roles
Roles []string
Expand All @@ -37,6 +36,7 @@ const requestContextKey contextkey = 0
var requestCounter uint64

type CounterType int

const (
GNMI_GET CounterType = iota
GNMI_GET_FAIL
Expand All @@ -54,6 +54,9 @@ const (
DBUS_STOP_SERVICE
DBUS_RESTART_SERVICE
DBUS_FILE_STAT
DBUS_HALT_SYSTEM
DBUS_IMAGE_DOWNLOAD
DBUS_IMAGE_INSTALL
COUNTER_SIZE
)

Expand Down Expand Up @@ -91,14 +94,19 @@ func (c CounterType) String() string {
return "DBUS restart service"
case DBUS_FILE_STAT:
return "DBUS file stat"
case DBUS_HALT_SYSTEM:
return "DBUS halt system"
case DBUS_IMAGE_DOWNLOAD:
return "DBUS image download"
case DBUS_IMAGE_INSTALL:
return "DBUS image install"
default:
return ""
}
}

var globalCounters [COUNTER_SIZE]uint64


// GetContext function returns the RequestContext object for a
// gRPC request. RequestContext is maintained as a context value of
// the request. Creates a new RequestContext object is not already
Expand Down Expand Up @@ -134,4 +142,3 @@ func IncCounter(cnt CounterType) {
atomic.AddUint64(&globalCounters[cnt], 1)
SetMemCounters(&globalCounters)
}

Loading

0 comments on commit 4ab6795

Please sign in to comment.