|
14 | 14 | DEFAULT_GRAPHITE_CONTEXT = "" |
15 | 15 |
|
16 | 16 |
|
17 | | -@Publisher.supports_config(Parameter('graphite_host', default=DEFAULT_GRAPHITE_HOST), |
18 | | - Parameter('graphite_port', default=DEFAULT_GRAPHITE_PORT), |
19 | | - Parameter('graphite_context', default=DEFAULT_GRAPHITE_CONTEXT), |
20 | | - Parameter('publish_to_graphite', type=bool), |
21 | | - Parameter('output_file', type=str)) |
| 17 | +@Publisher.supports_config( |
| 18 | + Parameter("graphite_host", default=DEFAULT_GRAPHITE_HOST), |
| 19 | + Parameter("graphite_port", default=DEFAULT_GRAPHITE_PORT), |
| 20 | + Parameter("max_retries", default=2, comment="Number of retries allowed to send data to Graphite."), |
| 21 | + Parameter("retry_interval", default=60, comment="Number of seconds to wait between retries."), |
| 22 | + Parameter("graphite_context", default=DEFAULT_GRAPHITE_CONTEXT), |
| 23 | + Parameter("publish_to_graphite", type=bool), |
| 24 | + Parameter("output_file", type=str), |
| 25 | +) |
22 | 26 | class GenericPublisher(Publisher.Publisher, metaclass=abc.ABCMeta): |
23 | 27 |
|
24 | 28 | def __init__(self, config): |
25 | 29 | super().__init__(config) |
26 | | - self.graphite_host = config.get('graphite_host', DEFAULT_GRAPHITE_HOST) |
27 | | - self.graphite_port = config.get('graphite_port', DEFAULT_GRAPHITE_PORT) |
28 | | - self.graphite_context_header = config.get('graphite_context', DEFAULT_GRAPHITE_CONTEXT) |
29 | | - self.publish_to_graphite = config.get('publish_to_graphite') |
30 | | - self.output_file = config.get('output_file') |
| 30 | + self.graphite_host = config.get("graphite_host", DEFAULT_GRAPHITE_HOST) |
| 31 | + self.graphite_port = config.get("graphite_port", DEFAULT_GRAPHITE_PORT) |
| 32 | + self.graphite_context_header = config.get("graphite_context", DEFAULT_GRAPHITE_CONTEXT) |
| 33 | + self.max_retries = config.get("max_retries", 2) |
| 34 | + self.retry_interval = config.get("retry_interval", 60) |
| 35 | + self.publish_to_graphite = config.get("publish_to_graphite") |
| 36 | + self.output_file = config.get("output_file") |
31 | 37 | self.logger = self.logger.bind(class_module=__name__.split(".")[-1], ) |
32 | 38 |
|
33 | 39 | @classmethod |
@@ -60,11 +66,14 @@ def publish(self, data_block): |
60 | 66 | self.logger.exception(f"Failed to extract {product} from data block.") |
61 | 67 | return |
62 | 68 | if self.graphite_host and self.publish_to_graphite: |
63 | | - end_point = graphite.Graphite(host=self.graphite_host, |
64 | | - pickle_port=self.graphite_port) |
65 | | - end_point.send_dict(self.graphite_context(data)[0], |
66 | | - self.graphite_context(data)[1], |
67 | | - debug_print=False, |
68 | | - send_data=True) |
| 69 | + end_point = graphite.Graphite(host=self.graphite_host, pickle_port=self.graphite_port) |
| 70 | + end_point.send_dict( |
| 71 | + self.graphite_context(data)[0], |
| 72 | + self.graphite_context(data)[1], |
| 73 | + debug_print=False, |
| 74 | + send_data=True, |
| 75 | + max_retries=self.max_retries, |
| 76 | + retry_interval=self.retry_interval, |
| 77 | + ) |
69 | 78 | if not self.output_file: |
70 | 79 | self.logger.debug(data.to_csv(self.output_file, index=False)) |
0 commit comments