[VOL-5506] Enable grpc stats
Change-Id: I40e147b0519fe757479a5dd8b2eaae70753044c4
Signed-off-by: Abhay Kumar <abhay.kumar@radisys.com>
diff --git a/VERSION b/VERSION
index c1e43e6..0833a98 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.7.3
+3.7.4
diff --git a/go.mod b/go.mod
index f53a24f..c25ae89 100644
--- a/go.mod
+++ b/go.mod
@@ -16,6 +16,7 @@
github.com/opencord/voltha-protos/v5 v5.6.6
github.com/opentracing/opentracing-go v1.2.0
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
+ github.com/prometheus/client_golang v1.23.2
github.com/stretchr/testify v1.11.1
github.com/uber/jaeger-client-go v2.30.0+incompatible
google.golang.org/grpc v1.76.0
@@ -60,7 +61,6 @@
github.com/pierrec/lz4/v4 v4.1.22 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
- github.com/prometheus/client_golang v1.23.2 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.66.1 // indirect
github.com/prometheus/procfs v0.16.1 // indirect
diff --git a/rw_core/config/config.go b/rw_core/config/config.go
index 4356f1f..13cfabc 100644
--- a/rw_core/config/config.go
+++ b/rw_core/config/config.go
@@ -43,6 +43,7 @@
RWCoreCert string
RWCoreCA string
ProbeAddress string
+ PrometheusAddress string
TraceAgentAddress string
VolthaStackID string
KVStoreTimeout time.Duration
@@ -173,6 +174,11 @@
":8080",
"The address on which to listen to answer liveness and readiness probe queries over HTTP")
+ fs.StringVar(&cf.PrometheusAddress,
+ "prometheus_address",
+ ":8081",
+ "Used for exposing the metrics to prometheus")
+
fs.BoolVar(&(cf.TraceEnabled),
"trace_enabled",
false,
diff --git a/rw_core/main.go b/rw_core/main.go
index 70c4b35..13eca83 100644
--- a/rw_core/main.go
+++ b/rw_core/main.go
@@ -20,6 +20,7 @@
"context"
"fmt"
"io"
+ "net/http"
"os"
"time"
@@ -29,6 +30,7 @@
"github.com/opencord/voltha-lib-go/v7/pkg/log"
"github.com/opencord/voltha-lib-go/v7/pkg/probe"
"github.com/opencord/voltha-lib-go/v7/pkg/version"
+ "github.com/prometheus/client_golang/prometheus/promhttp"
)
func printBanner() {
@@ -106,6 +108,24 @@
// Create a context adding the status update channel
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
+ http.Handle("/metrics", promhttp.Handler())
+ go func() {
+ logger.Infof(ctx, "Metrics available at %s/metrics", cf.PrometheusAddress)
+ // Create HTTP server with explicit timeouts to prevent slowloris attacks and resource exhaustion.
+ // Using http.ListenAndServe() directly doesn't allow setting timeouts, which is a security risk.
+ // The server uses http.DefaultServeMux (nil handler) which includes the /metrics endpoint registered above.
+ metricsServer := &http.Server{
+ Addr: cf.PrometheusAddress,
+ Handler: nil,
+ ReadHeaderTimeout: 10 * time.Second,
+ ReadTimeout: 30 * time.Second,
+ WriteTimeout: 30 * time.Second,
+ IdleTimeout: 120 * time.Second,
+ }
+ if err := metricsServer.ListenAndServe(); err != nil {
+ logger.Errorw(ctx, "failed to start metrics HTTP server: ", log.Fields{"error": err})
+ }
+ }()
/*
* Create and start the liveness and readiness container management probes. This