-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add support for sentinel opensergo datasource #3142
base: 2.2.x-ospp2023
Are you sure you want to change the base?
Changes from all commits
b22fcb4
db4d491
5ceef78
5c4593f
ed194d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright 2013-2018 the original author or authors. | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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 com.alibaba.cloud.sentinel.datasource.config; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import com.alibaba.cloud.commons.lang.StringUtils; | ||
import com.alibaba.cloud.sentinel.datasource.RuleType; | ||
import com.alibaba.cloud.sentinel.datasource.factorybean.OpenSergoDataSourceFactoryBean; | ||
import com.alibaba.csp.sentinel.datasource.OpenSergoDataSourceGroup; | ||
import com.alibaba.csp.sentinel.datasource.OpenSergoSentinelConstants; | ||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager; | ||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager; | ||
import com.alibaba.csp.sentinel.util.AppNameUtil; | ||
|
||
import org.springframework.util.CollectionUtils; | ||
|
||
/** | ||
* OpenSergo Properties class Using by {@link DataSourcePropertiesConfiguration} and | ||
* {@link OpenSergoDataSourceFactoryBean}. | ||
* | ||
* @author musi | ||
* @author <a href="[email protected]"></a> | ||
*/ | ||
public class OpenSergoDataSourceProperties extends AbstractDataSourceProperties { | ||
private static final String FLOW = "flow"; | ||
private static final String DEGRADE = "degrade"; | ||
private String host = "127.0.0.1"; | ||
|
||
private int port = 10246; | ||
|
||
private String namespace = "default"; | ||
|
||
private String app = AppNameUtil.getAppName(); | ||
|
||
private Set<String> enabledRules = new HashSet<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, It is better to use Enum type. I will fix it! |
||
|
||
public OpenSergoDataSourceProperties() { | ||
super(OpenSergoDataSourceFactoryBean.class.getName()); | ||
} | ||
|
||
public void postRegister(OpenSergoDataSourceGroup dataSourceGroup) { | ||
// TODO: SystemRule and ParamFlowRule | ||
if (enabledRules.contains(FLOW)) { | ||
FlowRuleManager.register2Property(dataSourceGroup.subscribeFlowRules()); | ||
} | ||
if (enabledRules.contains(DEGRADE)) { | ||
DegradeRuleManager.register2Property(dataSourceGroup.subscribeDegradeRules()); | ||
} | ||
// When there is no enabled-rules, try ruleType | ||
RuleType ruleType = getRuleType(); | ||
switch (ruleType) { | ||
case FLOW: | ||
FlowRuleManager.register2Property(dataSourceGroup.subscribeFlowRules()); | ||
break; | ||
case DEGRADE: | ||
DegradeRuleManager.register2Property(dataSourceGroup.subscribeDegradeRules()); | ||
break; | ||
} | ||
Comment on lines
+66
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As your comment, these code lines should be wrapped in condition |
||
} | ||
|
||
public String getHost() { | ||
return host; | ||
} | ||
|
||
public void setHost(String host) { | ||
this.host = host; | ||
} | ||
|
||
public int getPort() { | ||
return port; | ||
} | ||
|
||
public void setPort(int port) { | ||
this.port = port; | ||
} | ||
|
||
public String getNamespace() { | ||
return namespace; | ||
} | ||
|
||
public void setNamespace(String namespace) { | ||
this.namespace = namespace; | ||
} | ||
|
||
public String getApp() { | ||
return app; | ||
} | ||
|
||
public void setApp(String app) { | ||
this.app = app; | ||
} | ||
|
||
public Set<String> getEnabledRules() { | ||
return enabledRules; | ||
} | ||
|
||
public void setEnabledRules(Set<String> enabledRules) { | ||
this.enabledRules = enabledRules; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright 2013-2018 the original author or authors. | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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 com.alibaba.cloud.sentinel.datasource.factorybean; | ||
|
||
import java.util.Set; | ||
|
||
import com.alibaba.csp.sentinel.datasource.Converter; | ||
import com.alibaba.csp.sentinel.datasource.OpenSergoDataSourceGroup; | ||
|
||
import org.springframework.beans.factory.FactoryBean; | ||
|
||
/** | ||
* A {@link FactoryBean} for creating {@link OpenSergoDataSourceGroup} instance. | ||
* | ||
* @author musi | ||
* @author <a href="[email protected]"></a> | ||
* @see OpenSergoDataSourceGroup | ||
*/ | ||
public class OpenSergoDataSourceFactoryBean | ||
implements FactoryBean<OpenSergoDataSourceGroup> { | ||
|
||
private String host; | ||
|
||
private int port; | ||
|
||
private String namespace; | ||
|
||
private String app; | ||
|
||
private Set<String> enabledRules; | ||
|
||
private Converter converter; | ||
|
||
@Override | ||
public OpenSergoDataSourceGroup getObject() throws Exception { | ||
return new OpenSergoDataSourceGroup(host, port, namespace, app); | ||
} | ||
|
||
@Override | ||
public Class<?> getObjectType() { | ||
return OpenSergoDataSourceGroup.class; | ||
} | ||
|
||
public String getHost() { | ||
return host; | ||
} | ||
|
||
public void setHost(String host) { | ||
this.host = host; | ||
} | ||
|
||
public int getPort() { | ||
return port; | ||
} | ||
|
||
public void setPort(int port) { | ||
this.port = port; | ||
} | ||
|
||
public String getNamespace() { | ||
return namespace; | ||
} | ||
|
||
public void setNamespace(String namespace) { | ||
this.namespace = namespace; | ||
} | ||
|
||
public String getApp() { | ||
return app; | ||
} | ||
|
||
public void setApp(String app) { | ||
this.app = app; | ||
} | ||
|
||
public Set<String> getEnabledRules() { | ||
return enabledRules; | ||
} | ||
|
||
public void setEnabledRules(Set<String> enabledRules) { | ||
this.enabledRules = enabledRules; | ||
} | ||
|
||
public Converter getConverter() { | ||
return converter; | ||
} | ||
|
||
public void setConverter(Converter converter) { | ||
this.converter = converter; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whether to use
optional
, the integration ofopensergo
is at the discretion of the user.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this dependency, I can not use the OpenSergoDataSourceGroup