Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeEncode error with webhook sink when message contain a non-ASCII character #1117

Closed
Tassatux opened this issue Oct 9, 2023 · 2 comments
Labels
bug Something isn't working sink A new sink/Problem with a sink

Comments

@Tassatux
Copy link

Tassatux commented Oct 9, 2023

Describe the bug
UnicodeEncode error with webhook sink when finding message contain a non-ASCII character, like an emoji added by cpu_throttling enricher.

To Reproduce
Steps to reproduce the behavior:

  1. Configure a webhook sink
  2. Send Prometheus CPUThrottlingHigh alert

Expected behavior
The message should be encoded in utf-8 so bytes will be provided to requests.post() instead of unicode.

By default, if a python string (unicode) is provided to the http.client lib (used by requests), it will be encoded in latin-1 following RFC 2616.

Traceback

\u001b[32m2023-10-04 15:16:02.999 INFO     Loaded k8s pod netbox-prometheus-sd-fcc8c5c95-mv72k for alert CPUThrottlingHigh\u001b[0m
UnicodeEncodeError: 'latin-1' codec can't encode character '\\U0001f4d8' in position 194: Body ('📘') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.\u001b[0m
    raise UnicodeEncodeError(
  File \"/usr/local/lib/python3.9/http/client.py\
    body = _encode(body
  File \"/usr/local/lib/python3.9/http/client.py\
    self._send_request(method
  File \"/usr/local/lib/python3.9/http/client.py\
    super(HTTPConnection
  File \"/usr/local/lib/python3.9/site-packages/urllib3/connection.py\
    conn.request(method
  File \"/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py\
    httplib_response = self._make_request(
  File \"/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py\
    resp = conn.urlopen(
  File \"/usr/local/lib/python3.9/site-packages/requests/adapters.py\
    r = adapter.send(request
  File \"/usr/local/lib/python3.9/site-packages/requests/sessions.py\
    resp = self.send(prep
  File \"/usr/local/lib/python3.9/site-packages/requests/sessions.py\
    return session.request(method=method
  File \"/usr/local/lib/python3.9/site-packages/requests/api.py\
    return request('post'
  File \"/usr/local/lib/python3.9/site-packages/requests/api.py\
    r = requests.post(self.url
  File \"/app/src/robusta/core/sinks/webhook/webhook_sink.py\
Traceback (most recent call last):
None
 headers: 
\u001b[31m2023-10-04 15:16:01.011 ERROR    Webhook request error
@Tassatux Tassatux changed the title UnicodeDecode error with webhook sink when message contain a non-ASCII character UnicodeEncode error with webhook sink when message contain a non-ASCII character Oct 9, 2023
@aantn
Copy link
Collaborator

aantn commented Oct 11, 2023

Thanks for reporting - that looks like a bug!

Would you be interested in contributing a PR to fix? We are understaffed at the moment given world events, so it will take longer than usual for us to fix ourselves. Hope you understand!

@aantn
Copy link
Collaborator

aantn commented Oct 31, 2023

@swastik959 this is fixed now, right? Would it be alright to close?

@Sheeproid Sheeproid added bug Something isn't working sink A new sink/Problem with a sink labels Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sink A new sink/Problem with a sink
Projects
None yet
Development

No branches or pull requests

3 participants