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

Grafana 11 #7

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Grafana 11 #7

wants to merge 4 commits into from

Conversation

davhdavh
Copy link

What does this PR change?

  • Support grafana 9+ when configured with static config

Why?

Grafana removed support for DS_PROMETHEUS_DATASOURCE. Normally the importer of the json will silently fix the json for you, but when provisioning directly via url that is not possible.

Does this PR relate to any other PRs or Issues?

  • No

How will this PR impact users?

  • No

How was this PR tested?

  dashboardProviders:
    dashboardproviders.yaml:
      apiVersion: 1
      providers:
      - name: 'opencost-grafana-dashboard'
        orgId: 1
        folder: 'Opencost'
        type: file
        disableDeletion: true
        editable: false
        options:
          path: /var/lib/grafana/dashboards/opencost-grafana-dashboard
  dashboards:
    opencost-grafana-dashboard:
       opencost-cost-reporter-basic-overview:
         url: https://raw.githubusercontent.com/davhdavh/opencost-grafana-dashboard/grafana-11/dashboards/cost-reporter/opencost-cost-reporter-basic-overview.json
         token: ''
       opencost-cost-reporter-detailed-overview:
         url: https://raw.githubusercontent.com/davhdavh/opencost-grafana-dashboard/grafana-11/dashboards/cost-reporter/opencost-cost-reporter-detailed-overview.json
         token: ''

Does this PR require changes to documentation?

  • No

@asdfgugus
Copy link
Contributor

Thanks for the PR. I will review it ASAP!

Copy link
Contributor

@asdfgugus asdfgugus left a comment

Choose a reason for hiding this comment

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

Finally, I was able to review the PR!

},
"editorMode": "code",
"exemplar": false,
"expr": "topk(20,\n sum(\n sum(container_memory_allocation_bytes) \n by (namespace,instance)\n * on(instance) group_left() (\n\t\t\tnode_ram_hourly_cost{} / 1024 / 1024 / 1024 * 720\n\t\t\t+ on(node,instance_type) group_left()\n\t\t\tlabel_replace\n\t\t\t(\n\t\t\t\tkube_node_labels{}, \"instance_type\", \"$1\", \"label_node_kubernetes_io_instance_type\", \"(.*)\"\n\t\t\t) * 0\n\t\t)\n\n +\n\n sum(container_cpu_allocation) \n by (namespace,instance)\n * on(instance) group_left() (\n\t\t\tnode_cpu_hourly_cost{} * 720\n\t\t\t+ on(node,instance_type) group_left()\n\t\t\tlabel_replace\n\t\t\t(\n\t\t\t\tkube_node_labels{}, \"instance_type\", \"$1\", \"label_node_kubernetes_io_instance_type\", \"(.*)\"\n\t\t\t) * 0\n\t\t)\n ) by (namespace)\n)",
"expr": "topk(20,\n sum(\n sum(container_memory_allocation_bytes) \n by (namespace,instance)\n * on(instance) group_left() (\n\t\t\tnode_ram_hourly_cost{} / 1024 / 1024 / 1024 * 720\n\t\t\t+ on(node,instance_type) group_left()\n\t\t\tkube_node_info{} * 0\n\t\t)\n\n +\n\n sum(container_cpu_allocation) \n by (namespace,instance)\n * on(instance) group_left() (\n\t\t\tnode_cpu_hourly_cost{} * 720\n\t\t\t+ on(node,instance_type) group_left()\n\t\t\tkube_node_info{} * 0\n\t\t)\n ) by (namespace)\n)",
Copy link
Contributor

Choose a reason for hiding this comment

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

In some cases, replacements are necessary. Have you had any problems with this?

},
"definition": "label_values(kube_namespace_labels,namespace)",
"definition": "label_values(kube_namespace_created,namespace)",
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain further, why this needs to be changed?

},
"editorMode": "code",
"expr": "1 - (\n\navg_over_time(\n\n sum(sum(container_memory_allocation_bytes{namespace=~\"$namespace\"}) by (namespace, container,instance) * on(instance) group_left() (\n\t\t\t\tnode_ram_hourly_cost{} / 1024 / 1024 / 1024\n\t\t\t\t+ on(node,instance_type) group_left()\n\t\t\t\t\tlabel_replace\n\t\t\t\t\t(\n\t\t\t\t\t\tkube_node_labels{}, \"instance_type\", \"$1\", \"label_node_kubernetes_io_instance_type\", \"(.*)\"\n\t\t\t\t\t) * 0\n\t\t\t)\n + \n sum(container_cpu_allocation{namespace=~\"$namespace\"}) by (namespace,container,instance) * on(instance) group_left() (\n\t \t\t\tnode_cpu_hourly_cost{} + on(node,instance_type) group_left()\n\t\t \t\t\tlabel_replace\n\t\t \t\t\t(\n\t\t \t\t\t\tkube_node_labels{}, \"instance_type\", \"$1\", \"label_node_kubernetes_io_instance_type\", \"(.*)\"\n\t\t \t\t\t) * 0\n\t\t \t)) by (namespace) [1d:1h]\n )\n \n /\n \navg_over_time(\n\n sum(sum(container_memory_allocation_bytes{namespace=~\"$namespace\"}) by (namespace,container,instance) * on(instance) group_left() (\n\t\t\t\tnode_ram_hourly_cost{} / 1024 / 1024 / 1024\n\t\t\t\t+ on(node,instance_type) group_left()\n\t\t\t\t\tlabel_replace\n\t\t\t\t\t(\n\t\t\t\t\t\tkube_node_labels{}, \"instance_type\", \"$1\", \"label_node_kubernetes_io_instance_type\", \"(.*)\"\n\t\t\t\t\t) * 0\n\t\t\t)\n + \n sum(container_cpu_allocation{namespace=~\"$namespace\"}) by (namespace,container,instance) * on(instance) group_left() (\n\t \t\t\tnode_cpu_hourly_cost{} + on(node,instance_type) group_left()\n\t\t \t\t\tlabel_replace\n\t\t \t\t\t(\n\t\t \t\t\t\tkube_node_labels{}, \"instance_type\", \"$1\", \"label_node_kubernetes_io_instance_type\", \"(.*)\"\n\t\t \t\t\t) * 0\n\t\t \t)) by (namespace) [7d:1h]\n )\n )",
"expr": "1 - (\n\navg_over_time(\n\n sum(sum(container_memory_allocation_bytes{namespace=~\"$namespace\"}) by (namespace, container,instance) * on(instance) group_left() (\n\t\t\t\tnode_ram_hourly_cost{} / 1024 / 1024 / 1024\n\t\t\t\t+ on(node,instance_type) group_left()\n\t\t\t\t\tkube_node_info{} * 0\n\t\t\t)\n + \n sum(container_cpu_allocation{namespace=~\"$namespace\"}) by (namespace,container,instance) * on(instance) group_left() (\n\t \t\t\tnode_cpu_hourly_cost{} + on(node,instance_type) group_left()\n\t\t \t\t\tkube_node_info{} * 0\n\t\t \t)) by (namespace) [1d:1h]\n )\n \n /\n \navg_over_time(\n\n sum(sum(container_memory_allocation_bytes{namespace=~\"$namespace\"}) by (namespace,container,instance) * on(instance) group_left() (\n\t\t\t\tnode_ram_hourly_cost{} / 1024 / 1024 / 1024\n\t\t\t\t+ on(node,instance_type) group_left()\n\t\t\t\t\tkube_node_info{} * 0\n\t\t\t)\n + \n sum(container_cpu_allocation{namespace=~\"$namespace\"}) by (namespace,container,instance) * on(instance) group_left() (\n\t \t\t\tnode_cpu_hourly_cost{} + on(node,instance_type) group_left()\n\t\t \t\t\tkube_node_info{} * 0\n\t\t \t)) by (namespace) [7d:1h]\n )\n )",
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, in some cases the label replacement is necessary.

@asdfgugus
Copy link
Contributor

ping @davhdavh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants