Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .govulncheck.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
ignored-vulnerabilities: []
ignored-vulnerabilities:
# Incorrect parsing of IPv6 host literals in net/url
# Found in: net/url@go1.24.13
# Fixed in: net/url@go1.25.8
- id: GO-2026-4601
info: https://pkg.go.dev/vuln/GO-2026-4601
silence-until: 2026-04-23
# FileInfo can escape from a Root in os
# Found in: os@go1.24.13
# Fixed in: os@go1.25.8
- id: GO-2026-4602
info: https://pkg.go.dev/vuln/GO-2026-4602
silence-until: 2026-04-23
# URLs in meta content attribute actions are not escaped in html/template
# Found in: html/template@go1.24.13
# Fixed in: html/template@go1.25.8
- id: GO-2026-4603
info: https://pkg.go.dev/vuln/GO-2026-4603
silence-until: 2026-04-23
4 changes: 3 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"fmt"
"net/http"
"os"
"sigs.k8s.io/controller-runtime/pkg/cache"
"time"

"sigs.k8s.io/controller-runtime/pkg/cache"

toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
"github.com/codeready-toolchain/registration-service/pkg/auth"
"github.com/codeready-toolchain/registration-service/pkg/configuration"
Expand Down Expand Up @@ -119,6 +120,7 @@ func main() {
// Registration Service
// ---------------------------------------------
regsvcRegistry := prometheus.NewRegistry()
configuration.RegisterVersionMetrics(regsvcRegistry)
regsvcMetricsSrv, _ := server.StartMetricsServer(regsvcRegistry, server.RegSvcMetricsPort)
regsvcSrv := server.New(app)
err = regsvcSrv.SetupRoutes(proxy.DefaultPort, regsvcRegistry, nsClient)
Expand Down
11 changes: 0 additions & 11 deletions pkg/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

var (
// Commit current build commit set by build script.
Commit = "0"
// BuildTime set by build script in ISO 8601 (UTC) format:
// YYYY-MM-DDThh:mm:ssTZD (see https://www.w3.org/TR/NOTE-datetime for
// details).
BuildTime = "0"
// StartTime in ISO 8601 (UTC) format.
StartTime = time.Now().UTC().Format("2006-01-02T15:04:05Z")
)

var logger = logf.Log.WithName("configuration")

const (
Expand Down
46 changes: 46 additions & 0 deletions pkg/configuration/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package configuration

import (
"time"

"github.com/prometheus/client_golang/prometheus"
)

var (
// Commit current build commit set by build script.
Commit = "0"
// BuildTime set by build script in ISO 8601 (UTC) format:
// YYYY-MM-DDThh:mm:ssTZD (see https://www.w3.org/TR/NOTE-datetime for
// details).
BuildTime = "0"
// StartTime in ISO 8601 (UTC) format.
StartTime = time.Now().UTC().Format("2006-01-02T15:04:05Z")
)

var (
// RegistrationServiceShortCommitGaugeVec reflects the current short git commit of the registration service (via the `commit` label)
RegistrationServiceShortCommitGaugeVec *prometheus.GaugeVec
// RegistrationServiceCommitGaugeVec reflects the current full git commit of the registration service (via the `commit` label)
RegistrationServiceCommitGaugeVec *prometheus.GaugeVec
)

func RegisterVersionMetrics(registry *prometheus.Registry) {
// RegistrationServiceCommitGaugeVec reflects the current full git commit of the registration service (via the `commit` label)
RegistrationServiceCommitGaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "sandbox_registration_service_commit",
Help: "The commit of the registration service",
}, []string{"commit"})
RegistrationServiceCommitGaugeVec.WithLabelValues(Commit).SetToCurrentTime() // automatically set the value to the current time, so that the highest value is the current commit

// RegistrationServiceShortCommitGaugeVec reflects the current short git commit of the registration service (via the `commit` label)
RegistrationServiceShortCommitGaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "sandbox_registration_service_short_commit",
Help: "The short commit of the registration service",
}, []string{"commit"})
shortCommit := Commit
if len(Commit) >= 7 {
shortCommit = Commit[0:7]
}
RegistrationServiceShortCommitGaugeVec.WithLabelValues(shortCommit).SetToCurrentTime() // automatically set the value to the current time, so that the highest value is the current commit
registry.MustRegister(RegistrationServiceCommitGaugeVec, RegistrationServiceShortCommitGaugeVec)
}
41 changes: 41 additions & 0 deletions pkg/configuration/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package configuration_test

import (
"testing"
"time"

"github.com/codeready-toolchain/registration-service/pkg/configuration"

"github.com/prometheus/client_golang/prometheus"
promtestutil "github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/assert"
)

func TestVersionMetrics(t *testing.T) {

testData := []struct {
name string
commit string
shortCommit string
}{
{name: "when commit is longer than 7 characters", commit: "short12-34567890", shortCommit: "short12"},
{name: "when commit is shorter than 7 characters", commit: "short", shortCommit: "short"},
{name: "when commit is empty", commit: "", shortCommit: ""},
}

for _, test := range testData {
t.Run(test.name, func(t *testing.T) {
// given
configuration.Commit = test.commit
registry := prometheus.NewRegistry()

// when
configuration.RegisterVersionMetrics(registry)

// then
assert.InDelta(t, float64(time.Now().Unix()), promtestutil.ToFloat64(configuration.RegistrationServiceShortCommitGaugeVec.WithLabelValues(test.shortCommit)), float64(time.Minute.Seconds()))
assert.InDelta(t, float64(time.Now().Unix()), promtestutil.ToFloat64(configuration.RegistrationServiceCommitGaugeVec.WithLabelValues(test.commit)), float64(time.Minute.Seconds()))
})
}

}
1 change: 1 addition & 0 deletions pkg/server/metrics_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func StartMetricsServer(reg *prometheus.Registry, port int) (*http.Server, *gin.
DisableCompression: true,
}),
)))

log.Info("Starting the registration-service metrics server...")
srv := &http.Server{
Addr: fmt.Sprintf(":%d", port),
Expand Down
48 changes: 48 additions & 0 deletions pkg/server/metrics_server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package server_test

import (
"context"
"io"
"net/http"
"testing"
"time"

"github.com/codeready-toolchain/registration-service/pkg/configuration"
"github.com/codeready-toolchain/registration-service/pkg/server"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
)

func TestStartMetricsServer(t *testing.T) {
// given

configuration.Commit = "1234567890"
registry := prometheus.NewRegistry()
configuration.RegisterVersionMetrics(registry)
srv, _ := server.StartMetricsServer(registry, 8080)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
defer func(ctx context.Context) {
err := srv.Shutdown(ctx)
if err != nil {
t.Fatalf("failed to shutdown metrics server: %v", err)
}
}(ctx)
// make a request to the metrics server

resp, err := http.Get("http://localhost:8080/metrics")
if err != nil {
t.Fatalf("failed to make request to metrics server: %v", err)
}
defer resp.Body.Close()

// check the response
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("failed to read response body: %v", err)
}

// check the response body
assert.Contains(t, string(body), "sandbox_registration_service_commit")
assert.Contains(t, string(body), "sandbox_registration_service_short_commit")
}
2 changes: 1 addition & 1 deletion pkg/verification/sender/twilio_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c *MockTwilioConfig) TwilioSenderConfigs() []toolchainv1alpha1.TwilioSende

func TestTwilioSenderID(t *testing.T) {

cfg := &MockTwilioConfig{
cfg := &MockTwilioConfig{ //nolint:gosec
AccountSID: "TWILIO_SID_VALUE",
AuthToken: "AUTH_TOKEN_VALUE",
FromNumber: "+13334445555",
Expand Down
Loading