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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;

import jakarta.inject.Inject;
Expand Down Expand Up @@ -448,6 +449,14 @@ public Set<MessageCategory> getMessageCategories() {
public record Message(String priority, String category, String message) {
}

@GET
@Path("message/counts")
@Produces(MediaType.APPLICATION_JSON)
@Description("Returns count of messages by priority")
public Map<MessagePriority,AtomicLong> getMessageCounts() {
return monitor.getInformationFetcher().getSummaryForEndpoint().getMessageCounts();
}

@GET
@Path("messages")
@Produces(MediaType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ public List<TabletNeedingRecovery> getTabletsNeedingRecovery() {

private final Map<MessagePriority,Map<MessageCategory,Set<String>>> messages =
new EnumMap<>(MessagePriority.class);
private final EnumMap<MessagePriority,AtomicLong> messageCounts =
new EnumMap<>(MessagePriority.class);

private final Set<String> configuredCompactionResourceGroups = ConcurrentHashMap.newKeySet();

Expand All @@ -538,6 +540,9 @@ public SystemInformation(Cache<ServerId,MetricResponse> allMetrics, ServerContex
this.ctx = ctx;
this.rgLongRunningCompactionSize =
this.ctx.getConfiguration().getCount(Property.MONITOR_LONG_RUNNING_COMPACTION_LIMIT);
for (MessagePriority p : MessagePriority.values()) {
messageCounts.put(p, new AtomicLong(0));
}
}

public void clear() {
Expand Down Expand Up @@ -570,16 +575,25 @@ public void clear() {
componentStatuses.clear();
managerGoalState = null;
serverMetricsView.clear();
messageCounts.clear();
}

public void addMessage(MessagePriority pri, MessageCategory cat, String msg) {
messages.computeIfAbsent(pri, k -> new EnumMap<>(MessageCategory.class))
.computeIfAbsent(cat, k -> new TreeSet<>()).add(msg);
messageCounts.get(pri).incrementAndGet();
}

public void removeMessage(MessagePriority pri, MessageCategory cat, String part) {
messages.getOrDefault(pri, new EnumMap<>(MessageCategory.class))
.getOrDefault(cat, new HashSet<String>()).removeIf(s -> s.contains(part));
messageCounts.get(pri).updateAndGet(val -> {
if (val > 0) {
return val - 1;
} else {
return 0;
}
});
}

private void updateAggregates(final MetricResponse response,
Expand Down Expand Up @@ -1352,6 +1366,10 @@ public Map<MessagePriority,Map<MessageCategory,Set<String>>> getMessages() {
return this.messages;
}

public Map<MessagePriority,AtomicLong> getMessageCounts() {
return this.messageCounts;
}

public long getTimestamp() {
return this.timestamp.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const RUNNING_COMPACTIONS_BY_GROUP = 'runningCompactionsByGroup';
const AUTO_REFRESH_KEY = 'auto-refresh';
const MESSAGE_CATEGORIES = 'messageCategories';
const MESSAGES = 'messages';
const MESSAGE_COUNTS = 'messageCounts'
const RECOVERY = 'recovery';

// Override Length Menu options for dataTables
Expand Down Expand Up @@ -547,6 +548,14 @@ function getMessageCategories() {
return getJSONForTable(REST_V2_PREFIX + '/message/categories', MESSAGE_CATEGORIES);
}

/**
* REST GET call for /message/counts
* store it on a sessionStorage variable
*/
function getMessageCounts() {
return getJSONForTable(REST_V2_PREFIX + '/message/counts', MESSAGE_COUNTS);
}

/**
* REST GET call for /messages,
* results are not stored in session as this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ $(function () {
setTheme();
updateDarkThemeSwitch();
refreshSidebar();
refreshMessageBadge();
});

/**
Expand All @@ -165,6 +166,7 @@ function refreshSidebar() {
*/
function refreshNavBar() {
refreshSidebar();
refreshMessageBadge();
}

/**
Expand Down Expand Up @@ -220,3 +222,32 @@ function updateDarkThemeSwitch() {
document.documentElement.setAttribute('data-bs-theme', enableDarkTheme ? 'dark' : 'light');
});
}

/**
* Updates the badge on the Messages label on the Nav Bar
*/
function refreshMessageBadge() {
getMessageCounts().then(function () {

var messageAnchor = $('#message-anchor');

var msgCounts = getStoredJson(MESSAGE_COUNTS, {
"Critical": 0,
"High": 0,
"Info": 0
});
var critMsgCount = msgCounts.Critical;
var highMsgCount = msgCounts.High;

messageAnchor.find('span').remove();

if (critMsgCount > 0) {
messageAnchor.append('<span class="badge position-relative top-0 start-0 translate-middle-y rounded-pill bg-danger">' +
critMsgCount + '</span>');
} else if (highMsgCount > 0) {
messageAnchor.append(
'<span class="badge position-relative top-0 start-0 translate-middle-y rounded-pill bg-warning">' +
highMsgCount + '</span>');
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</ul>
</li>
<li>
<a class="nav-link" aria-current="page" href="messages">Messages</a>
<a id="message-anchor" class="nav-link" aria-current="page" href="messages">Messages</a>
</li>
<li class="dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
Expand Down
Loading