Skip to content

Commit

Permalink
HGWGDC-19759: Separate port for metrics in petasos-rewriter. (#7)
Browse files Browse the repository at this point in the history
* HGWGDC-19759: Separate port for metrics in petasos-rewriter.

* HGWGDC-19759: Revert petasos endpoint config changes
  • Loading branch information
chaitanyasingla-dt authored Oct 6, 2023
1 parent b17f522 commit e20e3c9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
5 changes: 3 additions & 2 deletions forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/getsentry/sentry-go"
"github.com/spf13/viper"
"io/ioutil"
"net/http"
"net/http/httputil"
"net/url"
"regexp"
"strings"

"github.com/getsentry/sentry-go"
"github.com/spf13/viper"

"github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"
)
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
spanIdHeader = "span-id"
traceIdHeader = "trace-id"
remoteUpdateEndpoint = "remoteUpdate.url"
metricsServerPort = "metricsOptions.port"
)

func init() {
Expand Down
17 changes: 14 additions & 3 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/viper"
Expand All @@ -18,17 +19,27 @@ type metricRegistry struct {
}

func provideMetrics(e *echo.Echo) {
metrics := echo.New()
metrics.Use(middleware.Logger())
metrics.Use(middleware.Recover())

mr := registerMetrics()

if err := prometheus.Register(mr.TotalRequests); err != nil {
e.Logger.Fatal(err)
metrics.Logger.Fatal(err)
}
if err := prometheus.Register(mr.ServerRequestDuration); err != nil {
e.Logger.Fatal(err)
metrics.Logger.Fatal(err)
}

metrics.Use(mr.getMiddleware())
metrics.GET("/metrics", echo.WrapHandler(promhttp.Handler()))

go func() {
metrics.Logger.Fatal(metrics.Start(":" + viper.GetString(metricsServerPort)))
}()

e.Use(mr.getMiddleware())
e.GET("/metrics", echo.WrapHandler(promhttp.Handler()))
}

func registerMetrics() *metricRegistry {
Expand Down
2 changes: 2 additions & 0 deletions petasos-rewriter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ remoteUpdate:
#
# (Optional)
metricsOptions:
# port on which metrics will be running
port: 1324
# namespace is the namespace of the metrics provided
# (Optional)
namespace: xmidt
Expand Down

0 comments on commit e20e3c9

Please sign in to comment.