canonical / mysql-k8s-operator

A Charmed Operator for running MySQL on Kubernetes
https://charmhub.io/mysql-k8s
Apache License 2.0
8 stars 15 forks source link

logging-relation-changed fails behind proxy #408

Open gboutry opened 2 months ago

gboutry commented 2 months ago

Steps to reproduce

  1. deploy behind proxy
  2. relate logging relation
  3. see the failure

Expected behavior

Relating logging provider behind a proxy should not fail, except if the proxy has not authorized the URL. (which in turn is another issue, since artifact comes from github...)

Actual behavior

Requests to fetch https://github.com/canonical/loki-k8s-operator/releases/download/promtail-v2.5.0/promtail-static-amd64.gz fails from within the relation library.

Error

2024-04-23T13:00:24.668Z [container-agent] 2024-04-23 13:00:24 ERROR juju-log logging:152: Uncaught exception while in charm code:                                                                                                                       
2024-04-23T13:00:24.668Z [container-agent] Traceback (most recent call last):                                                                                                                                                                            
2024-04-23T13:00:24.668Z [container-agent]   File "/usr/lib/python3.10/urllib/request.py", line 1348, in do_open                                                                                                                                         
2024-04-23T13:00:24.668Z [container-agent]     h.request(req.get_method(), req.selector, req.data, headers,                                                                                                                                              
2024-04-23T13:00:24.668Z [container-agent]   File "/usr/lib/python3.10/http/client.py", line 1283, in request                                                                                                                                            
2024-04-23T13:00:24.668Z [container-agent]     self._send_request(method, url, body, headers, encode_chunked)                                                                                                                                            
2024-04-23T13:00:24.668Z [container-agent]   File "/usr/lib/python3.10/http/client.py", line 1329, in _send_request                                                                                                                                      
2024-04-23T13:00:24.668Z [container-agent]     self.endheaders(body, encode_chunked=encode_chunked)                                                                                                                                                      
2024-04-23T13:00:24.668Z [container-agent]   File "/usr/lib/python3.10/http/client.py", line 1278, in endheaders                                                                                                                                         
2024-04-23T13:00:24.668Z [container-agent]     self._send_output(message_body, encode_chunked=encode_chunked)                                                                                                                                            
2024-04-23T13:00:24.668Z [container-agent]   File "/usr/lib/python3.10/http/client.py", line 1038, in _send_output                                                                                                                                       
2024-04-23T13:00:24.668Z [container-agent]     self.send(msg)                                                                                                                                                                                            
2024-04-23T13:00:24.668Z [container-agent]   File "/usr/lib/python3.10/http/client.py", line 976, in send                                                                                                                                                
2024-04-23T13:00:24.668Z [container-agent]     self.connect()                                                                                                                                                                                            
2024-04-23T13:00:24.668Z [container-agent]   File "/usr/lib/python3.10/http/client.py", line 1448, in connect                                                                                                                                            
2024-04-23T13:00:24.668Z [container-agent]     super().connect()                                                                                                                                                                                         
2024-04-23T13:00:24.668Z [container-agent]   File "/usr/lib/python3.10/http/client.py", line 942, in connect                                                                                                                                             
2024-04-23T13:00:24.668Z [container-agent]     self.sock = self._create_connection(                                                                                                                                                                      
2024-04-23T13:00:24.668Z [container-agent]   File "/usr/lib/python3.10/socket.py", line 845, in create_connection                                                                                                                                        
2024-04-23T13:00:24.668Z [container-agent]     raise err                                                                                                                                                                                                 
2024-04-23T13:00:24.668Z [container-agent]   File "/usr/lib/python3.10/socket.py", line 833, in create_connection                                                                                                                                        
2024-04-23T13:00:24.668Z [container-agent]     sock.connect(sa)                                                                                                                                                                                          
2024-04-23T13:00:24.668Z [container-agent] OSError: [Errno 113] No route to host                                                                                                                                                                         
2024-04-23T13:00:24.668Z [container-agent]                                                                                                                                                                                                               
2024-04-23T13:00:24.668Z [container-agent] During handling of the above exception, another exception occurred:                                                                                                                                           
2024-04-23T13:00:24.668Z [container-agent]                                                                                                                                                                                                               
2024-04-23T13:00:24.668Z [container-agent] Traceback (most recent call last):                                                                                                                                                                            
2024-04-23T13:00:24.668Z [container-agent]   File "/var/lib/juju/agents/unit-mysql-0/charm/./src/charm.py", line 770, in <module>                                                                                                                        
2024-04-23T13:00:24.668Z [container-agent]     main(MySQLOperatorCharm)                                                                                                                                                                                  
2024-04-23T13:00:24.668Z [container-agent]   File "/var/lib/juju/agents/unit-mysql-0/charm/venv/ops/main.py", line 456, in main                                                                                                                          
2024-04-23T13:00:24.668Z [container-agent]     _emit_charm_event(charm, dispatcher.event_name)                                                                                                                                                           
2024-04-23T13:00:24.668Z [container-agent]   File "/var/lib/juju/agents/unit-mysql-0/charm/venv/ops/main.py", line 144, in _emit_charm_event                                                                                                             
2024-04-23T13:00:24.668Z [container-agent]     event_to_emit.emit(*args, **kwargs)                                                                                                                                                                       
2024-04-23T13:00:24.668Z [container-agent]   File "/var/lib/juju/agents/unit-mysql-0/charm/venv/ops/framework.py", line 351, in emit                                                                                                                     
2024-04-23T13:00:24.668Z [container-agent]     framework._emit(event)                                                                                                                                                                                    
2024-04-23T13:00:24.668Z [container-agent]   File "/var/lib/juju/agents/unit-mysql-0/charm/venv/ops/framework.py", line 853, in _emit                                                                                                                    
2024-04-23T13:00:24.668Z [container-agent]     self._reemit(event_path)                                                                                                                                                                                  
2024-04-23T13:00:24.668Z [container-agent]   File "/var/lib/juju/agents/unit-mysql-0/charm/venv/ops/framework.py", line 943, in _reemit                                                                                                                  
2024-04-23T13:00:24.668Z [container-agent]     custom_handler(event)                                                                                                                                                                                     
2024-04-23T13:00:24.668Z [container-agent]   File "/var/lib/juju/agents/unit-mysql-0/charm/lib/charms/loki_k8s/v0/loki_push_api.py", line 1835, in _on_relation_changed                                                                                  
2024-04-23T13:00:24.668Z [container-agent]     self._setup_promtail()                                                                                                                                                                                    
2024-04-23T13:00:24.668Z [container-agent]   File "/var/lib/juju/agents/unit-mysql-0/charm/lib/charms/loki_k8s/v0/loki_push_api.py", line 2272, in _setup_promtail                                                                                       
2024-04-23T13:00:24.668Z [container-agent]     self._obtain_promtail(promtail_binaries[self._arch])                                                                                                                                                      
2024-04-23T13:00:24.668Z [container-agent]   File "/var/lib/juju/agents/unit-mysql-0/charm/lib/charms/loki_k8s/v0/loki_push_api.py", line 1971, in _obtain_promtail                                                                                      
2024-04-23T13:00:24.668Z [container-agent]     self._download_and_push_promtail_to_workload(promtail_info)                                                                                                                                               
2024-04-23T13:00:24.668Z [container-agent]   File "/var/lib/juju/agents/unit-mysql-0/charm/lib/charms/loki_k8s/v0/loki_push_api.py", line 2093, in _download_and_push_promtail_to_workload                                                               
2024-04-23T13:00:24.668Z [container-agent]     with request.urlopen(promtail_info["url"]) as r:                                                                                                                                                          
2024-04-23T13:00:24.668Z [container-agent]   File "/usr/lib/python3.10/urllib/request.py", line 216, in urlopen                                                                                                                                          
2024-04-23T13:00:24.668Z [container-agent]     return opener.open(url, data, timeout) 
2024-04-23T13:00:24.668Z [container-agent]   File "/usr/lib/python3.10/urllib/request.py", line 519, in open                                                                                                                                             
2024-04-23T13:00:24.668Z [container-agent]     response = self._open(req, data)                                                                                                                                                                          
2024-04-23T13:00:24.668Z [container-agent]   File "/usr/lib/python3.10/urllib/request.py", line 536, in _open                                                                                                                                            
2024-04-23T13:00:24.668Z [container-agent]     result = self._call_chain(self.handle_open, protocol, protocol +                                                                                                                                          
2024-04-23T13:00:24.668Z [container-agent]   File "/usr/lib/python3.10/urllib/request.py", line 496, in _call_chain                                                                                                                                      
2024-04-23T13:00:24.668Z [container-agent]     result = func(*args)                                                                                                                                                                                      
2024-04-23T13:00:24.668Z [container-agent]   File "/usr/lib/python3.10/urllib/request.py", line 1391, in https_open                                                                                                                                      
2024-04-23T13:00:24.668Z [container-agent]     return self.do_open(http.client.HTTPSConnection, req,                                                                                                                                                     
2024-04-23T13:00:24.668Z [container-agent]   File "/usr/lib/python3.10/urllib/request.py", line 1351, in do_open                                                                                                                                         
2024-04-23T13:00:24.668Z [container-agent]     raise URLError(err)                                                                                                                                                                                       
2024-04-23T13:00:24.668Z [container-agent] urllib.error.URLError: <urlopen error [Errno 113] No route to host>

After setting proxies within a debug-code execution, the charm code managed to download the artifact.

Additional context

Newer versions of the library support reading proxy information from JUJU_... vars: https://github.com/canonical/loki-k8s-operator/blob/9f7580e9b441697246f566c63dd7bd93858c2a33/lib/charms/loki_k8s/v0/loki_push_api.py#L2123

github-actions[bot] commented 2 months ago

https://warthogs.atlassian.net/browse/DPE-4193