9
9
This document explains how to use the two principal objects this library provides:
10
10
11
11
- `LokiPushApiProvider`: This object is meant to be used by any Charmed Operator that needs to
12
- implement the provider side of the `loki_push_api` relation interface. For instance, a Loki charm.
12
+ implement the provider side of the `loki_push_api` relation interface: for instance, a Loki charm.
13
13
The provider side of the relation represents the server side, to which logs are being pushed.
14
14
15
15
- `LokiPushApiConsumer`: This object is meant to be used by any Charmed Operator that needs to
@@ -533,7 +533,7 @@ def __init__(self, ...):
533
533
RelationRole ,
534
534
WorkloadEvent ,
535
535
)
536
- from ops .framework import EventBase , EventSource , Object , ObjectEvents
536
+ from ops .framework import BoundEvent , EventBase , EventSource , Object , ObjectEvents
537
537
from ops .jujuversion import JujuVersion
538
538
from ops .model import Container , ModelError , Relation
539
539
from ops .pebble import APIError , ChangeError , Layer , PathError , ProtocolError
@@ -546,7 +546,7 @@ def __init__(self, ...):
546
546
547
547
# Increment this PATCH version before using `charmcraft publish-lib` or reset
548
548
# to 0 if you are raising the major API version
549
- LIBPATCH = 13
549
+ LIBPATCH = 15
550
550
551
551
PYDEPS = ["cosl" ]
552
552
@@ -1543,10 +1543,13 @@ def __init__(
1543
1543
alert_rules_path : str = DEFAULT_ALERT_RULES_RELATIVE_PATH ,
1544
1544
recursive : bool = False ,
1545
1545
skip_alert_topology_labeling : bool = False ,
1546
+ * ,
1547
+ forward_alert_rules : bool = True ,
1546
1548
):
1547
1549
super ().__init__ (charm , relation_name )
1548
1550
self ._charm = charm
1549
1551
self ._relation_name = relation_name
1552
+ self ._forward_alert_rules = forward_alert_rules
1550
1553
self .topology = JujuTopology .from_charm (charm )
1551
1554
1552
1555
try :
@@ -1569,7 +1572,8 @@ def _handle_alert_rules(self, relation):
1569
1572
alert_rules = (
1570
1573
AlertRules (None ) if self ._skip_alert_topology_labeling else AlertRules (self .topology )
1571
1574
)
1572
- alert_rules .add_path (self ._alert_rules_path , recursive = self ._recursive )
1575
+ if self ._forward_alert_rules :
1576
+ alert_rules .add_path (self ._alert_rules_path , recursive = self ._recursive )
1573
1577
alert_rules_as_dict = alert_rules .as_dict ()
1574
1578
1575
1579
relation .data [self ._charm .app ]["metadata" ] = json .dumps (self .topology .as_dict ())
@@ -1617,6 +1621,9 @@ def __init__(
1617
1621
alert_rules_path : str = DEFAULT_ALERT_RULES_RELATIVE_PATH ,
1618
1622
recursive : bool = True ,
1619
1623
skip_alert_topology_labeling : bool = False ,
1624
+ * ,
1625
+ refresh_event : Optional [Union [BoundEvent , List [BoundEvent ]]] = None ,
1626
+ forward_alert_rules : bool = True ,
1620
1627
):
1621
1628
"""Construct a Loki charm client.
1622
1629
@@ -1642,6 +1649,9 @@ def __init__(
1642
1649
alert_rules_path: a string indicating a path where alert rules can be found
1643
1650
recursive: Whether to scan for rule files recursively.
1644
1651
skip_alert_topology_labeling: whether to skip the alert topology labeling.
1652
+ forward_alert_rules: a boolean flag to toggle forwarding of charmed alert rules.
1653
+ refresh_event: an optional bound event or list of bound events which
1654
+ will be observed to re-set scrape job data (IP address and others)
1645
1655
1646
1656
Raises:
1647
1657
RelationNotFoundError: If there is no relation in the charm's metadata.yaml
@@ -1667,14 +1677,26 @@ def __init__(
1667
1677
charm , relation_name , RELATION_INTERFACE_NAME , RelationRole .requires
1668
1678
)
1669
1679
super ().__init__ (
1670
- charm , relation_name , alert_rules_path , recursive , skip_alert_topology_labeling
1680
+ charm ,
1681
+ relation_name ,
1682
+ alert_rules_path ,
1683
+ recursive ,
1684
+ skip_alert_topology_labeling ,
1685
+ forward_alert_rules = forward_alert_rules ,
1671
1686
)
1672
1687
events = self ._charm .on [relation_name ]
1673
1688
self .framework .observe (self ._charm .on .upgrade_charm , self ._on_lifecycle_event )
1689
+ self .framework .observe (self ._charm .on .config_changed , self ._on_lifecycle_event )
1674
1690
self .framework .observe (events .relation_joined , self ._on_logging_relation_joined )
1675
1691
self .framework .observe (events .relation_changed , self ._on_logging_relation_changed )
1676
1692
self .framework .observe (events .relation_departed , self ._on_logging_relation_departed )
1677
1693
1694
+ if refresh_event :
1695
+ if not isinstance (refresh_event , list ):
1696
+ refresh_event = [refresh_event ]
1697
+ for ev in refresh_event :
1698
+ self .framework .observe (ev , self ._on_lifecycle_event )
1699
+
1678
1700
def _on_lifecycle_event (self , _ : HookEvent ):
1679
1701
"""Update require relation data on charm upgrades and other lifecycle events.
1680
1702
@@ -2550,10 +2572,17 @@ def __init__(
2550
2572
alert_rules_path : str = DEFAULT_ALERT_RULES_RELATIVE_PATH ,
2551
2573
recursive : bool = True ,
2552
2574
skip_alert_topology_labeling : bool = False ,
2575
+ refresh_event : Optional [Union [BoundEvent , List [BoundEvent ]]] = None ,
2576
+ forward_alert_rules : bool = True ,
2553
2577
):
2554
2578
_PebbleLogClient .check_juju_version ()
2555
2579
super ().__init__ (
2556
- charm , relation_name , alert_rules_path , recursive , skip_alert_topology_labeling
2580
+ charm ,
2581
+ relation_name ,
2582
+ alert_rules_path ,
2583
+ recursive ,
2584
+ skip_alert_topology_labeling ,
2585
+ forward_alert_rules = forward_alert_rules ,
2557
2586
)
2558
2587
self ._charm = charm
2559
2588
self ._relation_name = relation_name
@@ -2564,6 +2593,12 @@ def __init__(
2564
2593
self .framework .observe (on .relation_departed , self ._update_logging )
2565
2594
self .framework .observe (on .relation_broken , self ._update_logging )
2566
2595
2596
+ if refresh_event :
2597
+ if not isinstance (refresh_event , list ):
2598
+ refresh_event = [refresh_event ]
2599
+ for ev in refresh_event :
2600
+ self .framework .observe (ev , self ._update_logging )
2601
+
2567
2602
for container_name in self ._charm .meta .containers .keys ():
2568
2603
snake_case_container_name = container_name .replace ("-" , "_" )
2569
2604
self .framework .observe (
0 commit comments