Skip to content

Commit

Permalink
Merge pull request #263 from dippynark/enable-kubernetes-api-client-m…
Browse files Browse the repository at this point in the history
…etrics

Increment failure metric for Kubernetes API client
  • Loading branch information
satoru-takeuchi authored Jun 20, 2024
2 parents fa8cd0f + 000b8eb commit 0723820
Showing 1 changed file with 6 additions and 1 deletion.
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

0 comments on commit 0723820

Please sign in to comment.