Skip to content

Commit

Permalink
Fully working database pruning /w scheduling and frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
wielas committed Dec 13, 2023
1 parent ff1d094 commit d946e2f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function DatabaseManagementController($scope, $http, menuService, endpoin
// Initialize the configuration for pruning
$scope.pruneOnDemandConfig = {
ageThresholdWeeks: 1, // Default value or null if you prefer no default
deleteCustomGraphs: false
deleteCustomGraphData: false
};

// Variables for feedback messages
Expand All @@ -30,9 +30,17 @@ export function DatabaseManagementController($scope, $http, menuService, endpoin

// Function to prune the database
$scope.pruneDatabase = function () {
let weekOrWeeks = $scope.pruneOnDemandConfig.ageThresholdWeeks === 1 ? ' week' : ' weeks';
let confirmationMessage = 'Are you sure you want to prune all request data older than '
+ $scope.pruneOnDemandConfig.ageThresholdWeeks + weekOrWeeks + '?';
if (!confirm(confirmationMessage)) {
return; // Stop the function if the user clicks 'Cancel'
}

// Confirmation dialog
const pruneData = {
age_threshold_weeks: $scope.pruneOnDemandConfig.ageThresholdWeeks,
delete_custom_graphs: $scope.pruneOnDemandConfig.deleteCustomGraphs
delete_custom_graph_data: $scope.pruneOnDemandConfig.deleteCustomGraphData
};

$http.post('/dashboard/database_pruning/prune_on_demand', pruneData)
Expand Down
2 changes: 1 addition & 1 deletion flask_monitoringdashboard/static/js/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 22 additions & 17 deletions flask_monitoringdashboard/static/pages/database_management.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ <h4>Database Size</h4>
</div>
<div class="card-body">
<h5 class="mt-3">Current Database Size: </h5>
<p> {{ databaseSize }} <div ng-show="databaseSize != 'N/A'"> MB</div></p>
<p> {{ databaseSize }} </p>
</div>
</div>

Expand All @@ -19,16 +19,16 @@ <h4>Prune On Demand</h4>
<div class="form-group">
<label for="ageThresholdWeeksPrune"><b>How many weeks of data should be kept?:</b></label>
<input type="number" class="form-control" id="ageThresholdWeeksPrune"
ng-model="pruneOnDemandConfig.ageThresholdWeeks" min="1">
ng-model="pruneOnDemandConfig.ageThresholdWeeks" min="0">
<span ng-show="submitPruningOnDemandAttempted && !isValidPruneOnDemandAgeThresholdWeeks()"
class="help-block">Please enter a valid age in weeks.</span>
</div>

<!-- Delete Custom Graphs -->
<div class="checkbox">
<label>
<input type="checkbox" ng-model="pruneOnDemandConfig.deleteCustomGraphs"> <b>Delete Custom
Graphs</b>
<input type="checkbox" ng-model="pruneOnDemandConfig.deleteCustomGraphData"> <b>Delete Custom
Graph Data?</b>
</label>
</div>

Expand All @@ -55,19 +55,24 @@ <h4>Prune On Demand</h4>
<h4>Pruning Schedule</h4>
</div>
<div class="card-body">
<div ng-if="pruningSchedule">
<h5 class="mt-3">Pruning Schedule Details:</h5>
<p>Year: {{ pruningSchedule.year }}</p>
<p>Month: {{ pruningSchedule.month }}</p>
<p>Day of the Month: {{ pruningSchedule.day_of_the_month }}</p>
<p>Week: {{ pruningSchedule.week }}</p>
<p>Day of the Week: {{ pruningSchedule.day_of_the_week }}</p>
<p>Hour: {{ pruningSchedule.hour }}</p>
<p>Minute: {{ pruningSchedule.minute }}</p>
<p>Second: {{ pruningSchedule.second }}</p>
<p>Next Run Time: {{ pruningSchedule.next_run_time }}</p>
<p>Weeks to Keep: {{ pruningSchedule.weeks_to_keep }}</p>
<p>Delete Custom Graphs: {{ pruningSchedule.delete_custom_graphs }}</p>
<div ng-if="pruningSchedule" style="display: flex;">
<div style="padding-right: 20px; border-right: 1px solid black;">
<h5 class="mt-3">Cron Schedule:</h5>
<p>Year: {{ pruningSchedule.year }}</p>
<p>Month: {{ pruningSchedule.month }}</p>
<p>Day of the Month: {{ pruningSchedule.day_of_the_month }}</p>
<p>Week: {{ pruningSchedule.week }}</p>
<p>Day of the Week: {{ pruningSchedule.day_of_the_week }}</p>
<p>Hour: {{ pruningSchedule.hour }}</p>
<p>Minute: {{ pruningSchedule.minute }}</p>
<p>Second: {{ pruningSchedule.second }}</p>
</div>
<div style="margin-left: 20px;">
<h5 class="mt-3">Schedule Details:</h5>
<p>Next Run Time: {{ pruningSchedule.next_run_time }}</p>
<p>Weeks to Keep: {{ pruningSchedule.weeks_to_keep }}</p>
<p>Delete Custom Graphs: {{ pruningSchedule.delete_custom_graph_data }}</p>
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion flask_monitoringdashboard/views/pruning.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def prune_database_on_demand():
if not isinstance(weeks, int) or weeks < 0:
return jsonify({'error': 'age_threshold_weeks must be a natural number'}), 400
if not isinstance(delete_custom_graph_data, bool):
return jsonify({'error': 'delete_custom_graphs must be a boolean'}), 400
return jsonify({'error': 'delete_custom_graph_data must be a boolean'}), 400

# Prune database
prune_database_older_than_weeks(weeks, delete_custom_graph_data)
Expand Down

0 comments on commit d946e2f

Please sign in to comment.