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

Add coordinatorId to /v1/info #23910

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 @@ -34,20 +34,23 @@ public class ServerInfo

// optional to maintain compatibility with older servers
private final Optional<Duration> uptime;
private final Optional<String> coordinatorId;

@JsonCreator
public ServerInfo(
@JsonProperty("nodeVersion") NodeVersion nodeVersion,
@JsonProperty("environment") String environment,
@JsonProperty("coordinator") boolean coordinator,
@JsonProperty("starting") boolean starting,
@JsonProperty("uptime") Optional<Duration> uptime)
@JsonProperty("uptime") Optional<Duration> uptime,
@JsonProperty("coordinatorId") Optional<String> coordinatorId)
{
this.nodeVersion = requireNonNull(nodeVersion, "nodeVersion is null");
this.environment = requireNonNull(environment, "environment is null");
this.coordinator = coordinator;
this.starting = starting;
this.uptime = requireNonNull(uptime, "uptime is null");
this.coordinatorId = requireNonNull(coordinatorId, "coordinatorId is null");
}

@JsonProperty
Expand Down Expand Up @@ -80,6 +83,12 @@ public Optional<Duration> getUptime()
return uptime;
}

@JsonProperty
public Optional<String> getCoordinatorId()
{
return coordinatorId;
}

@Override
public boolean equals(Object o)
{
Expand Down Expand Up @@ -109,6 +118,7 @@ public String toString()
.add("environment", environment)
.add("coordinator", coordinator)
.add("uptime", uptime.orElse(null))
.add("coordinatorId", coordinatorId.orElse(null))
.omitNullValues()
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ public class TestServerInfo
@Test
public void testJsonRoundTrip()
{
assertJsonRoundTrip(new ServerInfo(UNKNOWN, "test", true, false, Optional.of(new Duration(2, MINUTES))));
assertJsonRoundTrip(new ServerInfo(UNKNOWN, "test", true, false, Optional.empty()));
assertJsonRoundTrip(new ServerInfo(UNKNOWN, "test", true, false, Optional.of(new Duration(2, MINUTES)), Optional.of("3sruz")));
assertJsonRoundTrip(new ServerInfo(UNKNOWN, "test", true, false, Optional.of(new Duration(2, MINUTES)), Optional.empty()));
assertJsonRoundTrip(new ServerInfo(UNKNOWN, "test", true, false, Optional.empty(), Optional.empty()));
}

@Test
public void testBackwardsCompatible()
{
ServerInfo newServerInfo = new ServerInfo(UNKNOWN, "test", true, false, Optional.empty());
ServerInfo newServerInfo = new ServerInfo(UNKNOWN, "test", true, false, Optional.empty(), Optional.empty());
ServerInfo legacyServerInfo = SERVER_INFO_CODEC.fromJson("{\"nodeVersion\":{\"version\":\"<unknown>\"},\"environment\":\"test\",\"coordinator\":true}");
assertThat(newServerInfo).isEqualTo(legacyServerInfo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.airlift.node.NodeInfo;
import io.trino.client.NodeVersion;
import io.trino.client.ServerInfo;
import io.trino.execution.QueryIdGenerator;
import io.trino.metadata.NodeState;
import io.trino.server.security.ResourceSecurity;
import jakarta.ws.rs.BadRequestException;
Expand Down Expand Up @@ -48,16 +49,24 @@ public class ServerInfoResource
private final boolean coordinator;
private final GracefulShutdownHandler shutdownHandler;
private final StartupStatus startupStatus;
private final Optional<QueryIdGenerator> queryIdGenerator;
private final long startTime = System.nanoTime();

@Inject
public ServerInfoResource(NodeVersion nodeVersion, NodeInfo nodeInfo, ServerConfig serverConfig, GracefulShutdownHandler shutdownHandler, StartupStatus startupStatus)
public ServerInfoResource(
NodeVersion nodeVersion,
NodeInfo nodeInfo,
ServerConfig serverConfig,
GracefulShutdownHandler shutdownHandler,
StartupStatus startupStatus,
Optional<QueryIdGenerator> queryIdGenerator)
{
this.version = requireNonNull(nodeVersion, "nodeVersion is null");
this.environment = nodeInfo.getEnvironment();
this.coordinator = serverConfig.isCoordinator();
this.shutdownHandler = requireNonNull(shutdownHandler, "shutdownHandler is null");
this.startupStatus = requireNonNull(startupStatus, "startupStatus is null");
this.queryIdGenerator = requireNonNull(queryIdGenerator, "queryIdGenerator is null");
}

@ResourceSecurity(PUBLIC)
Expand All @@ -66,7 +75,7 @@ public ServerInfoResource(NodeVersion nodeVersion, NodeInfo nodeInfo, ServerConf
public ServerInfo getInfo()
{
boolean starting = !startupStatus.isStartupComplete();
return new ServerInfo(version, environment, coordinator, starting, Optional.of(nanosSince(startTime)));
return new ServerInfo(version, environment, coordinator, starting, Optional.of(nanosSince(startTime)), queryIdGenerator.map(QueryIdGenerator::getCoordinatorId));
}

@ResourceSecurity(MANAGEMENT_WRITE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.Singleton;
import com.google.inject.multibindings.OptionalBinder;
import com.google.inject.multibindings.ProvidesIntoSet;
import io.airlift.concurrent.BoundedExecutor;
import io.airlift.configuration.AbstractConfigurationAwareModule;
Expand All @@ -44,6 +45,7 @@
import io.trino.execution.MemoryRevokingScheduler;
import io.trino.execution.NoOpFailureInjector;
import io.trino.execution.NodeTaskMap;
import io.trino.execution.QueryIdGenerator;
import io.trino.execution.QueryManagerConfig;
import io.trino.execution.SqlTaskManager;
import io.trino.execution.TableExecuteContextManager;
Expand Down Expand Up @@ -442,6 +444,7 @@ protected void setup(Binder binder)

// server info resource
jaxrsBinder(binder).bind(ServerInfoResource.class);
OptionalBinder.newOptionalBinder(binder, QueryIdGenerator.class);

// node status resource
jaxrsBinder(binder).bind(StatusResource.class);
Expand Down
Loading