Skip to content

Commit

Permalink
Merge pull request #65 from edgelesssys/feat/prometheus
Browse files Browse the repository at this point in the history
AB#364 Add prometheus metrics endpoint
  • Loading branch information
m1ghtym0 authored Dec 14, 2020
2 parents b0d9df7 + a2eed6d commit 81ce91a
Show file tree
Hide file tree
Showing 5 changed files with 316 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/coordinator/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func run(validator quote.Validator, issuer quote.Issuer, sealKey []byte, sealDir
dnsNames := strings.Split(dnsNamesString, ",")
clientServerAddr := util.MustGetenv(config.ClientAddr)
meshServerAddr := util.MustGetenv(config.MeshAddr)
promServerAddr := os.Getenv(config.PromAddr)

// creating core
zapLogger.Info("creating the Core object")
Expand All @@ -59,6 +60,11 @@ func run(validator quote.Validator, issuer quote.Issuer, sealKey []byte, sealDir
panic(err)
}

// start the prometheus server
if promServerAddr != "" {
go server.RunPrometheusServer(promServerAddr, zapLogger)
}

// start client server
zapLogger.Info("starting the client server")
mux := server.CreateServeMux(core)
Expand Down
3 changes: 3 additions & 0 deletions coordinator/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const MeshAddr = "EDG_COORDINATOR_MESH_ADDR"
// ClientAddr is the coordinator's address for the HTTP-REST server to listen on
const ClientAddr = "EDG_COORDINATOR_CLIENT_ADDR"

// PromAddr is the coordinator's address for the prometheus endpoint server to listen on
const PromAddr = "EDG_COORDINATOR_PROMETHEUS_ADDR"

// DNSNames are the alternative dns names for the coordinator's certificate
const DNSNames = "EDG_COORDINATOR_DNS_NAMES"

Expand Down
13 changes: 13 additions & 0 deletions coordinator/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
grpc_ctxtags "github.com/grpc-ecosystem/go-grpc-middleware/tags"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand Down Expand Up @@ -64,10 +66,12 @@ func RunMarbleServer(core *core.Core, addr string, addrChan chan string, errChan
grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(
grpc_ctxtags.StreamServerInterceptor(),
grpc_zap.StreamServerInterceptor(zapLogger),
grpc_prometheus.StreamServerInterceptor,
)),
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
grpc_ctxtags.UnaryServerInterceptor(),
grpc_zap.UnaryServerInterceptor(zapLogger),
grpc_prometheus.UnaryServerInterceptor,
)),
)

Expand Down Expand Up @@ -180,3 +184,12 @@ func RunClientServer(mux *http.ServeMux, address string, tlsConfig *tls.Config,
err := server.ListenAndServeTLS("", "")
zapLogger.Warn(err.Error())
}

// RunPrometheusServer runs a HTTP server handling the prometheus metrics endpoint
func RunPrometheusServer(address string, zapLogger *zap.Logger) {
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
zapLogger.Info("starting prometheus /metrics endpoint", zap.String("address", address))
err := http.ListenAndServe(address, mux)
zapLogger.Warn(err.Error())
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ require (
github.com/google/uuid v1.1.2
github.com/gorilla/handlers v1.5.1
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/prometheus/client_golang v1.8.0
github.com/spf13/afero v1.4.1
github.com/stretchr/testify v1.6.1
github.com/tidwall/gjson v1.6.1
Expand Down
Loading

0 comments on commit 81ce91a

Please sign in to comment.