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

Add config option to disable reporting #202

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion charmcraft-22.04.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,11 @@ config:
aren't sent to tracing backend at all. Anything outside of 0-100 range will be normalised
to this range by Grafana Agent.
type: float
default: 100.0
default: 100.0
reporting_enabled:
description: |
Toggle reporting of usage info to grafana, such as enabled feature flags.

Ref: https://grafana.com/docs/agent/latest/static/configuration/flags/#report-information-usage
type: boolean
default: true
28 changes: 22 additions & 6 deletions charmcraft-24.04.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ peers:

config:
options:
classic_snap:
description: |
Choose whether to use the classic snap over the strictly confined
one. Defaults to "true".
type: boolean
default: true
tls_insecure_skip_verify:
description: |
Flag to skip the verification for insecure TLS.
Expand Down Expand Up @@ -142,22 +148,32 @@ config:
default: false
tracing_sample_rate_charm:
description: >
This property defines the percentage of charm traces that are sent to the tracing backend.
This property defines the percentage of charm traces that are sent to tracing backend.
Setting it to 100 would mean all charm traces are kept, setting to 0 means charm traces
aren't sent to the tracing backend at all.
aren't sent to tracing backend at all. Anything outside of 0-100 range will be normalised
to this range by Grafana Agent.
type: float
default: 100.0
tracing_sample_rate_workload:
description: >
This property defines the percentage of workload traces that are sent to the tracing backend.
This property defines the percentage of workload traces that are sent to tracing backend.
Setting it to 100 would mean all workload traces are kept, setting to 0 means workload traces
aren't sent to the tracing backend at all.
aren't sent to tracing backend at all. Anything outside of 0-100 range will be normalised
to this range by Grafana Agent.
type: float
default: 1.0
tracing_sample_rate_error:
description: >
This property defines the percentage of error traces (from all sources) that are sent to the tracing backend.
This property defines the percentage of error traces (regardless of the type) that are sent to tracing backend.
Setting it to 100 would mean all error traces are kept, setting to 0 means error traces
aren't sent to the tracing backend at all.
aren't sent to tracing backend at all. Anything outside of 0-100 range will be normalised
to this range by Grafana Agent.
type: float
default: 100.0
reporting_enabled:
description: |
Toggle reporting of usage info to grafana, such as enabled feature flags.

Ref: https://grafana.com/docs/agent/latest/static/configuration/flags/#report-information-usage
type: boolean
default: true
16 changes: 4 additions & 12 deletions lib/charms/grafana_cloud_integrator/v0/cloud_config_requirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

LIBID = "e6f580481c1b4388aa4d2cdf412a47fa"
LIBAPI = 0
LIBPATCH = 6
LIBPATCH = 7

DEFAULT_RELATION_NAME = "grafana-cloud-config"

Expand Down Expand Up @@ -83,16 +83,8 @@ def _events(self):
@property
def credentials(self):
"""Return the credentials, if any; otherwise, return None."""
if not all(
self._is_not_empty(x)
for x in [
self._data.get("username", ""),
self._data.get("password", ""),
]):
return Credentials(
self._data.get("username", ""),
self._data.get("password", "")
)
if (username := self._data.get("username", "").strip()) and (password := self._data.get("password", "").strip()):
return Credentials(username, password)
return None

@property
Expand Down Expand Up @@ -148,4 +140,4 @@ def _data(self):
for relation in self._charm.model.relations[self._relation_name]:
logger.info("%s %s %s", relation, self._relation_name, relation.data[relation.app])
return relation.data[relation.app]
return {}
return {}
5 changes: 4 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ def _verify_snap_track(self) -> None:
try:
# install_ga_snap calls snap.ensure so it should do the right thing whether the track
# changes or not.
install_ga_snap(classic=bool(self.config["classic_snap"]))
install_ga_snap(
classic=bool(self.config["classic_snap"]),
config={"reporting-enabled": "1" if self.config["reporting_enabled"] else "0"},
)
except (snap.SnapError, SnapSpecError) as e:
raise GrafanaAgentInstallError("Failed to refresh grafana-agent.") from e

Expand Down
17 changes: 11 additions & 6 deletions src/snap_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import logging
import platform
import subprocess
from typing import Dict, Optional

import charms.operator_libs_linux.v2.snap as snap_lib

Expand All @@ -24,10 +25,10 @@
_grafana_agent_snap_name = "grafana-agent"
_grafana_agent_snaps = {
# (confinement, arch): revision
("strict", "amd64"): 51, # 0.40.4
("strict", "arm64"): 52, # 0.40.4
("classic", "amd64"): 82, # 0.40.4
("classic", "arm64"): 83, # 0.40.4
("strict", "amd64"): 84, # 0.40.4
("strict", "arm64"): 85, # 0.40.4
("classic", "amd64"): 86, # 0.40.4
("classic", "arm64"): 87, # 0.40.4
Copy link
Contributor Author

Choose a reason for hiding this comment

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

}


Expand All @@ -37,7 +38,7 @@ class SnapSpecError(Exception):
pass


def install_ga_snap(classic: bool):
def install_ga_snap(classic: bool, config: Optional[Dict[str, str]] = None):
"""Looks up system details and installs the appropriate grafana-agent snap revision."""
arch = get_system_arch()
confinement = "classic" if classic else "strict"
Expand All @@ -47,13 +48,14 @@ def install_ga_snap(classic: bool):
raise SnapSpecError(
f"Snap spec not found for arch={arch} and confinement={confinement}"
) from e
_install_snap(name=_grafana_agent_snap_name, revision=revision, classic=classic)
_install_snap(name=_grafana_agent_snap_name, revision=revision, classic=classic, config=config)


def _install_snap(
name: str,
revision: str,
classic: bool = False,
config: Optional[Dict[str, str]] = None,
):
"""Install and pin the given snap revision.

Expand All @@ -79,6 +81,9 @@ def _install_snap(
else:
snap.ensure(state=snap_lib.SnapState.Present, revision=revision, classic=classic)

if config:
snap.set(config)

snap.hold()


Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ deps =
asyncstdlib
# Libjuju needs to track the juju version
juju ~= 3.3.0
# https://github.com/juju/python-libjuju/issues/1184
websockets<14.0
# Temporarily pinning pytest due to https://github.com/charmed-kubernetes/pytest-operator/issues/131
pytest ~= 8.1.1
prometheus-api-client
Expand Down