redhat-cop / openshift-toolkit

A collection of code samples to help you get started with OpenShift
Apache License 2.0
232 stars 150 forks source link

Add dashboard capacity-by-nodetype #112

Open bszeti opened 4 years ago

bszeti commented 4 years ago

Custom dashboards about resource utilization and node capacity (grouped by node role).

etsauer commented 4 years ago

hey @bszeti it looks like there is likely some overlap between these dashboards, and the one that we have in https://github.com/redhat-cop/openshift-toolkit/tree/master/capacity-dashboard. Could you take a look at this, and maybe suggest some enhancements so that we don't end up with competing solutions in the same repo?

cc: @raffaelespazzoli @shah-zobair

bszeti commented 4 years ago

Yes, and I've talked to Raffaele about this. The "capacity" dashboards requires a special "nodegroup" label on nodes and shows the resource utilization when we have different group of compute nodes in the claster. The "capacity-by-nodetype" dashboards don't need special labels, they work with the default "role.kubernetes.io/..." label, so they can be deployed on any OpenShift v3.11 clusters. So the two dashboards show similar metrics, but were built to solve a different problem.

etsauer commented 4 years ago

@bszeti ok, I would say that these dashboards should probably live in the /capacity-dashboard/ space, rather than the custom-dashboards space, which is really about deploying a customizable grafana, not about the dashboards.

bszeti commented 4 years ago

@etsauer ok, at the moment the "capacity dashboards" are duplicated in the repo. They are under "capacity-dashboard" directory and also in the yaml files under "custom-dasboards/.openshift/dashboards/capacity". The purpose of "custom-dashboards" is to be able to run openshift-applier and bring up a custom Grafana with all our custom dashboards, so it's easy to try. This is what I tried to follow in the first round. Do you want me to completely remove the "capacity-by-nodetype" dashboards from there and not make them part of the openshift-applier deployment? If yes, then I would add a new directory "capacity-by-nodetype-dashboard" (next to "capacity-dashboard") with the Grafana json files and README. Is that ok?

etsauer commented 4 years ago

@bszeti rather than have the dashboards in two places, I would just point applier to the dashboard in "{{ inventory_dir }}/../../../capacity-dashboard/grafana-dashboard-capacity-by-nodetype.yml"

bszeti commented 4 years ago

@etsauer I'm taking a look at this now. I see two use cases:

Ideally the ConfigMap yaml file should somehow refer to the json files, but I don't know if it's possible. Is there a way to do something like this with the applier:

apiVersion: v1
kind: ConfigMap
data:
  namespaces-in-cluster.json: **import** {{ inventory_dir }}/../../../capacity-dashboard/namespaces-in-cluster.json
  pods-in-namespace.json: **import** {{ inventory_dir }}/../../../capacity-dashboard/pods-in-namespace.json
  summary-by-node.json: **import** {{ inventory_dir }}/../../../capacity-dashboard/summary-by-node.json
  summary-by-nodetype.json: **import** {{ inventory_dir }}/../../../capacity-dashboard/summary-by-nodetype.json

If this is not possible, then I don't know how to support both scenarios (manual import and applier) without duplicating the json definitions.

etsauer commented 4 years ago

@bszeti So, I haven't tried this, but Applier supports Jinja2 templates, which has an include function. See if you can make that work. If you can it would be really nice to somehow document that approach, as this is a common sticking point with managing configmaps.

https://jinja.palletsprojects.com/en/2.10.x/templates/#include

bszeti commented 4 years ago

I'm trying to use jinja like this: {% include "namespaces-in-cluster.json" %} or _{% include inventorydir + '/../.openshift/dashboards/capacity-by-nodetype/namespaces-in-cluster.json' %} or even with absolute path {% include "/Users/bszeti/git/openshift-toolkit/custom-dashboards/.openshift/dashboards/capacity-by-nodetype/namespaces-in-cluster.json" %}

but I'm keep getting an error with applier:

TASK [openshift-applier : Process Jinja template] **** fatal: [localhost -> localhost]: FAILED! => {"changed": false, "msg": "TemplateNotFound: /Users/bszeti/git/openshift-toolkit/custom-dashboards/.applier/../.openshift/dashboards/capacity-by-nodetype/namespaces-in-cluster.json"}

Any ideas? How is the template lookup done in this task?

bszeti commented 4 years ago

It seems that the {% include [file] %} only works if the file is under the role. In this case "galaxy/openshift-applier/roles/openshift-applier", which is obviously not god for us. (Also "../../../../namespaces-in-cluster.json" didn't work"). Because of this I don't know how to arrange the files better than in the original commit.

Another related problem is that the included file is processed as a template so any "{{" causes issues. This later problem may be handled by adding {% raw %}...{% endraw %} in the included file...

For the record we tried:

{% macro include_namespaces_in_cluster() %}{% include 'namespaces-in-cluster.json' %}{% endmacro %}
data:
  namespaces-in-cluster.json: |
    {{ include_namespaces_in_cluster() | indent(4) }}
bszeti commented 4 years ago

@etsauer Any suggestions?