Skip to content

Commit

Permalink
export rekor build/version information
Browse files Browse the repository at this point in the history
Signed-off-by: cpanato <ctadeu@gmail.com>
  • Loading branch information
cpanato committed Sep 23, 2022
1 parent 7652a61 commit 3a49a93
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/rekor-server/app/root.go
Expand Up @@ -76,7 +76,7 @@ func init() {

rootCmd.PersistentFlags().String("rekor_server.signer", "memory",
`Rekor signer to use. Valid options are: [gcpkms, memory, filename containing PEM encoded private key].
Memory and file-based signers should only be used for testing.`)
Memory and file-based signers should only be used for testing.`)
rootCmd.PersistentFlags().String("rekor_server.signer-passwd", "", "Password to decrypt signer private key")

rootCmd.PersistentFlags().Uint16("port", 3000, "Port to bind to")
Expand Down
4 changes: 4 additions & 0 deletions cmd/rekor-server/app/serve.go
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/go-openapi/loads"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -74,6 +75,9 @@ var serveCmd = &cobra.Command{
}
log.Logger.Infof("starting rekor-server @ %v", viStr)

reg := prometheus.NewRegistry()
reg.MustRegister(api.NewVersionCollector("rekor", vi))

doc, _ := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON)
server := restapi.NewServer(operations.NewRekorServerAPI(doc))
defer func() {
Expand Down
24 changes: 24 additions & 0 deletions pkg/api/metrics.go
Expand Up @@ -16,10 +16,12 @@
package api

import (
"fmt"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"sigs.k8s.io/release-utils/version"
)

var (
Expand Down Expand Up @@ -52,3 +54,25 @@ var (
Help: "Api QPS by path, method, and response code",
}, []string{"path", "method", "code"})
)

// NewVersionCollector returns a collector that exports metrics about current version
// information.
func NewVersionCollector(program string, versionInfo version.Info) prometheus.Collector {
return promauto.NewGaugeFunc(
prometheus.GaugeOpts{
Namespace: program,
Name: "build_info",
Help: fmt.Sprintf(
"A metric with a constant '1' value labeled by version, revision, branch, and goversion from which %s was built.",
program,
),
ConstLabels: prometheus.Labels{
"version": versionInfo.GitVersion,
"revision": versionInfo.GitCommit,
"build_date": versionInfo.BuildDate,
"goversion": versionInfo.GoVersion,
},
},
func() float64 { return 1 },
)
}

0 comments on commit 3a49a93

Please sign in to comment.