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] Improve dashboards download script #3350

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

Conversation

xinity
Copy link

@xinity xinity commented Oct 10, 2024

This PR aims at improving the logging experience of the dowload dashboards script to :

  • avoid leaking git token in the execution logs
  • add more information about which download is downloaded from wich source
  • output the curl error message if any

@jkroepke
Copy link
Collaborator

Please bump the chart version, thanks!

@xinity xinity changed the title Improve dashboards download script [grafana] Improve dashboards download script Oct 10, 2024
Signed-off-by: Rachid Zarouali <[email protected]>
@xinity
Copy link
Author

xinity commented Oct 10, 2024

@jkroepke oups, missed this, done :)

@@ -81,7 +81,14 @@ download_dashboards.sh: |
{{- range $provider, $dashboards := .Values.dashboards }}
{{- range $key, $value := $dashboards }}
{{- if (or (hasKey $value "gnetId") (hasKey $value "url")) }}
curl -skf \
{{- if $value.url }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess, if someone changes the URL logic below, this may get forgotten. Not sure, if it make sense to move the Source URL logic to a dedicated template helper.

WDYT?

Copy link
Author

Choose a reason for hiding this comment

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

@jkroepke i assume that if the logic is changed then lines 120 and below will also be changed right ? :

not sure for now it worth it to move it into a helper template even though it would better in the future :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe @zanhsieh has an opinion here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@xinity @jkroepke
I would prefer

  1. Move source url to the _helper.tpl
  2. Set default revision as 1 as well set default source url.
  3. Move echo "downloading: {{ $key }} dashboard" out of if since both conditions output that string.

Comment on lines 85 to 89
{{- if $value.url }}
echo "Source Url: {{ $value.url }}"
{{- else }}
echo "Source Url: https://grafana.com/api/dashboards/{{ $value.gnetId }}/revisions/{{- if $value.revision -}}{{ $value.revision }}{{- else -}}1{{- end -}}/download"
{{- end }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
{{- if $value.url }}
echo "Source Url: {{ $value.url }}"
{{- else }}
echo "Source Url: https://grafana.com/api/dashboards/{{ $value.gnetId }}/revisions/{{- if $value.revision -}}{{ $value.revision }}{{- else -}}1{{- end -}}/download"
{{- end }}
echo "Source Url: {{ include "grafana.url" . }}

charts/grafana/templates/_helpers.tpl Outdated Show resolved Hide resolved
@jkroepke
Copy link
Collaborator

please fix CI failures and MR conflicts

@xinity
Copy link
Author

xinity commented Oct 14, 2024

@jkroepke will squash to improve readability

@zanhsieh
Copy link
Collaborator

@xinity
Please bump the chart version and sign DCO. Thank you.

xinity and others added 12 commits October 15, 2024 07:57
move the download message out of the if loop

Signed-off-by: Rachid Zarouali <[email protected]>
improvment thanks to community feedback,
need some testing

Signed-off-by: Rachid Zarouali <[email protected]>
Signed-off-by: Rachid Zarouali <[email protected]>
Signed-off-by: Charles Korn <[email protected]>
Signed-off-by: Charles Korn <[email protected]>
Signed-off-by: Charles Korn <[email protected]>
Signed-off-by: Rachid Zarouali <[email protected]>
Signed-off-by: Rachid Zarouali <[email protected]>
@xinity xinity force-pushed the feature/improve-grafana-download-dashboards branch from 6c00445 to 850d017 Compare October 15, 2024 07:58
@xinity xinity requested a review from a team as a code owner October 15, 2024 07:58
@xinity
Copy link
Author

xinity commented Oct 15, 2024

@zanhsieh too many commits but signed and fix :)

{{/*
Define the source URL
*/}}
{{- define "grafana.url" -}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
{{- define "grafana.url" -}}
{{- define "grafana.dashboard-dowload-url" -}}

@@ -81,7 +81,9 @@ download_dashboards.sh: |
{{- range $provider, $dashboards := .Values.dashboards }}
{{- range $key, $value := $dashboards }}
{{- if (or (hasKey $value "gnetId") (hasKey $value "url")) }}
curl -skf \
echo "downloading: {{ $key }} dashboard"
echo "Source Url: {{ include "grafana.url" . }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
echo "Source Url: {{ include "grafana.url" . }}
echo "Source URL: {{ include "grafana.dashboard-dowload-url" . }}

@@ -224,6 +224,16 @@ Formats imagePullSecrets. Input is (dict "root" . "imagePullSecrets" .{specific
{{- $secretFound}}
{{- end -}}


{{/*
Define the source URL
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please also add the template to the curl command!

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.

6 participants