Skip to content

Commit

Permalink
add optional secureJsonData to grafana datasources
Browse files Browse the repository at this point in the history
  • Loading branch information
lucabello committed Feb 6, 2024
1 parent 60fa058 commit 191a93f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/charms/grafana_k8s/v0/grafana_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
`refresh_event`: A `PebbleReady` event from `charm`, used to refresh
the IP address sent to Grafana on a charm lifecycle event or
pod restart
`extra_fields`: None
`secure_extra_fields`: None
The value of `source_url` should be a fully-resolvable URL for a valid Grafana
source, e.g., `http://example.com/api` or similar.
Expand Down Expand Up @@ -160,7 +162,7 @@ def __init__(self, *args):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 20
LIBPATCH = 21

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -324,6 +326,7 @@ def __init__(
refresh_event: Optional[Union[BoundEvent, List[BoundEvent]]] = None,
relation_name: str = DEFAULT_RELATION_NAME,
extra_fields: Optional[dict] = None,
secure_extra_fields: Optional[dict] = None,
) -> None:
"""Construct a Grafana charm client.
Expand Down Expand Up @@ -364,6 +367,8 @@ def __init__(
machine/VM restart.
extra_fields: a :dict: which is used for additional information required
for some datasources in the `jsonData` field
secure_extra_fields: a :dict: which is used for additional information required
for some datasources in the `secureJsonData`
"""
_validate_relation_by_interface_and_direction(
charm, relation_name, RELATION_INTERFACE_NAME, RelationRole.provides
Expand All @@ -382,6 +387,7 @@ def __init__(
extra_fields["implementation"] = "prometheus"

self._extra_fields = extra_fields
self._secure_extra_fields = secure_extra_fields

if not refresh_event:
if len(self._charm.meta.containers) == 1:
Expand Down Expand Up @@ -450,6 +456,7 @@ def _scrape_data(self) -> Dict:
"application": str(self._charm.model.app.name),
"type": self._source_type,
"extra_fields": self._extra_fields,
"secure_extra_fields": self._secure_extra_fields,
}
return data

Expand Down
2 changes: 2 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,8 @@ def _generate_datasource_config(self) -> str:
}
if source_info.get("extra_fields", None):
source["jsonData"] = source_info.get("extra_fields")
if source_info.get("secure_extra_fields", None):
source["secureJsonData"] = source_info.get("secure_extra_fields")

# set timeout for querying this data source
timeout = int(source.get("jsonData", {}).get("timeout", 0))
Expand Down

0 comments on commit 191a93f

Please # to comment.