Skip to content

Commit

Permalink
adding HA label to histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Oct 21, 2023
1 parent d391ba3 commit 985738f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
6 changes: 6 additions & 0 deletions apis/vshn/v1/dbaas_vshn_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions pkg/sliexporter/probes/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (redis VSHNRedis) GetInfo() ProbeInfo {
Namespace: redis.Namespace,
HighAvailable: false,
Organization: redis.Organization,
ServiceLevel: "bad one",
ServiceLevel: redis.ServiceLevel,
}
}

Expand All @@ -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)

Expand All @@ -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
}
9 changes: 7 additions & 2 deletions pkg/sliexporter/vshnredis_controller/vshnredis_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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"]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"]),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 985738f

Please sign in to comment.