Skip to content

Commit

Permalink
feat: add version metrics for yurt-manager and yurthub
Browse files Browse the repository at this point in the history
Signed-off-by: rambohe-ch <linbo.hlb@alibaba-inc.com>
  • Loading branch information
rambohe-ch committed Jul 15, 2024
1 parent 7ec6485 commit 1ad0e4c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/yurt-manager/app/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"k8s.io/klog/v2/klogr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/metrics"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
runtimewebhook "sigs.k8s.io/controller-runtime/pkg/webhook"

Expand Down Expand Up @@ -95,6 +96,7 @@ current state towards the desired state.`,
if s.Generic.Version {
return
}
projectinfo.RegisterVersionInfo(metrics.Registry, projectinfo.GetYurtManagerName())

PrintFlags(cmd.Flags())

Expand Down
1 change: 1 addition & 0 deletions cmd/yurthub/app/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func NewCmdStartYurtHub(ctx context.Context) *cobra.Command {
return
}
fmt.Printf("%s version: %#v\n", projectinfo.GetHubName(), projectinfo.Get())
projectinfo.RegisterVersionInfo(nil, projectinfo.GetHubName())

cmd.Flags().VisitAll(func(flag *pflag.Flag) {
klog.V(1).Infof("FLAG: --%s=%q", flag.Name, flag.Value)
Expand Down
44 changes: 44 additions & 0 deletions pkg/projectinfo/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2024 The OpenYurt 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 projectinfo

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

yurtutil "github.com/openyurtio/openyurt/pkg/util"
)

var (
buildInfo = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "openyurt",
Name: "version_info",
Help: "A metric with a constant '1' value labeled by git version, git commit, build date, Go version, compiler and nodepoollabelkey from which OpenYurt was built, and platform on which it is running.",
},
[]string{"component_name", "git_version", "git_commit", "build_date", "go_version", "compiler", "platform", "nodepoollabelkey"},
)
)

func RegisterVersionInfo(reg prometheus.Registerer, componentName string) {
info := Get()
if yurtutil.IsNil(reg) {
prometheus.MustRegister(buildInfo)
} else {
reg.MustRegister(buildInfo)
}
buildInfo.WithLabelValues(componentName, info.GitVersion, info.GitCommit, info.BuildDate, info.GoVersion, info.Compiler, info.Platform, info.NodePoolLabelKey).Set(1)
}

0 comments on commit 1ad0e4c

Please sign in to comment.