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

chore: log slow route query of topic #321

Merged
merged 2 commits into from
Oct 17, 2023
Merged
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 @@ -22,11 +22,17 @@
import apache.rocketmq.controller.v1.Topic;
import com.automq.rocketmq.controller.metadata.MetadataStore;
import com.automq.rocketmq.metadata.api.ProxyMetadataService;
import com.google.common.base.Stopwatch;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DefaultProxyMetadataService implements ProxyMetadataService {

private static final Logger LOGGER = LoggerFactory.getLogger(DefaultProxyMetadataService.class);

private final MetadataStore metadataStore;

public DefaultProxyMetadataService(MetadataStore metadataStore) {
Expand All @@ -35,7 +41,16 @@ public DefaultProxyMetadataService(MetadataStore metadataStore) {

@Override
public CompletableFuture<Topic> topicOf(String topicName) {
return metadataStore.describeTopic(null, topicName);
Stopwatch stopwatch = Stopwatch.createStarted();
return metadataStore.describeTopic(null, topicName).thenApplyAsync((topic -> {
long elapsed = stopwatch.elapsed().toMillis();
if (elapsed > 100) {
LOGGER.warn("It took {}ms to query topic {}", elapsed, topicName);
} else if (elapsed > 10) {
LOGGER.debug("It took {}ms to query topic {}", elapsed, topicName);
}
return topic;
}));
}

@Override
Expand Down