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

For gnmi_ext.proto, run protoc with github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.proto (this is for reflections). #170

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

hyun-arista
Copy link
Contributor

The Problem

gNMI server reflections is basically facing the same issue as mentioned in fullstorydev/grpcurl#22. When the gnmi_ext.proto file gets compiled with path proto/gnmi_ext/gnmi_ext.proto, gNMI server reflection breaks with the following error:

Failed to resolve symbol "gnmi.gNMI": file "proto/gnmi/gnmi.proto" included an unresolvable reference to ".gnmi_ext.Extension"

The Proposal

If gnmi_ext.proto gets compiled with github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.proto, gNMI server reflections work. So, I modified the gnmi_ext.proto portion in compile_protos.sh to (only the go binding):

protoc -I=$proto_imports_go --go_out=${GOPATH}/src --go_opt=paths=source_relative github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.proto

I assumed that the github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.proto path is under ${GOPATH}/src. $proto_imports_go includes ${GOPATH}/src so the go binding should be generated under ${GOPATH}/src/github.com/openconfig/gnmi/proto/gnmi_ext/.

Manual Testing

In my case, I have gnmi_ext.proto under /vendor/github.com/openconfig/gnmi/proto/gnmi_ext/. When I did

protoc -I=vendor --go_out=vendor --go_opt=paths=source_relative github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.proto

The generated go binding's source is identified as github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.proto and the gNMI server reflections work.

A Request

This is a message to the reviewer of this pull request. Please modify the python binding portion of compile_protos.sh if necessary. Also, please compile_protos.sh to modify gnmi_ext.pb.go under ${GOPATH}/src/github.com/openconfig/gnmi/proto/gnmi_ext/. Thank you.

@ElodinLaarz
Copy link

Problem recreation for folks following along at home:

mkdir /tmp/gnmi-example
cd /tmp/gnmi-example

go mod init github.com/ElodinLaarz/gnmi-test

Using your favorite means of creating a file, create a silly little gNMI server.

package main

import (
	"context"
	"flag"
	"fmt"
	"log"
	"net"

	"github.com/openconfig/gnmi/proto/gnmi"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
)

type Server struct {
	gnmi.UnimplementedGNMIServer
}

func (s *Server) Get(ctx context.Context, req *gnmi.GetRequest) (*gnmi.GetResponse, error) {
	return nil, nil
}

func (s *Server) Set(ctx context.Context, req *gnmi.SetRequest) (*gnmi.SetResponse, error) {
	return nil, nil
}

func (s *Server) Subscribe(stream gnmi.GNMI_SubscribeServer) error {
	return nil
}

func (s *Server) Capabilities(ctx context.Context, req *gnmi.CapabilityRequest) (*gnmi.CapabilityResponse, error) {
	return nil, nil
}

func main() {
	port := flag.String("port", ":9339", "Port to listen on")
	flag.Parse()

	lis, err := net.Listen("tcp", *port)
	if err != nil {
		log.Fatalf("Failed to listen: %v", err)
	}

	s := grpc.NewServer()
	gnmi.RegisterGNMIServer(s, &Server{})
	reflection.Register(s)

	fmt.Printf("gNMI Server is up and listening on localhost%s\n", *port)
	defer fmt.Println("Server shutdown.")

	if err := s.Serve(lis); err != nil {
		log.Fatalf("Failed to serve: %v", err)
	}
}
go get github.com/openconfig/gnmi/proto/gnmi
go get google.golang.org/grpc
go get google.golang.org/grpc/reflection

go mod vendor

go build
❯ grpcurl -plaintext localhost:9339 list 
gnmi.gNMI
grpc.reflection.v1.ServerReflection
grpc.reflection.v1alpha.ServerReflection

❯ grpcurl -plaintext localhost:9339 list gnmi.gNMI 
Failed to list methods for service "gnmi.gNMI": Symbol not found: gnmi.gNMI
caused by: File not found: github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.proto

Interrupt the server and run...

protoc -I=vendor --go_out=vendor --go_opt=paths=source_relative github.com/openconfig/gnmi/proto/gnmi_ext/gnmi_ext.proto

Restart the server and then we see it working as expected.

❯ grpcurl -plaintext localhost:9339 list gnmi.gNMI
gnmi.gNMI.Capabilities
gnmi.gNMI.Get
gnmi.gNMI.Set
gnmi.gNMI.Subscribe

@robshakir
Copy link
Contributor

This LGTM. We can fix the python at the point that someone needs this -- at the moment, I'm not actually sure we have anyone using the generated python here.

@robshakir robshakir merged commit 6db76cf into openconfig:master Jan 23, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants