Add ability to see history of http functions invocations

This commit is contained in:
Peter Stockings
2023-12-18 20:33:58 +11:00
parent 678e978b4b
commit 6f46198693
4 changed files with 77 additions and 3 deletions

12
app.py
View File

@@ -139,6 +139,18 @@ def delete_http_function():
except Exception as e:
return jsonify({"status": 'error', "message": str(e)}), 500
@ app.route("/dashboard/http_functions/logs", methods=["GET"])
def get_http_function_logs():
name = request.args.get('name')
http_function = db.get_http_function(name)
if not http_function:
return jsonify({'error': 'Function not found'}), 404
http_function_id = http_function['id']
http_function_invocations = db.get_http_function_invocations(http_function_id)
return render_template("dashboard/http_functions/logs.html", name=name, http_function_invocations=http_function_invocations)
@ app.route("/dashboard/timer_functions", methods=["GET"])
def dashboard_timer_functions():
return render_template("dashboard/timer_functions.html")

8
db.py
View File

@@ -76,3 +76,11 @@ class DataBase():
def add_http_function_invocation(self, http_function_id, status, request_data, response_data, logs):
self.execute(
'INSERT INTO http_function_invocations (http_function_id, status, request_data, response_data, logs) VALUES (%s, %s, %s, %s, %s)', [http_function_id, status, json.dumps(request_data), json.dumps(response_data), json.dumps(logs)], commit=True)
def get_http_function_invocations(self, http_function_id):
http_function_invocations = self.execute(
"""SELECT id, http_function_id, STATUS, invocation_time, request_data, response_data, LOGS
FROM http_function_invocations
WHERE http_function_id=9
ORDER BY invocation_time DESC""", [http_function_id])
return http_function_invocations

View File

@@ -47,9 +47,9 @@
<td class="p-4 align-middle [&amp;:has([role=checkbox])]:pr-0 hidden md:table-cell" data-id="68">
<button
class="inline-flex items-center justify-center text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-9 rounded-md px-3"
data-id="69" hx-get="{{ url_for('client', function=function.name) }}" hx-target="#container"
hx-swap="innerHTML">
Try
data-id="69" hx-get="{{ url_for('get_http_function_logs', name=function.name) }}"
hx-target="#container" hx-swap="innerHTML">
Logs
</button>
<button
class="inline-flex items-center justify-center text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-9 rounded-md px-3"
@@ -57,6 +57,12 @@
hx-target="#container" hx-swap="innerHTML">
Edit
</button>
<button
class="inline-flex items-center justify-center text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-9 rounded-md px-3"
data-id="69" hx-get="{{ url_for('client', function=function.name) }}" hx-target="#container"
hx-swap="innerHTML">
Try
</button>
</td>
</tr>
{% endfor %}

View File

@@ -0,0 +1,48 @@
<div class="flex items-center" data-id="51">
<h1 class="font-semibold text-lg md:text-2xl" data-id="52">Logs: <span class="font-mono">{{ name }}</span></h1>
<button
class="inline-flex items-center justify-center text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-9 rounded-md px-3 ml-auto"
hx-get="{{ url_for('dashboard_http_functions') }}" hx-target="#container" hx-swap="innerHTML">
Cancel
</button>
</div>
<div class="grid grid-cols-4 gap-4 p-4">
<!-- Headers -->
<div class="font-medium text-muted-foreground">Timestamp</div>
<div class="font-medium text-muted-foreground">Request</div>
<div class="font-medium text-muted-foreground">Response</div>
<div class="font-medium text-muted-foreground">Logs</div>
<!-- Data Rows -->
{% for invocation in http_function_invocations %}
<!-- Timestamp and Status -->
<div class="flex items-center space-x-2">
<span>{{ invocation.invocation_time.strftime('%Y-%m-%d %H:%M:%S') }}</span>
<button
class="{{ 'bg-green-400' if invocation.status == 'SUCCESS' else 'bg-red-400' }} hover:bg-opacity-75 text-white font-bold rounded-full h-fit p-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="{{ 'M5 13l4 4L19 7' if invocation.status == 'SUCCESS' else 'M6 18L18 6M6 6l12 12' }}"></path>
</svg>
</button>
</div>
<!-- Request Data -->
<div class="font-mono text-gray-400 overflow-auto">
{{ invocation.request_data }}
</div>
<!-- Response Data -->
<div class="font-mono text-gray-400 overflow-auto">
{{ invocation.response_data }}
</div>
<!-- Logs -->
<div class="space-y-1">
{% for log in invocation.logs %}
<div class="font-mono text-gray-400">{{ log }}</div>
{% endfor %}
</div>
{% endfor %}
</div>