You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2022/11/10 11:42:55 UTC

[GitHub] [servicecomb-java-chassis] zzj8886 opened a new pull request, #3472: Z30037389

zzj8886 opened a new pull request, #3472:
URL: https://github.com/apache/servicecomb-java-chassis/pull/3472

   Follow this checklist to help us incorporate your contribution quickly and easily:
   
    - [ ] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/SCB) filed for the change (usually before you start working on it).  Trivial changes like typos do not require a JIRA issue.  Your pull request should address just this issue, without pulling in other changes.
    - [ ] Each commit in the pull request should have a meaningful subject line and body.
    - [ ] Format the pull request title like `[SCB-XXX] Fixes bug in ApproximateQuantiles`, where you replace `SCB-XXX` with the appropriate JIRA issue.
    - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
    - [ ] Run `mvn clean install -Pit` to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
    - [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   ---
   


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

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] liubao68 commented on a diff in pull request #3472: Z30037389

Posted by GitBox <gi...@apache.org>.
liubao68 commented on code in PR #3472:
URL: https://github.com/apache/servicecomb-java-chassis/pull/3472#discussion_r1019018995


##########
governance/src/main/java/org/apache/servicecomb/governance/properties/GovernanceCacheProperties.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.servicecomb.governance.properties;
+
+import org.apache.servicecomb.governance.policy.GovernanceCachePolicy;
+
+
+/**
+ * 功能描述
+ *
+ * @since 2022-08-26
+ */
+public class GovernanceCacheProperties extends PolicyProperties<GovernanceCachePolicy> {
+    public static final String MATCH_CACHE_KEY = "servicecomb.cache";
+
+    public GovernanceCacheProperties() {

Review Comment:
   add construct public GovernanceCacheProperties(String key)



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

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] liubao68 commented on a diff in pull request #3472: Z30037389

Posted by GitBox <gi...@apache.org>.
liubao68 commented on code in PR #3472:
URL: https://github.com/apache/servicecomb-java-chassis/pull/3472#discussion_r1019026356


##########
governance/src/test/java/org/apache/servicecomb/governance/mockclasses/service/MockGovernanceCacheHandler.java:
##########
@@ -0,0 +1,32 @@
+/*
+ * 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.servicecomb.governance.mockclasses.service;
+
+import org.apache.servicecomb.governance.handler.GovernanceCacheHandler;
+import org.apache.servicecomb.governance.properties.GovernanceCacheProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class MockGovernanceCacheHandler {
+
+    @Bean("responseCacheHandler")
+    public GovernanceCacheHandler<String, Object> getResponseCacheHandler(GovernanceCacheProperties cacheProperties) {

Review Comment:
   Create a default bean. Users can define their custom bean and properties. 



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

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] zzj8886 closed pull request #3472: [SCB-2726] add TimeLimiter and Cache governance

Posted by GitBox <gi...@apache.org>.
zzj8886 closed pull request #3472: [SCB-2726] add TimeLimiter and Cache governance 
URL: https://github.com/apache/servicecomb-java-chassis/pull/3472


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

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] liubao68 commented on a diff in pull request #3472: Z30037389

Posted by GitBox <gi...@apache.org>.
liubao68 commented on code in PR #3472:
URL: https://github.com/apache/servicecomb-java-chassis/pull/3472#discussion_r1019055494


##########
governance/src/main/java/org/apache/servicecomb/governance/service/GovernanceCacheImpl.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.servicecomb.governance.service;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class GovernanceCacheImpl<K, V> implements GovernanceCache<K, V> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(GovernanceCacheImpl.class);
+
+    private final com.google.common.cache.Cache<K, V> cache;
+
+    public GovernanceCacheImpl(com.google.common.cache.Cache<K, V> cache) {

Review Comment:
   better use import



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

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] liubao68 commented on a diff in pull request #3472: Z30037389

Posted by GitBox <gi...@apache.org>.
liubao68 commented on code in PR #3472:
URL: https://github.com/apache/servicecomb-java-chassis/pull/3472#discussion_r1019018659


##########
governance/src/main/java/org/apache/servicecomb/governance/properties/GovernanceCacheProperties.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.servicecomb.governance.properties;
+
+import org.apache.servicecomb.governance.policy.GovernanceCachePolicy;
+
+
+/**
+ * 功能描述
+ *
+ * @since 2022-08-26
+ */

Review Comment:
   delete non meaning 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.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] liubao68 commented on a diff in pull request #3472: Z30037389

Posted by GitBox <gi...@apache.org>.
liubao68 commented on code in PR #3472:
URL: https://github.com/apache/servicecomb-java-chassis/pull/3472#discussion_r1019017288


##########
governance/src/main/java/org/apache/servicecomb/governance/handler/TimeLimiterHandler.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.servicecomb.governance.handler;
+
+import io.github.resilience4j.micrometer.tagged.TaggedTimeLimiterMetrics;
+import io.github.resilience4j.micrometer.tagged.TimeLimiterMetricNames;
+import io.github.resilience4j.timelimiter.TimeLimiter;
+import io.github.resilience4j.timelimiter.TimeLimiterConfig;
+import io.github.resilience4j.timelimiter.TimeLimiterRegistry;
+
+import org.apache.servicecomb.governance.marker.GovernanceRequest;
+import org.apache.servicecomb.governance.policy.TimeLimiterPolicy;
+import org.apache.servicecomb.governance.properties.TimeLimiterProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.time.Duration;
+
+public class TimeLimiterHandler extends AbstractGovernanceHandler<TimeLimiter, TimeLimiterPolicy> {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(TimeLimiterHandler.class);
+
+    private final TimeLimiterProperties timeLimiterProperties;
+
+    public TimeLimiterHandler(TimeLimiterProperties timeLimiterProperties) {
+        this.timeLimiterProperties = timeLimiterProperties;
+    }
+
+    @Override
+    protected String createKey(GovernanceRequest governanceRequest, TimeLimiterPolicy policy) {
+        return TimeLimiterProperties.MATCH_TIMELIMITER_KEY + "." + policy.getName();

Review Comment:
   timeLimiterProperties.getConfigKey



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

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] liubao68 commented on a diff in pull request #3472: Z30037389

Posted by GitBox <gi...@apache.org>.
liubao68 commented on code in PR #3472:
URL: https://github.com/apache/servicecomb-java-chassis/pull/3472#discussion_r1019016773


##########
governance/src/main/java/org/apache/servicecomb/governance/handler/GovernanceCacheHandler.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.servicecomb.governance.handler;
+
+import org.apache.servicecomb.governance.marker.GovernanceRequest;
+import org.apache.servicecomb.governance.policy.GovernanceCachePolicy;
+import org.apache.servicecomb.governance.properties.GovernanceCacheProperties;
+import org.apache.servicecomb.governance.service.GovernanceCache;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.time.Duration;
+
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+
+public class GovernanceCacheHandler<K, V>
+    extends AbstractGovernanceHandler<GovernanceCache<K, V>, GovernanceCachePolicy> {
+    private static final Logger LOGGER = LoggerFactory.getLogger(GovernanceCacheHandler.class);
+
+    private final GovernanceCacheProperties cacheProperties;
+
+    public GovernanceCacheHandler(GovernanceCacheProperties cacheProperties) {
+        this.cacheProperties = cacheProperties;
+    }
+
+    @Override
+    public GovernanceCachePolicy matchPolicy(GovernanceRequest governanceRequest) {
+        return matchersManager.match(governanceRequest, cacheProperties.getParsedEntity());
+    }
+
+    @Override
+    protected String createKey(GovernanceRequest governanceRequest, GovernanceCachePolicy policy) {
+        return GovernanceCacheProperties.MATCH_CACHE_KEY + "." + policy.getName();

Review Comment:
   change to cacheProperties.getConfigKey



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

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] liubao68 commented on a diff in pull request #3472: Z30037389

Posted by GitBox <gi...@apache.org>.
liubao68 commented on code in PR #3472:
URL: https://github.com/apache/servicecomb-java-chassis/pull/3472#discussion_r1019017485


##########
governance/src/main/java/org/apache/servicecomb/governance/handler/TimeLimiterHandler.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.servicecomb.governance.handler;
+
+import io.github.resilience4j.micrometer.tagged.TaggedTimeLimiterMetrics;
+import io.github.resilience4j.micrometer.tagged.TimeLimiterMetricNames;
+import io.github.resilience4j.timelimiter.TimeLimiter;
+import io.github.resilience4j.timelimiter.TimeLimiterConfig;
+import io.github.resilience4j.timelimiter.TimeLimiterRegistry;
+
+import org.apache.servicecomb.governance.marker.GovernanceRequest;
+import org.apache.servicecomb.governance.policy.TimeLimiterPolicy;
+import org.apache.servicecomb.governance.properties.TimeLimiterProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.time.Duration;
+
+public class TimeLimiterHandler extends AbstractGovernanceHandler<TimeLimiter, TimeLimiterPolicy> {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(TimeLimiterHandler.class);
+
+    private final TimeLimiterProperties timeLimiterProperties;
+
+    public TimeLimiterHandler(TimeLimiterProperties timeLimiterProperties) {
+        this.timeLimiterProperties = timeLimiterProperties;
+    }
+
+    @Override
+    protected String createKey(GovernanceRequest governanceRequest, TimeLimiterPolicy policy) {
+        return TimeLimiterProperties.MATCH_TIMELIMITER_KEY + "." + policy.getName();
+    }
+
+    @Override
+    public TimeLimiterPolicy matchPolicy(GovernanceRequest governanceRequest) {
+        return matchersManager.match(governanceRequest, timeLimiterProperties.getParsedEntity());
+    }
+
+    @Override
+    public Disposable<TimeLimiter> createProcessor(String key, GovernanceRequest governanceRequest,
+        TimeLimiterPolicy policy) {
+        return getTimeLimiter(key, policy);
+    }
+
+    private Disposable<TimeLimiter> getTimeLimiter(String key, TimeLimiterPolicy policy) {
+        LOGGER.info("applying new policy {} for {}", key, policy);
+        TimeLimiterConfig timeLimiterConfig = TimeLimiterConfig.custom()
+            .timeoutDuration(Duration.parse(policy.getTimeoutDuration()))
+            .cancelRunningFuture(policy.isCancelRunningFuture())
+            .build();
+        TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry.of(timeLimiterConfig);
+        if (meterRegistry != null) {
+            TaggedTimeLimiterMetrics.ofTimeLimiterRegistry(TimeLimiterMetricNames.custom()
+                .callsMetricName(TimeLimiterProperties.MATCH_TIMELIMITER_KEY + ".calls")

Review Comment:
   timeLimiterProperties.getConfigKey



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

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] liubao68 commented on a diff in pull request #3472: Z30037389

Posted by GitBox <gi...@apache.org>.
liubao68 commented on code in PR #3472:
URL: https://github.com/apache/servicecomb-java-chassis/pull/3472#discussion_r1019019388


##########
governance/src/main/java/org/apache/servicecomb/governance/properties/TimeLimiterProperties.java:
##########
@@ -0,0 +1,33 @@
+/*
+ * 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.servicecomb.governance.properties;
+
+
+import org.apache.servicecomb.governance.policy.TimeLimiterPolicy;
+
+public class TimeLimiterProperties extends PolicyProperties<TimeLimiterPolicy> {
+  public static final String MATCH_TIMELIMITER_KEY = "servicecomb.timeLimiter";
+
+  public TimeLimiterProperties() {

Review Comment:
   add constrctor TimeLimiterProperties(String key)



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

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] liubao68 commented on a diff in pull request #3472: Z30037389

Posted by GitBox <gi...@apache.org>.
liubao68 commented on code in PR #3472:
URL: https://github.com/apache/servicecomb-java-chassis/pull/3472#discussion_r1019016231


##########
governance/src/main/java/org/apache/servicecomb/governance/handler/DisposableGovernanceCache.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.servicecomb.governance.handler;
+
+
+import org.apache.servicecomb.governance.service.GovernanceCache;
+
+public class DisposableGovernanceCache<K,V> extends Disposable<GovernanceCache<K,V>> {

Review Comment:
   Do not need this . Use DisposableHolder is 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.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

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