Skip to content

Commit

Permalink
Fix Solana healthcheck (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
namikmesic authored Sep 15, 2022
1 parent 892f1d6 commit 4a1d0da
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/collectors/solana.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def is_connected(self) -> bool:
response = requests.get(self.health_uri, timeout=cfg.response_timeout)
response.raise_for_status()
except (IOError, requests.HTTPError) as err:
logger.error("Health check failed for {}.".format(strip_url(self.health_uri)))
logger.error("Health check failed for {}: {}".format(strip_url(self.health_uri), err))
return False
return response.ok

Expand Down
2 changes: 1 addition & 1 deletion src/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _instantiate_conflux(self):

def _instantiate_solana(self):
for item in cfg.endpoints:
logger.info("Initializing solana node {}".format(strip_url(item['ws_url'])))
logger.info("Initializing solana node {}".format(strip_url(item['https_url'])))
self.collectors.append(solana_collector(item['ws_url'], item['https_url'], item['provider']))
self.labels = self.collectors[0].labels

Expand Down
15 changes: 11 additions & 4 deletions src/helpers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import urllib.parse

def strip_url(url):
return urllib.parse.urlparse(url).netloc
"""This function strips the url from all parameters, usernames and passwords.
It is used to safely log errors without exposing keys and authentication parameters."""
return urllib.parse.urlparse(url).hostname


def url_join(url, path):
return urllib.parse.urljoin(url, path)
def url_join(url, target_path):
"""Function takes url, and returns url + target path. This function also preserves
all of the url parameters if they are present.
This is important since different RPCs use different auth mechanisms (path or parameter)"""
scheme, netloc, path, params, query, fragment = urllib.parse.urlparse(url)
path = path + target_path
path = path.replace('//', '/')
return urllib.parse.urlunparse((scheme, netloc, path, params, query, fragment))

0 comments on commit 4a1d0da

Please sign in to comment.