diff --git a/Makefile b/Makefile index c65327a44..be7337459 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,7 @@ help: Makefile @echo build-static: + rm -rf static/ make build-css make build-js python3 manage.py collectstatic diff --git a/controlpanel/api/models/app.py b/controlpanel/api/models/app.py index a5b5f0c59..9eff4f9a1 100644 --- a/controlpanel/api/models/app.py +++ b/controlpanel/api/models/app.py @@ -8,6 +8,7 @@ from django.db import models from django.db.models.signals import post_delete, post_save from django.dispatch import receiver +from django.template.loader import render_to_string from django.urls import reverse from django_extensions.db.fields import AutoSlugField from django_extensions.db.models import TimeStampedModel @@ -309,6 +310,19 @@ def auth_settings(self): def get_absolute_url(self): return reverse("manage-app", kwargs={"pk": self.pk}) + def get_logs_url(self, container="webapp", env="dev"): + """ + Builds a deep link to Kibana logs for the given container and environment. + """ + return render_to_string( + "includes/app-kibana-logs-url.html", + context={ + "namespace": self.namespace, + "container_name": container, + "env": env, + }, + ) + class AddCustomerError(Exception): pass diff --git a/controlpanel/frontend/jinja2/includes/app-deployment-settings.html b/controlpanel/frontend/jinja2/includes/app-deployment-settings.html index cc2364883..7dfff3dde 100644 --- a/controlpanel/frontend/jinja2/includes/app-deployment-settings.html +++ b/controlpanel/frontend/jinja2/includes/app-deployment-settings.html @@ -2,6 +2,8 @@ {% macro app_deployment_settings(app, env_name, app_domain, deployment_setting, request, csrf_input) %} {% set app_full_url = "https://" + app.app_url_name(env_name)+ "." + app_domain %} +

Namespace

+

{{ app.namespace }}-{{ env_name }}

If the app has been successfully deployed onto Cloud Platform, it can be accessed here:{{ app_full_url }}


@@ -127,4 +129,4 @@

App environment variables

-{% endmacro %} \ No newline at end of file +{% endmacro %} diff --git a/controlpanel/frontend/jinja2/includes/app-kibana-logs-url.html b/controlpanel/frontend/jinja2/includes/app-kibana-logs-url.html new file mode 100644 index 000000000..38740f357 --- /dev/null +++ b/controlpanel/frontend/jinja2/includes/app-kibana-logs-url.html @@ -0,0 +1 @@ +https://kibana.cloud-platform.service.justice.gov.uk/_plugin/kibana/app/discover#/?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now-24h,to:now))&_a=(columns:!(log),filters:!(('$state':(store:appState),meta:(alias:!n,disabled:!f,index:'167701b0-f8c0-11ec-b95c-1d65c3682287',key:kubernetes.namespace_name,negate:!f,params:(query:{{ namespace }}-{{ env }}),type:phrase),query:(match_phrase:(kubernetes.namespace_name:{{ namespace }}-{{ env }}))),('$state':(store:appState),meta:(alias:!n,disabled:!f,index:'167701b0-f8c0-11ec-b95c-1d65c3682287',key:kubernetes.container_name,negate:!f,params:(query:{{ container_name }}),type:phrase),query:(match_phrase:(kubernetes.container_name:{{ container_name }})))),index:'167701b0-f8c0-11ec-b95c-1d65c3682287',interval:auto,query:(language:kuery,query:''),sort:!()) diff --git a/controlpanel/frontend/jinja2/webapp-detail.html b/controlpanel/frontend/jinja2/webapp-detail.html index f15f70d2c..3fd6e0aa4 100644 --- a/controlpanel/frontend/jinja2/webapp-detail.html +++ b/controlpanel/frontend/jinja2/webapp-detail.html @@ -66,7 +66,10 @@

Source Code Repository

App logs

- {{ settings.KIBANA_BASE_URL }} + Logs are viewable in Kibana. Click the link below to view application logs for each environment: + {% for env, url in app_log_urls.items() %} +

{{ env.title() }} + {% endfor %}

App resources usage dashboard

diff --git a/controlpanel/frontend/views/app.py b/controlpanel/frontend/views/app.py index 79bb60908..a2da842f2 100644 --- a/controlpanel/frontend/views/app.py +++ b/controlpanel/frontend/views/app.py @@ -130,6 +130,10 @@ def get_context_data(self, **kwargs): context["repo_access_error_msg"] = access_repo_error_msg context["github_settings_access_error_msg"] = github_settings_access_error_msg + context["app_log_urls"] = {} + for env_name in context["deployments_settings"].keys(): + context["app_log_urls"].update({env_name: app.get_logs_url(env=env_name)}) + return context diff --git a/tests/api/models/test_app.py b/tests/api/models/test_app.py index 5ba10531c..6bede4ca5 100644 --- a/tests/api/models/test_app.py +++ b/tests/api/models/test_app.py @@ -222,3 +222,21 @@ def test_iam_role_arn(): def test_app_url_name(namespace, env, expected): app = App(namespace=namespace) assert app.app_url_name(env_name=env) == expected + + +@pytest.mark.parametrize("env", ["dev", "prod"], ids=["dev", "prod"]) +def test_get_logs_url(env): + expected = ( + "https://kibana.cloud-platform.service.justice.gov.uk/_plugin/kibana/app/discover#/?_g=(" + "filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now-24h,to:now))&_a=(columns:!" + "(log),filters:!(('$state':(store:appState),meta:(alias:!n,disabled:!f,index:'" + "167701b0-f8c0-11ec-b95c-1d65c3682287',key:kubernetes.namespace_name,negate:!f,params:(" + f"query:example-namespace-{env}),type:phrase),query:(match_phrase:(kubernetes." + f"namespace_name:example-namespace-{env}))),('$state':(store:appState),meta:(alias:!n" + ",disabled:!f,index:'167701b0-f8c0-11ec-b95c-1d65c3682287',key:kubernetes.container_name," + "negate:!f,params:(query:webapp),type:phrase),query:(match_phrase:(kubernetes." + "container_name:webapp)))),index:'167701b0-f8c0-11ec-b95c-1d65c3682287',interval:auto,query" + ":(language:kuery,query:''),sort:!())" + ) + app = App(namespace="example-namespace") + assert app.get_logs_url(env=env) == expected