Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,7 @@ whitelist.py
cloudbuild.yaml

# ignore docker related
Docker/.env*
Docker/.env*

# django admin static assests
static
53 changes: 53 additions & 0 deletions ddpui/admin/templates/static_admin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{% extends "admin/base_site.html" %}

{% block title %}Long-running flows{% endblock %}

{% block content %}
<h1>Long-running flows ({{nhours}} hrs)</h1>
{% for flow_run in flow_runs %}
<div class="module">
<h2><a href="{{ flow_run.flow_run_url }}" target="_blank" style="text-decoration: underline;">Flow Run</a></h2>
<p>State: {{ flow_run.state_name }}</p>
{% if flow_run.org_slug %}
<p>Org Slug: {{ flow_run.org_slug }}</p>
{% endif %}
{% if flow_run.tasks %}
<p>Tasks: {{ flow_run.tasks }}</p>
{% endif %}
{% if flow_run.flow_name %}
<p>Flow Name: {{ flow_run.flow_name }}</p>
{% endif %}
{% if flow_run.connection_id %}
{% if flow_run.connection_url %}
<p>Connection: <a href="{{ flow_run.connection_url }}">{{ flow_run.connection_id }}</a></p>
{% else %}
<p>Connection ID: {{ flow_run.connection_id }}</p>
{% endif %}
{% endif %}
<hr>
</div>
{% endfor %}

<h1>Airbyte workspaces</h1>
{% for w in workspaces %}
<div class="module">
<h2>Org: {{w.org_slug}}</h2>
<p>Workspace: <a href="{{ w.workspace_url }}" style="text-decoration: underline;">{{ w.workspace_id }}</a></p>
<hr>
</div>
{% endfor %}


<h1>LLM feedback</h1>
{% for session in llm_sessions %}
<div class="module">
<h2>Org: {{session.org_slug}}</h2>
{% for res in session.response %}
<p>Prompt: {{res.prompt}}</p>
<p>Response: {{res.response}}</p>
{% endfor %}
<p>Feedback: {{session.feedback}}</p>
<hr>
</div>
{% endfor %}
{% endblock %}
60 changes: 60 additions & 0 deletions ddpui/admin/views/custom_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from django.shortcuts import render
from ddpui.models.tasks import OrgTask
from ddpui.models.org import Org
from ddpui.models.llm import LlmSession
from ddpui.ddpprefect.prefect_service import get_long_running_flow_runs
from ddpui.utils.helpers import find_key_in_dictionary


def orgs_index_view(request):
nhours = 2
flow_runs = get_long_running_flow_runs(nhours)
context = {"flow_runs": [], "nhours": nhours, "workspaces": [], "llm_sessions": []}

# airbyte workspaces
for org in Org.objects.order_by("name"):
url = f"http://localhost:8000/workspaces/{org.airbyte_workspace_id}"
context["workspaces"].append(
{"org_slug": org.slug, "workspace_url": url, "workspace_id": org.airbyte_workspace_id}
)

# llm feedbacks if any
for session in LlmSession.objects.filter(feedback__isnull=False).order_by("-updated_at"):
context["llm_sessions"].append(
{
"org_slug": session.org.slug,
"response": session.response,
"feedback": session.feedback,
"user_prompts": "\n".join(session.user_prompts),
}
)

# long running flows
for flow_run in flow_runs:
flow_run_data = {
"state_name": flow_run["state_name"],
"flow_run_url": f"http://localhost:4200/flow-runs/flow-run/{flow_run['id']}",
"org_slug": find_key_in_dictionary(flow_run["parameters"], "org_slug"),
"tasks": [
x["slug"] for x in find_key_in_dictionary(flow_run["parameters"], "tasks") or []
],
"flow_name": find_key_in_dictionary(flow_run["parameters"], "flow_name"),
"connection_id": find_key_in_dictionary(flow_run["parameters"], "connection_id"),
"orgtask_org_slug": None,
"connection_url": None,
}

connection_id = flow_run_data["connection_id"]
if connection_id:
orgtask = OrgTask.objects.filter(connection_id=connection_id).first()
if orgtask:
flow_run_data["orgtask_org_slug"] = orgtask.org.slug
flow_run_data[
"connection_url"
] = f"http://localhost:8000/workspaces/{orgtask.org.airbyte_workspace_id}/connections/{connection_id}"
else:
flow_run_data["orgtask_org_slug"] = connection_id

context["flow_runs"].append(flow_run_data)

return render(request, "static_admin.html", context)
8 changes: 7 additions & 1 deletion ddpui/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "static")
# # Additional locations of static files
# STATICFILES_DIRS = [
# os.path.join(BASE_DIR, "assests"),
# ]

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
Expand Down Expand Up @@ -125,7 +131,7 @@
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"DIRS": [os.path.join(BASE_DIR, "ddpui", "admin", "templates")],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
Expand Down
7 changes: 7 additions & 0 deletions ddpui/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from django.contrib import admin
from django.urls import include, path
from django.http import HttpResponse
from django.conf import settings
from django.conf.urls.static import static

Check warning on line 6 in ddpui/urls.py

View check run for this annotation

Codecov / codecov/patch

ddpui/urls.py#L5-L6

Added lines #L5 - L6 were not covered by tests

from ddpui.routes import src_api
from ddpui.html.docs import get_dbt_docs
Expand All @@ -11,6 +13,8 @@
from ddpui.websockets.airbyte_consumer import SourceCheckConnectionConsumer
from ddpui.websockets.airbyte_consumer import DestinationCheckConnectionConsumer

from ddpui.admin.views.custom_views import orgs_index_view

Check warning on line 16 in ddpui/urls.py

View check run for this annotation

Codecov / codecov/patch

ddpui/urls.py#L16

Added line #L16 was not covered by tests


def trigger_error(request): # pylint: disable=unused-argument # skipcq PYK-W0612
"""endpoint to test sentry"""
Expand All @@ -23,6 +27,7 @@


urlpatterns = [
path("admin/orgs/", orgs_index_view, name="orgs_index_view"),
path("admin/", admin.site.urls),
path("healthcheck", healthcheck),
path("docs/<tokenhex>/", get_dbt_docs),
Expand All @@ -32,6 +37,8 @@
path("", src_api.urls),
]

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Check warning on line 40 in ddpui/urls.py

View check run for this annotation

Codecov / codecov/patch

ddpui/urls.py#L40

Added line #L40 was not covered by tests

# socket endpoints
ws_urlpatterns = [
path("wss/data_insights/", DataInsightsConsumer.as_asgi()),
Expand Down