[VOL-5506] Enable grpc stats

Change-Id: I78fe2235a2df26855053aa91da6f0b2c4fccd5f0
Signed-off-by: Abhay Kumar <abhay.kumar@radisys.com>
diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go
index ba0e564..d06607e 100644
--- a/internal/pkg/config/config.go
+++ b/internal/pkg/config/config.go
@@ -39,6 +39,7 @@
 	defaultEventtopic           = "voltha.events"
 	defaultOnunumber            = 1
 	defaultProbeAddress         = ":8080"
+	defaultPrometheusPort       = ":8081"
 	defaultLiveProbeInterval    = 60 * time.Second
 	defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
 	// defaultHeartbeatCheckInterval is the time in seconds the adapter will keep checking the hardware for heartbeat.
@@ -78,6 +79,7 @@
 	EventTopic                         string
 	LogLevel                           string
 	ProbeAddress                       string
+	PrometheusAddress                  string
 	GrpcAddress                        string
 	CoreEndpoint                       string
 	TraceAgentAddress                  string
@@ -123,6 +125,7 @@
 		Banner:                             defaultBanner,
 		DisplayVersionOnly:                 defaultDisplayVersionOnly,
 		ProbeAddress:                       defaultProbeAddress,
+		PrometheusAddress:                  defaultPrometheusPort,
 		LiveProbeInterval:                  defaultLiveProbeInterval,
 		NotLiveProbeInterval:               defaultNotLiveProbeInterval,
 		HeartbeatCheckInterval:             defaultHeartbeatCheckInterval,
@@ -201,6 +204,11 @@
 		defaultProbeAddress,
 		"The address on which to listen to answer liveness and readiness probe queries over HTTP.")
 
+	flag.StringVar(&(so.PrometheusAddress),
+		"prometheus_address",
+		defaultPrometheusPort,
+		"Used for exposing the metrics to prometheus.")
+
 	flag.DurationVar(&(so.LiveProbeInterval),
 		"live_probe_interval",
 		defaultLiveProbeInterval,
diff --git a/internal/pkg/core/device_handler.go b/internal/pkg/core/device_handler.go
index a72c011..c85be74 100755
--- a/internal/pkg/core/device_handler.go
+++ b/internal/pkg/core/device_handler.go
@@ -39,6 +39,7 @@
 	"github.com/gogo/protobuf/proto"
 	grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
 	grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
+	grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
 	"github.com/opencord/voltha-lib-go/v7/pkg/config"
 	"github.com/opencord/voltha-lib-go/v7/pkg/events/eventif"
 	flow_utils "github.com/opencord/voltha-lib-go/v7/pkg/flows"
@@ -1209,15 +1210,18 @@
 	}
 
 	logger.Debugw(ctx, "Dailing grpc", log.Fields{"device-id": dh.device.Id})
+	grpc_prometheus.EnableClientHandlingTimeHistogram()
 	// Use Interceptors to automatically inject and publish Open Tracing Spans by this GRPC client
 	dh.clientCon, err = grpc.Dial(dh.device.GetHostAndPort(),
 		grpc.WithInsecure(),
 		grpc.WithBlock(),
 		grpc.WithStreamInterceptor(grpc_middleware.ChainStreamClient(
 			grpc_opentracing.StreamClientInterceptor(grpc_opentracing.WithTracer(log.ActiveTracerProxy{})),
+			grpc_prometheus.StreamClientInterceptor,
 		)),
 		grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(
 			grpc_opentracing.UnaryClientInterceptor(grpc_opentracing.WithTracer(log.ActiveTracerProxy{})),
+			grpc_prometheus.UnaryClientInterceptor,
 		)))
 
 	if err != nil {