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

CSS-9168 Add resource lookup timeout as variable #29

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,9 @@ options:
The function the charm should provide, either `admin` or `usersync`.
type: string
default: admin
lookup-timeout:
description: |
The default timeout for the resource auto-complete
functionality for Ranger service in ms.
type: int
default: 3000
6 changes: 5 additions & 1 deletion lib/charms/data_platform_libs/v0/data_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def _on_topic_requested(self, event: TopicRequestedEvent):

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

PYDEPS = ["ops>=2.0.0"]

Expand Down Expand Up @@ -658,6 +658,10 @@ def set_content(self, content: Dict[str, str]) -> None:
if not self.meta:
return

# DPE-4182: do not create new revision if the content stay the same
if content == self.get_content():
return

if content:
self._move_to_new_label_if_needed()
self.meta.set_content(content)
Expand Down
3 changes: 2 additions & 1 deletion lib/charms/grafana_k8s/v0/grafana_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,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 = 35
LIBPATCH = 36

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -1050,6 +1050,7 @@ def __init__(

self.framework.observe(self._charm.on.leader_elected, self._update_all_dashboards_from_dir)
self.framework.observe(self._charm.on.upgrade_charm, self._update_all_dashboards_from_dir)
self.framework.observe(self._charm.on.config_changed, self._update_all_dashboards_from_dir)

self.framework.observe(
self._charm.on[self._relation_name].relation_created,
Expand Down
23 changes: 16 additions & 7 deletions lib/charms/loki_k8s/v0/loki_push_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
applications such as pebble, or charmed operators of workloads such as grafana-agent or promtail,
that can communicate with loki directly.

- `LogProxyConsumer`: This object can be used by any Charmed Operator which needs to
send telemetry, such as logs, to Loki through a Log Proxy by implementing the consumer side of the
`loki_push_api` relation interface.
- `LogProxyConsumer`: DEPRECATED.
This object can be used by any Charmed Operator which needs to send telemetry, such as logs, to
Loki through a Log Proxy by implementing the consumer side of the `loki_push_api` relation
interface.

Filtering logs in Loki is largely performed on the basis of labels. In the Juju ecosystem, Juju
topology labels are used to uniquely identify the workload which generates telemetry like logs.
Expand All @@ -38,13 +39,14 @@
- `charm`: A reference to the parent (Loki) charm.

- `relation_name`: The name of the relation that the charm uses to interact
with its clients, which implement `LokiPushApiConsumer` or `LogProxyConsumer`.
with its clients, which implement `LokiPushApiConsumer` or `LogProxyConsumer`
(note that LogProxyConsumer is deprecated).

If provided, this relation name must match a provided relation in metadata.yaml with the
`loki_push_api` interface.

The default relation name is "logging" for `LokiPushApiConsumer` and "log-proxy" for
`LogProxyConsumer`.
`LogProxyConsumer` (note that LogProxyConsumer is deprecated).

For example, a provider's `metadata.yaml` file may look as follows:

Expand Down Expand Up @@ -219,6 +221,9 @@ def __init__(self, *args):

## LogProxyConsumer Library Usage

> Note: This object is deprecated. Consider migrating to LogForwarder (see v1/loki_push_api) with
> the release of Juju 3.6 LTS.

Let's say that we have a workload charm that produces logs, and we need to send those logs to a
workload implementing the `loki_push_api` interface, such as `Loki` or `Grafana Agent`.

Expand Down Expand Up @@ -480,7 +485,7 @@ def _alert_rules_error(self, event):

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

PYDEPS = ["cosl"]

Expand Down Expand Up @@ -1539,7 +1544,8 @@ def __init__(
the Loki API endpoint to push logs. It is intended for workloads that can speak
loki_push_api (https://grafana.com/docs/loki/latest/api/#push-log-entries-to-loki), such
as grafana-agent.
(If you only need to forward a few workload log files, then use LogProxyConsumer.)
(If you need to forward workload stdout logs, then use v1/loki_push_api.LogForwarder; if
you need to forward log files, then use LogProxyConsumer.)

`LokiPushApiConsumer` can be instantiated as follows:

Expand Down Expand Up @@ -1728,6 +1734,9 @@ class LogProxyEvents(ObjectEvents):
class LogProxyConsumer(ConsumerBase):
"""LogProxyConsumer class.

> Note: This object is deprecated. Consider migrating to v1/loki_push_api.LogForwarder with the
> release of Juju 3.6 LTS.

The `LogProxyConsumer` object provides a method for attaching `promtail` to
a workload in order to generate structured logging data from applications
which traditionally log to syslog or do not have native Loki integration.
Expand Down
3 changes: 3 additions & 0 deletions src/relations/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ def _create_ranger_service(self, ranger, data, event):
)
service.configs = {
"username": f"relation_id_{event.relation.id}",
"resource.lookup.timeout.value.in.ms": self.charm.config[
"lookup-timeout"
],
}
for key, value in data.items():
if key not in ["name", "type"]:
Expand Down
20 changes: 20 additions & 0 deletions src/structured_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class CharmConfig(BaseConfigModel):
ranger_usersync_password: Optional[str]
policy_mgr_url: str
charm_function: FunctionType
lookup_timeout: int

@validator("*", pre=True)
@classmethod
Expand Down Expand Up @@ -113,3 +114,22 @@ def sync_ldap_url_validator(cls, value: str) -> Optional[str]:
if re.match(ldap_url_pattern, value) is not None:
return value
raise ValueError("Value incorrectly formatted.")

@validator("lookup_timeout")
@classmethod
def lookup_timeout_validator(cls, value: str) -> Optional[int]:
"""Check validity of `lookup_timeout` field.

Args:
value: timeout value

Returns:
int_value: integer for service configuration

Raises:
ValueError: in the case when the value is out of range
"""
int_value = int(value)
if 1000 <= int_value <= 10000:
AmberCharitos marked this conversation as resolved.
Show resolved Hide resolved
return int_value
raise ValueError("Value out of range.")
Loading