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

First TLS instrumentation #20

Merged
merged 29 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0a88983
first TLS instrumentation
Abuelodelanada Dec 8, 2023
849adcf
linting
Abuelodelanada Dec 8, 2023
0cdcbd0
let's use mimir default values
Abuelodelanada Dec 8, 2023
a2856ab
let's start with a simpler version
Abuelodelanada Dec 8, 2023
9f2d100
let's start with a simpler version
Abuelodelanada Dec 8, 2023
0af4dec
first instrumentation of TLS for nginx
Abuelodelanada Dec 12, 2023
64555d1
change client_auth_type value
Abuelodelanada Dec 12, 2023
6f0276a
add integration test
Abuelodelanada Dec 14, 2023
be384ca
Update tox.ini
Abuelodelanada Dec 14, 2023
482fd0c
address Leon's comments
Abuelodelanada Dec 14, 2023
563d632
server_name added
Abuelodelanada Dec 15, 2023
eae1a55
Dylan's suggestions addressed
Abuelodelanada Dec 15, 2023
c91f9b6
Merge branch 'main' into tls
Abuelodelanada Jan 5, 2024
924d51b
remove _build_tls_config
Abuelodelanada Jan 5, 2024
667593e
update loki_push_api
Abuelodelanada Jan 8, 2024
013ef3b
putting everything in order after the merge
Abuelodelanada Jan 8, 2024
3aa49b5
Merge branch 'main' into tls
Abuelodelanada Jan 8, 2024
0bbf84b
Merge branch 'main' into tls
Abuelodelanada Jan 11, 2024
9e92697
fix error in merge
Abuelodelanada Jan 11, 2024
6c701b6
change certhandler v0 with v1
Abuelodelanada Jan 11, 2024
4c3caff
fix integration tests
Abuelodelanada Jan 13, 2024
005f7ce
linting
Abuelodelanada Jan 13, 2024
9079331
Merge branch 'main' into tls
Abuelodelanada Jan 15, 2024
9d7e306
publish and grant certs
Abuelodelanada Jan 16, 2024
9eb38ea
update cert_handler
Abuelodelanada Jan 17, 2024
81f3ce4
change parameter name
Abuelodelanada Jan 17, 2024
9b43aa2
move methos from mimir_cluster to charm
Abuelodelanada Jan 17, 2024
666b14b
charm's code tidy up
Abuelodelanada Jan 17, 2024
8fc2489
add missing event handler
Abuelodelanada Jan 17, 2024
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
3 changes: 3 additions & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ parts:
charm-binary-python-packages:
- pydantic>2.0

# For v2.tls_certificates
- cryptography
- jsonschema
44 changes: 27 additions & 17 deletions lib/charms/loki_k8s/v0/loki_push_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
implement the provider side of the `loki_push_api` relation interface. For instance, a Loki charm.
The provider side of the relation represents the server side, to which logs are being pushed.

- `LokiPushApiConsumer`: This object is meant to be used by any Charmed Operator that needs to
send log to Loki by implementing the consumer side of the `loki_push_api` relation interface.
For instance, a Promtail or Grafana agent charm which needs to send logs to Loki.
- `LokiPushApiConsumer`: Used to obtain the loki api endpoint. This is useful for configuring
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
Expand Down Expand Up @@ -480,7 +480,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 = 22
LIBPATCH = 24

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -604,7 +604,9 @@ def _validate_relation_by_interface_and_direction(
actual_relation_interface = relation.interface_name
if actual_relation_interface != expected_relation_interface:
raise RelationInterfaceMismatchError(
relation_name, expected_relation_interface, actual_relation_interface
relation_name,
expected_relation_interface,
actual_relation_interface, # pyright: ignore
)

if expected_relation_role == RelationRole.provides:
Expand Down Expand Up @@ -866,20 +868,20 @@ def _from_dir(self, dir_path: Path, recursive: bool) -> List[dict]:

return alert_groups

def add_path(self, path: str, *, recursive: bool = False):
def add_path(self, path_str: str, *, recursive: bool = False):
"""Add rules from a dir path.

All rules from files are aggregated into a data structure representing a single rule file.
All group names are augmented with juju topology.

Args:
path: either a rules file or a dir of rules files.
path_str: either a rules file or a dir of rules files.
recursive: whether to read files recursively or not (no impact if `path` is a file).

Raises:
InvalidAlertRulePathError: if the provided path is invalid.
"""
path = Path(path) # type: Path
path = Path(path_str) # type: Path
if path.is_dir():
self.alert_groups.extend(self._from_dir(path, recursive))
elif path.is_file():
Expand Down Expand Up @@ -992,6 +994,8 @@ def __init__(self, handle, relation, relation_id, app=None, unit=None):

def snapshot(self) -> Dict:
"""Save event information."""
if not self.relation:
return {}
snapshot = {"relation_name": self.relation.name, "relation_id": self.relation.id}
if self.app:
snapshot["app_name"] = self.app.name
Expand Down Expand Up @@ -1052,7 +1056,7 @@ class LokiPushApiEvents(ObjectEvents):
class LokiPushApiProvider(Object):
"""A LokiPushApiProvider class."""

on = LokiPushApiEvents()
on = LokiPushApiEvents() # pyright: ignore

def __init__(
self,
Expand Down Expand Up @@ -1146,11 +1150,11 @@ def _on_logging_relation_changed(self, event: HookEvent):
event: a `CharmEvent` in response to which the consumer
charm must update its relation data.
"""
should_update = self._process_logging_relation_changed(event.relation)
should_update = self._process_logging_relation_changed(event.relation) # pyright: ignore
if should_update:
self.on.loki_push_api_alert_rules_changed.emit(
relation=event.relation,
relation_id=event.relation.id,
relation=event.relation, # pyright: ignore
relation_id=event.relation.id, # pyright: ignore
app=self._charm.app,
unit=self._charm.unit,
)
Expand Down Expand Up @@ -1517,7 +1521,7 @@ def loki_endpoints(self) -> List[dict]:
class LokiPushApiConsumer(ConsumerBase):
"""Loki Consumer class."""

on = LokiPushApiEvents()
on = LokiPushApiEvents() # pyright: ignore

def __init__(
self,
Expand Down Expand Up @@ -1760,7 +1764,7 @@ class LogProxyConsumer(ConsumerBase):
role.
"""

on = LogProxyEvents()
on = LogProxyEvents() # pyright: ignore

def __init__(
self,
Expand Down Expand Up @@ -1885,7 +1889,7 @@ def _on_relation_departed(self, _: RelationEvent) -> None:
self._container.stop(WORKLOAD_SERVICE_NAME)
self.on.log_proxy_endpoint_departed.emit()

def _get_container(self, container_name: str = "") -> Container:
def _get_container(self, container_name: str = "") -> Container: # pyright: ignore
"""Gets a single container by name or using the only container running in the Pod.

If there is more than one container in the Pod a `PromtailDigestError` is emitted.
Expand Down Expand Up @@ -1959,7 +1963,9 @@ def _add_pebble_layer(self, workload_binary_path: str) -> None:
}
},
}
self._container.add_layer(self._container_name, pebble_layer, combine=True)
self._container.add_layer(
self._container_name, pebble_layer, combine=True # pyright: ignore
)

def _create_directories(self) -> None:
"""Creates the directories for Promtail binary and config file."""
Expand Down Expand Up @@ -1996,7 +2002,11 @@ def _push_binary_to_workload(self, binary_path: str, workload_binary_path: str)
"""
with open(binary_path, "rb") as f:
self._container.push(
workload_binary_path, f, permissions=0o755, encoding=None, make_dirs=True
workload_binary_path,
f,
permissions=0o755,
encoding=None, # pyright: ignore
make_dirs=True,
)
logger.debug("The promtail binary file has been pushed to the workload container.")

Expand Down
Loading
Loading