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 build info metric #67

Merged
merged 2 commits into from
Jan 15, 2021
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
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)
}