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

feat: add operator build_info metrics and go runtime metrics #6044

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
26 changes: 26 additions & 0 deletions operator/cmd/operator/app/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import (
"flag"
"fmt"
"os"
"regexp"

"github.com/prometheus/client_golang/prometheus/collectors"
prometheusversion "github.com/prometheus/client_golang/prometheus/collectors/version"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/util/sets"
restclient "k8s.io/client-go/rest"
Expand All @@ -32,6 +35,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/healthz"
ctrlmetrics "sigs.k8s.io/controller-runtime/pkg/metrics"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

"github.com/karmada-io/karmada/operator/cmd/operator/app/options"
Expand Down Expand Up @@ -110,6 +114,28 @@ func Run(ctx context.Context, o *options.Options) error {
return err
}

if err := manager.AddReadyzCheck("readyz", healthz.Ping); err != nil {
klog.Errorf("Unable to set up ready check: %v", err)
return err
}
dongjiang1989 marked this conversation as resolved.
Show resolved Hide resolved

// Unregister default NewGoCollector
ctrlmetrics.Registry.Unregister(collectors.NewGoCollector())

ctrlmetrics.Registry.MustRegister(
collectors.NewGoCollector(
collectors.WithGoCollectorRuntimeMetrics(
collectors.MetricsGC,
collectors.MetricsScheduler,
collectors.MetricsMemory,
collectors.GoRuntimeMetricsRule{Matcher: regexp.MustCompile(`^/sync/.*`)},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with these metrics either.
Could you add some simple comments indicating the purpose or usage of each metric?

Copy link
Contributor Author

@dongjiang1989 dongjiang1989 Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chaosi-zju .
I got it.
Add comments for each metric.

Please re-check it.

BTW, I will extend these metrics to all other components.

),
),
)
dongjiang1989 marked this conversation as resolved.
Show resolved Hide resolved
ctrlmetrics.Registry.MustRegister(
prometheusversion.NewCollector("karmada_operator"),
)
dongjiang1989 marked this conversation as resolved.
Show resolved Hide resolved

controllerCtx := ctrlctx.Context{
Controllers: o.Controllers,
Manager: manager,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

125 changes: 125 additions & 0 deletions vendor/github.com/prometheus/common/version/info.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ github.com/pmezard/go-difflib/difflib
## explicit; go 1.20
github.com/prometheus/client_golang/prometheus
github.com/prometheus/client_golang/prometheus/collectors
github.com/prometheus/client_golang/prometheus/collectors/version
github.com/prometheus/client_golang/prometheus/internal
github.com/prometheus/client_golang/prometheus/promhttp
github.com/prometheus/client_golang/prometheus/testutil
Expand All @@ -397,6 +398,7 @@ github.com/prometheus/client_model/go
## explicit; go 1.20
github.com/prometheus/common/expfmt
github.com/prometheus/common/model
github.com/prometheus/common/version
# github.com/prometheus/procfs v0.15.1
## explicit; go 1.20
github.com/prometheus/procfs
Expand Down