Skip to content

Commit

Permalink
add build info metric (operator-framework#67)
Browse files Browse the repository at this point in the history
Co-authored-by: Joe Lanford <joe.lanford@gmail.com>
  • Loading branch information
anmol372 and joelanford committed Jan 15, 2021
1 parent 06e5a4f commit 16ddc79
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/onsi/ginkgo v1.14.1
github.com/onsi/gomega v1.10.2
github.com/operator-framework/operator-lib v0.3.0
github.com/prometheus/client_golang v1.7.1
github.com/sirupsen/logrus v1.7.0
github.com/spf13/afero v1.2.2
github.com/spf13/cobra v1.1.1
Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/healthz"
logf "sigs.k8s.io/controller-runtime/pkg/log"
zapl "sigs.k8s.io/controller-runtime/pkg/log/zap"
crmetrics "sigs.k8s.io/controller-runtime/pkg/metrics"

"github.com/joelanford/helm-operator/internal/metrics"
"github.com/joelanford/helm-operator/internal/version"
"github.com/joelanford/helm-operator/pkg/annotation"
"github.com/joelanford/helm-operator/pkg/manager"
Expand Down Expand Up @@ -96,6 +98,8 @@ func printVersion() {
func (r *run) run(cmd *cobra.Command) {
printVersion()

metrics.RegisterBuildInfo(crmetrics.Registry)

// Deprecated: OPERATOR_NAME environment variable is an artifact of the legacy operator-sdk project scaffolding.
// Flag `--leader-election-id` should be used instead.
if operatorName, found := os.LookupEnv("OPERATOR_NAME"); found {
Expand Down
45 changes: 45 additions & 0 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2021 The Operator-SDK Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package metrics

import (
"github.com/prometheus/client_golang/prometheus"

helmVersion "github.com/joelanford/helm-operator/internal/version"
)

const (
subsystem = "helm_operator"
)

var (
buildInfo = prometheus.NewGauge(
prometheus.GaugeOpts{
Subsystem: subsystem,
Name: "build_info",
Help: "Build information for the helm-operator binary",
ConstLabels: map[string]string{
"commit": helmVersion.GitCommit,
"version": helmVersion.GitVersion,
},
},
)
)

//RegisterBuildInfo registers buildInfo Collector to be included in metrics collection
func RegisterBuildInfo(r prometheus.Registerer) {
buildInfo.Set(1)
r.MustRegister(buildInfo)
}

0 comments on commit 16ddc79

Please sign in to comment.