Skip to content

Commit

Permalink
Add config option for disabling reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
sed-i committed Nov 2, 2024
1 parent 07a52a6 commit 1f8a0a2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
11 changes: 11 additions & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,14 @@ config:
automatically deduced from it).
See https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: string
phone_home:
description: |
When disabled, Grafana will be configured to not send anonymous usage statistics to stats.grafana.org, nor
periodically check for updates.
It is very helpful to the Grafana project, so please leave this enabled.
When enabled, Grafana will use its default values for analytics.
Ref: https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/#analytics
type: boolean
default: true
23 changes: 22 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ def _generate_grafana_config(self) -> str:
can be set in ENV variables, but leave for expansion later so we can
hide auth secrets
"""
configs = [self._generate_tracing_config()]
configs = [self._generate_tracing_config(), self._generate_analytics_config()]
if self.has_db:
configs.append(self._generate_database_config())
else:
Expand Down Expand Up @@ -799,6 +799,27 @@ def _generate_tracing_config(self) -> str:
ret = data.getvalue()
return ret

def _generate_analytics_config(self) -> str:
"""Generate analytics configuration.
Returns:
A string containing the analytics config to be stubbed into the config file.
"""
if self.config["phone_home"]:
return ""
config_ini = configparser.ConfigParser()
# Ref: https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/#analytics
config_ini["analytics"] = {
"reporting_enabled": "false",
"check_for_updates": "false",
"check_for_plugin_updates": "false",
}

data = StringIO()
config_ini.write(data)
ret = data.getvalue()
return ret

def _generate_database_config(self) -> str:
"""Generate a database configuration.
Expand Down

0 comments on commit 1f8a0a2

Please sign in to comment.