Skip to content

Commit

Permalink
feat: add connector build_info
Browse files Browse the repository at this point in the history
  • Loading branch information
mxyng committed Jun 28, 2022
1 parent dbb6b8b commit 9ca7448
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
3 changes: 1 addition & 2 deletions internal/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/go-playground/validator/v10"
"github.com/goware/urlx"
"github.com/infrahq/secrets"
"github.com/prometheus/client_golang/prometheus"
"gopkg.in/square/go-jose.v2"
"gopkg.in/square/go-jose.v2/jwt"
rbacv1 "k8s.io/api/rbac/v1"
Expand Down Expand Up @@ -509,7 +508,7 @@ func Run(ctx context.Context, options Options) error {
proxy := httputil.NewSingleHostReverseProxy(proxyHost)
proxy.Transport = proxyTransport

promRegistry := prometheus.NewRegistry()
promRegistry := setupMetrics()
metricsServer := &http.Server{
Addr: ":9090",
Handler: metrics.NewHandler(promRegistry),
Expand Down
26 changes: 26 additions & 0 deletions internal/connector/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package connector

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"

"github.com/infrahq/infra/internal"
)

func setupMetrics() *prometheus.Registry {
registry := prometheus.NewRegistry()
factory := promauto.With(registry)

factory.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "build",
Name: "info",
Help: "Build information about Infra Connector.",
}, []string{"branch", "version", "commit", "date"}).With(prometheus.Labels{
"branch": internal.Branch,
"version": internal.FullVersion(),
"commit": internal.Commit,
"date": internal.Date,
}).Set(1)

return registry
}
4 changes: 2 additions & 2 deletions internal/server/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/infrahq/infra/internal/server/models"
)

func SetupMetrics(db *gorm.DB) *prometheus.Registry {
func setupMetrics(db *gorm.DB) *prometheus.Registry {
reg := prometheus.NewRegistry()
factory := promauto.With(reg)

Expand All @@ -21,7 +21,7 @@ func SetupMetrics(db *gorm.DB) *prometheus.Registry {
Help: "Build information about Infra Server.",
}, []string{"branch", "version", "commit", "date"}).With(prometheus.Labels{
"branch": internal.Branch,
"version": internal.Version,
"version": internal.FullVersion(),
"commit": internal.Commit,
"date": internal.Date,
}).Set(1)
Expand Down
2 changes: 1 addition & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func registerUIRoutes(router *gin.Engine, opts UIOptions) {

func (s *Server) listen() error {
ginutil.SetMode()
promRegistry := SetupMetrics(s.db)
promRegistry := setupMetrics(s.db)
router := s.GenerateRoutes(promRegistry)

metricsServer := &http.Server{
Expand Down

0 comments on commit 9ca7448

Please sign in to comment.