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

ipc: Fix NPE from #1150 if IPC logger is not configured. #1157

Merged
merged 1 commit into from
Sep 13, 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 @@ -156,7 +156,7 @@ public IpcLogEntry withLatency(long latency, TimeUnit unit) {
* the request completes it is recommended to call {@link #markEnd()}.
*/
public IpcLogEntry markStart() {
if (registry != null && !disableMetrics && logger.inflightEnabled()) {
if (registry != null && !disableMetrics && logger != null && logger.inflightEnabled()) {
inflightId = getInflightId();
int n = logger.inflightRequests(inflightId).incrementAndGet();
registry.distributionSummary(inflightId).record(n);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.netflix.spectator.api.DefaultRegistry;
import com.netflix.spectator.api.DistributionSummary;
import com.netflix.spectator.api.ManualClock;
import com.netflix.spectator.api.NoopRegistry;
import com.netflix.spectator.api.Registry;
import com.netflix.spectator.api.Utils;
import com.netflix.spectator.api.patterns.CardinalityLimiters;
Expand All @@ -36,6 +37,8 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.jupiter.api.Assertions.assertSame;

public class IpcLogEntryTest {

private final ManualClock clock = new ManualClock();
Expand Down Expand Up @@ -889,4 +892,12 @@ public void endpointUnknownIfNotSet() {
Assertions.assertEquals("unknown", Utils.getTagValue(c.id(), "ipc.endpoint"));
});
}

@Test
public void markNullLogger() {
IpcLogEntry entry = new IpcLogEntry(clock)
.withRegistry(new NoopRegistry());
entry.markStart();
assertSame(entry, entry.markEnd());
}
}
Loading