danihodovic / celery-exporter

A Prometheus exporter for Celery metrics
MIT License
385 stars 85 forks source link

kombu.exceptions.ContentDisallowed: Refusing to deserialize untrusted content of type pickle (application/x-python-serialize) #261

Closed HutchNunez closed 3 months ago

HutchNunez commented 12 months ago

Hello,

Currently running celery with Django. I require these configurations

CELERY_TASK_SERIALIZER = "pickle"
CELERY_ACCEPT_CONTENT = ["json", "pickle"]

however the celery-exporter container is throwing these errors

2023-07-24 13:41:01,397] ERROR in app: Exception on /metrics [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2528, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1825, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1823, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/app/src/http_server.py", line 32, in metrics
    current_app.config["metrics_puller"]()
  File "/app/src/exporter.py", line 139, in scrape
    self.track_queue_metrics()
  File "/app/src/exporter.py", line 219, in track_queue_metrics
    for worker, stats in (self.app.control.inspect().stats() or {}).items()
  File "/usr/local/lib/python3.10/site-packages/celery/app/control.py", line 243, in stats
    return self._request('stats')
  File "/usr/local/lib/python3.10/site-packages/celery/app/control.py", line 106, in _request
    return self._prepare(self.app.control.broadcast(
  File "/usr/local/lib/python3.10/site-packages/celery/app/control.py", line 741, in broadcast
    return self.mailbox(conn)._broadcast(
  File "/usr/local/lib/python3.10/site-packages/kombu/pidbox.py", line 344, in _broadcast
    return self._collect(reply_ticket, limit=limit,
  File "/usr/local/lib/python3.10/site-packages/kombu/pidbox.py", line 386, in _collect
    self.connection.drain_events(timeout=timeout)
  File "/usr/local/lib/python3.10/site-packages/kombu/connection.py", line 316, in drain_events
    return self.transport.drain_events(self.connection, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/kombu/transport/virtual/base.py", line 971, in drain_events
    get(self._deliver, timeout=timeout)
  File "/usr/local/lib/python3.10/site-packages/kombu/transport/redis.py", line 584, in get
    ret = self.handle_event(fileno, event)
  File "/usr/local/lib/python3.10/site-packages/kombu/transport/redis.py", line 566, in handle_event
    return self.on_readable(fileno), self
  File "/usr/local/lib/python3.10/site-packages/kombu/transport/redis.py", line 562, in on_readable
    chan.handlers[type]()
  File "/usr/local/lib/python3.10/site-packages/kombu/transport/redis.py", line 967, in _brpop_read
    self.connection._deliver(loads(bytes_to_str(item)), dest)
  File "/usr/local/lib/python3.10/site-packages/kombu/transport/virtual/base.py", line 991, in _deliver
    callback(message)
  File "/usr/local/lib/python3.10/site-packages/kombu/transport/virtual/base.py", line 624, in _callback
    return callback(message)
  File "/usr/local/lib/python3.10/site-packages/kombu/messaging.py", line 620, in _receive_callback
    decoded = None if on_m else message.decode()
  File "/usr/local/lib/python3.10/site-packages/kombu/message.py", line 194, in decode
    self._decoded_cache = self._decode()
  File "/usr/local/lib/python3.10/site-packages/kombu/message.py", line 198, in _decode
    return loads(self.body, self.content_type,
  File "/usr/local/lib/python3.10/site-packages/kombu/serialization.py", line 242, in loads
    raise self._for_untrusted_content(content_type, 'untrusted')
kombu.exceptions.ContentDisallowed: Refusing to deserialize untrusted content of type pickle (application/x-python-serialize)
[2023-07-24 13:42:01,397] ERROR in app: Exception on /metrics [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2528, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1825, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1823, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/app/src/http_server.py", line 32, in metrics
    current_app.config["metrics_puller"]()
  File "/app/src/exporter.py", line 139, in scrape
    self.track_queue_metrics()
  File "/app/src/exporter.py", line 219, in track_queue_metrics
    for worker, stats in (self.app.control.inspect().stats() or {}).items()
  File "/usr/local/lib/python3.10/site-packages/celery/app/control.py", line 243, in stats
    return self._request('stats')
  File "/usr/local/lib/python3.10/site-packages/celery/app/control.py", line 106, in _request
    return self._prepare(self.app.control.broadcast(
  File "/usr/local/lib/python3.10/site-packages/celery/app/control.py", line 741, in broadcast
    return self.mailbox(conn)._broadcast(
  File "/usr/local/lib/python3.10/site-packages/kombu/pidbox.py", line 344, in _broadcast
    return self._collect(reply_ticket, limit=limit,
  File "/usr/local/lib/python3.10/site-packages/kombu/pidbox.py", line 386, in _collect
    self.connection.drain_events(timeout=timeout)
  File "/usr/local/lib/python3.10/site-packages/kombu/connection.py", line 316, in drain_events
    return self.transport.drain_events(self.connection, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/kombu/transport/virtual/base.py", line 971, in drain_events
    get(self._deliver, timeout=timeout)
  File "/usr/local/lib/python3.10/site-packages/kombu/transport/redis.py", line 584, in get
    ret = self.handle_event(fileno, event)
  File "/usr/local/lib/python3.10/site-packages/kombu/transport/redis.py", line 566, in handle_event
    return self.on_readable(fileno), self
  File "/usr/local/lib/python3.10/site-packages/kombu/transport/redis.py", line 562, in on_readable
    chan.handlers[type]()
  File "/usr/local/lib/python3.10/site-packages/kombu/transport/redis.py", line 967, in _brpop_read
    self.connection._deliver(loads(bytes_to_str(item)), dest)
  File "/usr/local/lib/python3.10/site-packages/kombu/transport/virtual/base.py", line 991, in _deliver
    callback(message)
  File "/usr/local/lib/python3.10/site-packages/kombu/transport/virtual/base.py", line 624, in _callback
    return callback(message)
  File "/usr/local/lib/python3.10/site-packages/kombu/messaging.py", line 620, in _receive_callback
    decoded = None if on_m else message.decode()
  File "/usr/local/lib/python3.10/site-packages/kombu/message.py", line 194, in decode
    self._decoded_cache = self._decode()
  File "/usr/local/lib/python3.10/site-packages/kombu/message.py", line 198, in _decode
    return loads(self.body, self.content_type,
  File "/usr/local/lib/python3.10/site-packages/kombu/serialization.py", line 242, in loads
    raise self._for_untrusted_content(content_type, 'untrusted')
kombu.exceptions.ContentDisallowed: Refusing to deserialize untrusted content of type pickle (application/x-python-serialize)
[ec2-user@ip-172-31-29-0 monitoring]$ 
LuYanFCP commented 11 months ago

@HutchNunez Hello, you can add cli args like --accept-content=json,pickle,application/json,application/json,application/x-python-serialize when docker start or direct executepython cli.py --accept-content=json,pickle,application/json,application/json,application/x-python-serialize

RemiDesgrange commented 6 months ago

It starts celery-exporter, but then we have a kombu.exceptions.SerializerNotInstalled: No encoder/decoder installed for application.

rojinebrahimi commented 3 months ago

I have the same issue; does anyone know how to solve it?

danihodovic commented 3 months ago

Both your Celery setup and the Celery-Exporter have to accept the same content type

See this CLI argument: https://github.com/danihodovic/celery-exporter/blob/1496ac0314f427ccb4cdd275877d123adf85a276/src/cli.py#L44

rojinebrahimi commented 3 months ago

Both your Celery setup and the Celery-Exporter have to accept the same content type

See this CLI argument: https://github.com/danihodovic/celery-exporter/blob/1496ac0314f427ccb4cdd275877d123adf85a276/src/cli.py#L44

Thank you! Resolved it.