saltstack / saltstack/salt

[BUG] the carbon returner has a type error

Open
#61,284 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description
There is a type error in the carbon returner, probably caused by the python2 -> python3 migration that has not been handled yet.

Setup
One needs to set up a carbon instance for the carbon returner and schedule a munin plugin to be run by the salt-minion scheduler to run any munin plugin on the machine in question and return data using the carbon returner.

Please be as specific as possible and give set-up details.

  • [ X] on-prem machine
  • VM (Virtualbox, KVM, etc. please specify)
  • VM running on a cloud service, please be explicit and add details
  • container (Kubernetes, Docker, containerd, etc. please specify)
  • or a combination, please be explicit
  • jails if it is FreeBSD

Steps to Reproduce the behavior
Add the following to minion.conf

carbon.host: 10.0.0.1
carbon.port: 2003
carbon.mode: text
schedule:
    munin:
        function: munin.run
        args:
            - cpu
        seconds: 60
        returner: carbon

Restart the salt minion and wait for the scheduler to run. In the logs the error below appears:

2021-11-23 11:42:33,024 [salt.utils.schedule:875 ][ERROR   ][4032195] Unhandled exception running munin.run
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/salt/utils/schedule.py", line 866, in handle_func
    self.returners[ret_str](ret)
  File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1201, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1216, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/salt/returners/carbon_return.py", line 297, in returner
    _send(saltdata, metric_base, opts)
  File "/usr/lib/python3/dist-packages/salt/returners/carbon_return.py", line 255, in _send
    sent_bytes = sock.send(data[total_sent_bytes:])
TypeError: a bytes-like object is required, not 'str'

Expected behavior
The data should be sent to the graphite instance.

Screenshots
None.

Versions Report

Salt Version:
          Salt: 3004
 
Dependency Versions:
          cffi: Not Installed
      cherrypy: Not Installed
      dateutil: 2.8.1
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.11.3
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.0
  msgpack-pure: Not Installed
  mysql-python: 1.4.4
     pycparser: Not Installed
      pycrypto: Not Installed
  pycryptodome: 3.9.7
        pygit2: Not Installed
        Python: 3.9.2 (default, Feb 28 2021, 17:03:44)
  python-gnupg: Not Installed
        PyYAML: 5.3.1
         PyZMQ: 20.0.0
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.4
 
System Versions:
          dist: debian 11 bullseye
        locale: utf-8
       machine: x86_64
       release: 5.10.0-8-amd64
        system: Linux
       version: Debian GNU/Linux 11 bullseye

Additional context
I will post a pull request with a very simple fix to this problem.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in salt/returners/carbon_return.py, especially _send around line 255 and the returner call around line 297. Reproduce with the provided carbon and scheduler configuration, then verify the carbon returner sends the data without the reported TypeError and reaches the Graphite instance.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability-sre
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.