diff options
author | Ilya Mashchenko <ilyamaschenko@gmail.com> | 2018-12-07 12:15:03 +0300 |
---|---|---|
committer | Chris Akritidis <43294513+cakrit@users.noreply.github.com> | 2018-12-07 10:15:03 +0100 |
commit | 5286dae8ebb09d2c9699cd38e8850c5481f3d742 (patch) | |
tree | 1d4706225c8e8d6fe76e0a626ac9b65c9f0c1133 /collectors/python.d.plugin/python_modules | |
parent | e096424786b36d0ba106c72b551a6ce37843be37 (diff) |
python.d.plugin update (#4936)
<!--
Describe the change in summary section, including rationale and degin decisions.
Include "Fixes #nnn" if you are fixing an existing issue.
In "Component Name" section write which component is changed in this PR. This
will help us review your PR quicker.
If you have more information you want to add, write them in "Additional
Information" section. This is usually used to help others understand your
motivation behind this change. A step-by-step reproduction of the problem is
helpful if there is no related issue.
-->
##### Summary
Fix: #4756
`python.d.plugin` updates:
* remove `retries` option
* make `penalty` configurable (enabled by default, max is 10 minutes)
> penalty indicates whether to apply penalty to update_every in case of failures.
> Penalty will increase every 5 failed updates in a row. Maximum penalty is 10 minutes.
> penalty: yes
##### Component Name
`python.d.plugin`
##### Additional Information
Diffstat (limited to 'collectors/python.d.plugin/python_modules')
-rw-r--r-- | collectors/python.d.plugin/python_modules/bases/FrameworkServices/SimpleService.py | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/collectors/python.d.plugin/python_modules/bases/FrameworkServices/SimpleService.py b/collectors/python.d.plugin/python_modules/bases/FrameworkServices/SimpleService.py index 9708ef7181..c7ab7f2445 100644 --- a/collectors/python.d.plugin/python_modules/bases/FrameworkServices/SimpleService.py +++ b/collectors/python.d.plugin/python_modules/bases/FrameworkServices/SimpleService.py @@ -18,6 +18,7 @@ RUNTIME_CHART_UPDATE = 'BEGIN netdata.runtime_{job_name} {since_last}\n' \ 'END\n' PENALTY_EVERY = 5 +MAX_PENALTY = 10 * 60 # 10 minutes class RuntimeCounters: @@ -26,7 +27,7 @@ class RuntimeCounters: :param configuration: <dict> """ self.update_every = int(configuration.pop('update_every')) - self.max_retries = int(configuration.pop('retries')) + self.do_penalty = configuration.pop('penalty') self.start_mono = 0 self.start_real = 0 @@ -34,6 +35,7 @@ class RuntimeCounters: self.penalty = 0 self.elapsed = 0 self.prev_update = 0 + self.runs = 1 def calc_next(self): @@ -49,10 +51,8 @@ class RuntimeCounters: def handle_retries(self): self.retries += 1 - if self.retries % PENALTY_EVERY: - return True - self.penalty = self.retries * self.update_every / 2 - return self.retries < self.max_retries + if self.do_penalty and self.retries % PENALTY_EVERY == 0: + self.penalty = round(min(self.retries * self.update_every / 2, MAX_PENALTY)) class SimpleService(Thread, PythonDLimitedLogger, OldVersionCompatibility, object): @@ -180,10 +180,7 @@ class SimpleService(Thread, PythonDLimitedLogger, OldVersionCompatibility, objec :return: None """ job = self._runtime_counters - self.debug('started, update frequency: {freq}, retries: {retries}'.format( - freq=job.update_every, - retries=job.max_retries - job.retries), - ) + self.debug('started, update frequency: {freq}'.format(freq=job.update_every)) while True: job.sleep_until_next() @@ -201,8 +198,7 @@ class SimpleService(Thread, PythonDLimitedLogger, OldVersionCompatibility, objec job.runs += 1 if not updated: - if not job.handle_retries(): - return + job.handle_retries() else: job.elapsed = int((monotonic() - job.start_mono) * 1e3) job.prev_update = job.start_real @@ -210,10 +206,10 @@ class SimpleService(Thread, PythonDLimitedLogger, OldVersionCompatibility, objec safe_print(RUNTIME_CHART_UPDATE.format(job_name=self.name, since_last=since, elapsed=job.elapsed)) - self.debug('update => [{status}] (elapsed time: {elapsed}, ' - 'retries left: {retries})'.format(status='OK' if updated else 'FAILED', - elapsed=job.elapsed if updated else '-', - retries=job.max_retries - job.retries)) + self.debug('update => [{status}] (elapsed time: {elapsed}, failed retries in a row: {retries})'.format( + status='OK' if updated else 'FAILED', + elapsed=job.elapsed if updated else '-', + retries=job.retries)) def update(self, interval): """ |