From 985738faad74bd71500878a0fbb44a5f9aba51ac Mon Sep 17 00:00:00 2001 From: "lukasz.widera@vshn.ch" <lukasz.widera@vshn.ch> Date: Sat, 21 Oct 2023 16:03:54 +0200 Subject: [PATCH] adding HA label to histogram --- apis/vshn/v1/dbaas_vshn_redis.go | 6 ++++++ pkg/sliexporter/probes/redis.go | 6 +++--- .../vshnredis_controller/vshnredis_controller.go | 9 +++++++-- .../vshnredis_controller/vshnredis_controller_test.go | 6 +++--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/apis/vshn/v1/dbaas_vshn_redis.go b/apis/vshn/v1/dbaas_vshn_redis.go index 9b62b6c4b0..948b2a9a8a 100644 --- a/apis/vshn/v1/dbaas_vshn_redis.go +++ b/apis/vshn/v1/dbaas_vshn_redis.go @@ -80,6 +80,12 @@ type VSHNRedisServiceSpec struct { // RedisSettings contains additional Redis settings. RedisSettings string `json:"redisSettings,omitempty"` + + // +kubebuilder:validation:Enum="besteffort";"guaranteed" + // +kubebuilder:default="besteffort" + + // ServiceLevel defines the service level of this service. Either Best Effort or Guaranteed Availability is allowed. + ServiceLevel VSHNDBaaSServiceLevel `json:"serviceLevel,omitempty"` } // VSHNRedisSizeSpec contains settings to control the sizing of a service. diff --git a/pkg/sliexporter/probes/redis.go b/pkg/sliexporter/probes/redis.go index c2712ed769..0b45efbc97 100644 --- a/pkg/sliexporter/probes/redis.go +++ b/pkg/sliexporter/probes/redis.go @@ -34,7 +34,7 @@ func (redis VSHNRedis) GetInfo() ProbeInfo { Namespace: redis.Namespace, HighAvailable: false, Organization: redis.Organization, - ServiceLevel: "bad one", + ServiceLevel: redis.ServiceLevel, } } @@ -47,7 +47,7 @@ func (redis VSHNRedis) Probe(ctx context.Context) error { return nil } -func NewRedis(service, name, namespace, organization string, ha bool, opts redis.Options) (*VSHNRedis, error) { +func NewRedis(service, name, namespace, organization, sla string, ha bool, opts redis.Options) (*VSHNRedis, error) { client := redis.NewClient(&opts) @@ -58,6 +58,6 @@ func NewRedis(service, name, namespace, organization string, ha bool, opts redis Namespace: namespace, HighAvailable: ha, Organization: organization, - ServiceLevel: "bad one", + ServiceLevel: sla, }, nil } diff --git a/pkg/sliexporter/vshnredis_controller/vshnredis_controller.go b/pkg/sliexporter/vshnredis_controller/vshnredis_controller.go index 170a538ba0..0bf43d0758 100644 --- a/pkg/sliexporter/vshnredis_controller/vshnredis_controller.go +++ b/pkg/sliexporter/vshnredis_controller/vshnredis_controller.go @@ -35,7 +35,7 @@ type VSHNRedisReconciler struct { ProbeManager probeManager StartupGracePeriod time.Duration - RedisDialer func(service, name, namespace, organization string, ha bool, opts redis.Options) (*probes.VSHNRedis, error) + RedisDialer func(service, name, namespace, organization, sla string, ha bool, opts redis.Options) (*probes.VSHNRedis, error) } type probeManager interface { @@ -135,6 +135,11 @@ func (r VSHNRedisReconciler) getRedisProber(ctx context.Context, inst *vshnv1.XV org := ns.GetLabels()[utils.OrgLabelName] + sla := inst.Spec.Parameters.Service.ServiceLevel + if sla == "" { + sla = vshnv1.BestEffort + } + certPair, err := tls.X509KeyPair(credentials.Data["tls.crt"], credentials.Data["tls.key"]) if err != nil { return nil, err @@ -146,7 +151,7 @@ func (r VSHNRedisReconciler) getRedisProber(ctx context.Context, inst *vshnv1.XV tlsConfig.RootCAs.AppendCertsFromPEM(credentials.Data["ca.crt"]) - prober, err = r.RedisDialer(vshnRedisServiceKey, inst.Name, inst.ObjectMeta.Labels[claimNamespaceLabel], org, false, redis.Options{ + prober, err = r.RedisDialer(vshnRedisServiceKey, inst.Name, inst.ObjectMeta.Labels[claimNamespaceLabel], org, string(sla), false, redis.Options{ Addr: string(credentials.Data["REDIS_HOST"]) + ":" + string(credentials.Data["REDIS_PORT"]), Username: string(credentials.Data["REDIS_USERNAME"]), Password: string(credentials.Data["REDIS_PASSWORD"]), diff --git a/pkg/sliexporter/vshnredis_controller/vshnredis_controller_test.go b/pkg/sliexporter/vshnredis_controller/vshnredis_controller_test.go index 97d4cafe6f..b66556824b 100644 --- a/pkg/sliexporter/vshnredis_controller/vshnredis_controller_test.go +++ b/pkg/sliexporter/vshnredis_controller/vshnredis_controller_test.go @@ -341,7 +341,7 @@ func TestVSHNRedis_PassCerdentials(t *testing.T) { }, }, ) - r.RedisDialer = func(service, name, namespace, organization string, ha bool, opts redis.Options) (*probes.VSHNRedis, error) { + r.RedisDialer = func(service, name, namespace, organization, sla string, ha bool, opts redis.Options) (*probes.VSHNRedis, error) { assert.Equal(t, "VSHNRedis", service) assert.Equal(t, "foo", name) @@ -360,7 +360,7 @@ func TestVSHNRedis_PassCerdentials(t *testing.T) { InsecureSkipVerify: true, } - return fakeRedisDialer(service, name, namespace, organization, false, redis.Options{ + return fakeRedisDialer(service, name, namespace, organization, "besteffort", false, redis.Options{ Addr: string(cred.Data["REDIS_HOST"]) + ":" + string(cred.Data["REDIS_PORT"]), Username: string(cred.Data["REDIS_USERNAME"]), Password: string(cred.Data["REDIS_PASSWORD"]), @@ -389,7 +389,7 @@ func TestVSHNRedis_PassCerdentials(t *testing.T) { assert.False(t, manager.probers[getFakeKey(pi)]) } -func fakeRedisDialer(service, name, namespace, organization string, ha bool, opts redis.Options) (*probes.VSHNRedis, error) { +func fakeRedisDialer(service, name, namespace, organization, sla string, ha bool, opts redis.Options) (*probes.VSHNRedis, error) { p := &probes.VSHNRedis{ Service: service, Name: name,