Skip to content

Commit d41b8e1

Browse files
authored
Merge pull request SimplyStaking#380 from nivasan1/nikhil/add-peering-alert
Nikhil/add peering alert
2 parents 40cdb9f + 0bceab1 commit d41b8e1

File tree

28 files changed

+1117
-698
lines changed

28 files changed

+1117
-698
lines changed

alerter/.coverage

104 KB
Binary file not shown.

alerter/src/alerter/alert_code/node/cosmos_alert_code.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ class CosmosNodeAlertCode(AlertCode):
4343
TendermintRPCDataObtainedAlert = 'cosmos_node_alert_39'
4444
MetricNotFoundErrorAlert = 'cosmos_node_alert_40'
4545
MetricFoundAlert = 'cosmos_node_alert_41'
46+
NodeIsNotPeeredWithSentinelAlert = 'cosmos_node_alert_42'
47+
NodeIsPeeredWithSentinelAlert = 'cosmos_node_alert_43'

alerter/src/alerter/alerters/alerter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ def _equal_condition_function(current: Any, previous: Any) -> bool:
4646
def _is_true_condition_function(current: Any) -> bool:
4747
return current is True
4848

49+
@staticmethod
50+
def _is_false_condition_function(current: Any) -> bool:
51+
return current is False
52+
4953
@staticmethod
5054
def _true_fn() -> bool:
5155
return True

alerter/src/alerter/alerters/node/cosmos.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,6 @@ def _process_tendermint_rpc_result(self, tendermint_data: Dict,
422422
parent_id, node_id, configs, is_validator)
423423

424424
# Check if some errors have been resolved
425-
426425
self.alerting_factory.classify_error_alert(
427426
InvalidUrlException.code,
428427
cosmos_alerts.TendermintRPCInvalidUrlAlert,
@@ -451,11 +450,16 @@ def _process_tendermint_rpc_result(self, tendermint_data: Dict,
451450
)
452451

453452
# Check if the alert rules are satisfied for the metrics
454-
455453
is_syncing_configs = (
456454
configs.validator_is_syncing if is_validator
457455
else configs.node_is_syncing
458456
)
457+
458+
is_peered_with_sentinel_configs = (
459+
configs.validator_is_peered_with_sentinel if is_validator
460+
else configs.node_is_peered_with_sentinel
461+
)
462+
459463
classification_fn = (
460464
self.alerting_factory
461465
.classify_solvable_conditional_alert_no_repetition
@@ -473,6 +477,20 @@ def _process_tendermint_rpc_result(self, tendermint_data: Dict,
473477
[node_name, Severity.INFO.value, last_monitored,
474478
parent_id, node_id]
475479
)
480+
## Only alert if the node is running mev_tendermint
481+
if str_to_bool(is_peered_with_sentinel_configs['enabled']) and meta_data['is_mev_tendermint_node']:
482+
current = data['is_peered_with_sentinel']['current']
483+
if current is not None:
484+
classification_fn(
485+
parent_id, node_id, MetricCode.NodeIsNotPeeredWithSentinel.value,
486+
cosmos_alerts.NodeIsNotPeeredWithSentinelAlert,
487+
self._is_false_condition_function, [current],
488+
[node_name, is_peered_with_sentinel_configs['severity'],
489+
last_monitored, parent_id, node_id], data_for_alerting,
490+
cosmos_alerts.NodeIsPeeredWithSentinelAlert,
491+
[node_name, Severity.INFO.value, last_monitored,
492+
parent_id, node_id]
493+
)
476494

477495
slashed_configs = configs.slashed
478496
if str_to_bool(slashed_configs['enabled']):

alerter/src/alerter/alerts/node/cosmos.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@ def __init__(self, origin_name: str, severity: str, timestamp: float,
8080
timestamp, parent_id, origin_id,
8181
GroupedCosmosNodeAlertsMetricCode.NodeIsSyncing, [origin_id])
8282

83+
class NodeIsPeeredWithSentinelAlert(Alert):
84+
def __init__(self, origin_name: str, severity: str, timestamp: float,
85+
parent_id: str, origin_id: str) -> None:
86+
super().__init__(
87+
CosmosNodeAlertCode.NodeIsPeeredWithSentinelAlert,
88+
"Node {} is peered with sentinel.".format(origin_name), severity,
89+
timestamp, parent_id, origin_id,
90+
GroupedCosmosNodeAlertsMetricCode.NodeIsNotPeeredWithSentinel, [origin_id])
91+
92+
class NodeIsNotPeeredWithSentinelAlert(Alert):
93+
def __init__(self, origin_name: str, severity: str, timestamp: float,
94+
parent_id: str, origin_id: str) -> None:
95+
super().__init__(
96+
CosmosNodeAlertCode.NodeIsNotPeeredWithSentinelAlert,
97+
"Node {} is not peered with sentinel.".format(origin_name), severity,
98+
timestamp, parent_id, origin_id,
99+
GroupedCosmosNodeAlertsMetricCode.NodeIsNotPeeredWithSentinel, [origin_id])
83100

84101
class ValidatorIsNotActiveAlert(Alert):
85102
def __init__(self, origin_name: str, severity: str, timestamp: float,

alerter/src/alerter/factory/cosmos_node_alerting_factory.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def create_alerting_state(
107107
AlertsMetricCode.MetricNotFound.value: False,
108108
}
109109
any_severity_sent = {
110+
AlertsMetricCode.NodeIsNotPeeredWithSentinel.value: False,
110111
AlertsMetricCode.NodeIsSyncing.value: False,
111112
AlertsMetricCode.ValidatorIsNotActive.value: False,
112113
AlertsMetricCode.ValidatorIsJailed.value: False,

alerter/src/alerter/grouped_alerts_metric_code/node/cosmos_node_metric_code.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class GroupedCosmosNodeAlertsMetricCode(GroupedAlertsMetricCode):
55
NodeIsDown = 'cosmos_node_is_down'
66
ValidatorWasSlashed = 'cosmos_node_slashed'
77
NodeIsSyncing = 'cosmos_node_syncing'
8+
NodeIsNotPeeredWithSentinel = 'cosmos_node_is_not_peered_with_sentinel'
89
ValidatorIsNotActive = 'cosmos_node_active'
910
ValidatorIsJailed = 'cosmos_node_jailed'
1011
BlocksMissedThreshold = 'cosmos_node_blocks_missed'

alerter/src/configs/alerts/node/cosmos.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def __init__(
1414
cannot_access_tendermint_rpc_validator: Dict,
1515
cannot_access_tendermint_rpc_node: Dict, missed_blocks: Dict,
1616
slashed: Dict, node_is_syncing: Dict, validator_is_syncing: Dict,
17-
validator_is_jailed: Dict) -> None:
17+
validator_is_jailed: Dict,
18+
node_is_peered_with_sentinel: Dict = None, validator_is_peered_with_sentinel: Dict = None) -> None:
1819
self._parent_id = parent_id
1920
self._cannot_access_validator = cannot_access_validator
2021
self._cannot_access_node = cannot_access_node
@@ -38,6 +39,8 @@ def __init__(
3839
self._node_is_syncing = node_is_syncing
3940
self._validator_is_syncing = validator_is_syncing
4041
self._validator_is_jailed = validator_is_jailed
42+
self._node_is_peered_with_sentinel = node_is_peered_with_sentinel
43+
self._validator_is_peered_with_sentinel = validator_is_peered_with_sentinel
4144

4245
def __eq__(self, other: Any) -> bool:
4346
return self.__dict__ == other.__dict__
@@ -110,6 +113,14 @@ def node_is_syncing(self) -> Dict:
110113
def validator_is_syncing(self) -> Dict:
111114
return self._validator_is_syncing
112115

116+
@property
117+
def node_is_peered_with_sentinel(self) -> Dict:
118+
return self._node_is_peered_with_sentinel
119+
120+
@property
121+
def validator_is_peered_with_sentinel(self) -> Dict:
122+
return self._validator_is_peered_with_sentinel
123+
113124
@property
114125
def validator_is_jailed(self) -> Dict:
115126
return self._validator_is_jailed

alerter/src/configs/factory/alerts/cosmos_alerts.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ def get_chain_name(self, parent_id: str,
6969

7070
return None
7171

72-
7372
class CosmosNodeAlertsConfigsFactory(CosmosAlertsConfigsFactory):
7473
"""
7574
This class manages the node alerts configs. The configs are indexed by the
@@ -125,7 +124,9 @@ def add_new_config(self, chain_name: str, sent_configs: Dict) -> None:
125124
slashed=filtered['slashed'],
126125
node_is_syncing=filtered['node_is_syncing'],
127126
validator_is_syncing=filtered['validator_is_syncing'],
128-
validator_is_jailed=filtered['validator_is_jailed']
127+
validator_is_jailed=filtered['validator_is_jailed'],
128+
node_is_peered_with_sentinel=filtered['node_is_peered_with_sentinel'],
129+
validator_is_peered_with_sentinel=filtered['validator_is_peered_with_sentinel'],
129130
)
130131

131132
self._configs[chain_name] = cosmos_node_alerts_config

alerter/src/data_store/redis/store_keys.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
_key_cosmos_node_last_monitored_prometheus = 'CosmosNode11'
5757
_key_cosmos_node_last_monitored_cosmos_rest = 'CosmosNode12'
5858
_key_cosmos_node_last_monitored_tendermint_rpc = 'CosmosNode13'
59+
_key_cosmos_node_is_peered = 'CosmosNode14'
5960

6061
# CosmosNetworkX_<cosmos_network_id>
6162
_key_cosmos_network_proposals = 'CosmosNetwork1'
@@ -407,6 +408,10 @@ def get_cosmos_node_voting_power(cosmos_node_id: str) -> str:
407408
def get_cosmos_node_is_syncing(cosmos_node_id: str) -> str:
408409
return Keys._as_prefix(_key_cosmos_node_is_syncing) + cosmos_node_id
409410

411+
@staticmethod
412+
def get_cosmos_node_is_peered(cosmos_node_id: str) -> str:
413+
return Keys._as_prefix(_key_cosmos_node_is_peered) + cosmos_node_id
414+
410415
@staticmethod
411416
def get_cosmos_node_bond_status(cosmos_node_id: str) -> str:
412417
return Keys._as_prefix(_key_cosmos_node_bond_status) + cosmos_node_id

0 commit comments

Comments
 (0)