Skip to content

Commit

Permalink
Merge pull request #40 from lwolf/expose-version-metric
Browse files Browse the repository at this point in the history
Expose binary version as a metric
  • Loading branch information
lwolf committed Mar 22, 2021
2 parents c4279fe + 9353a70 commit ce0ec3a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

VERSION ?= $(shell git rev-list --count HEAD)-$(shell git rev-parse --short=7 HEAD)
VERSION ?= $(shell git describe --tags --always --dirty="-dev")
# Image URL to use all building/pushing image targets
IMG ?= quay.io/lwolf/konsumerator:$(VERSION)
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
Expand Down
2 changes: 1 addition & 1 deletion config/samples/konsumerator_v1alpha1_consumer.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: konsumerator.lwolf.org/v1alpha1
apiVersion: konsumerator.lwolf.org/v1
kind: Consumer
metadata:
name: consumer-sample
Expand Down
2 changes: 1 addition & 1 deletion hack/ci/consumer-test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: konsumerator.lwolf.org/v1alpha1
apiVersion: konsumerator.lwolf.org/v1
kind: Consumer
metadata:
name: consumer-sample
Expand Down
19 changes: 17 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ package main

import (
"flag"
"fmt"
"os"
"runtime"

"github.com/prometheus/client_golang/prometheus"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/runtime"
kuberuntime "k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics"

konsumeratorv1 "github.com/lwolf/konsumerator/api/v1"
"github.com/lwolf/konsumerator/controllers"
Expand All @@ -33,8 +37,13 @@ import (

var (
Version string
scheme = runtime.NewScheme()
scheme = kuberuntime.NewScheme()
setupLog = ctrl.Log.WithName("setup")

metaInfoGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "konsumerator",
Name: "meta_info",
}, []string{"go_version", "binary_version"})
)

func init() {
Expand All @@ -55,6 +64,10 @@ func main() {
flag.BoolVar(&isDebug, "verbose", false, "Set log level to debug mode.")
flag.StringVar(&namespace, "namespace", "", "Run operator in guest mode, limit scope to only a single namespace. No CRD will be created")
flag.Parse()

metrics.Registry.MustRegister(metaInfoGauge)
metaInfoGauge.WithLabelValues(runtime.Version(), Version).Set(1)

setupLog.Info(
"Initializing konsumerator controller",
"version", Version,
Expand All @@ -70,9 +83,11 @@ func main() {
Scheme: scheme,
MetricsBindAddress: metricsAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: fmt.Sprintf("konsumerator-global"),
}
if guestMode {
options.Namespace = namespace
options.LeaderElectionID = fmt.Sprintf("konsumerator-%s", namespace)
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), options)
Expand Down

0 comments on commit ce0ec3a

Please sign in to comment.