duongkame commented on code in PR #4044: URL: https://github.com/apache/ozone/pull/4044#discussion_r1041309900
########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/grpc/metrics/GrpcOzoneManagerMetrics.java: ########## @@ -0,0 +1,182 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.hadoop.ozone.om.grpc.metrics; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.metrics2.annotation.Metric; +import org.apache.hadoop.metrics2.annotation.Metrics; +import org.apache.hadoop.metrics2.lib.MutableGaugeLong; +import org.apache.hadoop.metrics2.lib.MutableGaugeInt; +import org.apache.hadoop.metrics2.lib.MetricsRegistry; +import org.apache.hadoop.metrics2.lib.MutableQuantiles; +import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; +import org.apache.hadoop.metrics2.lib.MutableRate; +import org.apache.hadoop.ozone.OzoneConsts; +import org.apache.hadoop.ozone.om.grpc.GrpcOzoneManagerServer; +import org.apache.hadoop.ozone.om.OMConfigKeys; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Class which maintains metrics related to using GRPC with OzoneManager. + */ +@Metrics(about = "GRPC OM Metrics", context = OzoneConsts.OZONE) +public class GrpcOzoneManagerMetrics { Review Comment: I think these metrics are general for GRPC and should not be bound with just OM. Should we consider refactoring/moving it to `hdds-common`? ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java: ########## @@ -74,6 +74,7 @@ import org.apache.hadoop.hdds.utils.db.Table.KeyValue; import org.apache.hadoop.hdds.utils.db.TableIterator; import org.apache.hadoop.ozone.OzoneManagerVersion; +import org.apache.hadoop.ozone.om.grpc.GrpcOzoneManagerServer; Review Comment: nit: unused import? ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/grpc/GrpcOmServerRequestInterceptor.java: ########## @@ -0,0 +1,113 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.hadoop.ozone.om.grpc; + +import org.apache.commons.io.IOUtils; +import org.apache.hadoop.ozone.om.grpc.metrics.GrpcOzoneManagerMetrics; +import io.grpc.ForwardingServerCallListener.SimpleForwardingServerCallListener; +import io.grpc.Metadata; +import io.grpc.ServerCall; +import io.grpc.ServerCallHandler; +import io.grpc.ServerInterceptor; + +import java.io.ByteArrayOutputStream; +import java.io.ObjectOutputStream; +import java.io.InputStream; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.nio.ByteBuffer; + +/** + * Interceptor to gather metrics based on grpc server request. + */ +public class GrpcOmServerRequestInterceptor implements ServerInterceptor { + + private final GrpcOzoneManagerMetrics grpcMetrics; + private long bytesReceived; + private long receivedTime; + private long startTime; + private long endTime; + + public GrpcOmServerRequestInterceptor( + GrpcOzoneManagerMetrics grpcMetrics) { + super(); + this.grpcMetrics = grpcMetrics; + this.bytesReceived = 0; + } + + @Override + public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall( + ServerCall<ReqT, RespT> serverCall, Metadata headers, + ServerCallHandler<ReqT, RespT> serverCallHandler) { + + // received time + receivedTime = System.nanoTime(); + + return new SimpleForwardingServerCallListener<ReqT>( + serverCallHandler.startCall(serverCall, headers)) { + + @Override + public void onMessage(ReqT message) { + // start time + startTime = System.nanoTime(); + + ByteArrayOutputStream byteArrayOutputStream = + new ByteArrayOutputStream(); + try { + ObjectOutputStream outputStream = + new ObjectOutputStream(byteArrayOutputStream); + outputStream.writeObject(message); Review Comment: Is there a more efficient way to capture bytesReceived, rather than re-serializing all the messages? I just think this has to be considered carefully, the cost for this vs the need for the metrics. I'd rather have it as a client-side metrics if there's no efficient ways to capture it on server-side. ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/grpc/metrics/GrpcOzoneManagerMetrics.java: ########## @@ -0,0 +1,182 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.hadoop.ozone.om.grpc.metrics; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.metrics2.annotation.Metric; +import org.apache.hadoop.metrics2.annotation.Metrics; +import org.apache.hadoop.metrics2.lib.MutableGaugeLong; +import org.apache.hadoop.metrics2.lib.MutableGaugeInt; +import org.apache.hadoop.metrics2.lib.MetricsRegistry; +import org.apache.hadoop.metrics2.lib.MutableQuantiles; +import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; +import org.apache.hadoop.metrics2.lib.MutableRate; +import org.apache.hadoop.ozone.OzoneConsts; +import org.apache.hadoop.ozone.om.grpc.GrpcOzoneManagerServer; +import org.apache.hadoop.ozone.om.OMConfigKeys; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Class which maintains metrics related to using GRPC with OzoneManager. + */ +@Metrics(about = "GRPC OM Metrics", context = OzoneConsts.OZONE) +public class GrpcOzoneManagerMetrics { + + private static final Logger LOG = + LoggerFactory.getLogger(GrpcOzoneManagerMetrics.class); + private static final String SOURCE_NAME = + GrpcOzoneManagerMetrics.class.getSimpleName(); + + private final GrpcOzoneManagerServer grpcOmServer; + private final MetricsRegistry registry; + private final boolean grpcOmQuantileEnable; + + public GrpcOzoneManagerMetrics(GrpcOzoneManagerServer grpcOmServer, + Configuration conf) { + this.grpcOmServer = grpcOmServer; + String port = String.valueOf(grpcOmServer.getPort()); + registry = new MetricsRegistry("grpc").tag("port", "gRPC port", port); + int[] intervals = conf.getInts( + OMConfigKeys.OZONE_OM_S3_GPRC_METRICS_PERCENTILES_INTERVALS_KEY); + grpcOmQuantileEnable = (intervals.length > 0) && conf.getBoolean( + OMConfigKeys.OZONE_OM_S3_GPRC_METRICS_QUANTILE_ENABLED, Review Comment: So, this is a redundant flag I think. Users just need to rely on the interval config to enable or disable metrics quantile. ########## hadoop-ozone/dist/src/main/compose/ozone-grpc-om-s3/README.md: ########## @@ -0,0 +1,26 @@ +<!--- + Licensed 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. See accompanying LICENSE file. +--> + +# Using gRPC between OM and S3G + +This is the same as `compose/ozone` but for testing operations with gRPC enabled Review Comment: Did we already enable gRPC between S3G and OM by default? If so, do we really need to have this as a separated docker-compose setup, or just make gRPC enabled and tested by default as per `compose/ozone`? -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
