Skip to content

Commit

Permalink
Merge pull request #83 from dynatrace-oss/PCLOUDS-2747-How-to-avoid-S…
Browse files Browse the repository at this point in the history
…NAT-port-exhaustion-issues

PCLOUDS-2747 Making sure we close each opened connection
  • Loading branch information
NematulloKozimov authored Aug 25, 2023
2 parents 1be069f + 8e46b5b commit e786148
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
10 changes: 9 additions & 1 deletion host.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,13 @@
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 3.0.0)"
}
},
"extensions": {
"eventHubs": {
"initialOffsetOptions": {
"type": "fromEnd",
"enqueuedTimeUtc": ""
}
}
}
}
15 changes: 9 additions & 6 deletions logs_ingest/self_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def push_time_series_to_azure(self):
resource_id = os.environ.get("RESOURCE_ID", None)
region = os.environ.get("REGION", None)
if not resource_id or not region:
logging.info("Please set RESOURCE_ID and REGION in application settings to send self monitoring metrics to Azure")
logging.info(
"Please set RESOURCE_ID and REGION in application settings to send self-monitoring metrics to Azure")
return
resource_id = resource_id[1:] if resource_id.startswith('/') else resource_id
url = f"https://{region}.monitoring.azure.com/{resource_id}/metrics"
Expand All @@ -76,15 +77,17 @@ def push_time_series_to_azure(self):

metric_name = self_monitoring_metric.get("data", "").get("baseData", "").get("metric", "")
try:
urllib.request.urlopen(req)
logging.debug(f'Successfully sent self monitoring metric ({metric_name}) to Azure')
with urllib.request.urlopen(req) as response:
response.read()
logging.debug(f'Successfully sent self-monitoring metric ({metric_name}) to Azure')
except HTTPError as e:
logging.exception(
f'Failed to push self monitoring metric ({metric_name}) to Azure: {e.code}, reason: {e.reason}", url: {url}',
f'Failed to push self-monitoring metric ({metric_name}) to Azure: {e.code}, reason: {e.reason}", url: {url}',
"sfm-push-http-exception")
except Exception as e:
logging.exception(f"Failed to push self monitoring metric ({metric_name}) to Azure. Reason is {type(e).__name__} {e}",
"sfm-push-failure-exception")
logging.exception(
f"Failed to push self-monitoring metric ({metric_name}) to Azure. Reason is {type(e).__name__} {e}",
"sfm-push-failure-exception")

def prepare_metric_data(self):
time = self.execution_time.isoformat() + "Z"
Expand Down

0 comments on commit e786148

Please sign in to comment.