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 clustercache metrics #11789

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

cahillsf
Copy link
Member

@cahillsf cahillsf commented Feb 3, 2025

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Part of #11272

/area clustercache

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. area/clustercache Issues or PRs related to the clustercachetracker cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 3, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign vincepri for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 3, 2025
@cahillsf cahillsf marked this pull request as ready for review February 3, 2025 23:28
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 3, 2025
@@ -241,6 +241,7 @@ func (ca *clusterAccessor) Connect(ctx context.Context) (retErr error) {

if ca.Connected(ctx) {
log.V(6).Info("Skipping connect, already connected")
connectionUp.WithLabelValues(ca.cluster.String()).Set(1)
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't need this one here. The only way to get to Connected is through Connect and we're already setting the metric to 1 in l.269

@@ -264,6 +266,7 @@ func (ca *clusterAccessor) Connect(ctx context.Context) (retErr error) {
}

log.Info("Connected")
connectionUp.WithLabelValues(ca.cluster.String()).Set(1)
Copy link
Member

Choose a reason for hiding this comment

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

Should we move this into an else branch in the defer? Then the metric is handled in a single place

@@ -298,7 +301,9 @@ func (ca *clusterAccessor) Connect(ctx context.Context) (retErr error) {
// Disconnect disconnects a connection to the workload cluster.
func (ca *clusterAccessor) Disconnect(ctx context.Context) {
log := ctrl.LoggerFrom(ctx)

defer func() {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe let's move this directly above l.315?

Basically in l.307-l.310 nothing changes so we also don't have to change the metric

Not super important, but also to keep this similar to how we handle the metric in the Connect method

var (
healthCheck = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "capi_clustercache_health_check",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Name: "capi_clustercache_health_check",
Name: "capi_cluster_cache_health_check",

for consistency with capi_ssa_cache_hits_total (same below)


func init() {
// Register the metrics at the controller-runtime metrics registry.
ctrlmetrics.Registry.MustRegister(healthCheck)
Copy link
Member

Choose a reason for hiding this comment

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

We also have to register connectionUp

}

var (
healthCheck = prometheus.NewGaugeVec(
Copy link
Member

Choose a reason for hiding this comment

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

I think we should also have a _total metric for healthchecks. Could be useful to have a counter to see how often the health check succeeded/failed

healthCheck = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "capi_clustercache_health_check",
Help: "Result of a single clustercache healthcheck.",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Help: "Result of a single clustercache healthcheck.",
Help: "Result of the last clustercache healthcheck for a cluster.",

Name: "capi_clustercache_health_check",
Help: "Result of a single clustercache healthcheck.",
}, []string{
"cluster",
Copy link
Member

Choose a reason for hiding this comment

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

Do you know if there's some sort of standard/convention on how to encode namespace + name into metric labels?

If there is, would be nice to follow it to make it easier to correlate / join metrics

Copy link
Member Author

Choose a reason for hiding this comment

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

good point! will take a look into this

@cahillsf
Copy link
Member Author

cahillsf commented Feb 7, 2025

thanks for the review @sbueringer, everything except the label enhancement should be addressed (still have to look into this a bit)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/clustercache Issues or PRs related to the clustercachetracker cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants