Skip to content

Commit

Permalink
feat: Add build_info metric with version, sha, golang_version labels (#…
Browse files Browse the repository at this point in the history
…5213)

Co-authored-by: Jonathan Innis <[email protected]>
  • Loading branch information
nantiferov and jonathan-innis authored Dec 7, 2023
1 parent ba9916d commit 1e4e84d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"net"
"runtime"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -37,18 +38,22 @@ import (
"github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go/service/ssm"
"github.com/patrickmn/go-cache"
"github.com/prometheus/client_golang/prometheus"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
crmetrics "sigs.k8s.io/controller-runtime/pkg/metrics"

"github.com/samber/lo"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/transport"
"knative.dev/pkg/changeset"
"knative.dev/pkg/logging"
"knative.dev/pkg/ptr"

corev1beta1 "sigs.k8s.io/karpenter/pkg/apis/v1beta1"
"sigs.k8s.io/karpenter/pkg/metrics"
"sigs.k8s.io/karpenter/pkg/operator"
"sigs.k8s.io/karpenter/pkg/operator/scheme"

Expand All @@ -66,9 +71,19 @@ import (
"github.com/aws/karpenter-provider-aws/pkg/providers/version"
)

var BuildInfo = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: metrics.Namespace,
Name: "build_info",
Help: "A metric with a constant '1' value labeled by version from which karpenter was built.",
},
[]string{"version", "goversion", "sha"})

func init() {
lo.Must0(apis.AddToScheme(scheme.Scheme))
corev1beta1.NormalizedLabels = lo.Assign(corev1beta1.NormalizedLabels, map[string]string{"topology.ebs.csi.aws.com/zone": corev1.LabelTopologyZone})
crmetrics.Registry.MustRegister(BuildInfo)
BuildInfo.WithLabelValues(operator.Version, runtime.Version(), changeset.Get()).Set(1)
}

// Operator is injected into the AWS CloudProvider's factories
Expand Down

0 comments on commit 1e4e84d

Please sign in to comment.