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

THREESCALE-7961: Use sum_irate instead of sum_rate #740

Merged
merged 4 commits into from
May 4, 2022

Conversation

sergioifg94
Copy link
Contributor

Description

Link to JIRA: https://issues.redhat.com/browse/THREESCALE-7961

Add logic to use sum_irate in monitoring queries when the Openshift version is greater or equal than 4.9. Keep using sum_rate when the Openshift version is less than 4.9.

Verification steps

  1. On an Openshift 4.9 (or above) cluster
  2. Install 3scale operator from this PR and the monitoring stack
  3. Create an APIManager with monitoring enabled
  4. Verify that the Grafana dashboards that use sum_rate use now sum_irate and show data
  5. On an Openshift 4.8 (or below) cluster
  6. Repeat steps 2 and 3
  7. Verify that the Grafana dashboards continue using sum_rate and show data

Add logic to use `sum_irate` in monitoring queries when the Openshift
version is greater or equal than 4.9. Keep using `sum_rate` when the
Openshift version is less than 4.9.
// AddSumRateField creates a templateDataMutation that constructs a struct
// identical to the original with the added `SumRate` field, containing the
// value of sumRate
func AddSumRateField(sumRate string) TemplateDataMutation {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the motivation of this implementation based on the reflect package.

I am ok with it, but I would like to share that IMHO the complexity added to solve a relatively simple use case does not pay off.

Some (if not all) the dashboard templates have a new parameter called SumRate. I would add them to the data struct and the value passed to the SumRate will be computed based on the logic you implemented.

For example, in pkg/3scale/amp/component/generic_monitoring.go

func KubernetesResourcesByNamespaceGrafanaDashboard(sumRate string, ns string, appLabel string) *grafanav1alpha1.GrafanaDashboard {
	data := &struct {
		Namespace string
                SumRate string
	}{
		ns, sumRate,
	}
	return &grafanav1alpha1.GrafanaDashboard{
		ObjectMeta: metav1.ObjectMeta{
			Name: "kubernetes-resources-by-namespace",
			Labels: map[string]string{
				"monitoring-key": common.MonitoringKey,
				"app":            appLabel,
			},
		},
		Spec: grafanav1alpha1.GrafanaDashboardSpec{
			Json: assets.TemplateAsset("monitoring/kubernetes-resources-by-namespace-grafana-dashboard-1.json.tpl", data),
			Name: fmt.Sprintf("%s/kubernetes-resources-by-namespace-grafana-dashboard-1.json", ns),
		},
	}
}

The caller would be:

sumRate, err := helper.SumRateForOpenshiftVersion(r.Context(), r.Client())  
if err != nil {                                                             
    return reconcile.Result{}, err                                          
}                  

grafanaDashboard := component.KubernetesResourcesByNamespaceGrafanaDashboard(sumRate, r.apiManager.Namespace, *r.apiManager.Spec.AppLabel)
err = r.ReconcileGrafanaDashboard(grafanaDashboard, reconcilers.GenericGrafanaDashboardsMutator)   
if err != nil {                                                                                                  
    return reconcile.Result{}, err                                                                               
}                                                                                                                
                                                

Copy link
Contributor Author

@sergioifg94 sergioifg94 Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @eguzki I followed your suggestion and simplified the inclusion of the SumRate parameter into the templates

@sergioifg94 sergioifg94 force-pushed the THREESCALE-7961 branch 2 times, most recently from 9e3e092 to 595a0df Compare April 28, 2022 15:07
@sergioifg94 sergioifg94 changed the title [WIP] THREESCALE-7961: Use sum_irate instead of sum_rate THREESCALE-7961: Use sum_irate instead of sum_rate Apr 29, 2022
@sergioifg94 sergioifg94 requested a review from eguzki May 4, 2022 08:04
return sumRate, nil
}

type TemplateDataMutation func(interface{}) interface{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I missed it when removing the stuff from the initial implementation. Fixed it now

@codeclimate
Copy link

codeclimate bot commented May 4, 2022

Code Climate has analyzed commit a626076 and detected 31 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 2
Duplication 10
Style 19

View more on Code Climate.

@eguzki eguzki merged commit 3ae6e94 into 3scale:master May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants