From a5e2f57af28cfb5609b94d9a646d42cff0502794 Mon Sep 17 00:00:00 2001 From: Leon <82407168+sed-i@users.noreply.github.com> Date: Tue, 19 Nov 2024 21:47:04 -0500 Subject: [PATCH] Add config option to disable reporting (#202) * Add config option to disable reporting * Update snap revs * Write config file before snap install * Patch instead of symlink --- charmcraft-22.04.yaml | 201 ----------------- charmcraft-24.04.patch | 46 ++++ charmcraft-24.04.yaml | 169 -------------- charmcraft.yaml | 209 +++++++++++++++++- lib/charms/grafana_agent/v0/cos_agent.py | 12 +- src/charm.py | 19 +- src/snap_management.py | 17 +- tests/integration/test_classic_config_flag.py | 4 + tests/integration/test_juju_info_cos_agent.py | 4 + tox.ini | 4 +- 10 files changed, 296 insertions(+), 389 deletions(-) delete mode 100644 charmcraft-22.04.yaml create mode 100644 charmcraft-24.04.patch delete mode 100644 charmcraft-24.04.yaml mode change 120000 => 100644 charmcraft.yaml diff --git a/charmcraft-22.04.yaml b/charmcraft-22.04.yaml deleted file mode 100644 index 633fa3f..0000000 --- a/charmcraft-22.04.yaml +++ /dev/null @@ -1,201 +0,0 @@ -# Copyright 2021 Canonical Ltd. -# See LICENSE file for licensing details. - -name: grafana-agent -type: charm -subordinate: true - -description: A subordinate charm for Grafana Agent and an essential part of the COS Lite bundle. -summary: | - This Charmed Operator handles deployment, scaling, configuration, and Day 2 operations specific to Grafana Agent. - -links: - documentation: https://discourse.charmhub.io/t/grafana-agent-docs-index/13452 - website: https://charmhub.io/grafana-agent - source: https://github.com/canonical/grafana-agent-operator - issues: https://github.com/canonical/grafana-agent-operator/issues - -bases: - - build-on: - - name: "ubuntu" - channel: "22.04" - architectures: ["arm64"] - run-on: - - name: "ubuntu" - channel: "22.04" - architectures: ["arm64"] - - build-on: - - name: "ubuntu" - channel: "20.04" - architectures: ["arm64"] - run-on: - - name: "ubuntu" - channel: "20.04" - architectures: ["arm64"] - - build-on: - - name: "ubuntu" - channel: "22.04" - architectures: ["amd64"] - run-on: - - name: "ubuntu" - channel: "22.04" - architectures: ["amd64"] - - build-on: - - name: "ubuntu" - channel: "20.04" - architectures: ["amd64"] - run-on: - - name: "ubuntu" - channel: "20.04" - architectures: ["amd64"] - -parts: - charm: - build-packages: - - git - - # The following are needed for tls-certificates-interface - - build-essential - - python3-dev - - libffi-dev - - libssl-dev - - pkg-config - - rustc - - cargo - cos-tool: - plugin: dump - source: . - build-packages: - - curl - override-pull: | - curl -L -O https://github.com/canonical/cos-tool/releases/latest/download/cos-tool-${CRAFT_ARCH_BUILD_FOR} - chmod +x cos-tool-* - -requires: - certificates: - interface: tls-certificates - limit: 1 - description: | - Certificate for the grafana agent server (API endpoint is served on :12345 by default) - to use to authenticate to clients, and the CA certificate of the signing CA. - We currently assume that the same CA signs all scrape targets (e.g. principal units). - juju-info: - description: | - `juju-info` provides basic compatibility with all charms. - If all you want is /var/log logs and node_exporter metrics, - this relation will be enough. - interface: juju-info - scope: container - cos-agent: - description: | - `cos-agent` is a dedicated relation for the grafana agent machine - charm. It will allow you to set up custom scrape jobs, fetch files - from arbitrary locations, send alert rules, dashboards, etc. - interface: cos_agent - scope: container - - send-remote-write: - interface: prometheus_remote_write - logging-consumer: - interface: loki_push_api - grafana-cloud-config: - interface: grafana_cloud_config - limit: 1 - receive-ca-cert: - interface: certificate_transfer - description: | - Obtain TLS information (certificate, ca, chain) from another charm. - tracing: - interface: tracing - limit: 1 - -provides: - grafana-dashboards-provider: - interface: grafana_dashboard - -peers: - peers: - interface: grafana_agent_replica - -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. - If "true", self-signed certs can be seamlessly used; this setting - will be applied to all of the Agent configurations (Prometheus, - Loki). - type: boolean - default: false - global_scrape_timeout: - description: > - How long to wait before timing out a scrape from a target. - Supported units: y, w, d, h, m, s. - type: string - default: "10s" - global_scrape_interval: - description: > - How frequently should instances be scraped. - Supported units: y, w, d, h, m, s. - type: string - default: "1m" - always_enable_zipkin: - description: > - Force-enable the receiver for the 'zipkin' protocol in Grafana Agent, - even if there is no integration currently requesting it. - type: boolean - default: false - always_enable_otlp_grpc: - description: > - Force-enable the receiver for the 'otlp_grpc' protocol in Grafana Agent, - even if there is no integration currently requesting it. - type: boolean - default: false - always_enable_otlp_http: - description: > - Force-enable the receiver for the 'otlp_http' protocol in Grafana Agent, - even if there is no integration currently requesting it. - type: boolean - default: false - always_enable_jaeger_grpc: - description: > - Force-enable the receiver for the 'jaeger_grpc' protocol in Grafana Agent, - even if there is no integration currently requesting it. - type: boolean - default: false - always_enable_jaeger_thrift_http: - description: > - Force-enable the receiver for the 'jaeger_thrift_http' protocol in Grafana Agent, - even if there is no integration currently requesting it. - type: boolean - default: false - tracing_sample_rate_charm: - description: > - 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 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 tracing backend. - Setting it to 100 would mean all workload traces are kept, setting to 0 means workload traces - 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 (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 tracing backend at all. Anything outside of 0-100 range will be normalised - to this range by Grafana Agent. - type: float - default: 100.0 \ No newline at end of file diff --git a/charmcraft-24.04.patch b/charmcraft-24.04.patch new file mode 100644 index 0000000..c829c80 --- /dev/null +++ b/charmcraft-24.04.patch @@ -0,0 +1,46 @@ +--- charmcraft-22.04.yaml 2024-11-19 21:09:07.305181162 +0000 ++++ charmcraft-24.04.yaml 2024-11-19 21:09:07.305181162 +0000 +@@ -15,39 +15,10 @@ + source: https://github.com/canonical/grafana-agent-operator + issues: https://github.com/canonical/grafana-agent-operator/issues + +-bases: +- - build-on: +- - name: "ubuntu" +- channel: "22.04" +- architectures: ["arm64"] +- run-on: +- - name: "ubuntu" +- channel: "22.04" +- architectures: ["arm64"] +- - build-on: +- - name: "ubuntu" +- channel: "20.04" +- architectures: ["arm64"] +- run-on: +- - name: "ubuntu" +- channel: "20.04" +- architectures: ["arm64"] +- - build-on: +- - name: "ubuntu" +- channel: "22.04" +- architectures: ["amd64"] +- run-on: +- - name: "ubuntu" +- channel: "22.04" +- architectures: ["amd64"] +- - build-on: +- - name: "ubuntu" +- channel: "20.04" +- architectures: ["amd64"] +- run-on: +- - name: "ubuntu" +- channel: "20.04" +- architectures: ["amd64"] ++base: ubuntu@24.04 ++platforms: ++ amd64: ++ arm64: + + parts: + charm: diff --git a/charmcraft-24.04.yaml b/charmcraft-24.04.yaml deleted file mode 100644 index 4de0c3f..0000000 --- a/charmcraft-24.04.yaml +++ /dev/null @@ -1,169 +0,0 @@ -# Copyright 2021 Canonical Ltd. -# See LICENSE file for licensing details. - -name: grafana-agent -type: charm -subordinate: true - -description: A subordinate charm for Grafana Agent and an essential part of the COS Lite bundle. -summary: | - This Charmed Operator handles deployment, scaling, configuration, and Day 2 operations specific to Grafana Agent. - -links: - documentation: https://discourse.charmhub.io/t/grafana-agent-docs-index/13452 - website: https://charmhub.io/grafana-agent - source: https://github.com/canonical/grafana-agent-operator - issues: https://github.com/canonical/grafana-agent-operator/issues - -base: ubuntu@24.04 -platforms: - amd64: - arm64: - -parts: - charm: - build-packages: - - git - - # The following are needed for tls-certificates-interface - - build-essential - - python3-dev - - libffi-dev - - libssl-dev - - pkg-config - - rustc - - cargo - cos-tool: - plugin: dump - source: . - build-packages: - - curl - override-pull: | - curl -L -O https://github.com/canonical/cos-tool/releases/latest/download/cos-tool-${CRAFT_ARCH_BUILD_FOR} - chmod +x cos-tool-* - -requires: - certificates: - interface: tls-certificates - limit: 1 - description: | - Certificate for the grafana agent server (API endpoint is served on :12345 by default) - to use to authenticate to clients, and the CA certificate of the signing CA. - We currently assume that the same CA signs all scrape targets (e.g. principal units). - juju-info: - description: | - `juju-info` provides basic compatibility with all charms. - If all you want is /var/log logs and node_exporter metrics, - this relation will be enough. - interface: juju-info - scope: container - cos-agent: - description: | - `cos-agent` is a dedicated relation for the grafana agent machine - charm. It will allow you to set up custom scrape jobs, fetch files - from arbitrary locations, send alert rules, dashboards, etc. - interface: cos_agent - scope: container - - send-remote-write: - interface: prometheus_remote_write - logging-consumer: - interface: loki_push_api - grafana-cloud-config: - interface: grafana_cloud_config - limit: 1 - receive-ca-cert: - interface: certificate_transfer - description: | - Obtain TLS information (certificate, ca, chain) from another charm. - tracing: - interface: tracing - limit: 1 - -provides: - grafana-dashboards-provider: - interface: grafana_dashboard - -peers: - peers: - interface: grafana_agent_replica - -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. - If "true", self-signed certs can be seamlessly used; this setting - will be applied to all of the Agent configurations (Prometheus, - Loki). - type: boolean - default: false - global_scrape_timeout: - description: > - How long to wait before timing out a scrape from a target. - Supported units: y, w, d, h, m, s. - type: string - default: "10s" - global_scrape_interval: - description: > - How frequently should instances be scraped. - Supported units: y, w, d, h, m, s. - type: string - default: "1m" - always_enable_zipkin: - description: > - Force-enable the receiver for the 'zipkin' protocol in Grafana Agent, - even if there is no integration currently requesting it. - type: boolean - default: false - always_enable_otlp_grpc: - description: > - Force-enable the receiver for the 'otlp_grpc' protocol in Grafana Agent, - even if there is no integration currently requesting it. - type: boolean - default: false - always_enable_otlp_http: - description: > - Force-enable the receiver for the 'otlp_http' protocol in Grafana Agent, - even if there is no integration currently requesting it. - type: boolean - default: false - always_enable_jaeger_grpc: - description: > - Force-enable the receiver for the 'jaeger_grpc' protocol in Grafana Agent, - even if there is no integration currently requesting it. - type: boolean - default: false - always_enable_jaeger_thrift_http: - description: > - Force-enable the receiver for the 'jaeger_thrift_http' protocol in Grafana Agent, - even if there is no integration currently requesting it. - type: boolean - default: false - tracing_sample_rate_charm: - description: > - This property defines the percentage of charm traces that are sent to the 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. - 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. - 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. - 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. - 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. - type: float - default: 100.0 diff --git a/charmcraft.yaml b/charmcraft.yaml deleted file mode 120000 index a49ad6e..0000000 --- a/charmcraft.yaml +++ /dev/null @@ -1 +0,0 @@ -charmcraft-22.04.yaml \ No newline at end of file diff --git a/charmcraft.yaml b/charmcraft.yaml new file mode 100644 index 0000000..b4f7b90 --- /dev/null +++ b/charmcraft.yaml @@ -0,0 +1,208 @@ +# Copyright 2021 Canonical Ltd. +# See LICENSE file for licensing details. + +name: grafana-agent +type: charm +subordinate: true + +description: A subordinate charm for Grafana Agent and an essential part of the COS Lite bundle. +summary: | + This Charmed Operator handles deployment, scaling, configuration, and Day 2 operations specific to Grafana Agent. + +links: + documentation: https://discourse.charmhub.io/t/grafana-agent-docs-index/13452 + website: https://charmhub.io/grafana-agent + source: https://github.com/canonical/grafana-agent-operator + issues: https://github.com/canonical/grafana-agent-operator/issues + +bases: + - build-on: + - name: "ubuntu" + channel: "22.04" + architectures: ["arm64"] + run-on: + - name: "ubuntu" + channel: "22.04" + architectures: ["arm64"] + - build-on: + - name: "ubuntu" + channel: "20.04" + architectures: ["arm64"] + run-on: + - name: "ubuntu" + channel: "20.04" + architectures: ["arm64"] + - build-on: + - name: "ubuntu" + channel: "22.04" + architectures: ["amd64"] + run-on: + - name: "ubuntu" + channel: "22.04" + architectures: ["amd64"] + - build-on: + - name: "ubuntu" + channel: "20.04" + architectures: ["amd64"] + run-on: + - name: "ubuntu" + channel: "20.04" + architectures: ["amd64"] + +parts: + charm: + build-packages: + - git + + # The following are needed for tls-certificates-interface + - build-essential + - python3-dev + - libffi-dev + - libssl-dev + - pkg-config + - rustc + - cargo + cos-tool: + plugin: dump + source: . + build-packages: + - curl + override-pull: | + curl -L -O https://github.com/canonical/cos-tool/releases/latest/download/cos-tool-${CRAFT_ARCH_BUILD_FOR} + chmod +x cos-tool-* + +requires: + certificates: + interface: tls-certificates + limit: 1 + description: | + Certificate for the grafana agent server (API endpoint is served on :12345 by default) + to use to authenticate to clients, and the CA certificate of the signing CA. + We currently assume that the same CA signs all scrape targets (e.g. principal units). + juju-info: + description: | + `juju-info` provides basic compatibility with all charms. + If all you want is /var/log logs and node_exporter metrics, + this relation will be enough. + interface: juju-info + scope: container + cos-agent: + description: | + `cos-agent` is a dedicated relation for the grafana agent machine + charm. It will allow you to set up custom scrape jobs, fetch files + from arbitrary locations, send alert rules, dashboards, etc. + interface: cos_agent + scope: container + + send-remote-write: + interface: prometheus_remote_write + logging-consumer: + interface: loki_push_api + grafana-cloud-config: + interface: grafana_cloud_config + limit: 1 + receive-ca-cert: + interface: certificate_transfer + description: | + Obtain TLS information (certificate, ca, chain) from another charm. + tracing: + interface: tracing + limit: 1 + +provides: + grafana-dashboards-provider: + interface: grafana_dashboard + +peers: + peers: + interface: grafana_agent_replica + +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. + If "true", self-signed certs can be seamlessly used; this setting + will be applied to all of the Agent configurations (Prometheus, + Loki). + type: boolean + default: false + global_scrape_timeout: + description: > + How long to wait before timing out a scrape from a target. + Supported units: y, w, d, h, m, s. + type: string + default: "10s" + global_scrape_interval: + description: > + How frequently should instances be scraped. + Supported units: y, w, d, h, m, s. + type: string + default: "1m" + always_enable_zipkin: + description: > + Force-enable the receiver for the 'zipkin' protocol in Grafana Agent, + even if there is no integration currently requesting it. + type: boolean + default: false + always_enable_otlp_grpc: + description: > + Force-enable the receiver for the 'otlp_grpc' protocol in Grafana Agent, + even if there is no integration currently requesting it. + type: boolean + default: false + always_enable_otlp_http: + description: > + Force-enable the receiver for the 'otlp_http' protocol in Grafana Agent, + even if there is no integration currently requesting it. + type: boolean + default: false + always_enable_jaeger_grpc: + description: > + Force-enable the receiver for the 'jaeger_grpc' protocol in Grafana Agent, + even if there is no integration currently requesting it. + type: boolean + default: false + always_enable_jaeger_thrift_http: + description: > + Force-enable the receiver for the 'jaeger_thrift_http' protocol in Grafana Agent, + even if there is no integration currently requesting it. + type: boolean + default: false + tracing_sample_rate_charm: + description: > + 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 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 tracing backend. + Setting it to 100 would mean all workload traces are kept, setting to 0 means workload traces + 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 (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 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 \ No newline at end of file diff --git a/lib/charms/grafana_agent/v0/cos_agent.py b/lib/charms/grafana_agent/v0/cos_agent.py index 8a52457..cc4da25 100644 --- a/lib/charms/grafana_agent/v0/cos_agent.py +++ b/lib/charms/grafana_agent/v0/cos_agent.py @@ -235,10 +235,10 @@ def __init__(self, *args): import pydantic from cosl import GrafanaDashboard, JujuTopology from cosl.rules import AlertRules -from ops import CharmBase from ops.charm import RelationChangedEvent from ops.framework import EventBase, EventSource, Object, ObjectEvents from ops.model import ModelError, Relation +from ops.testing import CharmType if TYPE_CHECKING: try: @@ -468,7 +468,7 @@ def dump(self, databag: Optional[MutableMapping] = None, clear: bool = True): return databag -class CosAgentProviderUnitData(DatabagModel): # pyright: ignore [reportGeneralTypeIssues] +class CosAgentProviderUnitData(DatabagModel): """Unit databag model for `cos-agent` relation.""" # The following entries are the same for all units of the same principal. @@ -495,7 +495,7 @@ class CosAgentProviderUnitData(DatabagModel): # pyright: ignore [reportGeneralT KEY: ClassVar[str] = "config" -class CosAgentPeersUnitData(DatabagModel): # pyright: ignore [reportGeneralTypeIssues] +class CosAgentPeersUnitData(DatabagModel): """Unit databag model for `peers` cos-agent machine charm peer relation.""" # We need the principal unit name and relation metadata to be able to render identifiers @@ -594,7 +594,7 @@ class Receiver(pydantic.BaseModel): ) -class CosAgentRequirerUnitData(DatabagModel): # pyright: ignore [reportGeneralTypeIssues] # noqa: D101 +class CosAgentRequirerUnitData(DatabagModel): # noqa: D101 """Application databag model for the COS-agent requirer.""" receivers: List[Receiver] = pydantic.Field( @@ -608,7 +608,7 @@ class COSAgentProvider(Object): def __init__( self, - charm: CharmBase, + charm: CharmType, relation_name: str = DEFAULT_RELATION_NAME, metrics_endpoints: Optional[List["_MetricsEndpointDict"]] = None, metrics_rules_dir: str = "./src/prometheus_alert_rules", @@ -877,7 +877,7 @@ class COSAgentRequirer(Object): def __init__( self, - charm: CharmBase, + charm: CharmType, *, relation_name: str = DEFAULT_RELATION_NAME, peer_relation_name: str = DEFAULT_PEER_RELATION_NAME, diff --git a/src/charm.py b/src/charm.py index c2ca187..3056a2a 100755 --- a/src/charm.py +++ b/src/charm.py @@ -19,10 +19,10 @@ from charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm from cosl import JujuTopology from cosl.rules import AlertRules -from ops.main import main +from ops import main from ops.model import BlockedStatus, MaintenanceStatus, Relation -from grafana_agent import METRICS_RULES_SRC_PATH, GrafanaAgentCharm +from grafana_agent import CONFIG_PATH, METRICS_RULES_SRC_PATH, GrafanaAgentCharm from snap_management import SnapSpecError, install_ga_snap logger = logging.getLogger(__name__) @@ -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 @@ -244,8 +247,16 @@ def on_install(self, _event) -> None: def _install(self) -> None: """Install/refresh the Grafana Agent snap.""" self.unit.status = MaintenanceStatus("Installing grafana-agent snap") + # Grafana-agent is not yet available, so no config update needed yet. + # On install, create a config file, to avoid a transient error: + # error reading config file open /etc/grafana-agent.yaml: no such file or directory + if not os.path.exists(CONFIG_PATH): + self.write_file(CONFIG_PATH, yaml.dump(self._generate_config())) try: - 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 install grafana-agent.") from e diff --git a/src/snap_management.py b/src/snap_management.py index 9cf7201..b62e8f9 100644 --- a/src/snap_management.py +++ b/src/snap_management.py @@ -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 @@ -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"): 94, # 0.40.4 + ("strict", "arm64"): 96, # 0.40.4 + ("classic", "amd64"): 95, # 0.40.4 + ("classic", "arm64"): 97, # 0.40.4 } @@ -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" @@ -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. @@ -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() diff --git a/tests/integration/test_classic_config_flag.py b/tests/integration/test_classic_config_flag.py index 507f712..0e161c8 100644 --- a/tests/integration/test_classic_config_flag.py +++ b/tests/integration/test_classic_config_flag.py @@ -24,6 +24,10 @@ async def ssh(ops_test, app_name: str, command: str) -> List[str]: pytest.fail(f"Failed to run ssh command '{command}' in {app_name}: {e.message}") +async def test_setup_env(ops_test: OpsTest): + await ops_test.model.set_config({"logging-config": "=WARNING; unit=DEBUG"}) + + @pytest.mark.abort_on_fail async def test_build_and_deploy(ops_test: OpsTest, grafana_agent_charm): # Principal diff --git a/tests/integration/test_juju_info_cos_agent.py b/tests/integration/test_juju_info_cos_agent.py index 766574d..302e3c4 100644 --- a/tests/integration/test_juju_info_cos_agent.py +++ b/tests/integration/test_juju_info_cos_agent.py @@ -42,6 +42,10 @@ async def ssh_units(ops_test, app_name: str, command: str) -> List[str]: pytest.fail(f"Failed to run ssh command '{command}' in {app_name}: {e.message}") +async def test_setup_env(ops_test: OpsTest): + await ops_test.model.set_config({"logging-config": "=WARNING; unit=DEBUG"}) + + @pytest.mark.abort_on_fail async def test_build_and_deploy(ops_test: OpsTest, grafana_agent_charm): # Principal diff --git a/tox.ini b/tox.ini index 861565b..695744d 100644 --- a/tox.ini +++ b/tox.ini @@ -101,9 +101,9 @@ depends = relative_files = True [testenv:pack-24.04] -description = Link charmcraft-24.04.yaml to charmcraft.yaml, pack and restore +description = Patch charmcraft.yaml with necessary changes for a 24.04 build, pack and restore allowlist_externals = sh commands = - sh -c "ln -srf {toxinidir}/charmcraft-24.04.yaml {toxinidir}/charmcraft.yaml && charmcraft pack --project-dir={toxinidir}; ln -srf {toxinidir}/charmcraft-22.04.yaml {toxinidir}/charmcraft.yaml" + sh -c "patch {toxinidir}/charmcraft.yaml < {toxinidir}/charmcraft-24.04.patch && charmcraft pack --project-dir={toxinidir}; git -C {toxinidir} restore charmcraft.yaml"