Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import numpy as np
|
|
| 4 |
import gradio as gr
|
| 5 |
import requests
|
| 6 |
import pandas as pd
|
| 7 |
-
import datetime
|
| 8 |
from typing import List, Dict, Any
|
| 9 |
import hashlib
|
| 10 |
|
|
@@ -67,25 +67,34 @@ class BusinessImpactCalculator:
|
|
| 67 |
self.revenue_per_request = revenue_per_request
|
| 68 |
|
| 69 |
def calculate_impact(self, event: ReliabilityEvent, duration_minutes: int = 5) -> Dict[str, Any]:
|
| 70 |
-
"""
|
| 71 |
|
| 72 |
-
#
|
| 73 |
-
|
| 74 |
-
throughput_reduction = max(0, 1 - (event.throughput / normal_throughput))
|
| 75 |
|
| 76 |
-
#
|
| 77 |
-
|
| 78 |
-
self.revenue_per_request * (duration_minutes / 60))
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
# Severity classification
|
| 84 |
-
if revenue_loss >
|
| 85 |
severity = "CRITICAL"
|
| 86 |
elif revenue_loss > 100 or affected_users > 1000:
|
| 87 |
severity = "HIGH"
|
| 88 |
-
elif revenue_loss >
|
| 89 |
severity = "MEDIUM"
|
| 90 |
else:
|
| 91 |
severity = "LOW"
|
|
@@ -94,7 +103,7 @@ class BusinessImpactCalculator:
|
|
| 94 |
'revenue_loss_estimate': round(revenue_loss, 2),
|
| 95 |
'affected_users_estimate': affected_users,
|
| 96 |
'severity_level': severity,
|
| 97 |
-
'throughput_reduction_pct': round(
|
| 98 |
}
|
| 99 |
|
| 100 |
business_calculator = BusinessImpactCalculator()
|
|
@@ -285,7 +294,7 @@ def submit_event(component, latency, error_rate, throughput, cpu_util, memory_ut
|
|
| 285 |
|
| 286 |
if result["business_impact"]:
|
| 287 |
impact = result["business_impact"]
|
| 288 |
-
output_msg += f"\n💰 Business Impact: ${impact['revenue_loss_estimate']} | 👥 {impact['affected_users_estimate']} users"
|
| 289 |
|
| 290 |
if result["healing_actions"]:
|
| 291 |
actions = ", ".join(result["healing_actions"])
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
import requests
|
| 6 |
import pandas as pd
|
| 7 |
+
import datetime
|
| 8 |
from typing import List, Dict, Any
|
| 9 |
import hashlib
|
| 10 |
|
|
|
|
| 67 |
self.revenue_per_request = revenue_per_request
|
| 68 |
|
| 69 |
def calculate_impact(self, event: ReliabilityEvent, duration_minutes: int = 5) -> Dict[str, Any]:
|
| 70 |
+
"""Enhanced business impact calculation"""
|
| 71 |
|
| 72 |
+
# More realistic impact calculation
|
| 73 |
+
base_revenue_per_minute = 100 # Base revenue per minute for the service
|
|
|
|
| 74 |
|
| 75 |
+
# Calculate impact based on severity of anomalies
|
| 76 |
+
impact_multiplier = 1.0
|
|
|
|
| 77 |
|
| 78 |
+
if event.latency_p99 > 300:
|
| 79 |
+
impact_multiplier += 0.5 # High latency impact
|
| 80 |
+
if event.error_rate > 0.1:
|
| 81 |
+
impact_multiplier += 0.8 # High error rate impact
|
| 82 |
+
if event.cpu_util and event.cpu_util > 0.9:
|
| 83 |
+
impact_multiplier += 0.3 # Resource exhaustion impact
|
| 84 |
+
|
| 85 |
+
revenue_loss = base_revenue_per_minute * impact_multiplier * (duration_minutes / 60)
|
| 86 |
+
|
| 87 |
+
# More realistic user impact
|
| 88 |
+
base_users_affected = 1000 # Base user count
|
| 89 |
+
user_impact_multiplier = (event.error_rate * 10) + (max(0, event.latency_p99 - 100) / 500)
|
| 90 |
+
affected_users = int(base_users_affected * user_impact_multiplier)
|
| 91 |
|
| 92 |
# Severity classification
|
| 93 |
+
if revenue_loss > 500 or affected_users > 5000:
|
| 94 |
severity = "CRITICAL"
|
| 95 |
elif revenue_loss > 100 or affected_users > 1000:
|
| 96 |
severity = "HIGH"
|
| 97 |
+
elif revenue_loss > 50 or affected_users > 500:
|
| 98 |
severity = "MEDIUM"
|
| 99 |
else:
|
| 100 |
severity = "LOW"
|
|
|
|
| 103 |
'revenue_loss_estimate': round(revenue_loss, 2),
|
| 104 |
'affected_users_estimate': affected_users,
|
| 105 |
'severity_level': severity,
|
| 106 |
+
'throughput_reduction_pct': round(min(100, user_impact_multiplier * 100), 1)
|
| 107 |
}
|
| 108 |
|
| 109 |
business_calculator = BusinessImpactCalculator()
|
|
|
|
| 294 |
|
| 295 |
if result["business_impact"]:
|
| 296 |
impact = result["business_impact"]
|
| 297 |
+
output_msg += f"\n💰 Business Impact: ${impact['revenue_loss_estimate']} | 👥 {impact['affected_users_estimate']} users | 🚨 {impact['severity_level']}"
|
| 298 |
|
| 299 |
if result["healing_actions"]:
|
| 300 |
actions = ", ".join(result["healing_actions"])
|