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

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

 ##
 File path: 
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/grpc/GRPCCallback.java
 ##
 @@ -0,0 +1,144 @@
+/*
+ * 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;
+import org.apache.skywalking.oap.server.library.util.GRPCStreamStatus;
+
+/**
+ * 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) {
 
 Review comment:
   > What if the user delete the gRPC hooks entirely? Say target host and port 
is empty
   
   If  target host and port is empty, may not step into 
`onGRPCAlarmSettingUpdated` method.


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] JaredTan95 commented on a change in pull request #4344: supprt gRPC alarm hook.

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

 ##
 File path: 
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/grpc/GRPCCallback.java
 ##
 @@ -0,0 +1,144 @@
+/*
+ * 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;
+import org.apache.skywalking.oap.server.library.util.GRPCStreamStatus;
+
+/**
+ * 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) {
 
 Review comment:
   > What if the user delete the gRPC hooks entirely? Say target host and port 
is empty
   
   If  target host and port is empty, may not step into 
`onGRPCAlarmSettingUpdated` method.


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] JaredTan95 commented on a change in pull request #4344: supprt gRPC alarm hook.

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

 ##
 File path: 
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/grpc/GRPCCallback.java
 ##
 @@ -0,0 +1,144 @@
+/*
+ * 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;
+import org.apache.skywalking.oap.server.library.util.GRPCStreamStatus;
+
+/**
+ * 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());
 
 Review comment:
   If that, GRPCClient instance will be initialized every time in`doAlarm` 
mthoid, may not appropriate.


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] JaredTan95 commented on a change in pull request #4344: supprt gRPC alarm hook.

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

 ##
 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:
   Considering `exporter 
grpc`(https://github.com/apache/skywalking/blob/5b255ba3e3b50e0e0196b28cdca21dcd5c9c3da2/oap-server/exporter/src/main/java/org/apache/skywalking/oap/server/exporter/provider/grpc/GRPCExporter.java#L173)
  have 

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

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

 ##
 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:
   Considering `exporter 
grpc`(https://github.com/apache/skywalking/blob/5b255ba3e3b50e0e0196b28cdca21dcd5c9c3da2/oap-server/exporter/src/main/java/org/apache/skywalking/oap/server/exporter/provider/grpc/GRPCExporter.java#L173)
  have 

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

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

 ##
 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`.
 
 Review comment:
   I agree with you, but link `alarm-hook.proto` from docs to `source code` dir 
looks weird. show part of `alarm-hook.proto` and explain `alarm-hook.proto`'s 
location may be more friendly. 


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] JaredTan95 commented on a change in pull request #4344: supprt gRPC alarm hook.

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

 ##
 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] JaredTan95 commented on a change in pull request #4344: supprt gRPC alarm hook.

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

 ##
 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:
   But, we should reconnect when client 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] JaredTan95 commented on a change in pull request #4344: supprt gRPC alarm hook.

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

 ##
 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:
   mistake, i will remove it.


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] JaredTan95 commented on a change in pull request #4344: supprt gRPC alarm hook.

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

 ##
 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:
   This way may not appropriate. I am working on it~


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] JaredTan95 commented on a change in pull request #4344: supprt gRPC alarm hook.

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

 ##
 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:
   Agree


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] JaredTan95 commented on a change in pull request #4344: supprt gRPC alarm hook.

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

 ##
 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:
   make sense


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] JaredTan95 commented on a change in pull request #4344: supprt gRPC alarm hook.

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

 ##
 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:
   Yeah


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