scwhittle commented on code in PR #30211: URL: https://github.com/apache/beam/pull/30211#discussion_r1486301208
########## runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/windmill/client/grpc/ChannelzServlet.java: ########## @@ -0,0 +1,284 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.runners.dataflow.worker.windmill.client.grpc; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import javax.annotation.Nullable; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.beam.runners.dataflow.worker.options.StreamingDataflowWorkerOptions; +import org.apache.beam.runners.dataflow.worker.status.BaseStatusServlet; +import org.apache.beam.runners.dataflow.worker.status.DebugCapture; +import org.apache.beam.runners.dataflow.worker.windmill.WindmillServerStub; +import org.apache.beam.vendor.grpc.v1p60p1.io.grpc.channelz.v1.*; +import org.apache.beam.vendor.grpc.v1p60p1.io.grpc.protobuf.services.ChannelzService; +import org.apache.beam.vendor.grpc.v1p60p1.io.grpc.stub.StreamObserver; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableSet; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.net.HostAndPort; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.util.concurrent.SettableFuture; + +/** Respond to /channelz with the GRPC channelz data. */ +public class ChannelzServlet extends BaseStatusServlet implements DebugCapture.Capturable { + private static final String PATH = "/channelz"; + private static final int MAX_TOP_CHANNELS_TO_RETURN = 100; + + private final ChannelzService channelzService; + private final WindmillServerStub windmillServerStub; + private final boolean showOnlyWindmillServiceChannels; + + public ChannelzServlet(StreamingDataflowWorkerOptions options) { + super(PATH); + channelzService = ChannelzService.newInstance(MAX_TOP_CHANNELS_TO_RETURN); + windmillServerStub = options.getWindmillServerStub(); + showOnlyWindmillServiceChannels = options.getChannelzShowOnlyWindmillServiceChannels(); + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + response.setStatus(HttpServletResponse.SC_OK); + PrintWriter writer = response.getWriter(); + captureData(writer); + } + + @Override + public String pageName() { + return PATH; + } + + @Override + public void captureData(PrintWriter writer) { + writer.println("<html>"); + writer.println("<h1>Channelz</h1>"); + appendTopChannels(writer); + writer.println("</html>"); + } + + // channelz proto says there won't be cycles in the ref graph. + // we track visited ids to be defensive and prevent any accidental cycles. + static class VisitedSets { + Set<Long> channels = new HashSet<>(); + Set<Long> subchannels = new HashSet<>(); + } + + private void appendTopChannels(PrintWriter writer) { + SettableFuture<GetTopChannelsResponse> future = SettableFuture.create(); + channelzService.getTopChannels( + GetTopChannelsRequest.newBuilder().build(), getStreamObserver(future)); Review Comment: this will truncate if over 100 channels, could examine response and loop over start index ########## runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/status/WorkerStatusPages.java: ########## @@ -67,17 +75,26 @@ public class WorkerStatusPages { // Add default capture pages (threadz, statusz) this.capturePages.add(threadzServlet); this.capturePages.add(statuszServlet); + if (options.isStreaming()) { Review Comment: instead of this you could have a separate method to register channelz with a function that filters the channels rendered Martin just had a PR removing the stub from the options so I think this won't work after syncing. ########## runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/windmill/client/grpc/ChannelzServlet.java: ########## @@ -0,0 +1,284 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.runners.dataflow.worker.windmill.client.grpc; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import javax.annotation.Nullable; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.beam.runners.dataflow.worker.options.StreamingDataflowWorkerOptions; +import org.apache.beam.runners.dataflow.worker.status.BaseStatusServlet; +import org.apache.beam.runners.dataflow.worker.status.DebugCapture; +import org.apache.beam.runners.dataflow.worker.windmill.WindmillServerStub; +import org.apache.beam.vendor.grpc.v1p60p1.io.grpc.channelz.v1.*; +import org.apache.beam.vendor.grpc.v1p60p1.io.grpc.protobuf.services.ChannelzService; +import org.apache.beam.vendor.grpc.v1p60p1.io.grpc.stub.StreamObserver; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableSet; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.net.HostAndPort; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.util.concurrent.SettableFuture; + +/** Respond to /channelz with the GRPC channelz data. */ +public class ChannelzServlet extends BaseStatusServlet implements DebugCapture.Capturable { + private static final String PATH = "/channelz"; + private static final int MAX_TOP_CHANNELS_TO_RETURN = 100; + + private final ChannelzService channelzService; + private final WindmillServerStub windmillServerStub; + private final boolean showOnlyWindmillServiceChannels; + + public ChannelzServlet(StreamingDataflowWorkerOptions options) { + super(PATH); + channelzService = ChannelzService.newInstance(MAX_TOP_CHANNELS_TO_RETURN); + windmillServerStub = options.getWindmillServerStub(); + showOnlyWindmillServiceChannels = options.getChannelzShowOnlyWindmillServiceChannels(); + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + response.setStatus(HttpServletResponse.SC_OK); + PrintWriter writer = response.getWriter(); + captureData(writer); + } + + @Override + public String pageName() { + return PATH; Review Comment: could take this as a param. Then in the future we could register bigquery channelz for example as separate page -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
