You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2020/02/10 09:44:49 UTC
[GitHub] [skywalking] JaredTan95 opened a new pull request #4344: supprt
gRPC alarm hook.
JaredTan95 opened a new pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344
Please answer these questions before submitting pull request
- Why submit this pull request?
- [ ] Bug fix
- [ ] New feature provided
- [ ] Improve performance
- Related issues
___
### New feature or improvement
- Describe the details and related test reports.
send alarm message through remote gRPC way.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on issue #4344: supprt gRPC alarm
hook.
Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#issuecomment-585052587
@kezhenxu94 Recheck?
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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> 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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] kezhenxu94 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377996414
##########
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.
Of course you should take care whether the client is initialized or not
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] kezhenxu94 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r378103923
##########
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.
Following the `codeStyle.xml`, the `import` order is deterministic, these changes are expected because I didn't format them before
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] codecov-io commented on issue #4344: supprt gRPC alarm
hook.
Posted by GitBox <gi...@apache.org>.
codecov-io commented on issue #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#issuecomment-584597339
# [Codecov](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`master@11f0ea1`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference#section-missing-base-commit).
> The diff coverage is `n/a`.
[](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #4344 +/- ##
=========================================
Coverage ? 26.42%
=========================================
Files ? 1179
Lines ? 26743
Branches ? 3690
=========================================
Hits ? 7068
Misses ? 19051
Partials ? 624
```
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=footer). Last update [11f0ea1...2f5a4ee](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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> alarmMessage) {
+
+ if (alarmServiceStub == null) {
+ return;
+ }
+
+ StreamObserver<org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage> streamObserver =
+ alarmServiceStub.withDeadlineAfter(10, TimeUnit.SECONDS).doAlarm(new StreamObserver<Response>() {
+ @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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] codecov-io edited a comment on issue #4344: supprt
gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on issue #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#issuecomment-584597339
# [Codecov](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=h1) Report
> Merging [#4344](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=desc) into [master](https://codecov.io/gh/apache/skywalking/commit/2f5a4ee7453dfe82cd0ae6f4a8f27382a9336b44?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.
[](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #4344 +/- ##
=======================================
Coverage 26.42% 26.42%
=======================================
Files 1179 1179
Lines 26743 26743
Branches 3690 3690
=======================================
Hits 7068 7068
Misses 19051 19051
Partials 624 624
```
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=footer). Last update [2f5a4ee...5a36298](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] JaredTan95 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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> 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<org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage> streamObserver =
+ alarmServiceStub.withDeadlineAfter(10, TimeUnit.SECONDS).doAlarm(new StreamObserver<Response>() {
+ @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) {
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Send {} alarm message to {}:{}.", alarmMessage.size(),
+ alarmSetting.getTargetHost(), alarmSetting.getTargetPort()
+ );
+ }
+
+ if (sleepTime > 2000L) {
+ log.debug("Send {} alarm message to {}:{}, wait {} milliseconds.", alarmMessage.size(),
Review comment:
This should be a warning?
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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> alarmMessage) {
+
+ if (alarmSetting == null) {
+ return;
+ }
+
+ // recreate gRPC client if host and port configuration changed.
+ onGRPCAlarmSettingUpdated(alarmRulesWatcher.getGrpchookSetting());
+
+ ExportStatus status = new ExportStatus();
+
+ StreamObserver<org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage> streamObserver =
+ alarmServiceStub.withDeadlineAfter(10, TimeUnit.SECONDS).doAlarm(new StreamObserver<Response>() {
+ @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, 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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on issue #4344: supprt gRPC alarm
hook.
Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#issuecomment-584538031
The strict format rule has been merged, please update this PR.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] kezhenxu94 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377988008
##########
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:
Alarm is rare in most cases, this client may be lazily initialized (in doAlarm 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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] JaredTan95 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] kezhenxu94 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377711492
##########
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> alarmMessage) {
+
+ if (alarmSetting == null) {
+ return;
+ }
+
+ // recreate gRPC client if host and port configuration changed.
+ onGRPCAlarmSettingUpdated(alarmRulesWatcher.getGrpchookSetting());
+
+ ExportStatus status = new ExportStatus();
+
+ StreamObserver<org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage> streamObserver =
+ alarmServiceStub.withDeadlineAfter(10, TimeUnit.SECONDS).doAlarm(new StreamObserver<Response>() {
+ @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:
> ExportStatus is in exporter, why use it in the alarm?
Maybe a `CountDownLatch` makes it more convenient?
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] JaredTan95 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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> alarmMessage) {
+
+ if (alarmSetting == null) {
+ return;
+ }
+
+ // recreate gRPC client if host and port configuration changed.
+ onGRPCAlarmSettingUpdated(alarmRulesWatcher.getGrpchookSetting());
+
+ ExportStatus status = new ExportStatus();
+
+ StreamObserver<org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage> streamObserver =
+ alarmServiceStub.withDeadlineAfter(10, TimeUnit.SECONDS).doAlarm(new StreamObserver<Response>() {
+ @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 to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
[WIP]supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
wu-sheng commented on a change in pull request #4344: [WIP]supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377000041
##########
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> alarmMessage) {
+
+ if (alarmServiceStub == null) {
+ return;
+ }
+
+ StreamObserver<org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage> streamObserver =
+ alarmServiceStub.withDeadlineAfter(10, TimeUnit.SECONDS).doAlarm(new StreamObserver<Response>() {
+ @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:
Waiting for your update.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] kezhenxu94 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377711492
##########
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> alarmMessage) {
+
+ if (alarmSetting == null) {
+ return;
+ }
+
+ // recreate gRPC client if host and port configuration changed.
+ onGRPCAlarmSettingUpdated(alarmRulesWatcher.getGrpchookSetting());
+
+ ExportStatus status = new ExportStatus();
+
+ StreamObserver<org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage> streamObserver =
+ alarmServiceStub.withDeadlineAfter(10, TimeUnit.SECONDS).doAlarm(new StreamObserver<Response>() {
+ @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:
> ExportStatus is in exporter, why use it in the alarm?
Maybe a `CountDownLatch` makes it more convenient and safe (in terms of thread visibility)?
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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> 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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] kezhenxu94 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377996822
##########
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:
Anyway, not important thing, mark as resolved
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] JaredTan95 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] JaredTan95 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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> alarmMessage) {
+
+ if (alarmServiceStub == null) {
+ return;
+ }
+
+ StreamObserver<org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage> streamObserver =
+ alarmServiceStub.withDeadlineAfter(10, TimeUnit.SECONDS).doAlarm(new StreamObserver<Response>() {
+ @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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on issue #4344: supprt gRPC alarm
hook.
Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#issuecomment-584442704
Yes.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] JaredTan95 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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> 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<org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage> streamObserver =
+ alarmServiceStub.withDeadlineAfter(10, TimeUnit.SECONDS).doAlarm(new StreamObserver<Response>() {
+ @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) {
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Send {} alarm message to {}:{}.", alarmMessage.size(),
+ alarmSetting.getTargetHost(), alarmSetting.getTargetPort()
+ );
+ }
+
+ if (sleepTime > 2000L) {
+ log.debug("Send {} alarm message to {}:{}, wait {} milliseconds.", alarmMessage.size(),
Review comment:
Yeah, `warn` is enough.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] JaredTan95 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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> 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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] JaredTan95 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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> alarmMessage) {
+
+ if (alarmSetting == null) {
+ return;
+ }
+
+ // recreate gRPC client if host and port configuration changed.
+ onGRPCAlarmSettingUpdated(alarmRulesWatcher.getGrpchookSetting());
+
+ ExportStatus status = new ExportStatus();
+
+ StreamObserver<org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage> streamObserver =
+ alarmServiceStub.withDeadlineAfter(10, TimeUnit.SECONDS).doAlarm(new StreamObserver<Response>() {
+ @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 the same problem and for reuse `ExportStatus`, move to higher-level package looks good.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] codecov-io edited a comment on issue #4344: supprt
gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on issue #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#issuecomment-584597339
# [Codecov](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=h1) Report
> Merging [#4344](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=desc) into [master](https://codecov.io/gh/apache/skywalking/commit/2f5a4ee7453dfe82cd0ae6f4a8f27382a9336b44?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `41.3%`.
[](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #4344 +/- ##
=========================================
- Coverage 26.42% 26.4% -0.02%
=========================================
Files 1179 1180 +1
Lines 26743 26767 +24
Branches 3690 3696 +6
=========================================
+ Hits 7068 7069 +1
- Misses 19051 19070 +19
- Partials 624 628 +4
```
| [Impacted Files](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [...king/oap/server/library/util/GRPCStreamStatus.java](https://codecov.io/gh/apache/skywalking/pull/4344/diff?src=pr&el=tree#diff-b2FwLXNlcnZlci9zZXJ2ZXItbGlicmFyeS9saWJyYXJ5LXV0aWwvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NreXdhbGtpbmcvb2FwL3NlcnZlci9saWJyYXJ5L3V0aWwvR1JQQ1N0cmVhbVN0YXR1cy5qYXZh) | `0% <ø> (ø)` | |
| [.../server/core/alarm/provider/grpc/GRPCCallback.java](https://codecov.io/gh/apache/skywalking/pull/4344/diff?src=pr&el=tree#diff-b2FwLXNlcnZlci9zZXJ2ZXItYWxhcm0tcGx1Z2luL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9za3l3YWxraW5nL29hcC9zZXJ2ZXIvY29yZS9hbGFybS9wcm92aWRlci9ncnBjL0dSUENDYWxsYmFjay5qYXZh) | `60.86% <35.71%> (-11.68%)` | :arrow_down: |
| [...ver/core/alarm/provider/grpc/GRPCAlarmSetting.java](https://codecov.io/gh/apache/skywalking/pull/4344/diff?src=pr&el=tree#diff-b2FwLXNlcnZlci9zZXJ2ZXItYWxhcm0tcGx1Z2luL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9za3l3YWxraW5nL29hcC9zZXJ2ZXIvY29yZS9hbGFybS9wcm92aWRlci9ncnBjL0dSUENBbGFybVNldHRpbmcuamF2YQ==) | `50% <50%> (ø)` | |
| [...ap/server/exporter/provider/grpc/GRPCExporter.java](https://codecov.io/gh/apache/skywalking/pull/4344/diff?src=pr&el=tree#diff-b2FwLXNlcnZlci9leHBvcnRlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2t5d2Fsa2luZy9vYXAvc2VydmVyL2V4cG9ydGVyL3Byb3ZpZGVyL2dycGMvR1JQQ0V4cG9ydGVyLmphdmE=) | `75.82% <50%> (-2.34%)` | :arrow_down: |
| [.../skywalking/apm/agent/core/remote/GRPCChannel.java](https://codecov.io/gh/apache/skywalking/pull/4344/diff?src=pr&el=tree#diff-YXBtLXNuaWZmZXIvYXBtLWFnZW50LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NreXdhbGtpbmcvYXBtL2FnZW50L2NvcmUvcmVtb3RlL0dSUENDaGFubmVsLmphdmE=) | `81.25% <0%> (-6.25%)` | :arrow_down: |
| [.../agent/core/context/trace/AbstractTracingSpan.java](https://codecov.io/gh/apache/skywalking/pull/4344/diff?src=pr&el=tree#diff-YXBtLXNuaWZmZXIvYXBtLWFnZW50LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NreXdhbGtpbmcvYXBtL2FnZW50L2NvcmUvY29udGV4dC90cmFjZS9BYnN0cmFjdFRyYWNpbmdTcGFuLmphdmE=) | `61.6% <0%> (-2.68%)` | :arrow_down: |
| [...king/apm/agent/core/remote/GRPCChannelManager.java](https://codecov.io/gh/apache/skywalking/pull/4344/diff?src=pr&el=tree#diff-YXBtLXNuaWZmZXIvYXBtLWFnZW50LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NreXdhbGtpbmcvYXBtL2FnZW50L2NvcmUvcmVtb3RlL0dSUENDaGFubmVsTWFuYWdlci5qYXZh) | `69.23% <0%> (-1.29%)` | :arrow_down: |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=footer). Last update [2f5a4ee...0635bbe](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] JaredTan95 commented on issue #4344: supprt gRPC alarm
hook.
Posted by GitBox <gi...@apache.org>.
JaredTan95 commented on issue #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#issuecomment-584439653
Acording to https://github.com/apache/skywalking/pull/4337, should remove `@author` anonatation, 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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] JaredTan95 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] codecov-io edited a comment on issue #4344: supprt
gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on issue #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#issuecomment-584597339
# [Codecov](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=h1) Report
> Merging [#4344](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=desc) into [master](https://codecov.io/gh/apache/skywalking/commit/0635bbe9b637a9baabd2ca244cdf99e6d9f62efe?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.
[](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #4344 +/- ##
=======================================
Coverage 26.43% 26.43%
=======================================
Files 1180 1180
Lines 26767 26767
Branches 3696 3696
=======================================
Hits 7075 7075
Misses 19065 19065
Partials 627 627
```
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=footer). Last update [0635bbe...abaee0f](https://codecov.io/gh/apache/skywalking/pull/4344?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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> 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<org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage> streamObserver =
+ alarmServiceStub.withDeadlineAfter(10, TimeUnit.SECONDS).doAlarm(new StreamObserver<Response>() {
+ @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) {
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Send {} alarm message to {}:{}.", alarmMessage.size(),
+ alarmSetting.getTargetHost(), alarmSetting.getTargetPort()
+ );
+ }
+
+ if (sleepTime > 2000L) {
+ log.debug("Send {} alarm message to {}:{}, wait {} milliseconds.", alarmMessage.size(),
+ alarmSetting.getTargetHost(), alarmSetting.getTargetPort(), sleepTime
+ );
+ cycle = 2000L;
+ }
+ }
+ }
+
+ private void onGRPCAlarmSettingUpdated(GRPCAlarmSetting grpcAlarmSetting) {
+ if (!grpcAlarmSetting.equals(alarmSetting)) {
+ grpcClient = new GRPCClient(grpcAlarmSetting.getTargetHost(), grpcAlarmSetting.getTargetPort());
Review comment:
There is a connection leak here, the old one should be closed.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] kezhenxu94 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377987571
##########
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());
+ }
+ }
+
+ @Override
+ public void doAlarm(List<AlarmMessage> alarmMessage) {
+
+ if (alarmSetting == null) {
+ return;
+ }
+
+ // recreate gRPC client if host and port configuration changed.
+ onGRPCAlarmSettingUpdated(alarmRulesWatcher.getGrpchookSetting());
+
+ GRPCStreamStatus status = new GRPCStreamStatus();
+
+ StreamObserver<org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage> streamObserver =
+ alarmServiceStub.withDeadlineAfter(10, TimeUnit.SECONDS).doAlarm(new StreamObserver<Response>() {
+ @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 ignored) {
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Send {} alarm message to {}:{}.", alarmMessage.size(),
+ alarmSetting.getTargetHost(), alarmSetting.getTargetPort()
+ );
+ }
+
+ if (sleepTime > 2000L) {
+ log.warn("Send {} alarm message to {}:{}, wait {} milliseconds.", alarmMessage.size(),
+ alarmSetting.getTargetHost(), alarmSetting.getTargetPort(), sleepTime
+ );
+ cycle = 2000L;
+ }
+ }
+ }
+
+ private void onGRPCAlarmSettingUpdated(GRPCAlarmSetting grpcAlarmSetting) {
+ if (!grpcAlarmSetting.equals(alarmSetting)) {
+ grpcClient.shutdown();
+ grpcClient = new GRPCClient(grpcAlarmSetting.getTargetHost(), grpcAlarmSetting.getTargetPort());
Review comment:
What if the user delete the gRPC hooks entirely? Say target host and port is empty
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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> 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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] kezhenxu94 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377695139
##########
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> alarmMessage) {
+
+ if (alarmSetting == null) {
+ return;
+ }
+
+ // recreate gRPC client if host and port configuration changed.
+ onGRPCAlarmSettingUpdated(alarmRulesWatcher.getGrpchookSetting());
+
+ ExportStatus status = new ExportStatus();
+
+ StreamObserver<org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage> streamObserver =
+ alarmServiceStub.withDeadlineAfter(10, TimeUnit.SECONDS).doAlarm(new StreamObserver<Response>() {
+ @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;
+ /**
Review comment:
Dangling Javadoc comment
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] JohnNiang commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
JohnNiang commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377652539
##########
File path: oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/grpc/GRPCAlarmSetting.java
##########
@@ -27,4 +28,20 @@
public class GRPCAlarmSetting extends ModuleConfig {
private String targetHost;
private int targetPort;
+
+ @Override
+ public boolean equals(final Object o) {
Review comment:
`equals` and `hashCode` methods could be replaced by Lombok annotation: `@EqualsAndHashCode(callSuper = false)`
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] JaredTan95 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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> alarmMessage) {
+
+ if (alarmSetting == null) {
+ return;
+ }
+
+ // recreate gRPC client if host and port configuration changed.
+ onGRPCAlarmSettingUpdated(alarmRulesWatcher.getGrpchookSetting());
+
+ ExportStatus status = new ExportStatus();
+
+ StreamObserver<org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage> streamObserver =
+ alarmServiceStub.withDeadlineAfter(10, TimeUnit.SECONDS).doAlarm(new StreamObserver<Response>() {
+ @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 the same problem and for reuse `ExportStatus`, move to higher-level package just ok.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] JaredTan95 merged pull request #4344: supprt gRPC
alarm hook.
Posted by GitBox <gi...@apache.org>.
JaredTan95 merged pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] JaredTan95 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] kezhenxu94 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377711492
##########
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> alarmMessage) {
+
+ if (alarmSetting == null) {
+ return;
+ }
+
+ // recreate gRPC client if host and port configuration changed.
+ onGRPCAlarmSettingUpdated(alarmRulesWatcher.getGrpchookSetting());
+
+ ExportStatus status = new ExportStatus();
+
+ StreamObserver<org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage> streamObserver =
+ alarmServiceStub.withDeadlineAfter(10, TimeUnit.SECONDS).doAlarm(new StreamObserver<Response>() {
+ @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:
> ExportStatus is in exporter, why use it in the alarm?
Maybe a `CountDownLatch` is enough to make it more convenient and safe (in terms of thread visibility)?
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] JaredTan95 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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> 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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] kezhenxu94 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377694858
##########
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> alarmMessage) {
+
+ if (alarmSetting == null) {
+ return;
+ }
+
+ // recreate gRPC client if host and port configuration changed.
+ onGRPCAlarmSettingUpdated(alarmRulesWatcher.getGrpchookSetting());
+
+ ExportStatus status = new ExportStatus();
+
+ StreamObserver<org.apache.skywalking.oap.server.core.alarm.grpc.AlarmMessage> streamObserver =
+ alarmServiceStub.withDeadlineAfter(10, TimeUnit.SECONDS).doAlarm(new StreamObserver<Response>() {
+ @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:
There may be thread-visibility issue, `org.apache.skywalking.oap.server.core.exporter.ExportStatus#done` is not `volatile`, BTW, `ExportStatus` can be annotated with Lombok annotations
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] kezhenxu94 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #4344: supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377670357
##########
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:
We may not need to show "Part of protocol" file, my suggestion is to **link** to the `alarm-hook.proto` file directly, because the gRPC receiver may be implemented in any language, and the `proto` file is fundamental in any kind of implementation. If I were the user, I'd like to click the link and navigate to the `proto` file directly, instead of finding in the souce codes myself.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] JaredTan95 commented on a change in pull request
#4344: supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] wu-sheng commented on a change in pull request #4344:
supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [skywalking] JohnNiang commented on a change in pull request #4344:
[WIP]supprt gRPC alarm hook.
Posted by GitBox <gi...@apache.org>.
JohnNiang commented on a change in pull request #4344: [WIP]supprt gRPC alarm hook.
URL: https://github.com/apache/skywalking/pull/4344#discussion_r377105587
##########
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:
This code language could be `protobuf`. It will result as following:
```protobuf
message AlarmMessage {
int64 scopeId = 1;
string scope = 2;
string name = 3;
int64 id0 = 4;
int64 id1 = 5;
string ruleName = 6;
string alarmMessage = 7;
int64 startTime = 8;
}
```
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services