Skip to content

Commit

Permalink
Refactored threescale external resource metric creation
Browse files Browse the repository at this point in the history
  • Loading branch information
obrienrobert committed Mar 30, 2020
1 parent 7ccc31e commit 0179289
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
62 changes: 31 additions & 31 deletions pkg/products/threescale/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,15 +562,6 @@ func (r *Reconciler) reconcileExternalDatasources(ctx context.Context, serverCli
return integreatlyv1alpha1.PhaseFailed, fmt.Errorf("failed to reconcile backend redis request: %w", err)
}

// create the prometheus availability rule
if _, err = resources.CreateRedisAvailabilityAlert(ctx, serverClient, r.installation, backendRedis); err != nil {
return integreatlyv1alpha1.PhaseFailed, fmt.Errorf("failed to create backend redis prometheus alert for threescale: %w", err)
}
// create backend connectivity alert
if _, err = resources.CreateRedisConnectivityAlert(ctx, serverClient, r.installation, backendRedis); err != nil {
return integreatlyv1alpha1.PhaseFailed, fmt.Errorf("failed to create backend redis prometheus connectivity alert for threescale: %s", err)
}

// setup system redis custom resource
// this will be used by the cloud resources operator to provision a redis instance
logrus.Info("Creating system redis instance")
Expand All @@ -583,17 +574,6 @@ func (r *Reconciler) reconcileExternalDatasources(ctx context.Context, serverCli
return integreatlyv1alpha1.PhaseFailed, fmt.Errorf("failed to reconcile system redis request: %w", err)
}

// create the prometheus availability rule
_, err = resources.CreateRedisAvailabilityAlert(ctx, serverClient, r.installation, systemRedis)
if err != nil {
return integreatlyv1alpha1.PhaseFailed, fmt.Errorf("failed to create system redis prometheus alert for threescale: %w", err)
}
// create system redis connectivity alert
_, err = resources.CreateRedisConnectivityAlert(ctx, serverClient, r.installation, systemRedis)
if err != nil {
return integreatlyv1alpha1.PhaseFailed, fmt.Errorf("failed to create system redis prometheus connectivity alert for threescale: %s", err)
}

// setup postgres cr for the cloud resource operator
// this will be used by the cloud resources operator to provision a postgres instance
logrus.Info("Creating postgres instance")
Expand All @@ -606,22 +586,20 @@ func (r *Reconciler) reconcileExternalDatasources(ctx context.Context, serverCli
return integreatlyv1alpha1.PhaseFailed, fmt.Errorf("failed to reconcile postgres request: %w", err)
}

// create the prometheus availability rule
_, err = resources.CreatePostgresAvailabilityAlert(ctx, serverClient, r.installation, postgres)
if err != nil {
return integreatlyv1alpha1.PhaseFailed, fmt.Errorf("failed to create postgres prometheus alert for threescale: %w", err)
}
// create postgres connectivity alert
_, err = resources.CreatePostgresConnectivityAlert(ctx, serverClient, r.installation, postgres)
if err != nil {
return integreatlyv1alpha1.PhaseFailed, fmt.Errorf("failed to create postgres prometheus connectivity alert for threescale: %s", err)
}

// wait for the backend redis cr to reconcile
if backendRedis.Status.Phase != types.PhaseComplete {
return integreatlyv1alpha1.PhaseAwaitingComponents, nil
}

// create the prometheus availability rule
if _, err = resources.CreateRedisAvailabilityAlert(ctx, serverClient, r.installation, backendRedis); err != nil {
return integreatlyv1alpha1.PhaseFailed, fmt.Errorf("failed to create backend redis prometheus alert for threescale: %w", err)
}
// create backend connectivity alert
if _, err = resources.CreateRedisConnectivityAlert(ctx, serverClient, r.installation, backendRedis); err != nil {
return integreatlyv1alpha1.PhaseFailed, fmt.Errorf("failed to create backend redis prometheus connectivity alert for threescale: %s", err)
}

// get the secret created by the cloud resources operator
// containing backend redis connection details
credSec := &corev1.Secret{}
Expand Down Expand Up @@ -654,6 +632,17 @@ func (r *Reconciler) reconcileExternalDatasources(ctx context.Context, serverCli
return integreatlyv1alpha1.PhaseAwaitingComponents, nil
}

// create the prometheus availability rule
_, err = resources.CreateRedisAvailabilityAlert(ctx, serverClient, r.installation, systemRedis)
if err != nil {
return integreatlyv1alpha1.PhaseFailed, fmt.Errorf("failed to create system redis prometheus alert for threescale: %w", err)
}
// create system redis connectivity alert
_, err = resources.CreateRedisConnectivityAlert(ctx, serverClient, r.installation, systemRedis)
if err != nil {
return integreatlyv1alpha1.PhaseFailed, fmt.Errorf("failed to create system redis prometheus connectivity alert for threescale: %s", err)
}

// get the secret created by the cloud resources operator
// containing system redis connection details
systemCredSec := &corev1.Secret{}
Expand Down Expand Up @@ -687,6 +676,17 @@ func (r *Reconciler) reconcileExternalDatasources(ctx context.Context, serverCli
return integreatlyv1alpha1.PhaseAwaitingComponents, nil
}

// create the prometheus availability rule
_, err = resources.CreatePostgresAvailabilityAlert(ctx, serverClient, r.installation, postgres)
if err != nil {
return integreatlyv1alpha1.PhaseFailed, fmt.Errorf("failed to create postgres prometheus alert for threescale: %w", err)
}
// create postgres connectivity alert
_, err = resources.CreatePostgresConnectivityAlert(ctx, serverClient, r.installation, postgres)
if err != nil {
return integreatlyv1alpha1.PhaseFailed, fmt.Errorf("failed to create postgres prometheus connectivity alert for threescale: %s", err)
}

// get the secret containing redis credentials
postgresCredSec := &corev1.Secret{}
err = serverClient.Get(ctx, k8sclient.ObjectKey{Name: postgres.Status.SecretRef.Name, Namespace: postgres.Status.SecretRef.Namespace}, postgresCredSec)
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func CreatePostgresConnectivityAlert(ctx context.Context, client k8sclient.Clien
}

// CreateRedisAvailabilityAlert creates a PrometheusRule alert to watch for the availability
// of a Redis cacheu
// of a Redis cache
func CreateRedisAvailabilityAlert(ctx context.Context, client k8sclient.Client, inst *v1alpha1.RHMI, cr *crov1.Redis) (*prometheusv1.PrometheusRule, error) {
if strings.ToLower(inst.Spec.UseClusterStorage) == "true" {
logrus.Info("skipping redis alert creation, useClusterStorage is true")
Expand Down

0 comments on commit 0179289

Please sign in to comment.