From 35c6d6cd11f06141f2cdbf57a22c608997115c5d Mon Sep 17 00:00:00 2001 From: Natalie Clara Petersen Date: Fri, 7 Feb 2025 08:58:37 +0100 Subject: [PATCH] =?UTF-8?q?Exceptions=20vises=20p=C3=A5=20dashboard=20som?= =?UTF-8?q?=20json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/exceptions.py | 17 ++++++++++ .../database/exception_info.py | 11 ++++++- flask_monitoringdashboard/frontend/js/app.js | 7 ++++ .../frontend/js/controllers/exceptionInfo.js | 32 +++++++++++++++++++ .../frontend/js/services/menu.js | 2 +- .../static/elements/menu.html | 5 +++ .../static/pages/new_dashboard.html | 5 +++ flask_monitoringdashboard/views/endpoint.py | 15 ++++++++- 8 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 flask_monitoringdashboard/controllers/exceptions.py create mode 100644 flask_monitoringdashboard/frontend/js/controllers/exceptionInfo.js create mode 100644 flask_monitoringdashboard/static/pages/new_dashboard.html diff --git a/flask_monitoringdashboard/controllers/exceptions.py b/flask_monitoringdashboard/controllers/exceptions.py new file mode 100644 index 000000000..a805d03b2 --- /dev/null +++ b/flask_monitoringdashboard/controllers/exceptions.py @@ -0,0 +1,17 @@ +from flask_monitoringdashboard.database.exception_info import get_exceptions_with_timestamps + +def get_exceptions_with_timestamp(session): + """ + :param session: session for the database + :param endpoints: a list of endpoints, encoded by their name + :return: for every endpoint in endpoints, a list with the performance + """ + + return [ + { + 'type': exception.exception_type, + 'message': exception.exception_msg, + 'timestamp': exception.time_requested + } + for exception in get_exceptions_with_timestamps(session) + ] \ No newline at end of file diff --git a/flask_monitoringdashboard/database/exception_info.py b/flask_monitoringdashboard/database/exception_info.py index 1f9b910c4..ae94da7f2 100644 --- a/flask_monitoringdashboard/database/exception_info.py +++ b/flask_monitoringdashboard/database/exception_info.py @@ -2,7 +2,7 @@ Contains all functions that access an ExceptionInfo object. """ -from flask_monitoringdashboard.database import CodeLine, ExceptionInfo, ExceptionStackLine +from flask_monitoringdashboard.database import CodeLine, ExceptionInfo, ExceptionStackLine, Request from flask_monitoringdashboard.database.code_line import get_code_line def get_exception_info(session, request_id: int): @@ -48,3 +48,12 @@ def add_exception_stack_line(session, request_id, position, code_line: CodeLine) code_id=db_code_line.id, ) ) + +def get_exceptions_with_timestamps(session): + results = session.query( + ExceptionInfo.exception_type, + ExceptionInfo.exception_msg, + Request.time_requested + ).join(Request, ExceptionInfo.request_id == Request.id).all() + + return results \ No newline at end of file diff --git a/flask_monitoringdashboard/frontend/js/app.js b/flask_monitoringdashboard/frontend/js/app.js index 823213e09..b1b070ced 100644 --- a/flask_monitoringdashboard/frontend/js/app.js +++ b/flask_monitoringdashboard/frontend/js/app.js @@ -23,6 +23,7 @@ import moment from 'moment'; window.moment = moment; import { OverviewController } from "./controllers/OverviewController"; +import { ExceptionController } from "./controllers/exceptionInfo"; import { HourlyLoadController } from "./controllers/hourlyLoad"; import { MultiVersionController } from "./controllers/multiVersion"; import { DailyUtilizationController } from "./controllers/dailyUtilization"; @@ -95,6 +96,12 @@ app.config(['$locationProvider', '$routeProvider', function ($locationProvider, templateUrl: 'static/pages/overview.html', controller: ['$scope', '$http', '$location', 'menuService', 'endpointService', OverviewController] }) + // Natalie --> + .when('/new_dashboard', { + templateUrl: 'static/pages/new_dashboard.html', + controller: ['$scope', '$http', 'menuService', 'endpointService', ExceptionController] + }) + // <-- .when('/hourly_load', { templateUrl: 'static/pages/plotly_graph.html', controller: ['$scope', '$http', 'menuService', 'plotlyService', 'infoService', diff --git a/flask_monitoringdashboard/frontend/js/controllers/exceptionInfo.js b/flask_monitoringdashboard/frontend/js/controllers/exceptionInfo.js new file mode 100644 index 000000000..01a9131ea --- /dev/null +++ b/flask_monitoringdashboard/frontend/js/controllers/exceptionInfo.js @@ -0,0 +1,32 @@ +// dette er frontend, husk "npm run build" fra frontend/ for at kunne se dine ændringer +// Opsætning første gang: npm install --save-dev webpack webpack-cli babel-loader @babel/core @babel/preset-env + +export function ExceptionController ($scope, $http, menuService, endpointService) { + endpointService.reset(); + // Hvis værdien 'new_dashboard' nedenfor ændres skal den også ændres i menuService, men den bruges ingen andre steder + menuService.reset('new_dashboard'); // Fokus når man klikker på den i menuen (den bliver hvid og de andre bliver grå) + + // Route http://127.0.0.1:4200/dashboard/new_dashboard sættes i frontend/app.js + + $scope.message = "Welcome to the New Dashboard!"; // scope bruges i static/pages/new_dashboard.html + $scope.table = []; + // Hvis static/pages/new_dashboard.html filen skal renames, skal frontend/app.js lige opdateres + + /* + API og frontend virker til at køre på samme port så vidt jeg har forstået, og API routing specificeres i view layer + + API specificeres lige nu i views/endpoint.py som bruger metoder fra database/ core/ og controllers/ + vi bør rykke API ud i en views/excpetion.py i stedet, men da jeg selv forsøgte dette kunne http://127.0.0.1:4200/dashboard/api/exception_info ikke findes + + filer der muliggør API lige nu (fra bunden og op): + database/exception_info -> controllers/exceptions -> views/endpoint.py --api--> frontend/js/controllers/exceptionInfo.js + + */ + $http.get('api/exception_info').then(function (response) { + console.log("DATA START"); + console.log(response.data); + console.log("DATA SLUT"); + $scope.table = response.data; + }); + +}; \ No newline at end of file diff --git a/flask_monitoringdashboard/frontend/js/services/menu.js b/flask_monitoringdashboard/frontend/js/services/menu.js index 7f09f2e8a..c628afa6d 100644 --- a/flask_monitoringdashboard/frontend/js/services/menu.js +++ b/flask_monitoringdashboard/frontend/js/services/menu.js @@ -12,7 +12,7 @@ export default function ($http, endpointService) { $('#collapseCustomGraphs').collapse('hide'); } - var dashboardPages = ['overview', 'hourly_load', 'multi_version', 'daily_load', 'api_performance', 'reporting']; + var dashboardPages = ['overview', 'new_dashboard', 'hourly_load', 'multi_version', 'daily_load', 'api_performance', 'reporting']; if (dashboardPages.includes(page)) { $('#collapseDashboard').collapse('show'); diff --git a/flask_monitoringdashboard/static/elements/menu.html b/flask_monitoringdashboard/static/elements/menu.html index 6f2137064..ed7285d63 100644 --- a/flask_monitoringdashboard/static/elements/menu.html +++ b/flask_monitoringdashboard/static/elements/menu.html @@ -11,6 +11,11 @@
  • Hourly API Utilization
  • + +
  • + Exception Monitoring +
  • +
  • Multi Version API Utilization
  • diff --git a/flask_monitoringdashboard/static/pages/new_dashboard.html b/flask_monitoringdashboard/static/pages/new_dashboard.html new file mode 100644 index 000000000..4f1eeda05 --- /dev/null +++ b/flask_monitoringdashboard/static/pages/new_dashboard.html @@ -0,0 +1,5 @@ +
    +

    New Dashboard

    +

    {{ message }}

    +

    {{ table }}

    +
    \ No newline at end of file diff --git a/flask_monitoringdashboard/views/endpoint.py b/flask_monitoringdashboard/views/endpoint.py index cf07aa5ea..4c99c876f 100644 --- a/flask_monitoringdashboard/views/endpoint.py +++ b/flask_monitoringdashboard/views/endpoint.py @@ -22,8 +22,21 @@ get_endpoints, get_endpoints_hits, ) +from flask_monitoringdashboard.controllers.exceptions import get_exceptions_with_timestamp - +@blueprint.route('/api/exception_info') +@secure +def get_exception_info(): + """ + Get information about all the exceptions that have occured for all endpoint + :return: A JSON-list with a JSON-object per endpoint + """ + post_to_back_if_telemetry_enabled(**{'name': 'exception_info'}) # Ved ikke 100% hvorfor, tror det er business behov, ikke et funktionelt behov som sådan + with session_scope() as session: + exceptions = get_exceptions_with_timestamp(session) + + return jsonify(exceptions) + @blueprint.route('/api/overview', methods=['GET', 'POST']) @secure def get_overview():