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

Increment failure metric for Kubernetes API client #263

Merged
Merged
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
Increment failure metric for Kubernetes API client
Signed-off-by: Luke Addison <lukeaddison785@gmail.com>
  • Loading branch information
dippynark committed Jun 19, 2024
commit 000b8ebd01fb53fd048cb899d8c39dd73848bbe8
7 changes: 6 additions & 1 deletion internal/runners/k8s_metrics_api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"
"github.com/topolvm/pvc-autoresizer/internal/metrics"
"golang.org/x/sync/errgroup"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -26,17 +27,20 @@ func (c *k8sMetricsApiClient) GetMetrics(ctx context.Context) (map[types.Namespa
// create a Kubernetes client using in-cluster configuration
config, err := rest.InClusterConfig()
if err != nil {
metrics.MetricsClientFailTotal.Increment()
return nil, err
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
metrics.MetricsClientFailTotal.Increment()
return nil, err
}

// get a list of nodes and IP addresses
nodes, err := clientset.CoreV1().Nodes().List(context.Background(), v1.ListOptions{})
nodes, err := clientset.CoreV1().Nodes().List(ctx, v1.ListOptions{})
if err != nil {
metrics.MetricsClientFailTotal.Increment()
return nil, err
}

Expand All @@ -54,6 +58,7 @@ func (c *k8sMetricsApiClient) GetMetrics(ctx context.Context) (map[types.Namespa

// wait for all queries to complete and handle any errors
if err := eg.Wait(); err != nil {
metrics.MetricsClientFailTotal.Increment()
return nil, err
}

Expand Down