Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1269 A bug on the metric calculation inside async API clients #1270

Merged
merged 1 commit into from
Jan 23, 2024
Merged
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 @@ -65,7 +65,7 @@ public <T extends AuditApiResponse> CompletableFuture<T> execute(
return CompletableFuture.supplyAsync(() -> {
String messageId = messageIdGenerator.generate();
addMessageId(teamId, methodName, messageId);
initCurrentQueueSizeStatsIfAbsent(teamId, methodName);
syncCurrentQueueSizeStats(teamId, methodName);
if (NO_TOKEN_METHOD_NAMES.contains(methodName) || teamId == null) {
return runWithoutQueue(teamId, methodName, methodsSupplier);
} else {
Expand All @@ -80,9 +80,9 @@ public <T extends AuditApiResponse> CompletableFuture<T> execute(
}, executorService);
}

private void initCurrentQueueSizeStatsIfAbsent(String teamId, String methodNameWithSuffix) {
private void syncCurrentQueueSizeStats(String teamId, String methodNameWithSuffix) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this method is a private one, we can safely rename it to represent more accurate behavior.

if (teamId != null) {
metricsDatastore.setCurrentQueueSize(config.getExecutorName(), teamId, methodNameWithSuffix, 0);
metricsDatastore.updateCurrentQueueSize(config.getExecutorName(), teamId, methodNameWithSuffix);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public <T extends SlackApiResponse> CompletableFuture<T> execute(
String messageId = messageIdGenerator.generate();
String methodNameWithSuffix = toMethodNameWithSuffix(methodName, params);
addMessageId(teamId, methodNameWithSuffix, messageId);
initCurrentQueueSizeStatsIfAbsent(teamId, methodNameWithSuffix);
syncCurrentQueueSizeStats(teamId, methodNameWithSuffix);
return enqueueThenRun(
messageId,
teamId,
Expand All @@ -85,9 +85,9 @@ public <T extends SlackApiResponse> CompletableFuture<T> execute(
}, executorService);
}

private void initCurrentQueueSizeStatsIfAbsent(String teamId, String methodNameWithSuffix) {
private void syncCurrentQueueSizeStats(String teamId, String methodNameWithSuffix) {
if (teamId != null) {
metricsDatastore.setCurrentQueueSize(config.getExecutorName(), teamId, methodNameWithSuffix, 0);
metricsDatastore.updateCurrentQueueSize(config.getExecutorName(), teamId, methodNameWithSuffix);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,6 @@ public void updateCurrentQueueSize(String executorName, String teamId, String me
@Override
public void setCurrentQueueSize(String executorName, String teamId, String methodName, Integer size) {
if (this.isStatsEnabled()) {
CopyOnWriteArrayList<String> messageIds = getOrCreateMessageIds(executorName, teamId, methodName);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines of code are completely unnecessary. They are just an overhead when executing this method.

Integer totalSize = messageIds.size();
RateLimitQueue<SUPPLIER, MSG> queue = getRateLimitQueue(executorName, teamId);
if (queue != null) {
totalSize += queue.getCurrentActiveQueueSize(methodName);
}
getOrCreateTeamLiveStats(executorName, teamId).getCurrentQueueSize().put(methodName, totalSize);
getOrCreateTeamLiveStats(executorName, teamId).getCurrentQueueSize().put(methodName, size);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public <T extends SCIMApiResponse> CompletableFuture<T> execute(
return CompletableFuture.supplyAsync(() -> {
String messageId = messageIdGenerator.generate();
addMessageId(teamId, endpointName, messageId);
initCurrentQueueSizeStatsIfAbsent(teamId, endpointName);
syncCurrentQueueSizeStats(teamId, endpointName);
if (NO_TOKEN_METHOD_NAMES.contains(endpointName) || teamId == null) {
return runWithoutQueue(teamId, endpointName, methodsSupplier);
} else {
Expand All @@ -77,14 +77,9 @@ public <T extends SCIMApiResponse> CompletableFuture<T> execute(
}, executorService);
}

private void initCurrentQueueSizeStatsIfAbsent(String teamId, SCIMEndpointName endpointName) {
private void syncCurrentQueueSizeStats(String teamId, SCIMEndpointName endpointName) {
if (teamId != null) {
metricsDatastore.setCurrentQueueSize(
config.getExecutorName(),
teamId,
endpointName.name(),
0
);
metricsDatastore.updateCurrentQueueSize(config.getExecutorName(), teamId, endpointName.name());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public <T extends SCIM2ApiResponse> CompletableFuture<T> execute(
return CompletableFuture.supplyAsync(() -> {
String messageId = messageIdGenerator.generate();
addMessageId(teamId, endpointName, messageId);
initCurrentQueueSizeStatsIfAbsent(teamId, endpointName);
syncCurrentQueueSizeStats(teamId, endpointName);
if (NO_TOKEN_METHOD_NAMES.contains(endpointName) || teamId == null) {
return runWithoutQueue(teamId, endpointName, methodsSupplier);
} else {
Expand All @@ -77,14 +77,9 @@ public <T extends SCIM2ApiResponse> CompletableFuture<T> execute(
}, executorService);
}

private void initCurrentQueueSizeStatsIfAbsent(String teamId, SCIM2EndpointName endpointName) {
private void syncCurrentQueueSizeStats(String teamId, SCIM2EndpointName endpointName) {
if (teamId != null) {
metricsDatastore.setCurrentQueueSize(
config.getExecutorName(),
teamId,
endpointName.name(),
0
);
metricsDatastore.updateCurrentQueueSize(config.getExecutorName(), teamId, endpointName.name());
}
}

Expand Down