[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.

2020-02-12 Thread GitBox
wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r378111507
 
 

 ##
 File path: 
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/AlarmRulesWatcher.java
 ##
 @@ -18,23 +18,22 @@
 
 package org.apache.skywalking.oap.server.core.alarm.provider;
 
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.skywalking.oap.server.configuration.api.ConfigChangeWatcher;
 import org.apache.skywalking.oap.server.core.Const;
 import org.apache.skywalking.oap.server.core.alarm.AlarmModule;
+import 
org.apache.skywalking.oap.server.core.alarm.provider.grpc.GRPCAlarmSetting;
 
 Review comment:
   Got it. I was expected the format check will do in a strict way, it will 
make the changelog more clear for everyone.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.

2020-02-11 Thread GitBox
wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r378059399
 
 

 ##
 File path: 
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/AlarmRulesWatcher.java
 ##
 @@ -18,23 +18,22 @@
 
 package org.apache.skywalking.oap.server.core.alarm.provider;
 
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.skywalking.oap.server.configuration.api.ConfigChangeWatcher;
 import org.apache.skywalking.oap.server.core.Const;
 import org.apache.skywalking.oap.server.core.alarm.AlarmModule;
+import 
org.apache.skywalking.oap.server.core.alarm.provider.grpc.GRPCAlarmSetting;
 
 Review comment:
   FYI @kezhenxu94 By following your style, do we have a format way to make 
sure all these imports are in the same order rather than different people using 
different orders.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.

2020-02-11 Thread GitBox
wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377716826
 
 

 ##
 File path: 
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/grpc/GRPCCallback.java
 ##
 @@ -0,0 +1,145 @@
+/*
+ * 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.skywalking.oap.server.core.alarm.provider.grpc;
+
+import io.grpc.stub.StreamObserver;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.core.alarm.AlarmCallback;
+import org.apache.skywalking.oap.server.core.alarm.AlarmMessage;
+import org.apache.skywalking.oap.server.core.alarm.grpc.AlarmServiceGrpc;
+import org.apache.skywalking.oap.server.core.alarm.grpc.Response;
+import org.apache.skywalking.oap.server.core.alarm.provider.AlarmRulesWatcher;
+import org.apache.skywalking.oap.server.core.exporter.ExportStatus;
+import org.apache.skywalking.oap.server.library.client.grpc.GRPCClient;
+
+/**
+ * Use SkyWalking alarm grpc API call a remote methods.
+ */
+@Slf4j
+public class GRPCCallback implements AlarmCallback {
+
+private AlarmRulesWatcher alarmRulesWatcher;
+
+private GRPCAlarmSetting alarmSetting;
+
+private AlarmServiceGrpc.AlarmServiceStub alarmServiceStub;
+
+private GRPCClient grpcClient;
+
+public GRPCCallback(AlarmRulesWatcher alarmRulesWatcher) {
+this.alarmRulesWatcher = alarmRulesWatcher;
+alarmSetting = alarmRulesWatcher.getGrpchookSetting();
+
+if (alarmSetting != null) {
+grpcClient = new GRPCClient(alarmSetting.getTargetHost(), 
alarmSetting.getTargetPort());
+}
+}
+
+@Override
+public void doAlarm(List alarmMessage) {
+
+if (alarmSetting == null) {
+return;
+}
+
+// recreate gRPC client if host and port configuration changed.
+onGRPCAlarmSettingUpdated(alarmRulesWatcher.getGrpchookSetting());
+
+ExportStatus status = new ExportStatus();
+
+
StreamObserver 
streamObserver =
+alarmServiceStub.withDeadlineAfter(10, 
TimeUnit.SECONDS).doAlarm(new StreamObserver() {
+@Override
+public void onNext(Response response) {
+// ignore empty response
+}
+
+@Override
+public void onError(Throwable throwable) {
+status.done();
+if (log.isDebugEnabled()) {
+log.debug("Send alarm message failed: {}", 
throwable.getMessage());
+}
+}
+
+@Override
+public void onCompleted() {
+status.done();
+if (log.isDebugEnabled()) {
+log.debug("Send alarm message successful.");
+}
+}
+});
+
+alarmMessage.forEach(message -> {
+
org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage.Builder builder =
+
org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage.newBuilder();
+
+builder.setScopeId(message.getScopeId());
+builder.setScope(message.getScope());
+builder.setName(message.getName());
+builder.setId0(message.getId0());
+builder.setId1(message.getId1());
+builder.setRuleName(message.getRuleName());
+builder.setAlarmMessage(message.getAlarmMessage());
+builder.setStartTime(message.getStartTime());
+
+streamObserver.onNext(builder.build());
+});
+
+streamObserver.onCompleted();
+
+long sleepTime = 0;
+long cycle = 100L;
+/**
+ * For memory safe of oap, we must wait for the peer confirmation.
+ */
+while (!status.isDone()) {
 
 Review comment:
   It works, or move `ExportStatus` to higher-level package, such as 
`library-util`.


This is an automated message from the Apache Git Service.
To respond to the message, 

[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.

2020-02-11 Thread GitBox
wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377709241
 
 

 ##
 File path: 
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/grpc/GRPCCallback.java
 ##
 @@ -0,0 +1,145 @@
+/*
+ * 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.skywalking.oap.server.core.alarm.provider.grpc;
+
+import io.grpc.stub.StreamObserver;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.core.alarm.AlarmCallback;
+import org.apache.skywalking.oap.server.core.alarm.AlarmMessage;
+import org.apache.skywalking.oap.server.core.alarm.grpc.AlarmServiceGrpc;
+import org.apache.skywalking.oap.server.core.alarm.grpc.Response;
+import org.apache.skywalking.oap.server.core.alarm.provider.AlarmRulesWatcher;
+import org.apache.skywalking.oap.server.core.exporter.ExportStatus;
 
 Review comment:
   ExportStatus is in exporter, why use it in the alarm?  


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.

2020-02-11 Thread GitBox
wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377706433
 
 

 ##
 File path: 
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/grpc/GRPCCallback.java
 ##
 @@ -0,0 +1,145 @@
+/*
+ * 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.skywalking.oap.server.core.alarm.provider.grpc;
+
+import io.grpc.stub.StreamObserver;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.core.alarm.AlarmCallback;
+import org.apache.skywalking.oap.server.core.alarm.AlarmMessage;
+import org.apache.skywalking.oap.server.core.alarm.grpc.AlarmServiceGrpc;
+import org.apache.skywalking.oap.server.core.alarm.grpc.Response;
+import org.apache.skywalking.oap.server.core.alarm.provider.AlarmRulesWatcher;
+import org.apache.skywalking.oap.server.core.exporter.ExportStatus;
+import org.apache.skywalking.oap.server.library.client.grpc.GRPCClient;
+
+/**
+ * Use SkyWalking alarm grpc API call a remote methods.
+ */
+@Slf4j
+public class GRPCCallback implements AlarmCallback {
+
+private AlarmRulesWatcher alarmRulesWatcher;
+
+private GRPCAlarmSetting alarmSetting;
+
+private AlarmServiceGrpc.AlarmServiceStub alarmServiceStub;
+
+private GRPCClient grpcClient;
+
+public GRPCCallback(AlarmRulesWatcher alarmRulesWatcher) {
+this.alarmRulesWatcher = alarmRulesWatcher;
+alarmSetting = alarmRulesWatcher.getGrpchookSetting();
+
+if (alarmSetting != null) {
+grpcClient = new GRPCClient(alarmSetting.getTargetHost(), 
alarmSetting.getTargetPort());
+}
+}
+
+@Override
+public void doAlarm(List alarmMessage) {
+
+if (alarmSetting == null) {
+return;
+}
+
+// recreate gRPC client if host and port configuration changed.
+onGRPCAlarmSettingUpdated(alarmRulesWatcher.getGrpchookSetting());
+
+ExportStatus status = new ExportStatus();
+
+
StreamObserver 
streamObserver =
+alarmServiceStub.withDeadlineAfter(10, 
TimeUnit.SECONDS).doAlarm(new StreamObserver() {
+@Override
+public void onNext(Response response) {
+// ignore empty response
+}
+
+@Override
+public void onError(Throwable throwable) {
+status.done();
+if (log.isDebugEnabled()) {
+log.debug("Send alarm message failed: {}", 
throwable.getMessage());
+}
+}
+
+@Override
+public void onCompleted() {
+status.done();
+if (log.isDebugEnabled()) {
+log.debug("Send alarm message successful.");
+}
+}
+});
+
+alarmMessage.forEach(message -> {
+
org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage.Builder builder =
+
org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage.newBuilder();
+
+builder.setScopeId(message.getScopeId());
+builder.setScope(message.getScope());
+builder.setName(message.getName());
+builder.setId0(message.getId0());
+builder.setId1(message.getId1());
+builder.setRuleName(message.getRuleName());
+builder.setAlarmMessage(message.getAlarmMessage());
+builder.setStartTime(message.getStartTime());
+
+streamObserver.onNext(builder.build());
+});
+
+streamObserver.onCompleted();
+
+long sleepTime = 0;
+long cycle = 100L;
+/**
+ * For memory safe of oap, we must wait for the peer confirmation.
+ */
+while (!status.isDone()) {
 
 Review comment:
   Yes, I agree. I missed that last time. 


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 

[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.

2020-02-11 Thread GitBox
wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377668907
 
 

 ##
 File path: 
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/grpc/GRPCCallback.java
 ##
 @@ -0,0 +1,145 @@
+/*
+ * 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.skywalking.oap.server.core.alarm.provider.grpc;
+
+import io.grpc.stub.StreamObserver;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.core.alarm.AlarmCallback;
+import org.apache.skywalking.oap.server.core.alarm.AlarmMessage;
+import org.apache.skywalking.oap.server.core.alarm.grpc.AlarmServiceGrpc;
+import org.apache.skywalking.oap.server.core.alarm.grpc.Response;
+import org.apache.skywalking.oap.server.core.alarm.provider.AlarmRulesWatcher;
+import org.apache.skywalking.oap.server.core.exporter.ExportStatus;
+import org.apache.skywalking.oap.server.library.client.grpc.GRPCClient;
+
+/**
+ * Use SkyWalking alarm grpc API call a remote methods.
+ */
+@Slf4j
+public class GRPCCallback implements AlarmCallback {
+
+private AlarmRulesWatcher alarmRulesWatcher;
+
+private GRPCAlarmSetting alarmSetting;
+
+private AlarmServiceGrpc.AlarmServiceStub alarmServiceStub;
+
+private GRPCClient grpcClient;
+
+public GRPCCallback(AlarmRulesWatcher alarmRulesWatcher) {
+this.alarmRulesWatcher = alarmRulesWatcher;
+alarmSetting = alarmRulesWatcher.getGrpchookSetting();
+
+if (alarmSetting != null) {
+grpcClient = new GRPCClient(alarmSetting.getTargetHost(), 
alarmSetting.getTargetPort());
+}
+}
+
+@Override
+public void doAlarm(List alarmMessage) {
+
+if (alarmSetting == null) {
+return;
+}
+
+// recreate gRPC client if host and port configuration changed.
+onGRPCAlarmSettingUpdated(alarmRulesWatcher.getGrpchookSetting());
+
+grpcClient.connect();
+alarmServiceStub = AlarmServiceGrpc.newStub(grpcClient.getChannel());
 
 Review comment:
   We should, but, the setting could not change here.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.

2020-02-11 Thread GitBox
wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377652350
 
 

 ##
 File path: 
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/grpc/GRPCCallback.java
 ##
 @@ -0,0 +1,145 @@
+/*
+ * 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.skywalking.oap.server.core.alarm.provider.grpc;
+
+import io.grpc.stub.StreamObserver;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.core.alarm.AlarmCallback;
+import org.apache.skywalking.oap.server.core.alarm.AlarmMessage;
+import org.apache.skywalking.oap.server.core.alarm.grpc.AlarmServiceGrpc;
+import org.apache.skywalking.oap.server.core.alarm.grpc.Response;
+import org.apache.skywalking.oap.server.core.alarm.provider.AlarmRulesWatcher;
+import org.apache.skywalking.oap.server.core.exporter.ExportStatus;
+import org.apache.skywalking.oap.server.library.client.grpc.GRPCClient;
+
+/**
+ * Use SkyWalking alarm grpc API call a remote methods.
+ */
+@Slf4j
+public class GRPCCallback implements AlarmCallback {
+
+private AlarmRulesWatcher alarmRulesWatcher;
+
+private GRPCAlarmSetting alarmSetting;
+
+private AlarmServiceGrpc.AlarmServiceStub alarmServiceStub;
+
+private GRPCClient grpcClient;
+
+public GRPCCallback(AlarmRulesWatcher alarmRulesWatcher) {
+this.alarmRulesWatcher = alarmRulesWatcher;
+alarmSetting = alarmRulesWatcher.getGrpchookSetting();
+
+if (alarmSetting != null) {
+grpcClient = new GRPCClient(alarmSetting.getTargetHost(), 
alarmSetting.getTargetPort());
+}
+}
+
+@Override
+public void doAlarm(List alarmMessage) {
+
+if (alarmSetting == null) {
+return;
+}
+
+// recreate gRPC client if host and port configuration changed.
+onGRPCAlarmSettingUpdated(alarmRulesWatcher.getGrpchookSetting());
+
+grpcClient.connect();
+alarmServiceStub = AlarmServiceGrpc.newStub(grpcClient.getChannel());
 
 Review comment:
   I think we should not create stub and connect every time. Right?


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.

2020-02-11 Thread GitBox
wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377652037
 
 

 ##
 File path: 
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/grpc/GRPCCallback.java
 ##
 @@ -0,0 +1,145 @@
+/*
+ * 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.skywalking.oap.server.core.alarm.provider.grpc;
+
+import io.grpc.stub.StreamObserver;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.core.alarm.AlarmCallback;
+import org.apache.skywalking.oap.server.core.alarm.AlarmMessage;
+import org.apache.skywalking.oap.server.core.alarm.grpc.AlarmServiceGrpc;
+import org.apache.skywalking.oap.server.core.alarm.grpc.Response;
+import org.apache.skywalking.oap.server.core.alarm.provider.AlarmRulesWatcher;
+import org.apache.skywalking.oap.server.core.exporter.ExportStatus;
+import org.apache.skywalking.oap.server.library.client.grpc.GRPCClient;
+
+/**
+ * Use SkyWalking alarm grpc API call a remote methods.
+ */
+@Slf4j
+public class GRPCCallback implements AlarmCallback {
+
+private AlarmRulesWatcher alarmRulesWatcher;
+
+private GRPCAlarmSetting alarmSetting;
+
+private AlarmServiceGrpc.AlarmServiceStub alarmServiceStub;
+
+private GRPCClient grpcClient;
+
+public GRPCCallback(AlarmRulesWatcher alarmRulesWatcher) {
+this.alarmRulesWatcher = alarmRulesWatcher;
+alarmSetting = alarmRulesWatcher.getGrpchookSetting();
+
+if (alarmSetting != null) {
+grpcClient = new GRPCClient(alarmSetting.getTargetHost(), 
alarmSetting.getTargetPort());
+}
+}
+
+@Override
+public void doAlarm(List alarmMessage) {
+
+if (alarmSetting == null) {
+return;
+}
+
+// recreate gRPC client if host and port configuration changed.
+onGRPCAlarmSettingUpdated(alarmRulesWatcher.getGrpchookSetting());
+
+grpcClient.connect();
+alarmServiceStub = AlarmServiceGrpc.newStub(grpcClient.getChannel());
+
+ExportStatus status = new ExportStatus();
+
+
StreamObserver 
streamObserver =
+alarmServiceStub.withDeadlineAfter(10, 
TimeUnit.SECONDS).doAlarm(new StreamObserver() {
+@Override
+public void onNext(Response response) {
+// ignore empty response
+}
+
+@Override
+public void onError(Throwable throwable) {
+status.done();
+if (log.isDebugEnabled()) {
+log.debug("Send alarm message failed: {}", 
throwable.getMessage());
+}
+}
+
+@Override
+public void onCompleted() {
+status.done();
+if (log.isDebugEnabled()) {
+log.debug("Send alarm message successful.");
+}
+}
+});
+
+alarmMessage.forEach(message -> {
+
org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage.Builder builder =
+
org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage.newBuilder();
+
+builder.setScopeId(message.getScopeId());
+builder.setScope(message.getScope());
+builder.setName(message.getName());
+builder.setId0(message.getId0());
+builder.setId1(message.getId1());
+builder.setRuleName(message.getRuleName());
+builder.setAlarmMessage(message.getAlarmMessage());
+builder.setStartTime(message.getStartTime());
+
+streamObserver.onNext(builder.build());
+});
+
+streamObserver.onCompleted();
+
+long sleepTime = 0;
+long cycle = 100L;
+/**
+ * For memory safe of oap, we must wait for the peer confirmation.
+ */
+while (!status.isDone()) {
+try {
+sleepTime += cycle;
+Thread.sleep(cycle);
+} catch (InterruptedException e) {
+

[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.

2020-02-11 Thread GitBox
wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377652695
 
 

 ##
 File path: 
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/grpc/GRPCCallback.java
 ##
 @@ -0,0 +1,145 @@
+/*
+ * 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.skywalking.oap.server.core.alarm.provider.grpc;
+
+import io.grpc.stub.StreamObserver;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.core.alarm.AlarmCallback;
+import org.apache.skywalking.oap.server.core.alarm.AlarmMessage;
+import org.apache.skywalking.oap.server.core.alarm.grpc.AlarmServiceGrpc;
+import org.apache.skywalking.oap.server.core.alarm.grpc.Response;
+import org.apache.skywalking.oap.server.core.alarm.provider.AlarmRulesWatcher;
+import org.apache.skywalking.oap.server.core.exporter.ExportStatus;
+import org.apache.skywalking.oap.server.library.client.grpc.GRPCClient;
+
+/**
+ * Use SkyWalking alarm grpc API call a remote methods.
+ */
+@Slf4j
+public class GRPCCallback implements AlarmCallback {
+
+private AlarmRulesWatcher alarmRulesWatcher;
+
+private GRPCAlarmSetting alarmSetting;
+
+private AlarmServiceGrpc.AlarmServiceStub alarmServiceStub;
+
+private GRPCClient grpcClient;
+
+public GRPCCallback(AlarmRulesWatcher alarmRulesWatcher) {
+this.alarmRulesWatcher = alarmRulesWatcher;
+alarmSetting = alarmRulesWatcher.getGrpchookSetting();
+
+if (alarmSetting != null) {
+grpcClient = new GRPCClient(alarmSetting.getTargetHost(), 
alarmSetting.getTargetPort());
+}
+}
+
+@Override
+public void doAlarm(List alarmMessage) {
+
+if (alarmSetting == null) {
+return;
+}
+
+// recreate gRPC client if host and port configuration changed.
+onGRPCAlarmSettingUpdated(alarmRulesWatcher.getGrpchookSetting());
+
+grpcClient.connect();
+alarmServiceStub = AlarmServiceGrpc.newStub(grpcClient.getChannel());
+
+ExportStatus status = new ExportStatus();
+
+
StreamObserver 
streamObserver =
+alarmServiceStub.withDeadlineAfter(10, 
TimeUnit.SECONDS).doAlarm(new StreamObserver() {
+@Override
+public void onNext(Response response) {
+// ignore empty response
+}
+
+@Override
+public void onError(Throwable throwable) {
+status.done();
+if (log.isDebugEnabled()) {
+log.debug("Send alarm message failed: {}", 
throwable.getMessage());
+}
+}
+
+@Override
+public void onCompleted() {
+status.done();
+if (log.isDebugEnabled()) {
+log.debug("Send alarm message successful.");
+}
+}
+});
+
+alarmMessage.forEach(message -> {
+
org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage.Builder builder =
+
org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage.newBuilder();
+
+builder.setScopeId(message.getScopeId());
+builder.setScope(message.getScope());
+builder.setName(message.getName());
+builder.setId0(message.getId0());
+builder.setId1(message.getId1());
+builder.setRuleName(message.getRuleName());
+builder.setAlarmMessage(message.getAlarmMessage());
+builder.setStartTime(message.getStartTime());
+
+streamObserver.onNext(builder.build());
+});
+
+streamObserver.onCompleted();
+
+long sleepTime = 0;
+long cycle = 100L;
+/**
+ * For memory safe of oap, we must wait for the peer confirmation.
+ */
+while (!status.isDone()) {
+try {
+sleepTime += cycle;
+Thread.sleep(cycle);
+} catch (InterruptedException e) {
+

[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.

2020-02-11 Thread GitBox
wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377651089
 
 

 ##
 File path: 
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/grpc/GRPCAlarmSetting.java
 ##
 @@ -0,0 +1,47 @@
+/*
+ * 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.skywalking.oap.server.core.alarm.provider.grpc;
+
+import java.util.Objects;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.skywalking.oap.server.library.module.ModuleConfig;
+
+@Setter
+@Getter
+public class GRPCAlarmSetting extends ModuleConfig {
 
 Review comment:
   Why this extends `ModuleConfig`?


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.

2020-02-11 Thread GitBox
wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377650108
 
 

 ##
 File path: docs/en/setup/backend/backend-alarm.md
 ##
 @@ -115,9 +115,11 @@ Example as following
 ```
 
 ## gRPCHook
-This code language could be `Protobuf` which are defined in 
`oap-server/server-alarm-plugin/src/main/proto/alarm-hook.proto`.
-It will result as following:
-```text
+The alarm message will send through remote gRPC method by `Protobuf` content 
type. 
+The message format with following key information which are defined in 
`oap-server/server-alarm-plugin/src/main/proto/alarm-hook.proto`.
+
+Example as following
 
 Review comment:
   This is not example, this is the message protocol :)


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.

2020-02-11 Thread GitBox
wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377634229
 
 

 ##
 File path: 
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/grpc/GRPCCallback.java
 ##
 @@ -0,0 +1,130 @@
+/*
+ * 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.skywalking.oap.server.core.alarm.provider.grpc;
+
+import io.grpc.stub.StreamObserver;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.core.alarm.AlarmCallback;
+import org.apache.skywalking.oap.server.core.alarm.AlarmMessage;
+import org.apache.skywalking.oap.server.core.alarm.grpc.AlarmServiceGrpc;
+import org.apache.skywalking.oap.server.core.alarm.grpc.Response;
+import org.apache.skywalking.oap.server.core.alarm.provider.AlarmRulesWatcher;
+import org.apache.skywalking.oap.server.core.exporter.ExportStatus;
+import org.apache.skywalking.oap.server.library.client.grpc.GRPCClient;
+
+/**
+ * Use SkyWalking alarm grpc API call a remote methods.
+ */
+@Slf4j
+public class GRPCCallback implements AlarmCallback {
+
+private GRPCAlarmSetting alarmSetting;
+
+private AlarmServiceGrpc.AlarmServiceStub alarmServiceStub;
+
+private GRPCClient grpcClient;
+
+public GRPCCallback(AlarmRulesWatcher alarmRulesWatcher) {
+alarmSetting = alarmRulesWatcher.getGrpchookSetting();
+}
+
+@Override
+public void doAlarm(List alarmMessage) {
+
+if (alarmSetting == null) {
+return;
+}
+
+grpcClient = new GRPCClient(alarmSetting.getTargetHost(), 
alarmSetting.getTargetPort());
 
 Review comment:
   Take a look at how HTTP works, it should be similar, just keep the existing 
client settings, and only create the new stub when settings changed.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.

2020-02-11 Thread GitBox
wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377609473
 
 

 ##
 File path: 
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/grpc/GRPCCallback.java
 ##
 @@ -0,0 +1,123 @@
+/*
+ * 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.skywalking.oap.server.core.alarm.provider.grpc;
+
+import io.grpc.stub.StreamObserver;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.core.alarm.AlarmCallback;
+import org.apache.skywalking.oap.server.core.alarm.AlarmMessage;
+import org.apache.skywalking.oap.server.core.alarm.grpc.AlarmServiceGrpc;
+import org.apache.skywalking.oap.server.core.alarm.grpc.Response;
+import org.apache.skywalking.oap.server.core.alarm.provider.AlarmRulesWatcher;
+import org.apache.skywalking.oap.server.core.exporter.ExportStatus;
+import org.apache.skywalking.oap.server.library.client.grpc.GRPCClient;
+
+/**
+ * Use SkyWalking alarm grpc API call a remote methods.
+ */
+@Slf4j
+public class GRPCCallback implements AlarmCallback {
+
+GRPCAlarmSetting alarmSetting;
+
+private AlarmServiceGrpc.AlarmServiceStub alarmServiceStub;
+
+public GRPCCallback(AlarmRulesWatcher alarmRulesWatcher) {
+alarmSetting = alarmRulesWatcher.getGrpchookSetting();
+if (alarmSetting != null) {
+GRPCClient client = new GRPCClient(alarmSetting.getTargetHost(), 
alarmSetting.getTargetPort());
 
 Review comment:
   Look like this setting isn't supporting dynamic change? But the HTTP could. 
I think we should keep this consistent?


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.

2020-02-11 Thread GitBox
wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377609073
 
 

 ##
 File path: 
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/grpc/GRPCCallback.java
 ##
 @@ -0,0 +1,123 @@
+/*
+ * 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.skywalking.oap.server.core.alarm.provider.grpc;
+
+import io.grpc.stub.StreamObserver;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.core.alarm.AlarmCallback;
+import org.apache.skywalking.oap.server.core.alarm.AlarmMessage;
+import org.apache.skywalking.oap.server.core.alarm.grpc.AlarmServiceGrpc;
+import org.apache.skywalking.oap.server.core.alarm.grpc.Response;
+import org.apache.skywalking.oap.server.core.alarm.provider.AlarmRulesWatcher;
+import org.apache.skywalking.oap.server.core.exporter.ExportStatus;
+import org.apache.skywalking.oap.server.library.client.grpc.GRPCClient;
+
+/**
+ * Use SkyWalking alarm grpc API call a remote methods.
+ */
+@Slf4j
+public class GRPCCallback implements AlarmCallback {
+
+GRPCAlarmSetting alarmSetting;
 
 Review comment:
   Why isn't this private?


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.

2020-02-11 Thread GitBox
wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377605723
 
 

 ##
 File path: docs/en/setup/backend/backend-alarm.md
 ##
 @@ -113,6 +114,24 @@ Example as following
 }]
 ```
 
+## gRPCHook
+The alarm message will send through remote gRPC method by `Protobuf` content 
type. 
+The message format with following key information which are defined in 
`oap-server/server-alarm-plugin/src/main/proto/alarm-hook.proto`.
+
+Example as following
+```text
 
 Review comment:
   @JaredTan95 This should be fixed.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.

2020-02-10 Thread GitBox
wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377411742
 
 

 ##
 File path: 
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/exporter/ExportData.java
 ##
 @@ -0,0 +1,37 @@
+/*
+ * 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.skywalking.oap.server.core.exporter;
+
+import lombok.Getter;
+import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
+import org.apache.skywalking.oap.server.core.analysis.metrics.MetricsMetaInfo;
+
+/**
+ * @author jian.tan
 
 Review comment:
   Don't add `@author`, all these will be removed by @kezhenxu94 's PR once for 
all.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.

2020-02-10 Thread GitBox
wu-sheng commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r376959676
 
 

 ##
 File path: 
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/grpc/GRPCCallback.java
 ##
 @@ -0,0 +1,102 @@
+/*
+ * 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.skywalking.oap.server.core.alarm.provider.grpc;
+
+import io.grpc.stub.StreamObserver;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.core.alarm.AlarmCallback;
+import org.apache.skywalking.oap.server.core.alarm.AlarmMessage;
+import org.apache.skywalking.oap.server.core.alarm.grpc.AlarmServiceGrpc;
+import org.apache.skywalking.oap.server.core.alarm.grpc.Response;
+import org.apache.skywalking.oap.server.core.alarm.provider.AlarmRulesWatcher;
+import org.apache.skywalking.oap.server.library.client.grpc.GRPCClient;
+
+/**
+ * Use SkyWalking alarm grpc API call a remote methods.
+ *
+ * @author jian.tan
+ */
+@Slf4j
+public class GRPCCallback implements AlarmCallback {
+
+GRPCAlarmSetting alarmSetting;
+
+private AlarmServiceGrpc.AlarmServiceStub alarmServiceStub;
+
+public GRPCCallback(AlarmRulesWatcher alarmRulesWatcher) {
+alarmSetting = alarmRulesWatcher.getGrpchookSetting();
+if (alarmSetting != null) {
+GRPCClient client = new GRPCClient(alarmSetting.getTargetHost(), 
alarmSetting.getTargetPort());
+client.connect();
+alarmServiceStub = AlarmServiceGrpc.newStub(client.getChannel());
+}
+}
+
+@Override public void doAlarm(List alarmMessage) {
+
+if (alarmServiceStub == null) {
+return;
+}
+
+
StreamObserver 
streamObserver =
+alarmServiceStub.withDeadlineAfter(10, 
TimeUnit.SECONDS).doAlarm(new StreamObserver() {
+@Override public void onNext(Response response) {
+
+}
+
+@Override public void onError(Throwable throwable) {
+if (log.isDebugEnabled()) {
+log.debug("Send alarm message failed: {}", 
throwable.getMessage());
+}
+
+}
+
+@Override public void onCompleted() {
+if (log.isDebugEnabled()) {
+log.debug("Send alarm message successful.");
+}
+}
+});
+
+alarmMessage.forEach(message -> {
+
org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage.Builder builder =
+
org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage.newBuilder();
+
+builder.setScopeId(message.getScopeId());
+builder.setScope(message.getScope());
+builder.setName(message.getName());
+builder.setId0(message.getId0());
+builder.setId1(message.getId1());
+builder.setRuleName(message.getRuleName());
+builder.setAlarmMessage(message.getAlarmMessage());
+builder.setStartTime(message.getStartTime());
+
+streamObserver.onNext(builder.build());
+});
+
+streamObserver.onCompleted();
+
+if (log.isDebugEnabled()) {
 
 Review comment:
   If you are using gRPC stream, you should use wait for the onComplete event 
to avoid the memory leak. What do you think?


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services