Skip to content

Commit

Permalink
Add duration filter
Browse files Browse the repository at this point in the history
  • Loading branch information
DomGarguilo committed Oct 17, 2024
1 parent 1b8b7f4 commit 4828fdb
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ private RunningCompactions getSampleData() {

RunningCompactionInfo rci1 =
new RunningCompactionInfo("server1", "queue1", "ecid1", "USER", "tableId1", 150, 0.1f,
Duration.ofMinutes(15).toNanos(), TCompactionState.ASSIGNED.name(), 10000);
Duration.ofMinutes(15).toMillis(), TCompactionState.ASSIGNED.name(), 10000);
RunningCompactionInfo rci2 =
new RunningCompactionInfo("server2", "queue2", "ecid2", "SYSTEM", "tableId2", 265, 0.2f,
Duration.ofMinutes(2).toNanos(), TCompactionState.CANCELLED.name(), 20000);
Duration.ofHours(2).toMillis(), TCompactionState.CANCELLED.name(), 20000);
RunningCompactionInfo rci3 =
new RunningCompactionInfo("server3", "queue3", "ecid3", "USER", "tableId3", 3555, 0.3f,
Duration.ofMinutes(70).toNanos(), TCompactionState.IN_PROGRESS.name(), 30000);
Duration.ofMinutes(70).toMillis(), TCompactionState.IN_PROGRESS.name(), 30000);
RunningCompactionInfo rci4 =
new RunningCompactionInfo("localhost:9999", "default", "ecid4", "SYSTEM", "1", 132342, 0.1f,
Duration.ofSeconds(15).toNanos(), TCompactionState.IN_PROGRESS.name(), 10000);
Duration.ofSeconds(15).toMillis(), TCompactionState.IN_PROGRESS.name(), 10000);

List<RunningCompactionInfo> running = List.of(rci1, rci2, rci3, rci4);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,24 +157,95 @@ $(document).ready(function () {
$(this).addClass('is-invalid');
}
}

$('#hostname-filter').on('keyup', function () {
handleFilterKeyup.call(this, this.value, $('#hostname-feedback'), 0);
});

$('#queue-filter').on('keyup', function () {
handleFilterKeyup.call(this, this.value, $('#queue-feedback'), 3);
});

$('#tableid-filter').on('keyup', function () {
handleFilterKeyup.call(this, this.value, $('#tableid-feedback'), 4);
});

// Placeholder for the age range filter
$('#age-filter').on('keyup', function () {
$('#duration-filter').on('keyup', function () {
runningTable.draw();
});

// Custom filter function for duration
$.fn.dataTable.ext.search.push(function (settings, data, dataIndex) {
if (settings.nTable.id !== 'runningTable') {
return true;
}

const durationStr = data[8]; // duration is in the 9th column (index 8)
const durationSeconds = parseDuration(durationStr);

const input = $('#duration-filter').val().trim();
if (input === '') {
return true;
}

const match = validateDurationInput(input);
if (!match) {
$('#duration-feedback').show();
return false;
}

$('#duration-feedback').hide();
const operator = match[1];
const value = parseInt(match[2]);
const unit = match[3];
const filterSeconds = convertToSeconds(value, unit);

switch (operator) {
case '>':
return durationSeconds > filterSeconds;
case '>=':
return durationSeconds >= filterSeconds;
case '<':
return durationSeconds < filterSeconds;
case '<=':
return durationSeconds <= filterSeconds;
default:
return true;
}
});

// Helper function to convert duration strings to seconds
function convertToSeconds(value, unit) {
switch (unit.toLowerCase()) {
case 's':
return value;
case 'm':
return value * 60;
case 'h':
return value * 3600;
case 'd':
return value * 86400;
default:
return value;
}
}

// Helper function to validate duration input. Makes sure that the input is in the format of '<operator> <value> <unit>'
function validateDurationInput(input) {
return input.match(/^([<>]=?)\s*(\d+)([smhd])$/i);
}

/**
* @param {number} durationStr duration in milliseconds
* @returns duration in seconds
*/
function parseDuration(durationStr) {
// Assuming durationStr is in milliseconds
const milliseconds = parseInt(durationStr, 10);
const seconds = milliseconds / 1000;
return seconds;
}

// Create a table for compaction coordinator
coordinatorTable = $('#coordinatorTable').DataTable({
"ajax": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@
<input type="text" id="tableid-filter" class="form-control" placeholder="Enter table ID regex">
<small id="tableid-feedback" class="form-text text-danger" style="display:none;">Invalid regex pattern</small>
</div>
<div class="mb-3" id="age-filter-container" style="display: none;">
<label for="age-filter" class="form-label">Age Range Filter</label>
<input type="text" id="age-filter" class="form-control" placeholder="Enter age range (e.g., 10s, 5m)">
<div class="mb-3">
<label for="duration-filter" class="form-label">Duration Filter</label>
<input type="text" id="duration-filter" class="form-control" placeholder="Enter duration (e.g., &gt;10m, &lt;1h, &gt;=5s, &lt;=2d)">
<small id="duration-feedback" class="form-text text-danger" style="display:none;">Invalid duration format</small>
</div>
</div>
</div>
Expand Down

0 comments on commit 4828fdb

Please sign in to comment.