Skip to content

Commit

Permalink
Merge pull request #19 from rmb938/removemetric
Browse files Browse the repository at this point in the history
remove host port metric since it doesn't go away on leader change
  • Loading branch information
rmb938 authored Feb 19, 2021
2 parents d80a482 + ed859bd commit 983a22b
Showing 1 changed file with 0 additions and 22 deletions.
22 changes: 0 additions & 22 deletions controllers/hostport_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,19 @@ import (
"sync"

"github.com/go-logr/logr"
"github.com/prometheus/client_golang/prometheus"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/metrics"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

hostportv1alpha1 "github.com/rmb938/hostport-allocator/api/v1alpha1"
)

var (
metricsHostPortInfo = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "hostport",
Name: "hostport_port",
Help: "The port allocated to the hostport",
},
[]string{"name"},
)
)

func init() {
metrics.Registry.MustRegister(metricsHostPortInfo)
}

// HostPortReconciler reconciles a HostPort object
type HostPortReconciler struct {
client.Client
Expand All @@ -72,16 +55,11 @@ func (r *HostPortReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
err := r.Get(ctx, req.NamespacedName, hp)
if err != nil {
if apierrors.IsNotFound(err) {
metricsHostPortInfo.DeleteLabelValues(req.Name)
return ctrl.Result{}, nil
}
return ctrl.Result{}, err
}

metricsHostPortInfo.With(prometheus.Labels{
"name": hp.Name,
}).Set(float64(hp.Status.Port))

// if port is deleting
if hp.DeletionTimestamp.IsZero() == false {

Expand Down

0 comments on commit 983a22b

Please sign in to comment.