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

[DEVOPS-824] Limit name length #92

Merged
merged 6 commits into from
Sep 17, 2018
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[DEVOPS-824] Delete metric if redis-failover no longer exist
Julio Chana committed Sep 14, 2018

Unverified

No user is associated with the committer email.
commit 11a358449fed58ef8d126d83fa3c9933029c24d0
1 change: 1 addition & 0 deletions metrics/dummy.go
Original file line number Diff line number Diff line change
@@ -8,3 +8,4 @@ type dummy struct{}

func (d *dummy) SetClusterOK(namespace string, name string) {}
func (d *dummy) SetClusterError(namespace string, name string) {}
func (d *dummy) DeleteCluster(namespace string, name string) {}
6 changes: 6 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ const (
type Instrumenter interface {
SetClusterOK(namespace string, name string)
SetClusterError(namespace string, name string)
DeleteCluster(namespace string, name string)
}

// PromMetrics implements the instrumenter so the metrics can be managed by Prometheus.
@@ -71,3 +72,8 @@ func (p *PromMetrics) SetClusterOK(namespace string, name string) {
func (p *PromMetrics) SetClusterError(namespace string, name string) {
p.clusterOK.WithLabelValues(namespace, name).Set(0)
}

// DeleteCluster set the cluster status to Error
func (p *PromMetrics) DeleteCluster(namespace string, name string) {
p.clusterOK.DeleteLabelValues(namespace, name)
}
21 changes: 21 additions & 0 deletions metrics/metrics_test.go
Original file line number Diff line number Diff line change
@@ -87,6 +87,27 @@ func TestPrometheusMetrics(t *testing.T) {
},
expCode: http.StatusOK,
},
{
name: "Deleting a cluster should remove it",
addMetrics: func(pm *metrics.PromMetrics) {
pm.SetClusterOK("testns1", "test")
pm.DeleteCluster("testns1", "test")
},
expMetrics: []string{},
expCode: http.StatusOK,
},
{
name: "Deleting a cluster should remove only the desired one",
addMetrics: func(pm *metrics.PromMetrics) {
pm.SetClusterOK("testns1", "test")
pm.SetClusterOK("testns2", "test")
pm.DeleteCluster("testns1", "test")
},
expMetrics: []string{
`my_metrics_controller_cluster_ok{name="test",namespace="testns2"} 1`,
},
expCode: http.StatusOK,
},
}

for _, test := range tests {
5 changes: 5 additions & 0 deletions operator/redisfailover/handler.go
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package redisfailover
import (
"context"
"fmt"
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
@@ -83,6 +84,10 @@ func (r *RedisFailoverHandler) Add(_ context.Context, obj runtime.Object) error

// Delete handles the deletion of a RF.
func (r *RedisFailoverHandler) Delete(_ context.Context, name string) error {
n := strings.Split(name, "/")
if len(n) >= 2 {
r.mClient.DeleteCluster(n[0], n[1])
}
// No need to do anything, it will be handled by the owner reference done
// on the creation.
r.logger.Debugf("ignoring, kubernetes GCs all using the objects OwnerReference metadata")