Skip to content

Adapted the graphite sender plugin for new Python plugin API#877

Closed
dmitrkul wants to merge 1 commit intobareos:masterfrom
dmitrkul:master
Closed

Adapted the graphite sender plugin for new Python plugin API#877
dmitrkul wants to merge 1 commit intobareos:masterfrom
dmitrkul:master

Conversation

@dmitrkul
Copy link

@dmitrkul dmitrkul commented Jun 30, 2021

I have adapted the plugin according to the recommendations in the documentation https://docs.bareos.org/TasksAndConcepts/Plugins.html#porting-existing-python-plugins.

But after the changes, all backup jobs crash with this problem:

30-Jun 10:43 bareos:director JobId 17: Fatal error: bareosdir: Traceback (most recent call last):
File "/usr/lib/bareos/plugins/BareosDirWrapper.py", line 40, in handle_plugin_event
return bareos_dir_plugin_object.handle_plugin_event(event)
File "/usr/lib/bareos/plugins/BareosDirPluginGraphiteSender.py", line 72, in handle_plugin_event
super(BareosDirPluginGraphiteSender, self).handle_plugin_event(event)
File "/usr/lib/bareos/plugins/BareosDirPluginBaseclass.py", line 130, in handle_plugin_event
"bDirEventJobRun event triggered at Unix time %s\n" % (self.jobRunTime),
RuntimeError: ../../../../../../core/src/plugins/dird/python/module/bareosdir.cc:357 :plugin_ctx is unset

In debug I see that context is set

bareos:director (150): dird/dir_plugins.cc:517-0 === enter NewPlugins ===
bareos:director (150): dird/dir_plugins.cc:525-0 dir-plugin-list size=1
bareos:director (150): dird/dir_plugins.cc:393-0 Instantiate dir-plugin_ctx_list=7fcd480d92e0 JobId=19
bareos:director (150): dird/dir_plugins.cc:789-0 dir-plugin: Plugin registered event=11
bareos:director (150): python/python-dir.cc:578-0 python3-dir: Trying to load module with name bareos-dir-graphite-sender
bareos:director (150): python/python-dir.cc:592-0 python3-dir: Successfully loaded module with name bareos-dir-graphite-sender
bareos:director (100): module/bareosdir.cc:359-0 python3-dir-mod: Constructor called in module BareosDirPluginBaseclass
bareos:director (150): module/bareosdir.cc:413-0 python3-dir-mod: PyBareosRegisterEvents registering event 1
bareos:director (150): dird/dir_plugins.cc:789-0 dir-plugin: Plugin registered event=1
bareos:director (150): module/bareosdir.cc:413-0 python3-dir-mod: PyBareosRegisterEvents registering event 2
bareos:director (150): dird/dir_plugins.cc:789-0 dir-plugin: Plugin registered event=2
bareos:director (150): module/bareosdir.cc:413-0 python3-dir-mod: PyBareosRegisterEvents registering event 3
bareos:director (150): dird/dir_plugins.cc:789-0 dir-plugin: Plugin registered event=3
bareos:director (150): module/bareosdir.cc:413-0 python3-dir-mod: PyBareosRegisterEvents registering event 4
bareos:director (150): dird/dir_plugins.cc:789-0 dir-plugin: Plugin registered event=4
bareos:director (150): dird/dir_plugins.cc:594-0 dir-plugin: return Job name=ldap01.msk.avito.ru-ldap-job.2021-06-30_12.17.13_10
bareos:director (150): dird/dir_plugins.cc:604-0 dir-plugin: return bDirVarLevel=F
bareos:director (150): dird/dir_plugins.cc:609-0 dir-plugin: return bDirVarType=B
bareos:director (150): dird/dir_plugins.cc:589-0 dir-plugin: return bDirVarJobId=19
bareos:director (150): dird/dir_plugins.cc:614-0 dir-plugin: return bDirVarClient=ldap01.msk.avito.ru-fd
bareos:director (150): dird/dir_plugins.cc:682-0 dir-plugin: return bDirVarJobStatus=C
bareos:director (150): dird/dir_plugins.cc:687-0 dir-plugin: return bDirVarPriority=10
bareos:director (100): module/bareosdir.cc:359-0 python3-dir-mod: JobName = ldap01.msk.avito.ru-ldap-job.2021-06-30_12.17.13_10 - level = F - type = 66 - Id = 19 - Client = ldap01.msk.avito.ru-fd - jobStatus = 67 - Priority = 10 - BareosDirPluginBaseclass
bareos:director (100): module/bareosdir.cc:359-0 python3-dir-mod: plugin def parser called with
bareos:director (100): module/bareosdir.cc:359-0 python3-dir-mod: key:val = :bareos:director (150): dird/dir_plugins.cc:227-0 dir-plugin_ctx_list=7fcd480d92e0 JobId=19

But

bareos:director (150): dird/dir_plugins.cc:227-19 dir-plugin_ctx_list=7fcd480d92e0 JobId=19
bareos:director (150): include/python_plugins_common.inc:124-19 bareosdir: Traceback (most recent call last):
File "/usr/lib/bareos/plugins/BareosDirWrapper.py", line 40, in handle_plugin_event
return bareos_dir_plugin_object.handle_plugin_event(event)
File "/usr/lib/bareos/plugins/BareosDirPluginGraphiteSender.py", line 72, in handle_plugin_event
super(BareosDirPluginGraphiteSender, self).handle_plugin_event(event)
File "/usr/lib/bareos/plugins/BareosDirPluginBaseclass.py", line 130, in handle_plugin_event
"bDirEventJobRun event triggered at Unix time %s\n" % (self.jobRunTime),
RuntimeError: ../../../../../../core/src/plugins/dird/python/module/bareosdir.cc:357 :plugin_ctx is unset

…s 20 documentation

Thank you for contributing to the Bareos Project!

Please check

  • Short description and the purpose of this PR is present above this paragraph
  • Your name is present in the AUTHORS file (optional)

If you have any questions or problems, please give a comment in the PR.

Helpful documentation and best practices

Checklist for the reviewer of the PR (will be processed by the Bareos team)

General
  • PR name is meaningful
  • Purpose of the PR is understood
  • Separate commit for this PR in the CHANGELOG.md, PR number referenced is same
  • Commit descriptions are understandable and well formatted
Source code quality
  • Source code changes are understandable
  • Variable and function names are meaningful
  • Code comments are correct (logically and spelling)
  • Required documentation changes are present and part of the PR
  • bareos-check-sources --since-merge does not report any problems
  • git status should not report modifications in the source tree after building and testing
Tests
  • Decision taken that a system- or unittest is required (if not, then remove this paragraph)
  • The decision towards a systemtest is reasonable compared to a unittest
  • Testname matches exactly what is being tested
  • Output of the test leads quickly to the origin of the fault

@dmitrkul dmitrkul changed the title Some changes in python graphite sender plugin by recommends of bareo… I have adapted the graphite sender plugin for new Python plugin API Jun 30, 2021
@dmitrkul dmitrkul changed the title I have adapted the graphite sender plugin for new Python plugin API Adapted the graphite sender plugin for new Python plugin API Jun 30, 2021
@pstorz pstorz requested a review from aussendorf July 1, 2021 09:09
@aussendorf
Copy link
Contributor

Hi @dmitrkul - thanks for contributing.

just for completeness: can you confirm that you've tested the patch and that it works with graphite? (sorry, I have no graphite environment ready to quickly test it).

This patch needs to be aligned with #PR881, as both affect the base-class.

@dmitrkul
Copy link
Author

dmitrkul commented Jul 8, 2021 via email

@dmitrkul
Copy link
Author

dmitrkul commented Jul 8, 2021 via email

@benibr
Copy link
Contributor

benibr commented Jul 19, 2021

I get the same error in #881 with another plugin I wrote:

File "/usr/lib/bareos/plugins/BareosDirPluginPrometheusExporter.py", line 190, in push_job_information
    JobMessage(M_INFO, "---------> {}\n".format(self.jobStatus))
RuntimeError: ../../../../../../core/src/plugins/dird/python/module/bareosdir.cc:378 :plugin_ctx is unset

Seems that the Error lies somewhere in the Python plugin, right?!

@dmitrkul
Copy link
Author

dmitrkul commented Jul 21, 2021 via email

@dmitrkul
Copy link
Author

dmitrkul commented Aug 3, 2021

Hi.
What are the next steps? Is there any plan to fix this error?

@sduehr
Copy link
Member

sduehr commented Sep 14, 2021

As we've had conflicting contributions for BareosDirPluginBaseclass.py from this PR and PR #881, I've created a the new PR #923 which also contains a fix for the plugin_ctx is unset runtime error.

Could you please modify this PR so that it only contains the graphite sender plugin?

@sduehr
Copy link
Member

sduehr commented Sep 14, 2021

Regarding the graphite plugin, I'd like to propose that you don't use
from bareosdir import *
but instead only
import bareosdir

and furthermore please replace
return bRCs[b'bRC_OK']
by
return bareosdir.bRC_OK

as well as
bDirEventType['bDirEventJobEnd']
by
bareosdir.bDirEventJobEnd

to adapt the code properly the modernized python plugin API.
See also https://docs.bareos.org/TasksAndConcepts/Plugins.html#modernization-of-the-python-plugin-api

@dmitrkul
Copy link
Author

dmitrkul commented Sep 15, 2021 via email

@sduehr
Copy link
Member

sduehr commented Sep 15, 2021

Ok, how did you test that?
The fix for the plugin_ctx is unset error is in the bareos-dir C code, so you must either locally build the branch https://github.com/bareos/bareos/tree/dev/sduehr/master/fix-python-dir-sd-plugin
or wait for the packages from the PR #923 to appear at
https://download.bareos.org/bareos/experimental/CD/PR-923/

Only replacing BareosDirPluginBaseclass.py does not fix the plugin_ctx is unset error.

@dmitrkul
Copy link
Author

dmitrkul commented Sep 15, 2021 via email

@sduehr sduehr requested review from sduehr and removed request for aussendorf September 30, 2021 13:23
Copy link
Member

@sduehr sduehr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have suggested some changes. Also please remove BareosDirPluginBaseclass.py from your fork/branch, as PR #923 has now been merged into master.

# we return OK in anyway, we do not want to produce Bareos errors just because of failing
# Nagios notifications
return bRCs['bRC_OK']
return bRCs[b'bRC_OK']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return bRCs[b'bRC_OK']
return bareosdir.bRC_OK

@@ -25,7 +25,6 @@
# Functions taken and adapted from bareos-dir.py

from bareosdir import *
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from bareosdir import *
import bareosdir

self.transmitResult()

return bRCs['bRC_OK']
return bRCs[b'bRC_OK']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return bRCs[b'bRC_OK']
return bareosdir.bRC_OK

self.metrics['bareos.jobs.{}.status.other'.format(job)] = 1

DebugMessage(context, 100, "Graphite metrics: {}\n".format(self.metrics))
DebugMessage(100, "Graphite metrics: {}\n".format(self.metrics))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DebugMessage(100, "Graphite metrics: {}\n".format(self.metrics))
bareosdir.DebugMessage(100, "Graphite metrics: {}\n".format(self.metrics))

Overload this method if you want ot submit your changes on a different way
'''
DebugMessage(context, 100, "Submitting metrics to {}:{}".format(self.collectorHost,
DebugMessage(100, "Submitting metrics to {}:{}".format(self.collectorHost,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DebugMessage(100, "Submitting metrics to {}:{}".format(self.collectorHost,
bareosdir.DebugMessage(100, "Submitting metrics to {}:{}".format(self.collectorHost,

sock.close()
except Exception as e:
JobMessage(context, bJobMessageType['M_WARNING'],
JobMessage(bJobMessageType['M_WARNING'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
JobMessage(bJobMessageType['M_WARNING'],
bareosdir.JobMessage(bareosdir.M_WARNING,

context, plugindef)
return bareos_dir_consts.bRCs['bRC_OK']
plugindef)
return bareosdir.bRCs[b'bRC_OK']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return bareosdir.bRCs[b'bRC_OK']
return bareosdir.bRC_OK

@sduehr
Copy link
Member

sduehr commented Oct 18, 2021

Hi,

meanwhile PR #923 has been merged into the master branch.
Could you please rebase your fork/branch to master or at least remove BareosDirPluginBaseclass.py and apply the suggested changes to resolve the merge conflict? And for sure please verify if the plugin works now.

@dmitrkul dmitrkul closed this Oct 19, 2021
@dmitrkul
Copy link
Author

dmitrkul commented Oct 19, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants