Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Prometheus build_info metrics #300

Merged
merged 1 commit into from
Jun 16, 2023
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ acceptance-prepare: install-tools
go run cmd/acceptance/main.go prepare --verbose

acceptance-destroy: install-tools
go run cmd/acceptance/main.go prepare --verbose
go run cmd/acceptance/main.go destroy

generate: install-tools
controller-gen object paths="./apis/rbac/..."
Expand Down
6 changes: 0 additions & 6 deletions apis/vault/v1alpha1/secretsinjector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/metrics"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

Expand Down Expand Up @@ -88,11 +87,6 @@ var (
)
)

func init() {
// Register custom metrics with the global controller runtime prometheus registry
metrics.Registry.MustRegister(handleTotal, mutateTotal, skipTotal, errorsTotal)
}

func (i *SecretsInjector) Handle(ctx context.Context, req admission.Request) (resp admission.Response) {
labels := prometheus.Labels{"pod_namespace": req.Namespace}
logger := i.logger.WithValues("uuid", string(req.UID))
Expand Down
18 changes: 18 additions & 0 deletions cmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/alecthomas/kingpin"
"github.com/go-logr/logr"
"github.com/prometheus/client_golang/prometheus"
zaplogfmt "github.com/sykesm/zap-logfmt"
zapopt "go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand Down Expand Up @@ -77,3 +78,20 @@ func VersionStanza() string {
Version, Commit, GoVersion, runtime.GOOS, runtime.GOARCH, Date,
)
}

var (
BuildInfo = prometheus.NewGaugeFunc(
prometheus.GaugeOpts{
Name: "theatre_build_info",
Help: "A metric with a constant '1' value labeled by version, commit, goversion from which %s was built, and the goos and goarch for the build.",
ConstLabels: prometheus.Labels{
"version": Version,
"commit": Commit,
DragosDumitrache marked this conversation as resolved.
Show resolved Hide resolved
"goversion": GoVersion,
"goos": runtime.GOOS,
"goarch": runtime.GOARCH,
},
},
func() float64 { return 1 },
)
)
4 changes: 4 additions & 0 deletions cmd/rbac-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // this is required to auth against GCP
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/metrics"

rbacv1alpha1 "github.com/gocardless/theatre/v3/apis/rbac/v1alpha1"
"github.com/gocardless/theatre/v3/cmd"
Expand All @@ -39,6 +40,9 @@ var (
func init() {
_ = clientgoscheme.AddToScheme(scheme)
_ = rbacv1alpha1.AddToScheme(scheme)

// Register custom metrics with the global controller runtime prometheus registry
metrics.Registry.MustRegister(cmd.BuildInfo)
}

func main() {
Expand Down
6 changes: 6 additions & 0 deletions cmd/vault-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // this is required to auth against GCP
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/metrics"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

vaultv1alpha1 "github.com/gocardless/theatre/v3/apis/vault/v1alpha1"
Expand Down Expand Up @@ -43,6 +44,11 @@ var (
serviceAccountTokenAudience = app.Flag("service-account-token-audience", "Audience for the projected service account token").String()
)

func init() {
// Register custom metrics with the global controller runtime prometheus registry
metrics.Registry.MustRegister(cmd.BuildInfo)
}

func main() {
kingpin.MustParse(app.Parse(os.Args[1:]))
logger := commonOpts.Logger()
Expand Down
4 changes: 4 additions & 0 deletions cmd/workloads-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // this is required to auth against GCP
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/metrics"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

rbacv1alpha1 "github.com/gocardless/theatre/v3/apis/rbac/v1alpha1"
Expand Down Expand Up @@ -39,6 +40,9 @@ func init() {
_ = clientgoscheme.AddToScheme(scheme)
_ = workloadsv1alpha1.AddToScheme(scheme)
_ = rbacv1alpha1.AddToScheme(scheme)

// Register custom metrics with the global controller runtime prometheus registry
metrics.Registry.MustRegister(cmd.BuildInfo)
}

func main() {
Expand Down