Skip to content

Commit

Permalink
[improve][broker]Change the log level to reduce repeated error logs (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
rayluoluo committed Aug 27, 2024
1 parent cd3519a commit d9bd6b0
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.AllArgsConstructor;
Expand All @@ -54,7 +55,8 @@ public class LinuxInfoUtils {
// NIC type
private static final int ARPHRD_ETHER = 1;
private static final String NIC_SPEED_TEMPLATE = "/sys/class/net/%s/speed";

private static final long errLogPrintedFrequencyInReadingNicLimits = 1000;
private static final AtomicLong failedCounterInReadingNicLimits = new AtomicLong(0);
private static Object /*jdk.internal.platform.Metrics*/ metrics;
private static Method getMetricsProviderMethod;
private static Method getCpuQuotaMethod;
Expand Down Expand Up @@ -251,7 +253,15 @@ public static double getTotalNicLimit(List<String> nics, BitRateUnit bitRateUnit
try {
return readDoubleFromFile(getReplacedNICPath(NIC_SPEED_TEMPLATE, nicPath));
} catch (IOException e) {
log.error("[LinuxInfo] Failed to get total nic limit.", e);
// ERROR-level logs about NIC rate limiting reading failures are periodically printed but not
// continuously printed
if (failedCounterInReadingNicLimits.getAndIncrement() % errLogPrintedFrequencyInReadingNicLimits == 0) {
log.error("[LinuxInfo] Failed to get the nic limit of {}.", nicPath, e);
} else {
if (log.isDebugEnabled()) {
log.debug("[LinuxInfo] Failed to get the nic limit of {}.", nicPath, e);
}
}
return 0d;
}
}).sum(), BitRateUnit.Megabit);
Expand Down

0 comments on commit d9bd6b0

Please sign in to comment.