[GitHub] [skywalking] wu-sheng commented on a change in pull request #4987: support sampleRate as Dynamic Configuration (#4968)

2020-07-06 Thread GitBox


wu-sheng commented on a change in pull request #4987:
URL: https://github.com/apache/skywalking/pull/4987#discussion_r450284077



##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceServiceModuleConfig.java
##
@@ -51,6 +51,9 @@
 @Setter
 @Getter
 private UninstrumentedGatewaysConfig uninstrumentedGatewaysConfig;
+@Setter
+@Getter
+private TraceSampleRateWatcher traceSampleRateWatcher;

Review comment:
   OK, ignore this. Continue on others.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] wu-sheng commented on a change in pull request #4987: support sampleRate as Dynamic Configuration (#4968)

2020-07-06 Thread GitBox


wu-sheng commented on a change in pull request #4987:
URL: https://github.com/apache/skywalking/pull/4987#discussion_r450280604



##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/listener/TraceSegmentSampler.java
##
@@ -25,7 +25,7 @@
  * ignored
  */
 public class TraceSegmentSampler {
-private TraceServiceModuleConfig config;
+private volatile TraceServiceModuleConfig config;

Review comment:
   You are always using the same `config#getTraceSampleRateWatcher ` 
reference, right? As the `config` is never changed, you don't need this. 
`volatile` could cause more CPU, please use it if necessary.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] wu-sheng commented on a change in pull request #4987: support sampleRate as Dynamic Configuration (#4968)

2020-07-06 Thread GitBox


wu-sheng commented on a change in pull request #4987:
URL: https://github.com/apache/skywalking/pull/4987#discussion_r450269014



##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceServiceModuleConfig.java
##
@@ -51,6 +51,9 @@
 @Setter
 @Getter
 private UninstrumentedGatewaysConfig uninstrumentedGatewaysConfig;
+@Setter
+@Getter
+private TraceSampleRateWatcher traceSampleRateWatcher;

Review comment:
   Config should only be changed through the initialization stage. Nothing 
more.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] wu-sheng commented on a change in pull request #4987: support sampleRate as Dynamic Configuration (#4968)

2020-07-06 Thread GitBox


wu-sheng commented on a change in pull request #4987:
URL: https://github.com/apache/skywalking/pull/4987#discussion_r450267890



##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceServiceModuleConfig.java
##
@@ -51,6 +51,9 @@
 @Setter
 @Getter
 private UninstrumentedGatewaysConfig uninstrumentedGatewaysConfig;
+@Setter
+@Getter
+private TraceSampleRateWatcher traceSampleRateWatcher;

Review comment:
   Why config has reference to watcher? This is strange. Watcher should be 
a part of `TraceSegmentSampler`





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] wu-sheng commented on a change in pull request #4987: support sampleRate as Dynamic Configuration (#4968)

2020-07-06 Thread GitBox


wu-sheng commented on a change in pull request #4987:
URL: https://github.com/apache/skywalking/pull/4987#discussion_r450267143



##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/listener/TraceSegmentSampler.java
##
@@ -25,7 +25,7 @@
  * ignored
  */
 public class TraceSegmentSampler {
-private TraceServiceModuleConfig config;
+private volatile TraceServiceModuleConfig config;

Review comment:
   No one will change this reference, @killGC 





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] wu-sheng commented on a change in pull request #4987: support sampleRate as Dynamic Configuration (#4968)

2020-07-06 Thread GitBox


wu-sheng commented on a change in pull request #4987:
URL: https://github.com/apache/skywalking/pull/4987#discussion_r450251240



##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/listener/TraceSegmentSampler.java
##
@@ -25,7 +25,7 @@
  * ignored
  */
 public class TraceSegmentSampler {
-private TraceServiceModuleConfig config;
+private volatile TraceServiceModuleConfig config;

Review comment:
   This change is not right. Please read my review more carefully.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] wu-sheng commented on a change in pull request #4987: support sampleRate as Dynamic Configuration (#4968)

2020-07-06 Thread GitBox


wu-sheng commented on a change in pull request #4987:
URL: https://github.com/apache/skywalking/pull/4987#discussion_r450197761



##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/listener/TraceSegmentSampler.java
##
@@ -18,18 +18,20 @@
 
 package 
org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener;
 
+import 
org.apache.skywalking.oap.server.receiver.trace.provider.TraceServiceModuleConfig;
+
 /**
  * The sampler makes the sampling mechanism works at backend side. Sample 
result: [0,sampleRate) sampled, (sampleRate,~)
  * ignored
  */
 public class TraceSegmentSampler {
-private int sampleRate = 1;
+private TraceServiceModuleConfig config;

Review comment:
   @killGC Could you finish this? then it is ready to merge.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] wu-sheng commented on a change in pull request #4987: support sampleRate as Dynamic Configuration (#4968)

2020-07-05 Thread GitBox


wu-sheng commented on a change in pull request #4987:
URL: https://github.com/apache/skywalking/pull/4987#discussion_r449961053



##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/listener/TraceSegmentSampler.java
##
@@ -18,18 +18,20 @@
 
 package 
org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener;
 
+import 
org.apache.skywalking.oap.server.receiver.trace.provider.TraceServiceModuleConfig;
+
 /**
  * The sampler makes the sampling mechanism works at backend side. Sample 
result: [0,sampleRate) sampled, (sampleRate,~)
  * ignored
  */
 public class TraceSegmentSampler {
-private int sampleRate = 1;
+private TraceServiceModuleConfig config;

Review comment:
   As `TraceServiceModuleConfig#sampleRate` could be changed across thread, 
recommend to add `volatile`
   
   > private volatile int sampleRate = 1;
   
   Just for avoiding unexpected behaviour.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] wu-sheng commented on a change in pull request #4987: support sampleRate as Dynamic Configuration (#4968)

2020-07-04 Thread GitBox


wu-sheng commented on a change in pull request #4987:
URL: https://github.com/apache/skywalking/pull/4987#discussion_r449754625



##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceSampleRateWatcherTest.java
##
@@ -0,0 +1,109 @@
+/*
+ * 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.receiver.trace.provider;
+
+import org.apache.skywalking.oap.server.configuration.api.ConfigChangeWatcher;
+import org.apache.skywalking.oap.server.configuration.api.ConfigTable;
+import 
org.apache.skywalking.oap.server.configuration.api.ConfigWatcherRegister;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import java.util.Optional;
+import java.util.Set;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TraceSampleRateWatcherTest {
+private TraceModuleProvider traceModuleProvider;
+
+@Before
+public void init() {
+traceModuleProvider = new TraceModuleProvider();
+}
+
+@Test
+public void TestInit() {
+TraceSampleRateWatcher traceSampleRateWatcher = new 
TraceSampleRateWatcher(traceModuleProvider);
+Assert.assertEquals(traceSampleRateWatcher.getSampleRate(), 1);
+Assert.assertEquals(traceSampleRateWatcher.value(), "1");
+}
+
+@Test(timeout = 2)
+public void testDynamicUpdate() throws InterruptedException {
+ConfigWatcherRegister register = new MockConfigWatcherRegister(3);
+
+TraceSampleRateWatcher watcher = new 
TraceSampleRateWatcher(traceModuleProvider);
+register.registerConfigChangeWatcher(watcher);
+register.start();
+
+while (watcher.getSampleRate() == 1) {
+Thread.sleep(2000);
+}
+assertThat(watcher.getSampleRate(), is(9000));
+assertThat(traceModuleProvider.getModuleConfig().getSampleRate(), 
is(1));
+}
+
+@Test
+public void TestNotify() {

Review comment:
   FYI @kezhenxu94 Could you check why the method name format didn't check 
this?





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] wu-sheng commented on a change in pull request #4987: support sampleRate as Dynamic Configuration (#4968)

2020-07-04 Thread GitBox


wu-sheng commented on a change in pull request #4987:
URL: https://github.com/apache/skywalking/pull/4987#discussion_r449754600



##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceSampleRateWatcherTest.java
##
@@ -0,0 +1,109 @@
+/*
+ * 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.receiver.trace.provider;
+
+import org.apache.skywalking.oap.server.configuration.api.ConfigChangeWatcher;
+import org.apache.skywalking.oap.server.configuration.api.ConfigTable;
+import 
org.apache.skywalking.oap.server.configuration.api.ConfigWatcherRegister;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import java.util.Optional;
+import java.util.Set;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TraceSampleRateWatcherTest {
+private TraceModuleProvider traceModuleProvider;
+
+@Before
+public void init() {
+traceModuleProvider = new TraceModuleProvider();
+}
+
+@Test
+public void TestInit() {

Review comment:
   ```suggestion
   public void testInit() {
   ```

##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceSampleRateWatcherTest.java
##
@@ -0,0 +1,109 @@
+/*
+ * 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.receiver.trace.provider;
+
+import org.apache.skywalking.oap.server.configuration.api.ConfigChangeWatcher;
+import org.apache.skywalking.oap.server.configuration.api.ConfigTable;
+import 
org.apache.skywalking.oap.server.configuration.api.ConfigWatcherRegister;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import java.util.Optional;
+import java.util.Set;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TraceSampleRateWatcherTest {
+private TraceModuleProvider traceModuleProvider;
+
+@Before
+public void init() {
+traceModuleProvider = new TraceModuleProvider();
+}
+
+@Test
+public void TestInit() {
+TraceSampleRateWatcher traceSampleRateWatcher = new 
TraceSampleRateWatcher(traceModuleProvider);
+Assert.assertEquals(traceSampleRateWatcher.getSampleRate(), 1);
+Assert.assertEquals(traceSampleRateWatcher.value(), "1");
+}
+
+@Test(timeout = 2)
+public void testDynamicUpdate() throws InterruptedException {
+ConfigWatcherRegister register = new MockConfigWatcherRegister(3);
+
+TraceSampleRateWatcher watcher = new 
TraceSampleRateWatcher(traceModuleProvider);
+register.registerConfigChangeWatcher(watcher);
+register.start();
+
+while (watcher.getSampleRate() == 1) {
+Thread.sleep(2000);
+}
+assertThat(watcher.getSampleRate(), is(9000));
+assertThat(traceModuleProvider.getModuleConfig().getSampleRate(), 
is(1));
+}
+
+@Test
+public void TestN

[GitHub] [skywalking] wu-sheng commented on a change in pull request #4987: support sampleRate as Dynamic Configuration (#4968)

2020-07-03 Thread GitBox


wu-sheng commented on a change in pull request #4987:
URL: https://github.com/apache/skywalking/pull/4987#discussion_r449606222



##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceSampleRateWatcher.java
##
@@ -0,0 +1,69 @@
+/*
+ * 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.receiver.trace.provider;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.configuration.api.ConfigChangeWatcher;
+import org.apache.skywalking.oap.server.receiver.trace.module.TraceModule;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+@Slf4j
+public class TraceSampleRateWatcher extends ConfigChangeWatcher {

Review comment:
   @killGC Could you finish the UT codes ASAP, I have to wait that before 
merging.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] wu-sheng commented on a change in pull request #4987: support sampleRate as Dynamic Configuration (#4968)

2020-07-02 Thread GitBox


wu-sheng commented on a change in pull request #4987:
URL: https://github.com/apache/skywalking/pull/4987#discussion_r449328243



##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceSampleRateWatcher.java
##
@@ -0,0 +1,69 @@
+/*
+ * 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.receiver.trace.provider;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.configuration.api.ConfigChangeWatcher;
+import org.apache.skywalking.oap.server.receiver.trace.module.TraceModule;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+@Slf4j
+public class TraceSampleRateWatcher extends ConfigChangeWatcher {
+private  AtomicReference sampleRate;

Review comment:
   ```suggestion
   private AtomicReference sampleRate;
   ```





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] wu-sheng commented on a change in pull request #4987: support sampleRate as Dynamic Configuration (#4968)

2020-07-02 Thread GitBox


wu-sheng commented on a change in pull request #4987:
URL: https://github.com/apache/skywalking/pull/4987#discussion_r449080233



##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceSampleRateWatcher.java
##
@@ -0,0 +1,69 @@
+/*
+ * 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.receiver.trace.provider;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.configuration.api.ConfigChangeWatcher;
+import org.apache.skywalking.oap.server.receiver.trace.module.TraceModule;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+@Slf4j
+public class TraceSampleRateWatcher extends ConfigChangeWatcher {
+private  AtomicReference sampleRate;
+
+public TraceSampleRateWatcher(TraceModuleProvider provider) {
+super(TraceModule.NAME, provider, "sampleRate");
+sampleRate = new AtomicReference<>();
+sampleRate.set(getDefaultValue());
+}
+
+private void activeSetting(String config) {
+if (log.isDebugEnabled()) {
+log.debug("Updating using new static config: {}", config);
+}
+try {
+sampleRate.set(Integer.parseInt(config));
+} catch (NumberFormatException ex) {
+log.error("Cannot load sampleRate from: {}", config, ex);
+}
+}
+
+@Override
+public void notify(ConfigChangeEvent value) {
+if (EventType.DELETE.equals(value.getEventType())) {
+activeSetting(String.valueOf(getDefaultValue()));
+} else {
+activeSetting(value.getNewValue());
+}
+}
+
+@Override
+public String value() {
+return String.valueOf(sampleRate.get());
+}
+
+public int getDefaultValue() {
+return ((TraceModuleProvider) 
this.getProvider()).getModuleConfig().getSampleRate();
+}
+
+public int getSampleRate() {
+return sampleRate.get() == null ? getDefaultValue() : sampleRate.get();

Review comment:
   I think you should use `sampleRate.get()` only. Why `sampleRate.get() == 
null`? In which case?





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] wu-sheng commented on a change in pull request #4987: support sampleRate as Dynamic Configuration (#4968)

2020-07-02 Thread GitBox


wu-sheng commented on a change in pull request #4987:
URL: https://github.com/apache/skywalking/pull/4987#discussion_r449079498



##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceSampleRateWatcher.java
##
@@ -0,0 +1,69 @@
+/*
+ * 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.receiver.trace.provider;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.configuration.api.ConfigChangeWatcher;
+import org.apache.skywalking.oap.server.receiver.trace.module.TraceModule;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+@Slf4j
+public class TraceSampleRateWatcher extends ConfigChangeWatcher {
+private  AtomicReference sampleRate;
+
+public TraceSampleRateWatcher(TraceModuleProvider provider) {
+super(TraceModule.NAME, provider, "sampleRate");
+sampleRate = new AtomicReference<>();
+sampleRate.set(getDefaultValue());
+}
+
+private void activeSetting(String config) {
+if (log.isDebugEnabled()) {
+log.debug("Updating using new static config: {}", config);
+}
+try {
+sampleRate.set(Integer.parseInt(config));
+} catch (NumberFormatException ex) {
+log.error("Cannot load sampleRate from: {}", config, ex);
+}
+}
+
+@Override
+public void notify(ConfigChangeEvent value) {
+if (EventType.DELETE.equals(value.getEventType())) {
+activeSetting(String.valueOf(getDefaultValue()));
+} else {
+activeSetting(value.getNewValue());
+}
+}
+
+@Override
+public String value() {
+return String.valueOf(sampleRate.get());
+}
+
+public int getDefaultValue() {

Review comment:
   Why public?





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] wu-sheng commented on a change in pull request #4987: support sampleRate as Dynamic Configuration (#4968)

2020-07-02 Thread GitBox


wu-sheng commented on a change in pull request #4987:
URL: https://github.com/apache/skywalking/pull/4987#discussion_r449079142



##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceSampleRateWatcher.java
##
@@ -0,0 +1,69 @@
+/*
+ * 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.receiver.trace.provider;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.configuration.api.ConfigChangeWatcher;
+import org.apache.skywalking.oap.server.receiver.trace.module.TraceModule;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+@Slf4j
+public class TraceSampleRateWatcher extends ConfigChangeWatcher {

Review comment:
   Please set up a UT for this. Test this watcher could be driven correctly.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [skywalking] wu-sheng commented on a change in pull request #4987: support sampleRate as Dynamic Configuration (#4968)

2020-07-01 Thread GitBox


wu-sheng commented on a change in pull request #4987:
URL: https://github.com/apache/skywalking/pull/4987#discussion_r448676691



##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceSampleRateWatcher.java
##
@@ -0,0 +1,70 @@
+/*
+ * 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.receiver.trace.provider;
+
+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.receiver.trace.module.TraceModule;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+@Slf4j
+public class TraceSampleRateWatcher extends ConfigChangeWatcher {
+private  AtomicReference settingsString;
+private  AtomicReference sampleRate;
+
+public TraceSampleRateWatcher(String config, TraceModuleProvider provider) 
{
+super(TraceModule.NAME, provider, "sampleRate");
+settingsString = new AtomicReference<>(Const.EMPTY_STRING);
+sampleRate = new AtomicReference<>();
+
+activeSetting(config);
+}
+
+private void activeSetting(String config) {
+if (log.isDebugEnabled()) {
+log.debug("Updating using new static config: {}", config);
+}
+settingsString.set(config);
+try {
+sampleRate.set(Integer.parseInt(config));
+} catch (NumberFormatException ex) {
+log.error("Cannot load sampleRate from: {}", config, ex);
+}
+}
+
+@Override
+public void notify(ConfigChangeEvent value) {
+if (EventType.DELETE.equals(value.getEventType())) {
+activeSetting("");

Review comment:
   What is the expected sampling rate if the delete happens?

##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceModuleProvider.java
##
@@ -75,8 +77,11 @@ public void prepare() throws ServiceNotProvidedException {
 
 uninstrumentedGatewaysConfig = new UninstrumentedGatewaysConfig(this);
 
+traceSampleRateWatcher = new 
TraceSampleRateWatcher(String.valueOf(moduleConfig.getSampleRate()), this);

Review comment:
   I think should not change to String here, please move this into the 
`TraceSampleRateWatcher`.

##
File path: 
oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/TraceSampleRateWatcher.java
##
@@ -0,0 +1,70 @@
+/*
+ * 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.receiver.trace.provider;
+
+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.receiver.trace.module.TraceModule;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+@Slf4j
+public class TraceSampleRateWatcher extends ConfigChangeWatcher {
+private  AtomicReference settingsString;

Review comment:
   I think you don't need `settingsString`





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