Skip to content

Commit

Permalink
MGDAPI-5808 : Removing OO
Browse files Browse the repository at this point in the history
  • Loading branch information
Boomatang authored and carlkyrillos committed Jul 21, 2023
1 parent 3903b6e commit 01bafe3
Show file tree
Hide file tree
Showing 37 changed files with 65 additions and 19,752 deletions.
3 changes: 1 addition & 2 deletions apis/v1alpha1/rhmi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@ var (
ProductsStage StageName = "products"
CompleteStage StageName = "complete"
UninstallProductsStage StageName = "uninstall - products"
UninstallObservabilityStage StageName = "uninstall - observability"
UninstallCloudResourcesStage StageName = "uninstall - cloud-resources"
UninstallBootstrap StageName = "uninstall - bootstrap"

ProductRHSSO ProductName = "rhsso"
ProductRHSSOUser ProductName = "rhssouser"
Product3Scale ProductName = "3scale"
ProductMonitoring ProductName = "middleware-monitoring"
ProductObservability ProductName = "observability"
ProductObservability ProductName = "observability" // TODO MGDAPI-5833
ProductCloudResources ProductName = "cloud-resources"
ProductMonitoringSpec ProductName = "monitoring-spec"
ProductMarin3r ProductName = "marin3r"
Expand Down
33 changes: 4 additions & 29 deletions controllers/rhmi/bootstrapReconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,7 @@ func (r *Reconciler) GetPreflightObject(_ string) k8sclient.Object {
func (r *Reconciler) Reconcile(ctx context.Context, installation *integreatlyv1alpha1.RHMI, serverClient k8sclient.Client, installationQuota *quota.Quota, request ctrl.Request) (integreatlyv1alpha1.StatusPhase, error) {
r.log.Info("Reconciling bootstrap stage")

observabilityConfig, err := r.ConfigManager.ReadObservability()
if err != nil {
return integreatlyv1alpha1.PhaseFailed, err
}

uninstall := false
if installation.DeletionTimestamp != nil {
uninstall = true
}

phase, err := r.ReconcileFinalizer(ctx, serverClient, installation, string(observabilityConfig.GetProductName()), uninstall, func() (integreatlyv1alpha1.StatusPhase, error) {
phase, err := resources.RemoveNamespace(ctx, installation, serverClient, observabilityConfig.GetNamespace(), r.log)
if err != nil || phase != integreatlyv1alpha1.PhaseCompleted {
return phase, err
}
return integreatlyv1alpha1.PhaseCompleted, nil
}, r.log)
if err != nil || phase != integreatlyv1alpha1.PhaseCompleted {
events.HandleError(r.recorder, installation, phase, "Failed to reconcile finalizer", err)
return phase, err
}

phase, err = resources.ReconcileLimitRange(ctx, serverClient, r.installation.Namespace, resources.DefaultLimitRangeParams)
phase, err := resources.ReconcileLimitRange(ctx, serverClient, r.installation.Namespace, resources.DefaultLimitRangeParams)
if err != nil || phase != integreatlyv1alpha1.PhaseCompleted {
events.HandleError(r.recorder, installation, phase, fmt.Sprintf("Failed to reconcile LimitRange for Namespace %s", r.installation.Namespace), err)
return phase, err
Expand Down Expand Up @@ -169,7 +147,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, installation *integreatlyv1a
return phase, errors.Wrap(err, "failed to check rate limit alert config settings")
}

observabilityConfig, err = r.ConfigManager.ReadObservability()
// TODO MGDAPI-5833 : Remove block
observabilityConfig, err := r.ConfigManager.ReadObservability()
if err != nil {
return integreatlyv1alpha1.PhaseFailed, err
}
Expand All @@ -181,11 +160,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, installation *integreatlyv1a
return integreatlyv1alpha1.PhaseFailed, err
}
}
phase, err = r.ReconcileNamespace(ctx, observabilityConfig.GetNamespace(), installation, serverClient, log)
if err != nil || phase != integreatlyv1alpha1.PhaseCompleted {
events.HandleError(r.recorder, installation, phase, "Failed to create observability operand namespace", err)
return phase, errors.Wrap(err, "failed to create observability operand namespace")
}
// MGDAPI-5833 : Remove block end

if err = r.processQuota(installation, request.Namespace, installationQuota, serverClient); err != nil {
events.HandleError(r.recorder, installation, integreatlyv1alpha1.PhaseFailed, "Error while processing the Quota", err)
Expand Down
16 changes: 0 additions & 16 deletions controllers/rhmi/prometheusRules.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,6 @@ func (r *RHMIReconciler) newAlertsReconciler(installation *integreatlyv1alpha1.R
Expr: intstr.FromString(fmt.Sprintf("max by(status, upgrading, version) (%s_state)", installationName)),
Record: fmt.Sprintf("status:upgrading:version:%s_state:max", installationName),
},
{
Expr: intstr.FromString(fmt.Sprintf("max by(state) (%s_critical_alerts)", installationName)),
Record: fmt.Sprintf("state:%ss_critical_alerts:max", installationName),
},
{
Expr: intstr.FromString(fmt.Sprintf("max by(state) (%s_warning_alerts)", installationName)),
Record: fmt.Sprintf("state:%ss_warning_alerts:max", installationName),
},
{
Expr: intstr.FromString("max by () (rhoam_7d_slo_percentile)"),
Record: fmt.Sprintf("%s_7d_slo_percentile:max", installationName),
},
{
Expr: intstr.FromString("max by () (rhoam_7d_slo_remaining_error_budget)"),
Record: fmt.Sprintf("%s_7d_slo_remaining_error_budget:max", installationName),
},
},
},
}
Expand Down
108 changes: 3 additions & 105 deletions controllers/rhmi/rhmi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ import (
"strings"
"time"

"github.com/go-openapi/strfmt"
"github.com/integr8ly/integreatly-operator/pkg/resources/cluster"
"github.com/integr8ly/integreatly-operator/pkg/resources/k8s"
"github.com/integr8ly/integreatly-operator/pkg/resources/quota"
"github.com/integr8ly/integreatly-operator/pkg/resources/sts"
prometheusv1 "github.com/prometheus/client_golang/api/prometheus/v1"
prometheusConfig "github.com/prometheus/common/config"

routev1 "github.com/openshift/api/route/v1"
appsv1Client "github.com/openshift/client-go/apps/clientset/versioned/typed/apps/v1"

"github.com/integr8ly/integreatly-operator/pkg/resources/cluster"
"github.com/integr8ly/integreatly-operator/pkg/resources/quota"

"github.com/integr8ly/integreatly-operator/pkg/resources/poddistribution"
"github.com/integr8ly/integreatly-operator/pkg/webhooks"

Expand Down Expand Up @@ -403,16 +403,6 @@ func (r *RHMIReconciler) Reconcile(ctx context.Context, request ctrl.Request) (c
metrics.SetQuota(installation.Status.Quota, installation.Status.ToQuota)
}

log.Info("set alerts summary metric")
err = r.composeAndSetSummaryMetrics(installation, configManager)
if err != nil {
if installation.Status.Version == "" && installation.Status.ToVersion != "" {
log.Warning(fmt.Sprintf("Initial installation, possible monitoring not available: %s", err))
} else {
log.Error("error setting alerts metric:", err)
}
}

log.Info("set cluster metric")
err = r.setRHOAMClusterMetric()
if err != nil {
Expand Down Expand Up @@ -1308,65 +1298,6 @@ func (r *RHMIReconciler) createInstallationCR(ctx context.Context, serverClient

}

func (r *RHMIReconciler) composeAndSetSummaryMetrics(installation *rhmiv1alpha1.RHMI, configManager *config.Manager) error {
var alerts []prometheusv1.Alert

alertingNamespaces, err := r.getAlertingNamespace(installation, configManager)
if err != nil {
return fmt.Errorf("getting alerting namespace failed: %w", err)
}

observability, err := configManager.ReadObservability()
if err != nil {
return fmt.Errorf("getting observability configuration failed: %w", err)
}

for namespace := range alertingNamespaces {
if namespace == observability.GetNamespace() {

url, err := r.getURLFromRoute("prometheus", namespace, r.restConfig)
if err != nil {
return fmt.Errorf("error getting route : %w", err)
}

token := prometheusConfig.Secret(r.restConfig.BearerToken)

alerts, err = metrics.GetCurrentAlerts(url, token)
if err != nil {
return err
}

critical, warning := formatAlerts(alerts)
metrics.SetRhoamCriticalAlerts(critical)
metrics.SetRhoamWarningAlerts(warning)

value, warnings, err := metrics.SloPercentile(url, token)
if err != nil {
return err
}

for _, warning := range warnings {
log.Warning(warning)
}
metrics.SetRhoam7DPercentile(value)

value, warnings, err = metrics.SloRemainingErrorBudget(url, token)
if err != nil {
return err
}

for _, warning := range warnings {
log.Warning(warning)
}
metrics.SetRhoam7DSloRemainingErrorBudget(value)

return nil
}
}

return nil
}

func (r *RHMIReconciler) setRHOAMClusterMetric() error {

clusterVersionCR, err := cluster.GetClusterVersionCR(context.TODO(), r.Client)
Expand Down Expand Up @@ -1526,36 +1457,3 @@ func getInstallation() (*rhmiv1alpha1.RHMI, error) {
},
}, nil
}

func formatAlerts(alerts []prometheusv1.Alert) (critical resources.AlertMetrics, warning resources.AlertMetrics) {
critical = resources.AlertMetrics{
Firing: 0,
Pending: 0,
}

warning = resources.AlertMetrics{
Firing: 0,
Pending: 0,
}

for _, alert := range alerts {
if alert.Labels["alertname"] == "DeadMansSwitch" {
// DeadManSwitch alert is always firing.
// Skipping its inclusion for a more accurate metric.
continue
}

switch {
case alert.State == prometheusv1.AlertStateFiring && alert.Labels["severity"] == "critical":
critical.Firing++
case alert.State == prometheusv1.AlertStatePending && alert.Labels["severity"] == "critical":
critical.Pending++
case alert.State == prometheusv1.AlertStateFiring && alert.Labels["severity"] == "warning":
warning.Firing++
case alert.State == prometheusv1.AlertStatePending && alert.Labels["severity"] == "warning":
warning.Pending++
}
}

return critical, warning
}
68 changes: 0 additions & 68 deletions controllers/rhmi/rhmi_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import (

rhmiv1alpha1 "github.com/integr8ly/integreatly-operator/apis/v1alpha1"
"github.com/integr8ly/integreatly-operator/pkg/config"
"github.com/integr8ly/integreatly-operator/pkg/resources"
"github.com/integr8ly/integreatly-operator/pkg/resources/marketplace"
"github.com/integr8ly/integreatly-operator/utils"
prometheusv1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/prometheus/common/model"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -106,71 +103,6 @@ func TestRHMIReconciler_getAlertingNamespace(t *testing.T) {
}
}

func TestFormatAlerts(t *testing.T) {
input := []prometheusv1.Alert{
{
Labels: model.LabelSet{"alertname": "dummy", "severity": "critical"},
State: prometheusv1.AlertStateFiring,
},
{
Labels: model.LabelSet{"alertname": "dummy", "severity": "critical"},
State: prometheusv1.AlertStateFiring,
},
{
Labels: model.LabelSet{"alertname": "dummy", "severity": "Low"},
State: prometheusv1.AlertStateFiring,
},
{
Labels: model.LabelSet{"alertname": "dummy", "severity": "critical"},
State: prometheusv1.AlertStatePending,
},
{
Labels: model.LabelSet{"alertname": "dummy", "severity": "critical"},
State: prometheusv1.AlertStatePending,
},

{
Labels: model.LabelSet{"alertname": "dummy two", "severity": "critical"},
State: prometheusv1.AlertStateFiring,
},
{
Labels: model.LabelSet{"alertname": "dummy two", "severity": "warning"},
State: prometheusv1.AlertStateFiring,
},
{
Labels: model.LabelSet{"alertname": "dummy two", "severity": "warning"},
State: prometheusv1.AlertStatePending,
},
{
Labels: model.LabelSet{"alertname": "DeadMansSwitch", "severity": "critical"},
State: prometheusv1.AlertStateFiring,
},
{
Labels: model.LabelSet{"alertname": "info alert", "severity": "info"},
State: prometheusv1.AlertStateFiring,
},
}
expectedCritical := resources.AlertMetrics{
Firing: 3,
Pending: 2,
}
expectedWarning := resources.AlertMetrics{
Firing: 1,
Pending: 1,
}

critical, warning := formatAlerts(input)

if !reflect.DeepEqual(critical, expectedCritical) {
t.Fatalf("critical alert metrics not equal; Actual: %v, Expected: %v", critical, expectedCritical)
}

if !reflect.DeepEqual(warning, expectedWarning) {
t.Fatalf("warning alert metrics not equal; Actual: %v, Expected: %v", warning, expectedWarning)
}

}

func TestHandleCROConfigDeletion(t *testing.T) {
scheme, err := utils.NewTestScheme()
if err != nil {
Expand Down
16 changes: 2 additions & 14 deletions controllers/rhmi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
Name: integreatlyv1alpha1.InstallStage,
Products: map[integreatlyv1alpha1.ProductName]integreatlyv1alpha1.RHMIProductStatus{
integreatlyv1alpha1.ProductCloudResources: {Name: integreatlyv1alpha1.ProductCloudResources},
integreatlyv1alpha1.ProductObservability: {Name: integreatlyv1alpha1.ProductObservability},
integreatlyv1alpha1.ProductObservability: {Name: integreatlyv1alpha1.ProductObservability}, // TODO MGDAPI-5833
integreatlyv1alpha1.ProductRHSSO: {Name: integreatlyv1alpha1.ProductRHSSO},
integreatlyv1alpha1.Product3Scale: {Name: integreatlyv1alpha1.Product3Scale},
integreatlyv1alpha1.ProductMarin3r: {Name: integreatlyv1alpha1.ProductMarin3r},
Expand All @@ -50,12 +50,6 @@ var (
integreatlyv1alpha1.ProductCloudResources: {Name: integreatlyv1alpha1.ProductCloudResources},
},
},
{
Name: integreatlyv1alpha1.UninstallObservabilityStage,
Products: map[integreatlyv1alpha1.ProductName]integreatlyv1alpha1.RHMIProductStatus{
integreatlyv1alpha1.ProductObservability: {Name: integreatlyv1alpha1.ProductObservability},
},
},
{
Name: integreatlyv1alpha1.UninstallBootstrap,
},
Expand All @@ -70,7 +64,7 @@ var (
Name: integreatlyv1alpha1.InstallStage,
Products: map[integreatlyv1alpha1.ProductName]integreatlyv1alpha1.RHMIProductStatus{
integreatlyv1alpha1.ProductCloudResources: {Name: integreatlyv1alpha1.ProductCloudResources},
integreatlyv1alpha1.ProductObservability: {Name: integreatlyv1alpha1.ProductObservability},
integreatlyv1alpha1.ProductObservability: {Name: integreatlyv1alpha1.ProductObservability}, // TODO MGDAPI-5833
integreatlyv1alpha1.ProductRHSSO: {Name: integreatlyv1alpha1.ProductRHSSO},
integreatlyv1alpha1.Product3Scale: {Name: integreatlyv1alpha1.Product3Scale},
integreatlyv1alpha1.ProductRHSSOUser: {Name: integreatlyv1alpha1.ProductRHSSOUser},
Expand All @@ -96,12 +90,6 @@ var (
integreatlyv1alpha1.ProductCloudResources: {Name: integreatlyv1alpha1.ProductCloudResources},
},
},
{
Name: integreatlyv1alpha1.UninstallObservabilityStage,
Products: map[integreatlyv1alpha1.ProductName]integreatlyv1alpha1.RHMIProductStatus{
integreatlyv1alpha1.ProductObservability: {Name: integreatlyv1alpha1.ProductObservability},
},
},
{
Name: integreatlyv1alpha1.UninstallBootstrap,
},
Expand Down
6 changes: 0 additions & 6 deletions controllers/rhmi/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ func TestReconciler_TypeFactory(t *testing.T) {
integreatlyv1alpha1.ProductCloudResources: {Name: integreatlyv1alpha1.ProductCloudResources},
},
},
{
Name: integreatlyv1alpha1.UninstallObservabilityStage,
Products: map[integreatlyv1alpha1.ProductName]integreatlyv1alpha1.RHMIProductStatus{
integreatlyv1alpha1.ProductObservability: {Name: integreatlyv1alpha1.ProductObservability},
},
},
{
Name: integreatlyv1alpha1.UninstallBootstrap,
},
Expand Down
4 changes: 0 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ func init() {
customMetrics.Registry.MustRegister(integreatlymetrics.CustomDomain)
customMetrics.Registry.MustRegister(integreatlymetrics.ThreeScalePortals)
customMetrics.Registry.MustRegister(integreatlymetrics.RhoamStateMetric)
customMetrics.Registry.MustRegister(integreatlymetrics.RhoamCriticalAlerts)
customMetrics.Registry.MustRegister(integreatlymetrics.RhoamWarningAlerts)
customMetrics.Registry.MustRegister(integreatlymetrics.Rhoam7DPercentile)
customMetrics.Registry.MustRegister(integreatlymetrics.Rhoam7DSloRemainingErrorBudget)

integreatlymetrics.OperatorVersion.Add(1)
utilruntime.Must(v1.Install(clientgoscheme.Scheme))
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type ConfigReadWriter interface {
ReadCloudResources() (*CloudResources, error)
ReadMonitoringSpec() (*MonitoringSpec, error)
ReadGrafana() (*Grafana, error)
ReadObservability() (*Observability, error)
ReadObservability() (*Observability, error) // TODO MGDAPI-5833 this needs to be removed
ReadMCG() (*MCG, error)
}

Expand Down
Loading

0 comments on commit 01bafe3

Please sign in to comment.