├── thalossphere-test ├── src │ └── main │ │ ├── resources │ │ ├── config │ │ │ └── agent.yaml │ │ └── example-agent.yaml │ │ └── java │ │ └── com │ │ └── thalossphere │ │ └── test │ │ ├── util │ │ └── NetUtilsTest.java │ │ ├── config │ │ └── PointcutConfigLoaderTest.java │ │ ├── classloader │ │ └── AgentClassLoaderTest.java │ │ ├── request │ │ ├── HeaderResolverTest.java │ │ ├── ParameterResolverTest.java │ │ ├── CookieResolverTest.java │ │ └── SimpleRequestResolverTest.java │ │ └── interceptor │ │ └── CustomInterceptor.java └── .gitignore ├── docs ├── ip.png ├── agent.png ├── api.png ├── logo.png ├── consumer.png ├── panoramic.png └── service-search.png ├── thalossphere-distribution ├── thalossphere-agent-distribution │ ├── src │ │ └── main │ │ │ └── resources │ │ │ ├── plugin-config.yaml │ │ │ └── agent.yaml │ └── .gitignore ├── .gitignore └── pom.xml ├── thalossphere-agent-core ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── services │ │ │ └── com.thalossphere.common.init.CoreInit │ │ └── java │ │ └── com │ │ └── thalossphere │ │ └── agent │ │ └── core │ │ ├── interceptor │ │ ├── MethodInterceptor.java │ │ ├── template │ │ │ └── InstantMethodInterceptorResult.java │ │ ├── type │ │ │ ├── ConstructorInterceptor.java │ │ │ └── StaticMethodInterceptor.java │ │ ├── MethodInterceptorOperator.java │ │ ├── MultiThreadConstructorInterceptor.java │ │ ├── MultiThreadMethodInterceptor.java │ │ └── MethodInterceptorManager.java │ │ ├── context │ │ ├── CustomContextAccessor.java │ │ └── CustomContext.java │ │ ├── builder │ │ ├── InterceptorBuilder.java │ │ ├── InterceptorBuilderChain.java │ │ ├── TargetObjectInterceptorBuilder.java │ │ └── MultiThreadMethodInterceptorBuilder.java │ │ ├── config │ │ ├── yaml │ │ │ ├── YamlMethodParameterPointcutConfig.java │ │ │ ├── YamlPointcutConfig.java │ │ │ ├── YamlClassPointcutConfig.java │ │ │ └── YamlMethodPointcutConfig.java │ │ ├── MethodMatcherConfig.java │ │ └── PointcutConfigLoader.java │ │ ├── utils │ │ ├── URLClassLoaderManager.java │ │ └── MethodTypeUtils.java │ │ ├── enums │ │ └── MethodTypeEnum.java │ │ ├── classloader │ │ ├── PluginsJarLoader.java │ │ └── AgentClassLoaderManager.java │ │ ├── matcher │ │ └── MultiThreadMethodMatch.java │ │ ├── AgentListener.java │ │ └── AgentBootstrap.java └── .gitignore ├── thalossphere-features ├── thalossphere-feature-removal │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── services │ │ │ │ └── com.thalossphere.common.init.CoreInit │ │ │ └── java │ │ │ └── com │ │ │ └── thalossphere │ │ │ └── feature │ │ │ └── removal │ │ │ ├── ServiceNodeCache.java │ │ │ ├── ServiceNode.java │ │ │ ├── RemovalInit.java │ │ │ └── RemovalTask.java │ └── .gitignore ├── thalossphere-feature-sentinel │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── services │ │ │ │ └── com.thalossphere.common.init.CoreInit │ │ │ └── java │ │ │ └── com │ │ │ └── thalossphere │ │ │ └── feature │ │ │ └── sentinel │ │ │ ├── datasource │ │ │ ├── SentinelDataSourceRuleLoader.java │ │ │ ├── SentinelConfigDataSourceTypeEnum.java │ │ │ └── SentinelDataSourceRuleLoaderManager.java │ │ │ ├── limiter │ │ │ ├── SentinelResource.java │ │ │ ├── SentinelLimiter.java │ │ │ ├── EntryContext.java │ │ │ └── support │ │ │ │ ├── SlowRatioCircuitBreakerLimiter.java │ │ │ │ └── DynamicMachineIndicatorsLimiter.java │ │ │ ├── constant │ │ │ └── SentinelConstant.java │ │ │ ├── utils │ │ │ └── SentinelContext.java │ │ │ └── init │ │ │ └── SentinelInit.java │ └── .gitignore ├── thalossphere-feature-register-center │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── services │ │ │ │ └── com.thalossphere.common.init.CoreInit │ │ │ └── java │ │ │ └── com │ │ │ └── thalossphere │ │ │ └── register │ │ │ └── center │ │ │ ├── selector │ │ │ └── ServerWeight.java │ │ │ ├── init │ │ │ └── RegisterCenterInit.java │ │ │ └── listener │ │ │ └── RefreshServerListListener.java │ └── .gitignore ├── thalossphere-feature-discovery-binder │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── thalossphere │ │ │ └── feature │ │ │ └── discovery │ │ │ └── binder │ │ │ ├── instance │ │ │ └── entity │ │ │ │ ├── ProviderFunction.java │ │ │ │ ├── Provider.java │ │ │ │ └── Consumer.java │ │ │ ├── event │ │ │ └── InstanceInitEvent.java │ │ │ ├── ProviderInterfaceManager.java │ │ │ └── ConsumerInterfaceUrlManager.java │ ├── .gitignore │ └── pom.xml ├── .gitignore └── pom.xml ├── thalossphere-extensions ├── thalossphere-extension-datasource │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── services │ │ │ │ └── com.thalossphere.common.init.CoreInit │ │ │ └── java │ │ │ └── com │ │ │ └── thalossphere │ │ │ └── extension │ │ │ └── datasource │ │ │ ├── entity │ │ │ ├── ElasticJobConfig.java │ │ │ ├── ZuulConfig.java │ │ │ ├── SpringCloudGatewayConfig.java │ │ │ ├── PluginConfig.java │ │ │ ├── RocketMQConfig.java │ │ │ └── SentinelConfig.java │ │ │ ├── support │ │ │ ├── local │ │ │ │ ├── YamlPluginConfig.java │ │ │ │ └── LocalPluginConfigLoader.java │ │ │ ├── apollo │ │ │ │ ├── ApolloConfigConstant.java │ │ │ │ ├── ApolloConfigListener.java │ │ │ │ └── ApolloPluginConfigLoader.java │ │ │ └── nacos │ │ │ │ ├── NacosConfigConstant.java │ │ │ │ └── NacosConfigListener.java │ │ │ ├── loader │ │ │ ├── PluginConfigLoader.java │ │ │ └── PluginConfigLoaderManager.java │ │ │ ├── enums │ │ │ └── PluginConfigDataSourceTypeEnum.java │ │ │ └── init │ │ │ └── DataSourceInit.java │ └── .gitignore ├── .gitignore └── pom.xml ├── thalossphere-common ├── src │ └── main │ │ └── java │ │ └── com │ │ └── thalossphere │ │ └── common │ │ ├── loadbalance │ │ ├── ArrayWeight.java │ │ ├── InstantWeight.java │ │ ├── UserWeight.java │ │ ├── RegionWeight.java │ │ └── TagWeight.java │ │ ├── request │ │ ├── RequestResolver.java │ │ ├── SimpleRequestResolver.java │ │ ├── HttpRequest.java │ │ ├── AttributeResolver.java │ │ ├── SimpleAttributeResolver.java │ │ ├── HeaderResolver.java │ │ ├── CookieResolver.java │ │ ├── ParameterResolver.java │ │ └── AbstractRequestResolver.java │ │ ├── config │ │ ├── OkHttpConfig.java │ │ ├── PluginConfigDataSource.java │ │ ├── YamlAgentConfig.java │ │ └── YamlAgentConfigCache.java │ │ ├── longpoll │ │ └── entity │ │ │ ├── ReleaseMessage.java │ │ │ └── NotificationRequest.java │ │ ├── eventbus │ │ ├── enums │ │ │ └── CmdEnum.java │ │ ├── event │ │ │ └── RefreshServerListEvent.java │ │ └── EventBusManager.java │ │ ├── init │ │ └── CoreInit.java │ │ ├── propagator │ │ ├── GatewayPropagator.java │ │ └── AbstractGatewayPropagator.java │ │ ├── transport │ │ └── SimpleHttpRequest.java │ │ ├── env │ │ └── Env.java │ │ ├── constant │ │ └── CommonConstant.java │ │ ├── tag │ │ ├── context │ │ │ ├── TagContext.java │ │ │ └── TagManager.java │ │ └── extract │ │ │ ├── TagExtract.java │ │ │ ├── ClientDefaultTagExtract.java │ │ │ ├── TagExtractManager.java │ │ │ ├── AbstractTagExtract.java │ │ │ ├── UserIdTagExtract.java │ │ │ └── RegionTagExtract.java │ │ ├── utils │ │ ├── DynamicServerListLoadBalancerCache.java │ │ ├── StringUtils.java │ │ └── NetUtils.java │ │ └── yaml │ │ └── YamlConstructor.java └── .gitignore ├── thalossphere-plugins ├── thalossphere-plugin-zuul │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── zuul-agent.yaml │ │ │ └── java │ │ │ └── com │ │ │ └── thalossphere │ │ │ └── agent │ │ │ └── plugin │ │ │ └── zuul │ │ │ └── propagator │ │ │ └── ZuulPropagator.java │ └── .gitignore ├── thalossphere-plugin-elasticjob2 │ ├── src │ │ └── main │ │ │ └── resources │ │ │ └── elasticjob2-agent.yaml │ └── .gitignore ├── .gitignore ├── thalossphere-plugin-fegin │ ├── .gitignore │ └── src │ │ └── main │ │ ├── resources │ │ └── feign-agent.yaml │ │ └── java │ │ └── com │ │ └── thalossphere │ │ └── agent │ │ └── plugin │ │ └── feign │ │ └── DynamicServerListLoadBalancerInterceptor.java ├── thalossphere-plugin-nacos │ ├── .gitignore │ └── src │ │ └── main │ │ ├── resources │ │ └── nacos-agent.yaml │ │ └── java │ │ └── com │ │ └── thalossphere │ │ └── agent │ │ └── plugin │ │ └── nacos │ │ ├── NacosServerPredicate.java │ │ └── NacosSelector.java ├── thalossphere-plugin-rocketmq4 │ ├── .gitignore │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── thalossphere │ │ │ └── agent │ │ │ └── plugin │ │ │ └── rocketmq │ │ │ ├── consumer │ │ │ ├── condition │ │ │ │ └── CidSplitMatchGrayCondition.java │ │ │ ├── DefaultMQPushConsumerInterceptor.java │ │ │ └── ClientConfigInterceptor.java │ │ │ ├── utils │ │ │ └── MessageQueueThreadLocalUtils.java │ │ │ └── producer │ │ │ └── DefaultMQProducerInterceptor.java │ │ └── resources │ │ └── rocketmq4-agent.yaml ├── thalossphere-plugin-springmvc │ ├── .gitignore │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── thalossphere │ │ │ └── agent │ │ │ └── plugin │ │ │ └── spring │ │ │ └── mvc │ │ │ └── RequestMappingHandlerMappingInterceptor.java │ │ └── resources │ │ └── springmvc-agent.yaml ├── thalossphere-plugin-resttemplate │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── resttemplate-agent.yaml │ │ │ └── java │ │ │ └── com │ │ │ └── thalossphere │ │ │ └── plugin │ │ │ └── resttemplate │ │ │ └── HttpAccessorInterceptor.java │ └── .gitignore ├── thalossphere-plugin-springcloudgateway │ ├── .gitignore │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── thalossphere │ │ │ └── agent │ │ │ └── plugin │ │ │ └── spring │ │ │ └── cloud │ │ │ └── gateway │ │ │ ├── SimpleGatewayParamParser.java │ │ │ └── propagator │ │ │ └── GatewayPropagator.java │ │ └── resources │ │ └── springcloudgateway-agent.yaml ├── thalossphere-plugin-mybatis │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── mybatis-agent.yaml │ │ │ └── java │ │ │ └── com │ │ │ └── thalossphere │ │ │ └── plugin │ │ │ └── mybatis │ │ │ ├── BaseExecutorInterceptor.java │ │ │ └── flow │ │ │ └── MybatisLimiter.java │ └── .gitignore ├── thalossphere-plugin-eureka │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── eureka-agent.yaml │ │ │ └── java │ │ │ └── com │ │ │ └── thalossphere │ │ │ └── agent │ │ │ └── plugin │ │ │ └── eureka │ │ │ ├── EurekaSelector.java │ │ │ ├── EurekaServerPredicate.java │ │ │ └── EurekaInstanceConfigBeanInterceptor.java │ └── .gitignore ├── thalossphere-plugin-consul │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── consul-agent.yaml │ │ │ └── java │ │ │ └── com │ │ │ └── thalossphere │ │ │ └── agent │ │ │ └── plugin │ │ │ └── consul │ │ │ ├── ConsulServerPredicate.java │ │ │ ├── ConsulSelector.java │ │ │ └── ConsulDiscoveryPropertiesInterceptor.java │ └── .gitignore ├── thalossphere-plugin-springboot2 │ ├── src │ │ └── main │ │ │ └── resources │ │ │ └── springboot2-agent.yaml │ └── .gitignore └── thalossphere-plugin-zookeeper │ ├── src │ └── main │ │ ├── resources │ │ └── zookeeper-agent.yaml │ │ └── java │ │ └── com │ │ └── thalossphere │ │ └── agent │ │ └── plugin │ │ └── zookeeper │ │ ├── ZookeeperServerPredicate.java │ │ ├── ZookeeperSelector.java │ │ └── ZookeeperDiscoveryPropertiesInterceptor.java │ └── .gitignore ├── thalossphere-examples ├── thalossphere-elasticjob-example │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.properties │ │ │ └── java │ │ │ └── com │ │ │ └── thalossphere │ │ │ └── elasticjob │ │ │ └── example │ │ │ ├── job │ │ │ └── MyJob.java │ │ │ ├── ElasticJobExampleApplication.java │ │ │ └── config │ │ │ └── JobEventConfig.java │ └── .gitignore ├── thalossphere-springcloud-example │ ├── thalossphere-springcloud-eureka-server │ │ ├── src │ │ │ └── main │ │ │ │ ├── resources │ │ │ │ └── application.yml │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── thalossphere │ │ │ │ └── spring │ │ │ │ └── cloud │ │ │ │ └── eureka │ │ │ │ └── server │ │ │ │ └── SpringCloudEurekaServerExampleApplication.java │ │ └── .gitignore │ ├── thalossphere-springcloud-service-a-example │ │ ├── src │ │ │ └── main │ │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── thalossphere │ │ │ │ │ └── spring │ │ │ │ │ └── cloud │ │ │ │ │ └── service │ │ │ │ │ └── consumer │ │ │ │ │ └── example │ │ │ │ │ ├── entity │ │ │ │ │ └── User.java │ │ │ │ │ ├── mapper │ │ │ │ │ └── UserMapper.java │ │ │ │ │ ├── config │ │ │ │ │ └── RestTemplateConfig.java │ │ │ │ │ └── SpringCloudServiceAExampleApplication.java │ │ │ │ └── resources │ │ │ │ └── application.yml │ │ └── .gitignore │ ├── thalossphere-springcloud-service-a1-example │ │ ├── src │ │ │ └── main │ │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── thalossphere │ │ │ │ │ └── spring │ │ │ │ │ └── cloud │ │ │ │ │ └── service │ │ │ │ │ └── consumer │ │ │ │ │ └── example │ │ │ │ │ ├── entity │ │ │ │ │ └── User.java │ │ │ │ │ ├── mapper │ │ │ │ │ └── UserMapper.java │ │ │ │ │ └── config │ │ │ │ │ └── RestTemplateConfig.java │ │ │ │ └── resources │ │ │ │ └── application.yml │ │ └── .gitignore │ ├── .gitignore │ ├── thalossphere-springcloud-gateway-example │ │ ├── .gitignore │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── thalossphere │ │ │ │ └── plugin │ │ │ │ └── spring │ │ │ │ └── cloud │ │ │ │ └── gateway │ │ │ │ └── example │ │ │ │ └── SpringCloudGatewayExampleApplication.java │ │ │ └── resources │ │ │ └── application.yml │ ├── thalossphere-springcloud-service-api-example │ │ ├── .gitignore │ │ ├── src │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── thalossphere │ │ │ │ └── spring │ │ │ │ └── cloud │ │ │ │ └── service │ │ │ │ └── api │ │ │ │ ├── entity │ │ │ │ └── TagEntity.java │ │ │ │ ├── SpringCloudCApi.java │ │ │ │ └── SpringCloudBApi.java │ │ └── pom.xml │ ├── thalossphere-springcloud-service-b-example │ │ ├── .gitignore │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── thalossphere │ │ │ │ └── spring │ │ │ │ └── cloud │ │ │ │ └── service │ │ │ │ └── provider │ │ │ │ └── example │ │ │ │ └── SpringCloudServiceBExampleApplication.java │ │ │ └── resources │ │ │ └── application.yml │ ├── thalossphere-springcloud-service-b1-example │ │ ├── .gitignore │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── thalossphere │ │ │ │ └── spring │ │ │ │ └── cloud │ │ │ │ └── service │ │ │ │ └── provider │ │ │ │ └── example │ │ │ │ └── SpringCloudServiceB1ExampleApplication.java │ │ │ └── resources │ │ │ └── application.yml │ ├── thalossphere-springcloud-service-c-example │ │ ├── .gitignore │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── thalossphere │ │ │ │ └── spring │ │ │ │ └── cloud │ │ │ │ └── service │ │ │ │ └── provider │ │ │ │ └── example │ │ │ │ ├── SpringCloudServiceCExampleApplication.java │ │ │ │ └── config │ │ │ │ └── RocketMQConfig.java │ │ │ └── resources │ │ │ └── application.yml │ ├── thalossphere-springcloud-service-c1-example │ │ ├── .gitignore │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── thalossphere │ │ │ │ └── spring │ │ │ │ └── cloud │ │ │ │ └── service │ │ │ │ └── provider │ │ │ │ └── example │ │ │ │ ├── SpringCloudServiceC1ExampleApplication.java │ │ │ │ └── config │ │ │ │ └── RocketMQConfig.java │ │ │ └── resources │ │ │ └── application.yml │ ├── thalossphere-springcloud-zuul-example │ │ ├── .gitignore │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── thalossphere │ │ │ │ └── spring │ │ │ │ └── cloud │ │ │ │ └── zuul │ │ │ │ └── example │ │ │ │ └── SpringCloudZuulExampleApplication.java │ │ │ └── resources │ │ │ └── application.yml │ └── pom.xml ├── thalossphere-rocketmq-example │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.properties │ │ │ └── java │ │ │ └── com │ │ │ └── thalossphere │ │ │ └── rocketmq │ │ │ └── example │ │ │ ├── RocketMQExampleApplication.java │ │ │ ├── controller │ │ │ └── RocketMQController.java │ │ │ └── MyTest.java │ └── .gitignore └── .gitignore ├── thalossphere-agent └── .gitignore └── .gitignore /thalossphere-test/src/main/resources/config/agent.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/ip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thalossphere-projects/thalossphere/HEAD/docs/ip.png -------------------------------------------------------------------------------- /docs/agent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thalossphere-projects/thalossphere/HEAD/docs/agent.png -------------------------------------------------------------------------------- /docs/api.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thalossphere-projects/thalossphere/HEAD/docs/api.png -------------------------------------------------------------------------------- /docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thalossphere-projects/thalossphere/HEAD/docs/logo.png -------------------------------------------------------------------------------- /thalossphere-distribution/thalossphere-agent-distribution/src/main/resources/plugin-config.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/consumer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thalossphere-projects/thalossphere/HEAD/docs/consumer.png -------------------------------------------------------------------------------- /docs/panoramic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thalossphere-projects/thalossphere/HEAD/docs/panoramic.png -------------------------------------------------------------------------------- /docs/service-search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thalossphere-projects/thalossphere/HEAD/docs/service-search.png -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/resources/META-INF/services/com.thalossphere.common.init.CoreInit: -------------------------------------------------------------------------------- 1 | com.thalossphere.agent.core.init.AgentInit -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-removal/src/main/resources/META-INF/services/com.thalossphere.common.init.CoreInit: -------------------------------------------------------------------------------- 1 | com.thalossphere.feature.removal.RemovalInit -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-sentinel/src/main/resources/META-INF/services/com.thalossphere.common.init.CoreInit: -------------------------------------------------------------------------------- 1 | com.thalossphere.feature.sentinel.init.SentinelInit -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/resources/META-INF/services/com.thalossphere.common.init.CoreInit: -------------------------------------------------------------------------------- 1 | com.thalossphere.extension.datasource.init.DataSourceInit -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-register-center/src/main/resources/META-INF/services/com.thalossphere.common.init.CoreInit: -------------------------------------------------------------------------------- 1 | com.thalossphere.register.center.init.RegisterCenterInit -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/interceptor/MethodInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.interceptor; 2 | 3 | public interface MethodInterceptor { 4 | } 5 | -------------------------------------------------------------------------------- /thalossphere-test/src/main/resources/example-agent.yaml: -------------------------------------------------------------------------------- 1 | pointcutConfigs: 2 | - className: com.flowpshere.test.AgentProxyCore 3 | methodPointcutConfigs: 4 | - methodName: instantHelloWord 5 | type: instant 6 | interceptorName: com.flowpshere.agent.CustomInterceptor -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/context/CustomContextAccessor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.context; 2 | 3 | public interface CustomContextAccessor { 4 | 5 | Object getCustomContext(); 6 | 7 | void setCustomContext(Object value); 8 | } 9 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/loadbalance/ArrayWeight.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.loadbalance; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public abstract class ArrayWeight { 7 | 8 | private double weight; 9 | 10 | public abstract Object getObj(); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/builder/InterceptorBuilder.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.builder; 2 | 3 | import net.bytebuddy.dynamic.DynamicType; 4 | 5 | public interface InterceptorBuilder { 6 | 7 | DynamicType.Builder intercept(DynamicType.Builder builder); 8 | } 9 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/request/RequestResolver.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.request; 2 | 3 | public interface RequestResolver { 4 | 5 | String getHeader(String key); 6 | 7 | String getCookie(String key); 8 | 9 | String getParameters(String key); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/loadbalance/InstantWeight.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.loadbalance; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class InstantWeight { 7 | 8 | private RegionWeight regionWeight; 9 | 10 | private UserWeight userWeight; 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/request/SimpleRequestResolver.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.request; 2 | 3 | public class SimpleRequestResolver extends AbstractRequestResolver { 4 | 5 | public SimpleRequestResolver(HttpRequest httpRequest) { 6 | super(httpRequest); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/config/yaml/YamlMethodParameterPointcutConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.config.yaml; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class YamlMethodParameterPointcutConfig { 7 | 8 | private int index; 9 | 10 | private String type; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/config/OkHttpConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.config; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class OkHttpConfig { 7 | 8 | private long connectTimeout = 30; 9 | 10 | private long writeTimeout = 30; 11 | 12 | private long readTimeout = 30; 13 | 14 | } -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/config/PluginConfigDataSource.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.config; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Properties; 6 | 7 | @Data 8 | public class PluginConfigDataSource { 9 | 10 | private String type; 11 | 12 | private Properties pros; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/loadbalance/UserWeight.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.loadbalance; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | @Data 8 | public class UserWeight { 9 | 10 | private List userIds; 11 | 12 | private List tagWeights; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/loadbalance/RegionWeight.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.loadbalance; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | @Data 8 | public class RegionWeight { 9 | 10 | private List regions; 11 | 12 | private List tagWeights; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/request/HttpRequest.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.request; 2 | 3 | import java.util.Map; 4 | 5 | public interface HttpRequest { 6 | 7 | Map getHeaders(); 8 | 9 | Map getCookies(); 10 | 11 | Map getParameters(); 12 | } 13 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/longpoll/entity/ReleaseMessage.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.longpoll.entity; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class ReleaseMessage { 7 | 8 | private String cmd; 9 | 10 | private String extendData; 11 | 12 | private String applicationName; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-zuul/src/main/resources/zuul-agent.yaml: -------------------------------------------------------------------------------- 1 | pointcutConfigs: 2 | - className: org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter 3 | methodPointcutConfigs: 4 | - methodName: forward 5 | type: instant 6 | interceptorName: com.thalossphere.agent.plugin.zuul.RibbonRoutingFilterInterceptor -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/java/com/thalossphere/extension/datasource/entity/ElasticJobConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.extension.datasource.entity; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class ElasticJobConfig { 7 | 8 | private boolean grayEnabled; 9 | 10 | private String ip; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/interceptor/template/InstantMethodInterceptorResult.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.interceptor.template; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class InstantMethodInterceptorResult { 7 | 8 | private boolean isContinue = true; 9 | 10 | private Object result = null; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-elasticjob2/src/main/resources/elasticjob2-agent.yaml: -------------------------------------------------------------------------------- 1 | pointcutConfigs: 2 | - className: com.dangdang.ddframe.job.lite.internal.sharding.ShardingService 3 | methodPointcutConfigs: 4 | - methodName: getShardingItems 5 | type: instant 6 | interceptorName: com.thalossphere.agent.plugin.elastic.job.ShardingServiceInterceptor -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-elasticjob-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=thalossphere-elasticjob-example 2 | server.port=8998 3 | myJob.cron=0/5 * * * * ? 4 | myJob.shardingTotalCount=1 5 | myJob.shardingItemParameters=0=Beijing,1=Shanghai,2=Guangzhou 6 | 7 | regCenter.serverList=localhost:2181 8 | regCenter.namespace=thalossphere-elasticjob-example -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-eureka-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8189 3 | eureka: 4 | instance: 5 | hostname: localhost 6 | client: 7 | registerWithEureka: false 8 | fetchRegistry: false 9 | serviceUrl: 10 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/interceptor/type/ConstructorInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.interceptor.type; 2 | 3 | import com.thalossphere.agent.core.interceptor.MethodInterceptor; 4 | 5 | public interface ConstructorInterceptor extends MethodInterceptor { 6 | 7 | void onConstructor(Object obj, Object[] allArguments); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/config/yaml/YamlPointcutConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.config.yaml; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.LinkedList; 6 | import java.util.List; 7 | 8 | @Data 9 | public class YamlPointcutConfig { 10 | 11 | private List pointcutConfigs = new LinkedList<>(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/eventbus/enums/CmdEnum.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.eventbus.enums; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | 6 | @AllArgsConstructor 7 | @Getter 8 | public enum CmdEnum { 9 | 10 | PROVIDER_OFFLINE("PROVIDER_OFFLINE","服务下线"); 11 | 12 | private String cmd; 13 | 14 | private String desc; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-sentinel/src/main/java/com/thalossphere/feature/sentinel/datasource/SentinelDataSourceRuleLoader.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.sentinel.datasource; 2 | 3 | 4 | import com.thalossphere.common.config.PluginConfigDataSource; 5 | 6 | public interface SentinelDataSourceRuleLoader { 7 | 8 | void load(PluginConfigDataSource pluginConfigDataSource); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/init/CoreInit.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.init; 2 | 3 | import com.thalossphere.common.config.YamlAgentConfig; 4 | 5 | import java.lang.instrument.Instrumentation; 6 | 7 | public interface CoreInit { 8 | 9 | void init(YamlAgentConfig yamlAgentConfig, ClassLoader classLoader, Instrumentation inst); 10 | 11 | int getOrder(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/java/com/thalossphere/extension/datasource/support/local/YamlPluginConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.extension.datasource.support.local; 2 | 3 | import com.thalossphere.extension.datasource.entity.PluginConfig; 4 | import lombok.Data; 5 | 6 | @Data 7 | public class YamlPluginConfig { 8 | 9 | private PluginConfig pluginConfig; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/utils/URLClassLoaderManager.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.utils; 2 | 3 | 4 | 5 | import java.net.URL; 6 | import java.net.URLClassLoader; 7 | 8 | public class URLClassLoaderManager { 9 | 10 | public static ClassLoader createClassLoader(URL[] urls, ClassLoader parent) { 11 | return new URLClassLoader(urls, parent); 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/propagator/GatewayPropagator.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.propagator; 2 | 3 | import com.thalossphere.common.loadbalance.InstantWeight; 4 | import com.thalossphere.common.request.AbstractAttributeResolver; 5 | 6 | public interface GatewayPropagator { 7 | 8 | void inject(InstantWeight instantWeight, AbstractAttributeResolver attributeResolver); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/transport/SimpleHttpRequest.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.transport; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | import java.io.Serializable; 7 | 8 | @Data 9 | @Accessors(chain = true) 10 | public class SimpleHttpRequest implements Serializable { 11 | 12 | private String url; 13 | 14 | private Object data; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-discovery-binder/src/main/java/com/thalossphere/feature/discovery/binder/instance/entity/ProviderFunction.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.discovery.binder.instance.entity; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | @Data 7 | @Accessors(chain = true) 8 | public class ProviderFunction extends Provider { 9 | 10 | private String url; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/interceptor/MethodInterceptorOperator.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.interceptor; 2 | 3 | import net.bytebuddy.description.method.MethodDescription; 4 | import net.bytebuddy.dynamic.DynamicType; 5 | 6 | public interface MethodInterceptorOperator { 7 | 8 | DynamicType.Builder intercept(DynamicType.Builder builder, MethodDescription pointcut); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-rocketmq-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=thalossphere-rocketmq-example 2 | server.port=8999 3 | 4 | spring.cloud.nacos.discovery.metadata.version=1.0.1 5 | spring.cloud.nacos.discovery.server-addr=localhost:8848 6 | spring.cloud.nacos.discovery.enabled=true 7 | spring.cloud.nacos.username=nacos 8 | spring.cloud.nacos.password=nacos 9 | spring.cloud.nacos.discovery.metadata.tag=tagA -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/java/com/thalossphere/extension/datasource/loader/PluginConfigLoader.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.extension.datasource.loader; 2 | 3 | import com.thalossphere.extension.datasource.entity.PluginConfig; 4 | 5 | import java.util.Properties; 6 | 7 | public interface PluginConfigLoader { 8 | 9 | PluginConfig load(ClassLoader classLoader, Properties properties); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/context/CustomContext.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.context; 2 | 3 | 4 | import lombok.Getter; 5 | 6 | @Getter 7 | public class CustomContext { 8 | 9 | private String tag; 10 | 11 | private Thread originThread; 12 | 13 | public CustomContext(String tag) { 14 | this.tag = tag; 15 | this.originThread = Thread.currentThread(); 16 | } 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-discovery-binder/src/main/java/com/thalossphere/feature/discovery/binder/instance/entity/Provider.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.discovery.binder.instance.entity; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | @Data 7 | @Accessors(chain = true) 8 | public class Provider { 9 | 10 | private String providerName; 11 | 12 | private String ip; 13 | 14 | private int port; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/config/yaml/YamlClassPointcutConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.config.yaml; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Collection; 6 | import java.util.LinkedList; 7 | 8 | @Data 9 | public class YamlClassPointcutConfig { 10 | 11 | private String className; 12 | 13 | private Collection methodPointcutConfigs = new LinkedList<>(); 14 | 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-elasticjob-example/src/main/java/com/thalossphere/elasticjob/example/job/MyJob.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.elasticjob.example.job; 2 | 3 | import com.dangdang.ddframe.job.api.ShardingContext; 4 | import com.dangdang.ddframe.job.api.simple.SimpleJob; 5 | 6 | public class MyJob implements SimpleJob { 7 | 8 | public void execute(ShardingContext shardingContext) { 9 | System.out.println("MyJob执行中"); 10 | } 11 | 12 | } 13 | 14 | -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/java/com/thalossphere/extension/datasource/entity/ZuulConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.extension.datasource.entity; 2 | 3 | import com.thalossphere.common.loadbalance.RegionWeight; 4 | import com.thalossphere.common.loadbalance.UserWeight; 5 | import lombok.Data; 6 | 7 | @Data 8 | public class ZuulConfig { 9 | 10 | private RegionWeight regionWeight; 11 | 12 | private UserWeight userWeight; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-discovery-binder/src/main/java/com/thalossphere/feature/discovery/binder/event/InstanceInitEvent.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.discovery.binder.event; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | @Data 7 | @Accessors(chain = true) 8 | public class InstanceInitEvent { 9 | 10 | private String applicationName; 11 | 12 | private String serverAddr; 13 | 14 | private int port; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/eventbus/event/RefreshServerListEvent.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.eventbus.event; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.experimental.Accessors; 7 | 8 | @Data 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | @Accessors(chain = true) 12 | public class RefreshServerListEvent { 13 | 14 | private String applicationName; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/longpoll/entity/NotificationRequest.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.longpoll.entity; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | import java.io.Serializable; 7 | 8 | @Data 9 | @Accessors(chain = true) 10 | public class NotificationRequest implements Serializable { 11 | 12 | private String applicationName; 13 | 14 | private String ip; 15 | 16 | private int port; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/java/com/thalossphere/extension/datasource/enums/PluginConfigDataSourceTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.extension.datasource.enums; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | 6 | @AllArgsConstructor 7 | @Getter 8 | public enum PluginConfigDataSourceTypeEnum { 9 | 10 | LOCAL("local"), 11 | NACOS("nacos"), 12 | APOLLO("apollo"); 13 | 14 | private String type; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-sentinel/src/main/java/com/thalossphere/feature/sentinel/datasource/SentinelConfigDataSourceTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.sentinel.datasource; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | 6 | @AllArgsConstructor 7 | @Getter 8 | public enum SentinelConfigDataSourceTypeEnum { 9 | 10 | LOCAL("local"), 11 | NACOS("nacos"), 12 | APOLLO("apollo"); 13 | 14 | private String type; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/enums/MethodTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.enums; 2 | 3 | public enum MethodTypeEnum { 4 | 5 | STATIC("static"), 6 | CONSTRUCTOR("constructor"), 7 | INSTANT("instant") 8 | ; 9 | 10 | private final String type; 11 | 12 | 13 | MethodTypeEnum(String type) { 14 | this.type = type; 15 | } 16 | 17 | public String getType() { 18 | return type; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/request/AttributeResolver.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.request; 2 | 3 | public interface AttributeResolver { 4 | 5 | default String getTag(RequestResolver requestResolver) { 6 | return null; 7 | } 8 | 9 | default String getUserId(RequestResolver requestResolver) { 10 | return null; 11 | } 12 | 13 | default String getRegion(RequestResolver requestResolver) { 14 | return null; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/env/Env.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.env; 2 | 3 | import java.util.Map; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | 6 | public class Env { 7 | 8 | private final static Map ENV = new ConcurrentHashMap<>(); 9 | 10 | public static void putAll(Map env) { 11 | ENV.putAll(env); 12 | } 13 | 14 | public static String get(String key) { 15 | return ENV.get(key); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/java/com/thalossphere/extension/datasource/entity/SpringCloudGatewayConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.extension.datasource.entity; 2 | 3 | import com.thalossphere.common.loadbalance.RegionWeight; 4 | import com.thalossphere.common.loadbalance.UserWeight; 5 | import lombok.Data; 6 | 7 | @Data 8 | public class SpringCloudGatewayConfig { 9 | 10 | private RegionWeight regionWeight; 11 | 12 | private UserWeight userWeight; 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-rocketmq-example/src/main/java/com/thalossphere/rocketmq/example/RocketMQExampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.rocketmq.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class RocketMQExampleApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(RocketMQExampleApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-a-example/src/main/java/com/thalossphere/spring/cloud/service/consumer/example/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.service.consumer.example.entity; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | import java.io.Serializable; 7 | 8 | @Data 9 | @Accessors(chain = true) 10 | public class User implements Serializable { 11 | 12 | private int id; 13 | 14 | private String username; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-a1-example/src/main/java/com/thalossphere/spring/cloud/service/consumer/example/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.service.consumer.example.entity; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | import java.io.Serializable; 7 | 8 | @Data 9 | @Accessors(chain = true) 10 | public class User implements Serializable { 11 | 12 | private int id; 13 | 14 | private String username; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/java/com/thalossphere/extension/datasource/support/apollo/ApolloConfigConstant.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.extension.datasource.support.apollo; 2 | 3 | public class ApolloConfigConstant { 4 | 5 | public static final String APP_ID = "appId"; 6 | 7 | public static final String ENV = "env"; 8 | 9 | public static final String APOLLO_META = "apolloMeta"; 10 | 11 | public static final String FLOW_SPHERE_CONFIG_JSON = "thalossphereConfigJson"; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /thalossphere-test/src/main/java/com/thalossphere/test/util/NetUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.test.util; 2 | 3 | import com.thalossphere.common.utils.NetUtils; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.util.StringUtils; 7 | 8 | public class NetUtilsTest { 9 | 10 | @Test 11 | public void getIpAddressTest() { 12 | String ipAddress = NetUtils.getIpAddress(); 13 | Assertions.assertTrue(!StringUtils.isEmpty(ipAddress)); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/loadbalance/TagWeight.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.loadbalance; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | 6 | @Data 7 | @NoArgsConstructor 8 | public class TagWeight extends ArrayWeight { 9 | 10 | private String tag; 11 | 12 | public TagWeight(String tag, double weight) { 13 | this.tag = tag; 14 | super.setWeight(weight); 15 | } 16 | 17 | @Override 18 | public Object getObj() { 19 | return tag; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/config/yaml/YamlMethodPointcutConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.config.yaml; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Collection; 6 | import java.util.LinkedList; 7 | 8 | @Data 9 | public class YamlMethodPointcutConfig { 10 | 11 | private String methodName; 12 | 13 | private String type; 14 | 15 | private String interceptorName; 16 | 17 | private Collection parameterPointcutConfigs = new LinkedList<>(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/constant/CommonConstant.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.constant; 2 | 3 | public interface CommonConstant { 4 | 5 | String REGION = "region"; 6 | 7 | String USER_ID = "user-id"; 8 | 9 | String PLUGINS = "plugins"; 10 | 11 | String TAG = "tag"; 12 | 13 | String SERVER_TAG = "thalossphere.tag"; 14 | 15 | String TIMESTAMP = "timestamp"; 16 | 17 | String SPRING_APPLICATION_NAME = "spring.application.name"; 18 | 19 | String SERVER_PORT = "server.port"; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /thalossphere-agent/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-common/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-examples/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-features/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-sentinel/src/main/java/com/thalossphere/feature/sentinel/limiter/SentinelResource.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.sentinel.limiter; 2 | 3 | import com.alibaba.csp.sentinel.EntryType; 4 | import lombok.Data; 5 | import lombok.experimental.Accessors; 6 | 7 | @Data 8 | @Accessors(chain = true) 9 | public class SentinelResource { 10 | 11 | private String resourceName; 12 | 13 | private String contextName; 14 | 15 | private String origin; 16 | 17 | private EntryType entryType = EntryType.OUT; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /thalossphere-plugins/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-test/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-agent-core/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-distribution/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/config/MethodMatcherConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.config; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import net.bytebuddy.description.method.MethodDescription; 6 | import net.bytebuddy.matcher.ElementMatcher; 7 | 8 | @Getter 9 | @AllArgsConstructor 10 | public class MethodMatcherConfig { 11 | 12 | private final ElementMatcher pointcut; 13 | 14 | private final String interceptorName; 15 | 16 | private final String type; 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-a-example/src/main/java/com/thalossphere/spring/cloud/service/consumer/example/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.service.consumer.example.mapper; 2 | 3 | import com.thalossphere.spring.cloud.service.consumer.example.entity.User; 4 | import org.apache.ibatis.annotations.Mapper; 5 | import org.apache.ibatis.annotations.Select; 6 | 7 | @Mapper 8 | public interface UserMapper { 9 | 10 | @Select("select * from t_user where id = #{id}") 11 | User findById(int id); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-a1-example/src/main/java/com/thalossphere/spring/cloud/service/consumer/example/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.service.consumer.example.mapper; 2 | 3 | import com.thalossphere.spring.cloud.service.consumer.example.entity.User; 4 | import org.apache.ibatis.annotations.Mapper; 5 | import org.apache.ibatis.annotations.Select; 6 | 7 | @Mapper 8 | public interface UserMapper { 9 | 10 | @Select("select * from t_user where id = #{id}") 11 | User findById(int id); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-fegin/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-nacos/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-rocketmq-example/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-discovery-binder/src/main/java/com/thalossphere/feature/discovery/binder/instance/entity/Consumer.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.discovery.binder.instance.entity; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | import java.io.Serializable; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | @Data 11 | @Accessors(chain = true) 12 | public class Consumer implements Serializable { 13 | 14 | private String applicationName; 15 | 16 | private Map> dependOnInterfaceList; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-removal/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-rocketmq4/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-springmvc/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/tag/context/TagContext.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.tag.context; 2 | 3 | public class TagContext { 4 | 5 | private static final ThreadLocal RULE_LOCAL = new ThreadLocal(); 6 | 7 | public static void set(String tag) { 8 | RULE_LOCAL.set(tag); 9 | } 10 | 11 | public static void remove() { 12 | if (RULE_LOCAL.get() != null) { 13 | RULE_LOCAL.remove(); 14 | } 15 | } 16 | 17 | public static String get() { 18 | return RULE_LOCAL.get(); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-elasticjob-example/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-elasticjob2/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-resttemplate/src/main/resources/resttemplate-agent.yaml: -------------------------------------------------------------------------------- 1 | pointcutConfigs: 2 | - className: org.springframework.http.client.support.HttpAccessor 3 | methodPointcutConfigs: 4 | - methodName: createRequest 5 | type: instant 6 | interceptorName: com.thalossphere.plugin.resttemplate.HttpAccessorInterceptor 7 | - className: org.springframework.web.client.RestTemplate 8 | methodPointcutConfigs: 9 | - methodName: doExecute 10 | type: instant 11 | interceptorName: com.thalossphere.plugin.resttemplate.RestTemplateInterceptor -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | /agent/** 35 | /ancient-agent/dependency-reduced-pom.xml 36 | -------------------------------------------------------------------------------- /thalossphere-distribution/thalossphere-agent-distribution/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/java/com/thalossphere/extension/datasource/entity/PluginConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.extension.datasource.entity; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class PluginConfig { 7 | 8 | private RocketMQConfig rocketMQConfig; 9 | 10 | private ElasticJobConfig elasticJobConfig; 11 | 12 | private SpringCloudGatewayConfig springCloudGatewayConfig; 13 | 14 | private ZuulConfig zuulConfig; 15 | 16 | private SentinelConfig sentinelConfig; 17 | 18 | private RemovalConfig removalConfig; 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-discovery-binder/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-register-center/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-nacos/src/main/resources/nacos-agent.yaml: -------------------------------------------------------------------------------- 1 | pointcutConfigs: 2 | - className: com.netflix.loadbalancer.CompositePredicate 3 | methodPointcutConfigs: 4 | - methodName: getEligibleServers 5 | type: instant 6 | interceptorName: com.thalossphere.agent.plugin.nacos.CompositePredicateInterceptor 7 | - className: com.alibaba.cloud.nacos.NacosDiscoveryProperties 8 | methodPointcutConfigs: 9 | - methodName: setMetadata 10 | type: instant 11 | interceptorName: com.thalossphere.agent.plugin.nacos.NacosDiscoveryPropertiesInterceptor -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-springcloudgateway/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-mybatis/src/main/resources/mybatis-agent.yaml: -------------------------------------------------------------------------------- 1 | pointcutConfigs: 2 | - className: org.apache.ibatis.executor.BaseExecutor 3 | methodPointcutConfigs: 4 | - methodName: update 5 | type: instant 6 | interceptorName: com.thalossphere.plugin.mybatis.BaseExecutorInterceptor 7 | - methodName: query 8 | type: instant 9 | interceptorName: com.thalossphere.plugin.mybatis.BaseExecutorInterceptor 10 | - methodName: queryCursor 11 | type: instant 12 | interceptorName: com.thalossphere.plugin.mybatis.BaseExecutorInterceptor -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-eureka/src/main/resources/eureka-agent.yaml: -------------------------------------------------------------------------------- 1 | pointcutConfigs: 2 | - className: com.netflix.loadbalancer.BaseLoadBalancer 3 | methodPointcutConfigs: 4 | - methodName: getAllServers 5 | type: instant 6 | interceptorName: com.thalossphere.agent.plugin.eureka.BaseLoadBalancerInterceptor 7 | - className: org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean 8 | methodPointcutConfigs: 9 | - methodName: getMetadataMap 10 | type: instant 11 | interceptorName: com.thalossphere.agent.plugin.eureka.EurekaInstanceConfigBeanInterceptor -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-consul/src/main/resources/consul-agent.yaml: -------------------------------------------------------------------------------- 1 | pointcutConfigs: 2 | - className: com.netflix.loadbalancer.CompositePredicate 3 | methodPointcutConfigs: 4 | - methodName: getEligibleServers 5 | type: instant 6 | interceptorName: com.thalossphere.agent.plugin.consul.CompositePredicateInterceptor 7 | - className: org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties 8 | methodPointcutConfigs: 9 | - methodName: getTags 10 | type: instant 11 | interceptorName: com.thalossphere.agent.plugin.consul.ConsulDiscoveryPropertiesInterceptor -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/utils/DynamicServerListLoadBalancerCache.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.utils; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class DynamicServerListLoadBalancerCache { 7 | 8 | private static final Map CACHE = new HashMap<>(); 9 | 10 | public static void add(String clientName, Object dynamicServerListLoadBalancer) { 11 | CACHE.put(clientName, dynamicServerListLoadBalancer); 12 | } 13 | 14 | public static Object get(String clientName) { 15 | return CACHE.get(clientName); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-springboot2/src/main/resources/springboot2-agent.yaml: -------------------------------------------------------------------------------- 1 | pointcutConfigs: 2 | - className: org.springframework.boot.context.event.EventPublishingRunListener 3 | methodPointcutConfigs: 4 | - methodName: running 5 | type: instant 6 | interceptorName: com.thalossphere.spring.boot2.EventPublishingRunListenerInterceptor 7 | - className: org.springframework.context.support.AbstractApplicationContext 8 | methodPointcutConfigs: 9 | - methodName: doClose 10 | type: instant 11 | interceptorName: com.thalossphere.spring.boot2.AppShutdownInterceptor 12 | 13 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/tag/extract/TagExtract.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.tag.extract; 2 | 3 | import com.thalossphere.common.loadbalance.InstantWeight; 4 | import com.thalossphere.common.request.AbstractAttributeResolver; 5 | import com.thalossphere.common.request.AttributeResolver; 6 | import com.thalossphere.common.request.RequestResolver; 7 | 8 | public interface TagExtract { 9 | 10 | String extract(InstantWeight instantWeight, AbstractAttributeResolver attributeResolver); 11 | 12 | boolean match(InstantWeight instantWeight, AbstractAttributeResolver attributeResolver); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/builder/InterceptorBuilderChain.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.builder; 2 | 3 | import net.bytebuddy.dynamic.DynamicType; 4 | 5 | public class InterceptorBuilderChain { 6 | 7 | public static DynamicType.Builder buildInterceptor(DynamicType.Builder builder, InterceptorBuilder... interceptorBuilders) { 8 | DynamicType.Builder result = builder; 9 | for (InterceptorBuilder interceptorBuilder : interceptorBuilders) { 10 | result = interceptorBuilder.intercept(result); 11 | } 12 | return result; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-gateway-example/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-a-example/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-a1-example/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-api-example/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-b-example/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-b1-example/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-c-example/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-c1-example/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/request/SimpleAttributeResolver.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.request; 2 | 3 | import com.google.common.collect.Lists; 4 | 5 | import java.util.List; 6 | 7 | public class SimpleAttributeResolver extends AbstractAttributeResolver { 8 | 9 | public SimpleAttributeResolver(RequestResolver requestResolver) { 10 | super(requestResolver); 11 | } 12 | 13 | @Override 14 | public List getAttributeResolverList() { 15 | return Lists.newArrayList(new CookieResolver() {}, new HeaderResolver() {}, new ParameterResolver() {}); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-zookeeper/src/main/resources/zookeeper-agent.yaml: -------------------------------------------------------------------------------- 1 | pointcutConfigs: 2 | - className: com.netflix.loadbalancer.CompositePredicate 3 | methodPointcutConfigs: 4 | - methodName: getEligibleServers 5 | type: instant 6 | interceptorName: com.thalossphere.agent.plugin.zookeeper.CompositePredicateInterceptor 7 | - className: org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryProperties 8 | methodPointcutConfigs: 9 | - methodName: getMetadata 10 | type: instant 11 | interceptorName: com.thalossphere.agent.plugin.zookeeper.ZookeeperDiscoveryPropertiesInterceptor -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-sentinel/src/main/java/com/thalossphere/feature/sentinel/limiter/SentinelLimiter.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.sentinel.limiter; 2 | 3 | import com.alibaba.csp.sentinel.Entry; 4 | import com.alibaba.csp.sentinel.SphU; 5 | import lombok.SneakyThrows; 6 | 7 | import java.util.concurrent.Callable; 8 | 9 | public interface SentinelLimiter { 10 | 11 | Object limit(SentinelResource sentinelResource, Callable callable); 12 | 13 | @SneakyThrows 14 | default Entry getEntry(SentinelResource sentinelResource) { 15 | return SphU.entry(sentinelResource.getResourceName()); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-elasticjob-example/src/main/java/com/thalossphere/elasticjob/example/ElasticJobExampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.elasticjob.example; 2 | 3 | import com.thalossphere.elasticjob.example.config.EmbedZookeeperServer; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | public class ElasticJobExampleApplication { 9 | 10 | public static void main(String[] args) { 11 | EmbedZookeeperServer.start(2181); 12 | SpringApplication.run(ElasticJobExampleApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/java/com/thalossphere/extension/datasource/support/nacos/NacosConfigConstant.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.extension.datasource.support.nacos; 2 | 3 | public class NacosConfigConstant { 4 | 5 | public static final String DATA_ID = "dataId"; 6 | 7 | public static final String GROUP_ID = "groupId"; 8 | 9 | public static final String SENTINEL_DATA_ID = "sentinelDataId"; 10 | 11 | public static final String SENTINEL_GROUP_ID = "sentinelGroupId"; 12 | 13 | public static final String DEFAULT_TIMEOUT = "3000"; 14 | 15 | public static final String TIMEOUT = "timeout"; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-register-center/src/main/java/com/thalossphere/register/center/selector/ServerWeight.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.register.center.selector; 2 | 3 | import com.thalossphere.common.loadbalance.ArrayWeight; 4 | import com.netflix.loadbalancer.Server; 5 | import lombok.Data; 6 | 7 | @Data 8 | public class ServerWeight extends ArrayWeight { 9 | 10 | private Server server; 11 | 12 | public ServerWeight(Server server, double weight) { 13 | this.server = server; 14 | super.setWeight(weight); 15 | } 16 | 17 | @Override 18 | public Object getObj() { 19 | return server; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-sentinel/src/main/java/com/thalossphere/feature/sentinel/constant/SentinelConstant.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.sentinel.constant; 2 | 3 | public class SentinelConstant { 4 | 5 | public static final String SENTINEL_FLOW_KEY = "sentinel-flow-rules"; 6 | 7 | public static final String SENTINEL_DEGRADE_KEY = "sentinel-degrade-rules"; 8 | 9 | public static final String SENTINEL_AUTHORITY_KEY = "sentinel-authority-rules"; 10 | 11 | public static final String SENTINEL_SYSTEM_KEY = "sentinel-system-rules"; 12 | 13 | public static final String SENTINEL_PARAM_FLOW_KEY = "sentinel-param-flow-rules"; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/yaml/YamlConstructor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.yaml; 2 | 3 | import org.yaml.snakeyaml.constructor.Constructor; 4 | 5 | public class YamlConstructor extends Constructor { 6 | 7 | private final Class rootClass; 8 | 9 | public YamlConstructor(Class rootClass) { 10 | this.rootClass = rootClass; 11 | } 12 | 13 | @Override 14 | protected Class getClassForName(String name) throws ClassNotFoundException { 15 | if (!name.equals(rootClass.getName())) { 16 | throw new RuntimeException(); 17 | } 18 | return super.getClassForName(name); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /thalossphere-extensions/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-zuul/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-sentinel/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-consul/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-eureka/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-mybatis/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-zookeeper/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/config/YamlAgentConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.config; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | @Data 9 | public class YamlAgentConfig { 10 | 11 | private PluginConfigDataSource pluginConfigDataSource; 12 | 13 | private List plugins = new ArrayList<>(); 14 | 15 | private boolean sentinelEnabled; 16 | 17 | private OkHttpConfig okHttpConfig = new OkHttpConfig(); 18 | 19 | private long longPollDelay = 3010; 20 | 21 | private String serverAddr; 22 | 23 | private boolean warmupEnabled; 24 | 25 | private boolean discoveryBinderEnabled; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-resttemplate/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-springboot2/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-eureka-server/src/main/java/com/thalossphere/spring/cloud/eureka/server/SpringCloudEurekaServerExampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.eureka.server; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @EnableEurekaServer 8 | @SpringBootApplication 9 | public class SpringCloudEurekaServerExampleApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringCloudEurekaServerExampleApplication.class); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-c-example/src/main/java/com/thalossphere/spring/cloud/service/provider/example/SpringCloudServiceCExampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.service.provider.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | @EnableFeignClients 8 | @SpringBootApplication 9 | public class SpringCloudServiceCExampleApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringCloudServiceCExampleApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /thalossphere-extensions/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | io.github.thalossphere-projects 6 | thalossphere 7 | 1.5.0.RELEASE 8 | 9 | thalossphere-extensions 10 | thalossphere-extensions 11 | pom 12 | 13 | 14 | thalossphere-extension-datasource 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-gateway-example/src/main/java/com/thalossphere/plugin/spring/cloud/gateway/example/SpringCloudGatewayExampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.plugin.spring.cloud.gateway.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ComponentScan; 6 | 7 | @ComponentScan("com.thalossphere") 8 | @SpringBootApplication 9 | public class SpringCloudGatewayExampleApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringCloudGatewayExampleApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-c1-example/src/main/java/com/thalossphere/spring/cloud/service/provider/example/SpringCloudServiceC1ExampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.service.provider.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | @EnableFeignClients 8 | @SpringBootApplication 9 | public class SpringCloudServiceC1ExampleApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringCloudServiceC1ExampleApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-a-example/src/main/java/com/thalossphere/spring/cloud/service/consumer/example/config/RestTemplateConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.service.consumer.example.config; 2 | 3 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.client.RestTemplate; 7 | 8 | @Configuration 9 | public class RestTemplateConfig { 10 | 11 | @Bean 12 | @LoadBalanced // 开启负载均衡 13 | public RestTemplate restTemplate() { 14 | return new RestTemplate(); 15 | } 16 | 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-a1-example/src/main/java/com/thalossphere/spring/cloud/service/consumer/example/config/RestTemplateConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.service.consumer.example.config; 2 | 3 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.client.RestTemplate; 7 | 8 | @Configuration 9 | public class RestTemplateConfig { 10 | 11 | @Bean 12 | @LoadBalanced // 开启负载均衡 13 | public RestTemplate restTemplate() { 14 | return new RestTemplate(); 15 | } 16 | 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-discovery-binder/src/main/java/com/thalossphere/feature/discovery/binder/ProviderInterfaceManager.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.discovery.binder; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | public class ProviderInterfaceManager { 9 | 10 | private static final List INTERFACE = new ArrayList<>(); 11 | 12 | public static void addInterfaceUrl(String url) { 13 | INTERFACE.add(url); 14 | } 15 | 16 | public static List getInterfaceUrlList() { 17 | return INTERFACE; 18 | } 19 | 20 | public static void clear() { 21 | INTERFACE.clear(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /thalossphere-distribution/thalossphere-agent-distribution/src/main/resources/agent.yaml: -------------------------------------------------------------------------------- 1 | plugins: 2 | - nacos 3 | - rocketmq4 4 | - springmvc 5 | - springcloudgateway 6 | - feign 7 | - elasticjob2 8 | - zuul 9 | - eureka 10 | - springboot2 11 | - zookeeper 12 | - consul 13 | - resttemplate 14 | - mybatis 15 | sentinelEnabled: false 16 | warmupEnabled: false 17 | discoveryBinderEnabled: true 18 | serverAddr: http://127.0.0.1:8224 19 | pluginConfigDataSource: 20 | # type: local 21 | type: nacos 22 | pros: 23 | dataId: default 24 | groupId: DEFAULT_GROUP 25 | timeout: 3000 26 | serverAddr: 127.0.0.1:8848 27 | # type: apollo 28 | # pros: 29 | # appId: 101 30 | # apolloMeta: http://localhost:8080 31 | # env: DEV -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-eureka-server/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-zuul-example/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/request/HeaderResolver.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.request; 2 | 3 | import com.thalossphere.common.constant.CommonConstant; 4 | 5 | public interface HeaderResolver extends AttributeResolver { 6 | 7 | @Override 8 | default String getTag(RequestResolver requestResolver) { 9 | return requestResolver.getHeader(CommonConstant.TAG); 10 | } 11 | 12 | @Override 13 | default String getUserId(RequestResolver requestResolver) { 14 | return requestResolver.getHeader(CommonConstant.USER_ID); 15 | } 16 | 17 | @Override 18 | default String getRegion(RequestResolver requestResolver) { 19 | return requestResolver.getHeader(CommonConstant.REGION); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-b-example/src/main/java/com/thalossphere/spring/cloud/service/provider/example/SpringCloudServiceBExampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.service.provider.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | @EnableFeignClients(basePackages = "com.thalossphere") 8 | @SpringBootApplication 9 | public class SpringCloudServiceBExampleApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringCloudServiceBExampleApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-sentinel/src/main/java/com/thalossphere/feature/sentinel/utils/SentinelContext.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.sentinel.utils; 2 | 3 | import com.alibaba.csp.sentinel.slots.block.BlockException; 4 | 5 | public class SentinelContext { 6 | 7 | private static final ThreadLocal THREAD_LOCAL = new ThreadLocal(); 8 | 9 | public static void set(BlockException exception) { 10 | THREAD_LOCAL.set(exception); 11 | } 12 | 13 | public static void remove() { 14 | if (THREAD_LOCAL.get() != null) { 15 | THREAD_LOCAL.remove(); 16 | } 17 | } 18 | 19 | public static BlockException get() { 20 | return THREAD_LOCAL.get(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/eventbus/EventBusManager.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.eventbus; 2 | 3 | import com.google.common.eventbus.EventBus; 4 | 5 | public class EventBusManager { 6 | 7 | private static final EventBus INSTANCE = new EventBus(); 8 | 9 | private EventBusManager() { 10 | 11 | } 12 | 13 | public static EventBus getInstance() { 14 | return INSTANCE; 15 | } 16 | 17 | public static void register(Object listener) { 18 | INSTANCE.register(listener); 19 | } 20 | 21 | public static void unregister(Object listener) { 22 | INSTANCE.unregister(listener); 23 | } 24 | 25 | public static void post(Object event) { 26 | INSTANCE.post(event); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-b1-example/src/main/java/com/thalossphere/spring/cloud/service/provider/example/SpringCloudServiceB1ExampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.service.provider.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | @EnableFeignClients(basePackages = "com.thalossphere") 8 | @SpringBootApplication 9 | public class SpringCloudServiceB1ExampleApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringCloudServiceB1ExampleApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/request/CookieResolver.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.request; 2 | 3 | import com.thalossphere.common.constant.CommonConstant; 4 | 5 | public interface CookieResolver extends AttributeResolver { 6 | 7 | 8 | @Override 9 | default String getTag(RequestResolver requestResolver) { 10 | return requestResolver.getCookie(CommonConstant.TAG); 11 | } 12 | 13 | @Override 14 | default String getUserId(RequestResolver requestResolver) { 15 | return requestResolver.getCookie(CommonConstant.USER_ID); 16 | } 17 | 18 | @Override 19 | default String getRegion(RequestResolver requestResolver) { 20 | return requestResolver.getCookie(CommonConstant.REGION); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/request/ParameterResolver.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.request; 2 | 3 | import com.thalossphere.common.constant.CommonConstant; 4 | 5 | public interface ParameterResolver extends AttributeResolver { 6 | 7 | @Override 8 | default String getTag(RequestResolver requestResolver) { 9 | return requestResolver.getParameters(CommonConstant.TAG); 10 | } 11 | 12 | @Override 13 | default String getUserId(RequestResolver requestResolver) { 14 | return requestResolver.getParameters(CommonConstant.USER_ID); 15 | } 16 | 17 | @Override 18 | default String getRegion(RequestResolver requestResolver) { 19 | return requestResolver.getParameters(CommonConstant.REGION); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-a-example/src/main/java/com/thalossphere/spring/cloud/service/consumer/example/SpringCloudServiceAExampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.service.consumer.example; 2 | 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.openfeign.EnableFeignClients; 7 | 8 | 9 | @EnableFeignClients(basePackages = "com.thalossphere") 10 | @SpringBootApplication 11 | public class SpringCloudServiceAExampleApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SpringCloudServiceAExampleApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/builder/TargetObjectInterceptorBuilder.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.builder; 2 | 3 | import com.thalossphere.agent.core.context.CustomContextAccessor; 4 | import net.bytebuddy.dynamic.DynamicType; 5 | import net.bytebuddy.implementation.FieldAccessor; 6 | 7 | public class TargetObjectInterceptorBuilder implements InterceptorBuilder { 8 | 9 | public static final String CONTEXT_ATTR_NAME = "_$CustomContextAccessorField_ws"; 10 | 11 | @Override 12 | public DynamicType.Builder intercept(DynamicType.Builder builder) { 13 | return builder.defineField(CONTEXT_ATTR_NAME, Object.class).implement(CustomContextAccessor.class).intercept(FieldAccessor.ofField(CONTEXT_ATTR_NAME)); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-zuul-example/src/main/java/com/thalossphere/spring/cloud/zuul/example/SpringCloudZuulExampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.zuul.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 7 | 8 | @EnableDiscoveryClient 9 | @EnableZuulProxy 10 | @SpringBootApplication 11 | public class SpringCloudZuulExampleApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SpringCloudZuulExampleApplication.class); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-rocketmq4/src/main/java/com/thalossphere/agent/plugin/rocketmq/consumer/condition/CidSplitMatchGrayCondition.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.rocketmq.consumer.condition; 2 | 3 | import com.thalossphere.common.tag.context.TagManager; 4 | 5 | import java.util.function.Predicate; 6 | 7 | public class CidSplitMatchGrayCondition implements Predicate { 8 | 9 | private final String tag; 10 | 11 | public CidSplitMatchGrayCondition(String tag) { 12 | this.tag = tag; 13 | } 14 | 15 | @Override 16 | public boolean test(String cid) { 17 | String[] cidSplit = cid.split("@"); 18 | if (cidSplit.length <= 2) { 19 | return false; 20 | } 21 | return cidSplit[1].equals(tag); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/classloader/PluginsJarLoader.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.classloader; 2 | 3 | import java.io.IOException; 4 | import java.net.URL; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.jar.JarFile; 8 | 9 | public class PluginsJarLoader { 10 | 11 | public static List getJarFileList(List urlList) { 12 | List jarFileList = new ArrayList<>(); 13 | for (URL url : urlList) { 14 | //读取到所有plugin jar 15 | try { 16 | jarFileList.add(new JarFile(url.getPath())); 17 | } catch (IOException e) { 18 | throw new RuntimeException(e); 19 | } 20 | } 21 | return jarFileList; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-gateway-example/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8089 3 | spring: 4 | application: 5 | name: insight-gateway 6 | cloud: 7 | gateway: 8 | routes: 9 | - id: test1 10 | uri: lb://service-a 11 | predicates: 12 | - Path=/myClient 13 | discovery: 14 | locator: 15 | enabled: true 16 | nacos: 17 | discovery: 18 | server-addr: localhost:8848 19 | enabled: true 20 | username: nacos 21 | password: nacos 22 | # consul: 23 | # host: localhost 24 | # port: 8500 25 | # discovery: 26 | # heartbeat: 27 | # enabled: true 28 | logging: 29 | level: 30 | com.thalossphere: 31 | debug 32 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-api-example/src/main/java/com/thalossphere/spring/cloud/service/api/entity/TagEntity.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.service.api.entity; 2 | 3 | 4 | import com.thalossphere.common.tag.context.TagManager; 5 | import lombok.Data; 6 | 7 | @Data 8 | public class TagEntity { 9 | 10 | private String tag; 11 | 12 | private String systemTag; 13 | 14 | private String consumer; 15 | 16 | 17 | 18 | public static TagEntity build(String consumer) { 19 | TagEntity tagEntity = new TagEntity(); 20 | tagEntity.setTag(TagManager.getTag()); 21 | tagEntity.setSystemTag(TagManager.getSystemTag()); 22 | tagEntity.setConsumer(consumer); 23 | return tagEntity; 24 | } 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-removal/src/main/java/com/thalossphere/feature/removal/ServiceNodeCache.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.removal; 2 | 3 | import java.util.Map; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | 6 | public class ServiceNodeCache { 7 | 8 | private static final Map INSTANCE_CALL_RESULT = new ConcurrentHashMap<>(); 9 | 10 | public static void saveInstanceCallResult(String key, ServiceNode instantInfo) { 11 | INSTANCE_CALL_RESULT.put(key, instantInfo); 12 | 13 | } 14 | 15 | public static Map getInstanceCallResult() { 16 | return INSTANCE_CALL_RESULT; 17 | } 18 | 19 | public static ServiceNode getInstance(String key) { 20 | return INSTANCE_CALL_RESULT.get(key); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/classloader/AgentClassLoaderManager.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.classloader; 2 | 3 | 4 | import com.thalossphere.agent.core.utils.URLUtils; 5 | 6 | import java.net.URL; 7 | import java.util.List; 8 | import java.util.jar.JarFile; 9 | 10 | public class AgentClassLoaderManager { 11 | 12 | public static AgentClassLoader getAgentPluginClassLoader(ClassLoader classLoader) { 13 | List jarFileList = getJarFileList(); 14 | return new AgentClassLoader(classLoader, jarFileList); 15 | } 16 | 17 | public static List getJarFileList() { 18 | List urlList = URLUtils.getPluginURL(); 19 | List jarFileList = PluginsJarLoader.getJarFileList(urlList); 20 | return jarFileList; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/tag/context/TagManager.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.tag.context; 2 | 3 | import com.thalossphere.common.utils.StringUtils; 4 | import lombok.extern.slf4j.Slf4j; 5 | 6 | import static com.thalossphere.common.constant.CommonConstant.SERVER_TAG; 7 | 8 | @Slf4j 9 | public class TagManager { 10 | 11 | public static String getTag() { 12 | String tag = TagContext.get(); 13 | if (StringUtils.isNotEmpty(tag)) { 14 | return tag; 15 | } 16 | if (log.isDebugEnabled()) { 17 | log.debug("[thalossphere] tag context is null"); 18 | } 19 | return System.getProperty(SERVER_TAG); 20 | } 21 | 22 | public static String getSystemTag() { 23 | return System.getProperty(SERVER_TAG); 24 | } 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/matcher/MultiThreadMethodMatch.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.matcher; 2 | 3 | import net.bytebuddy.description.NamedElement; 4 | import net.bytebuddy.matcher.ElementMatcher; 5 | 6 | public class MultiThreadMethodMatch extends ElementMatcher.Junction.AbstractBase { 7 | 8 | private static final String RUNNABLE_METHOD_NAME = "run"; 9 | 10 | private static final String CALLABLE_METHOD_NAME = "call"; 11 | 12 | @Override 13 | public boolean matches(T target) { 14 | NamedElement namedElement = (NamedElement) target; 15 | if (namedElement.getActualName().equals(RUNNABLE_METHOD_NAME) || namedElement.getActualName().equals(CALLABLE_METHOD_NAME)) { 16 | return true; 17 | } 18 | return false; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/utils/MethodTypeUtils.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.utils; 2 | 3 | import net.bytebuddy.description.method.MethodDescription; 4 | 5 | public class MethodTypeUtils { 6 | 7 | public static boolean isConstructorMethod(final MethodDescription.InDefinedShape methodDescription) { 8 | return methodDescription.isConstructor(); 9 | } 10 | 11 | public static boolean isStaticMethod(final MethodDescription.InDefinedShape methodDescription) { 12 | return methodDescription.isStatic() && isInstantMethod(methodDescription); 13 | } 14 | 15 | public static boolean isInstantMethod(final MethodDescription.InDefinedShape methodDescription) { 16 | return !(methodDescription.isAbstract() || methodDescription.isSynthetic()); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-zuul-example/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 5555 3 | spring: 4 | application: 5 | name: zuul-server 6 | cloud: 7 | # zookeeper: 8 | # connect-string: 127.0.0.1:2181 9 | nacos: 10 | discovery: 11 | server-addr: localhost:8848 12 | enabled: true 13 | username: nacos 14 | password: nacos 15 | # consul: 16 | # host: localhost 17 | # port: 8500 18 | # discovery: 19 | # heartbeat: 20 | # enabled: true 21 | 22 | #eureka: 23 | # client: 24 | # service-url: 25 | # defaultZone: http://${eureka.host:127.0.0.1}:${eureka.port:8189}/eureka/ 26 | # instance: 27 | # prefer-ip-address: true 28 | zuul: 29 | routes: 30 | path: /helloWord 31 | serviceId: service-a -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-rocketmq4/src/main/java/com/thalossphere/agent/plugin/rocketmq/utils/MessageQueueThreadLocalUtils.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.rocketmq.utils; 2 | 3 | import org.apache.rocketmq.common.message.MessageQueue; 4 | 5 | import java.util.List; 6 | 7 | public class MessageQueueThreadLocalUtils { 8 | 9 | private static final ThreadLocal> QUEUE_LIST = new ThreadLocal>(); 10 | 11 | 12 | public static void set(List queueList) { 13 | QUEUE_LIST.set(queueList); 14 | } 15 | 16 | public static void remove() { 17 | if (QUEUE_LIST.get() != null) { 18 | QUEUE_LIST.remove(); 19 | } 20 | } 21 | 22 | public static List get() { 23 | return QUEUE_LIST.get(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/interceptor/type/StaticMethodInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.interceptor.type; 2 | 3 | import com.thalossphere.agent.core.interceptor.MethodInterceptor; 4 | import com.thalossphere.agent.core.interceptor.template.InstantMethodInterceptorResult; 5 | 6 | import java.lang.reflect.Method; 7 | import java.util.concurrent.Callable; 8 | 9 | public interface StaticMethodInterceptor extends MethodInterceptor { 10 | 11 | void beforeMethod(Class clazz, Method method, Object[] args, Callable callable, InstantMethodInterceptorResult instantMethodInterceptorResult); 12 | 13 | void afterMethod(Class clazz, Method method, Object[] args, Object result); 14 | 15 | void exceptionMethod(Class clazz, Method method, Object[] args, Throwable throwable); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/config/PointcutConfigLoader.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.config; 2 | 3 | import com.thalossphere.agent.core.config.yaml.YamlClassPointcutConfig; 4 | import com.thalossphere.agent.core.config.yaml.YamlPointcutConfig; 5 | import com.thalossphere.agent.core.yaml.YamlResolver; 6 | 7 | import java.io.InputStream; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import java.util.Optional; 11 | 12 | public class PointcutConfigLoader { 13 | 14 | public static List load(String pluginName, ClassLoader classLoader) { 15 | return Optional.ofNullable(YamlResolver.parsePointcutConfig(pluginName, classLoader)) 16 | .map(YamlPointcutConfig::getPointcutConfigs) 17 | .orElse(new ArrayList<>()); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-b1-example/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8083 3 | spring: 4 | application: 5 | name: service-b 6 | cloud: 7 | # consul: 8 | # host: localhost 9 | # port: 8500 10 | # discovery: 11 | # heartbeat: 12 | # enabled: true 13 | nacos: 14 | config: 15 | file-extension: yaml 16 | server-addr: localhost:8848 17 | # zookeeper: 18 | # connect-string: 127.0.0.1:2181 19 | #eureka: 20 | # client: 21 | # service-url: 22 | # defaultZone: http://${eureka.host:127.0.0.1}:${eureka.port:8189}/eureka/ 23 | # nacos: 24 | discovery: 25 | server-addr: localhost:8848 26 | enabled: true 27 | username: nacos 28 | password: nacos 29 | thalossphere: 30 | instantInitEnabled: true -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-c-example/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8086 3 | spring: 4 | application: 5 | name: service-c 6 | cloud: 7 | # consul: 8 | # host: localhost 9 | # port: 8500 10 | # discovery: 11 | # heartbeat: 12 | # enabled: true 13 | nacos: 14 | config: 15 | file-extension: yaml 16 | server-addr: localhost:8848 17 | # zookeeper: 18 | # connect-string: 127.0.0.1:2181 19 | #eureka: 20 | # client: 21 | # service-url: 22 | # defaultZone: http://${eureka.host:127.0.0.1}:${eureka.port:8189}/eureka/ 23 | # nacos: 24 | discovery: 25 | server-addr: localhost:8848 26 | enabled: true 27 | username: nacos 28 | password: nacos 29 | thalossphere: 30 | instantInitEnabled: true -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-c1-example/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8085 3 | spring: 4 | application: 5 | name: service-c 6 | cloud: 7 | # consul: 8 | # host: localhost 9 | # port: 8500 10 | # discovery: 11 | # heartbeat: 12 | # enabled: true 13 | nacos: 14 | config: 15 | file-extension: yaml 16 | server-addr: localhost:8848 17 | # zookeeper: 18 | # connect-string: 127.0.0.1:2181 19 | #eureka: 20 | # client: 21 | # service-url: 22 | # defaultZone: http://${eureka.host:127.0.0.1}:${eureka.port:8189}/eureka/ 23 | # nacos: 24 | discovery: 25 | server-addr: localhost:8848 26 | enabled: true 27 | username: nacos 28 | password: nacos 29 | thalossphere: 30 | instantInitEnabled: true -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-b-example/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8084 3 | spring: 4 | application: 5 | name: service-b 6 | cloud: 7 | # consul: 8 | # host: localhost 9 | # port: 8500 10 | # discovery: 11 | # heartbeat: 12 | # enabled: true 13 | nacos: 14 | config: 15 | file-extension: yaml 16 | server-addr: localhost:8848 17 | discovery: 18 | server-addr: localhost:8848 19 | enabled: true 20 | username: nacos 21 | password: nacos 22 | # zookeeper: 23 | # connect-string: 127.0.0.1:2181 24 | #eureka: 25 | # client: 26 | # service-url: 27 | # defaultZone: http://${eureka.host:127.0.0.1}:${eureka.port:8189}/eureka/ 28 | # nacos: 29 | 30 | thalossphere: 31 | instantInitEnabled: true -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/java/com/thalossphere/extension/datasource/entity/RocketMQConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.extension.datasource.entity; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | @Data 8 | public class RocketMQConfig { 9 | 10 | private List consumerConfigList; 11 | 12 | private List producerConfigList; 13 | 14 | 15 | @Data 16 | public static class ConsumerConfig { 17 | 18 | private String consumerGroupName; 19 | 20 | private String tag; 21 | 22 | private List queueIdList; 23 | 24 | } 25 | 26 | @Data 27 | public static class ProducerConfig { 28 | 29 | private String topic; 30 | 31 | private String tag; 32 | 33 | private List queueIdList; 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-register-center/src/main/java/com/thalossphere/register/center/init/RegisterCenterInit.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.register.center.init; 2 | 3 | import com.thalossphere.common.config.YamlAgentConfig; 4 | import com.thalossphere.common.eventbus.EventBusManager; 5 | import com.thalossphere.common.init.CoreInit; 6 | import com.thalossphere.register.center.listener.RefreshServerListListener; 7 | 8 | import java.lang.instrument.Instrumentation; 9 | 10 | public class RegisterCenterInit implements CoreInit { 11 | 12 | @Override 13 | public void init(YamlAgentConfig yamlAgentConfig, ClassLoader classLoader, Instrumentation inst) { 14 | EventBusManager.getInstance().register(new RefreshServerListListener()); 15 | } 16 | 17 | @Override 18 | public int getOrder() { 19 | return 99; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-c-example/src/main/java/com/thalossphere/spring/cloud/service/provider/example/config/RocketMQConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.service.provider.example.config; 2 | 3 | 4 | import org.apache.rocketmq.client.exception.MQClientException; 5 | import org.apache.rocketmq.client.producer.DefaultMQProducer; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | @Configuration 10 | public class RocketMQConfig { 11 | 12 | @Bean 13 | public DefaultMQProducer producer() throws MQClientException { 14 | DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName"); 15 | producer.setNamesrvAddr("127.0.0.1:9876"); 16 | producer.start(); 17 | return producer; 18 | } 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-c1-example/src/main/java/com/thalossphere/spring/cloud/service/provider/example/config/RocketMQConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.service.provider.example.config; 2 | 3 | 4 | import org.apache.rocketmq.client.exception.MQClientException; 5 | import org.apache.rocketmq.client.producer.DefaultMQProducer; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | @Configuration 10 | public class RocketMQConfig { 11 | 12 | @Bean 13 | public DefaultMQProducer producer() throws MQClientException { 14 | DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName"); 15 | producer.setNamesrvAddr("127.0.0.1:9876"); 16 | producer.start(); 17 | return producer; 18 | } 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-sentinel/src/main/java/com/thalossphere/feature/sentinel/datasource/SentinelDataSourceRuleLoaderManager.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.sentinel.datasource; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class SentinelDataSourceRuleLoaderManager { 7 | 8 | private static final Map SENTINEL_RULE_LOADER_MAP = new HashMap<>(); 9 | 10 | static { 11 | SENTINEL_RULE_LOADER_MAP.put(SentinelConfigDataSourceTypeEnum.NACOS.getType(), new SentinelNacosDataSourceRuleLoader()); 12 | SENTINEL_RULE_LOADER_MAP.put(SentinelConfigDataSourceTypeEnum.APOLLO.getType(), new SentinelApolloDataSourceRuleLoader()); 13 | ; } 14 | 15 | public static SentinelDataSourceRuleLoader getLoader(String key) { 16 | return SENTINEL_RULE_LOADER_MAP.get(key); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /thalossphere-distribution/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | io.github.thalossphere-projects 7 | thalossphere 8 | 1.5.0.RELEASE 9 | 10 | 11 | pom 12 | thalossphere-distribution 13 | thalossphere-distribution 14 | thalossphere-distribution 15 | 16 | 17 | thalossphere-agent-distribution 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-api-example/src/main/java/com/thalossphere/spring/cloud/service/api/SpringCloudCApi.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.service.api; 2 | 3 | import com.thalossphere.spring.cloud.service.api.entity.TagEntity; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.web.bind.annotation.PostMapping; 7 | import org.springframework.web.bind.annotation.RequestBody; 8 | 9 | import java.util.List; 10 | 11 | @FeignClient(name = "service-c") 12 | public interface SpringCloudCApi { 13 | 14 | @PostMapping(value = "/service-c/helloWord",produces = MediaType.APPLICATION_JSON_VALUE) 15 | TagEntity helloWord(@RequestBody String str); 16 | 17 | @PostMapping("/service-c/tagSpread") 18 | void tagSpread(@RequestBody List tagList); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-springcloudgateway/src/main/java/com/thalossphere/agent/plugin/spring/cloud/gateway/SimpleGatewayParamParser.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.spring.cloud.gateway; 2 | 3 | import com.alibaba.csp.sentinel.adapter.gateway.common.param.GatewayParamParser; 4 | import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule; 5 | import com.alibaba.csp.sentinel.adapter.gateway.sc.ServerWebExchangeItemParser; 6 | import com.alibaba.csp.sentinel.util.function.Predicate; 7 | import org.springframework.web.server.ServerWebExchange; 8 | 9 | public class SimpleGatewayParamParser { 10 | 11 | public static Object[] parseParameterFor(String resource, ServerWebExchange request, Predicate rulePredicate) { 12 | return new GatewayParamParser<>(new ServerWebExchangeItemParser()).parseParameterFor(resource, request, rulePredicate); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /thalossphere-test/src/main/java/com/thalossphere/test/config/PointcutConfigLoaderTest.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.test.config; 2 | 3 | import com.thalossphere.agent.core.config.PointcutConfigLoader; 4 | import com.thalossphere.agent.core.config.yaml.YamlClassPointcutConfig; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.io.FileNotFoundException; 8 | import java.util.List; 9 | 10 | import static org.junit.jupiter.api.Assertions.assertNotNull; 11 | import static org.junit.jupiter.api.Assertions.assertTrue; 12 | 13 | public class PointcutConfigLoaderTest { 14 | 15 | @Test 16 | public void loadTest() throws FileNotFoundException { 17 | List classPointcutConfigs = PointcutConfigLoader.load("example", PointcutConfigLoaderTest.class.getClassLoader()); 18 | assertNotNull(classPointcutConfigs); 19 | assertTrue(classPointcutConfigs.size() > 0); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-api-example/src/main/java/com/thalossphere/spring/cloud/service/api/SpringCloudBApi.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.spring.cloud.service.api; 2 | 3 | import com.thalossphere.spring.cloud.service.api.entity.TagEntity; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | import org.springframework.web.bind.annotation.PostMapping; 6 | import org.springframework.web.bind.annotation.RequestBody; 7 | 8 | import java.util.List; 9 | 10 | @FeignClient(name = "service-b") 11 | public interface SpringCloudBApi { 12 | 13 | @PostMapping("/service-b/helloWord") 14 | List helloWord(@RequestBody String str); 15 | 16 | @PostMapping("/service-b/repeat") 17 | List repeat(@RequestBody String str); 18 | 19 | @PostMapping("/service-b/tagSpread") 20 | void tagSpread(@RequestBody List tagList); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-discovery-binder/src/main/java/com/thalossphere/feature/discovery/binder/ConsumerInterfaceUrlManager.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.discovery.binder; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | public class ConsumerInterfaceUrlManager { 9 | 10 | private static final Map> INTERFACE = new HashMap<>(); 11 | 12 | public static void addInterfaceUrl(String serviceName, String url) { 13 | List urlList = INTERFACE.getOrDefault(serviceName, new ArrayList<>()); 14 | urlList.add(url); 15 | INTERFACE.put(serviceName, urlList); 16 | } 17 | 18 | public static Map> getInterfaceUrlList() { 19 | return INTERFACE; 20 | } 21 | 22 | public static void clear() { 23 | INTERFACE.clear(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-springcloudgateway/src/main/java/com/thalossphere/agent/plugin/spring/cloud/gateway/propagator/GatewayPropagator.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.spring.cloud.gateway.propagator; 2 | 3 | import com.thalossphere.common.constant.CommonConstant; 4 | import com.thalossphere.common.propagator.AbstractGatewayPropagator; 5 | import org.springframework.http.server.reactive.ServerHttpRequest; 6 | 7 | public class GatewayPropagator extends AbstractGatewayPropagator { 8 | 9 | private final ServerHttpRequest request; 10 | 11 | 12 | public GatewayPropagator(ServerHttpRequest request) { 13 | this.request = request; 14 | } 15 | 16 | 17 | @Override 18 | public void doInject(String tag) { 19 | ServerHttpRequest.Builder requsetBuilder = request.mutate(); 20 | requsetBuilder.headers(headers -> headers.add(CommonConstant.TAG, tag)); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/interceptor/MultiThreadConstructorInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.interceptor; 2 | 3 | import com.thalossphere.agent.core.context.CustomContext; 4 | import com.thalossphere.agent.core.context.CustomContextAccessor; 5 | import com.thalossphere.common.tag.context.TagContext; 6 | import net.bytebuddy.implementation.bind.annotation.AllArguments; 7 | import net.bytebuddy.implementation.bind.annotation.RuntimeType; 8 | import net.bytebuddy.implementation.bind.annotation.This; 9 | 10 | public class MultiThreadConstructorInterceptor { 11 | 12 | @RuntimeType 13 | public void constructorMethodIntercept(@This Object obj, @AllArguments Object[] allArguments) { 14 | CustomContextAccessor customContextAccessor = (CustomContextAccessor) obj; 15 | customContextAccessor.setCustomContext(new CustomContext(TagContext.get())); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/utils/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.utils; 2 | 3 | public class StringUtils { 4 | 5 | public static boolean isEmpty(CharSequence cs) { 6 | return cs == null || cs.length() == 0; 7 | } 8 | 9 | public static boolean isNotEmpty(CharSequence cs) { 10 | return !isEmpty(cs); 11 | } 12 | 13 | public static String convertToPropertyName(String fieldName) { 14 | StringBuilder sb = new StringBuilder(); 15 | for (char c : fieldName.toCharArray()) { 16 | if (Character.isUpperCase(c)) { 17 | sb.append("-").append(Character.toLowerCase(c)); 18 | } else { 19 | sb.append(c); 20 | } 21 | } 22 | return sb.toString(); 23 | } 24 | 25 | public static void main(String[] args) { 26 | System.out.println(convertToPropertyName("eureka.client.service-url.defaultZone")); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-zuul/src/main/java/com/thalossphere/agent/plugin/zuul/propagator/ZuulPropagator.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.zuul.propagator; 2 | 3 | import com.thalossphere.common.constant.CommonConstant; 4 | import com.thalossphere.common.propagator.AbstractGatewayPropagator; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext; 7 | 8 | @Slf4j 9 | public class ZuulPropagator extends AbstractGatewayPropagator { 10 | 11 | private final RibbonCommandContext commandContext; 12 | 13 | public ZuulPropagator(RibbonCommandContext commandContext) { 14 | this.commandContext = commandContext; 15 | } 16 | 17 | @Override 18 | public void doInject(String tag) { 19 | if (log.isDebugEnabled()) { 20 | log.debug("[thalossphere] zuul doInject tag={}", tag); 21 | } 22 | commandContext.getHeaders().add(CommonConstant.TAG, tag); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/request/AbstractRequestResolver.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.request; 2 | 3 | import java.util.Map; 4 | 5 | public abstract class AbstractRequestResolver implements RequestResolver { 6 | 7 | private final HttpRequest httpRequest; 8 | 9 | public AbstractRequestResolver(HttpRequest httpRequest) { 10 | this.httpRequest = httpRequest; 11 | } 12 | 13 | @Override 14 | public String getHeader(String key) { 15 | Map headers = httpRequest.getHeaders(); 16 | return headers.get(key); 17 | } 18 | 19 | @Override 20 | public String getCookie(String key) { 21 | Map cookies = httpRequest.getCookies(); 22 | return cookies.get(key); 23 | } 24 | 25 | @Override 26 | public String getParameters(String key) { 27 | Map parameters = httpRequest.getParameters(); 28 | return parameters.get(key); 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-springcloudgateway/src/main/resources/springcloudgateway-agent.yaml: -------------------------------------------------------------------------------- 1 | pointcutConfigs: 2 | - className: org.springframework.cloud.gateway.filter.LoadBalancerClientFilter 3 | methodPointcutConfigs: 4 | - methodName: filter 5 | type: instant 6 | interceptorName: com.thalossphere.agent.plugin.spring.cloud.gateway.LoadBalancerClientFilterInterceptor 7 | - className: org.springframework.cloud.gateway.filter.AdaptCachedBodyGlobalFilter 8 | methodPointcutConfigs: 9 | - methodName: filter 10 | type: instant 11 | interceptorName: com.thalossphere.agent.plugin.spring.cloud.gateway.AdaptCachedBodyGlobalFilterInterceptor 12 | - className: org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler 13 | methodPointcutConfigs: 14 | - methodName: handle 15 | type: instant 16 | interceptorName: com.thalossphere.agent.plugin.spring.cloud.gateway.AbstractErrorWebExceptionHandlerInterceptor -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/propagator/AbstractGatewayPropagator.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.propagator; 2 | 3 | import com.thalossphere.common.loadbalance.InstantWeight; 4 | import com.thalossphere.common.request.AbstractAttributeResolver; 5 | import com.thalossphere.common.tag.extract.TagExtractManager; 6 | import lombok.extern.slf4j.Slf4j; 7 | 8 | import java.util.Objects; 9 | 10 | @Slf4j 11 | public abstract class AbstractGatewayPropagator implements GatewayPropagator { 12 | 13 | @Override 14 | public void inject(InstantWeight instantWeight, AbstractAttributeResolver attributeResolver) { 15 | if (Objects.isNull(instantWeight)) { 16 | return; 17 | } 18 | String tag = TagExtractManager.extract(instantWeight, attributeResolver); 19 | if (log.isDebugEnabled()) { 20 | log.debug("[thalossphere] extract tag={}", tag); 21 | } 22 | doInject(tag); 23 | } 24 | 25 | public abstract void doInject(String tag); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/tag/extract/ClientDefaultTagExtract.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.tag.extract; 2 | 3 | import com.thalossphere.common.loadbalance.InstantWeight; 4 | import com.thalossphere.common.request.AbstractAttributeResolver; 5 | import com.thalossphere.common.request.AttributeResolver; 6 | import com.thalossphere.common.request.RequestResolver; 7 | import com.thalossphere.common.tag.context.TagContext; 8 | import com.thalossphere.common.utils.StringUtils; 9 | 10 | public class ClientDefaultTagExtract implements TagExtract { 11 | 12 | 13 | @Override 14 | public String extract(InstantWeight instantWeight, AbstractAttributeResolver attributeResolver) { 15 | TagContext.set(attributeResolver.getTag()); 16 | return attributeResolver.getTag(); 17 | } 18 | 19 | @Override 20 | public boolean match(InstantWeight instantWeight, AbstractAttributeResolver attributeResolver) { 21 | return StringUtils.isNotEmpty(attributeResolver.getTag()); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-sentinel/src/main/java/com/thalossphere/feature/sentinel/limiter/EntryContext.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.sentinel.limiter; 2 | 3 | import com.alibaba.csp.sentinel.Entry; 4 | 5 | import java.util.LinkedList; 6 | import java.util.List; 7 | 8 | public class EntryContext { 9 | 10 | private static ThreadLocal> ENTRY_CONTEXT = new ThreadLocal>() { 11 | 12 | @Override 13 | protected LinkedList initialValue() { 14 | return new LinkedList<>(); 15 | } 16 | 17 | }; 18 | 19 | public static void add(Entry entry) { 20 | ENTRY_CONTEXT.get().addFirst(entry); 21 | } 22 | 23 | public static List get() { 24 | return ENTRY_CONTEXT.get(); 25 | } 26 | 27 | public static void clear() { 28 | exit(); 29 | ENTRY_CONTEXT.remove(); 30 | } 31 | 32 | public static void exit() { 33 | for (Entry entry : get()) { 34 | entry.exit(); 35 | } 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/tag/extract/TagExtractManager.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.tag.extract; 2 | 3 | import com.thalossphere.common.loadbalance.InstantWeight; 4 | import com.thalossphere.common.request.AbstractAttributeResolver; 5 | 6 | import java.util.LinkedList; 7 | import java.util.List; 8 | 9 | public class TagExtractManager { 10 | 11 | private static final List TAG_SELECTOR_LIST = new LinkedList<>(); 12 | 13 | static { 14 | TAG_SELECTOR_LIST.add(new ClientDefaultTagExtract()); 15 | TAG_SELECTOR_LIST.add(new RegionTagExtract()); 16 | TAG_SELECTOR_LIST.add(new UserIdTagExtract()); 17 | } 18 | 19 | public static String extract(InstantWeight instantWeight, AbstractAttributeResolver attributeResolver) { 20 | for (TagExtract selector : TAG_SELECTOR_LIST) { 21 | if (selector.match(instantWeight, attributeResolver)) { 22 | return selector.extract(instantWeight, attributeResolver); 23 | } 24 | } 25 | return null; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /thalossphere-features/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | io.github.thalossphere-projects 7 | thalossphere 8 | 1.5.0.RELEASE 9 | 10 | thalossphere-features 11 | thalossphere-features 12 | thalossphere-features 13 | pom 14 | 15 | 8 16 | 17 | 18 | 19 | thalossphere-feature-discovery-binder 20 | thalossphere-feature-removal 21 | thalossphere-feature-sentinel 22 | thalossphere-feature-register-center 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-consul/src/main/java/com/thalossphere/agent/plugin/consul/ConsulServerPredicate.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.consul; 2 | 3 | import com.thalossphere.common.constant.CommonConstant; 4 | import com.thalossphere.common.tag.context.TagContext; 5 | import com.google.common.base.Strings; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.cloud.consul.discovery.ConsulServer; 8 | 9 | import java.util.function.Predicate; 10 | 11 | @Slf4j 12 | public class ConsulServerPredicate implements Predicate { 13 | 14 | @Override 15 | public boolean test(ConsulServer consulServer) { 16 | String serverTag = consulServer.getMetadata().get(CommonConstant.SERVER_TAG); 17 | String tag = TagContext.get(); 18 | if (log.isDebugEnabled()) { 19 | log.debug("[thalossphere] consul predicate tag={}", tag); 20 | } 21 | if (!Strings.isNullOrEmpty(tag) && !tag.equals(serverTag) && !Strings.isNullOrEmpty(serverTag)) { 22 | return false; 23 | } 24 | return true; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/java/com/thalossphere/extension/datasource/support/apollo/ApolloConfigListener.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.extension.datasource.support.apollo; 2 | 3 | import com.ctrip.framework.apollo.ConfigChangeListener; 4 | import com.ctrip.framework.apollo.model.ConfigChange; 5 | import com.ctrip.framework.apollo.model.ConfigChangeEvent; 6 | import com.thalossphere.common.utils.JacksonUtils; 7 | import com.thalossphere.extension.datasource.cache.PluginConfigCache; 8 | import com.thalossphere.extension.datasource.entity.PluginConfig; 9 | 10 | import static com.thalossphere.extension.datasource.support.apollo.ApolloConfigConstant.FLOW_SPHERE_CONFIG_JSON; 11 | 12 | public class ApolloConfigListener implements ConfigChangeListener { 13 | 14 | @Override 15 | public void onChange(ConfigChangeEvent changeEvent) { 16 | ConfigChange configChange = changeEvent.getChange(FLOW_SPHERE_CONFIG_JSON); 17 | PluginConfig pluginConfig = JacksonUtils.toObj(configChange.getNewValue(), PluginConfig.class); 18 | PluginConfigCache.put(pluginConfig); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-consul/src/main/java/com/thalossphere/agent/plugin/consul/ConsulSelector.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.consul; 2 | 3 | import com.thalossphere.register.center.selector.InstanceSelector; 4 | import com.netflix.loadbalancer.Server; 5 | import org.springframework.cloud.consul.discovery.ConsulServer; 6 | 7 | import java.util.Map; 8 | 9 | public class ConsulSelector extends InstanceSelector { 10 | 11 | private static final ConsulSelector INSTANCE = new ConsulSelector(); 12 | 13 | public static ConsulSelector getInstance() { 14 | return INSTANCE; 15 | } 16 | 17 | @Override 18 | public Map getMetadata(Server server) { 19 | if (server instanceof ConsulServer) { 20 | ConsulServer consulServer = (ConsulServer) server; 21 | return consulServer.getMetadata(); 22 | } 23 | return null; 24 | } 25 | 26 | @Override 27 | public boolean isValidServer(Server server) { 28 | return server instanceof ConsulServer && new ConsulServerPredicate().test((ConsulServer) server); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-nacos/src/main/java/com/thalossphere/agent/plugin/nacos/NacosServerPredicate.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.nacos; 2 | 3 | import com.alibaba.cloud.nacos.ribbon.NacosServer; 4 | import com.thalossphere.common.constant.CommonConstant; 5 | import com.thalossphere.common.tag.context.TagContext; 6 | import com.google.common.base.Strings; 7 | import lombok.extern.slf4j.Slf4j; 8 | 9 | import java.util.function.Predicate; 10 | 11 | @Slf4j 12 | public class NacosServerPredicate implements Predicate { 13 | 14 | @Override 15 | public boolean test(NacosServer nacosServer) { 16 | String serverTag = nacosServer.getInstance().getMetadata().get(CommonConstant.SERVER_TAG); 17 | String tag = TagContext.get(); 18 | if (log.isDebugEnabled()) { 19 | log.debug("[thalossphere] nacos predicate tag={} serverTag={}", tag, serverTag); 20 | } 21 | if (!Strings.isNullOrEmpty(tag) && !tag.equals(serverTag) && !Strings.isNullOrEmpty(serverTag)) { 22 | return false; 23 | } 24 | 25 | return true; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/java/com/thalossphere/extension/datasource/init/DataSourceInit.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.extension.datasource.init; 2 | 3 | import com.thalossphere.common.config.YamlAgentConfig; 4 | import com.thalossphere.common.init.CoreInit; 5 | import com.thalossphere.extension.datasource.cache.PluginConfigCache; 6 | import com.thalossphere.extension.datasource.entity.PluginConfig; 7 | import com.thalossphere.extension.datasource.loader.PluginConfigLoaderManager; 8 | 9 | import java.lang.instrument.Instrumentation; 10 | 11 | public class DataSourceInit implements CoreInit { 12 | 13 | @Override 14 | public void init(YamlAgentConfig yamlAgentConfig, ClassLoader classLoader, Instrumentation inst) { 15 | PluginConfig pluginConfig = PluginConfigLoaderManager.getPluginConfigLoader(yamlAgentConfig.getPluginConfigDataSource().getType()) 16 | .load(classLoader, yamlAgentConfig.getPluginConfigDataSource().getPros()); 17 | PluginConfigCache.put(pluginConfig); 18 | } 19 | 20 | @Override 21 | public int getOrder() { 22 | return 1; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-nacos/src/main/java/com/thalossphere/agent/plugin/nacos/NacosSelector.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.nacos; 2 | 3 | import com.alibaba.cloud.nacos.ribbon.NacosServer; 4 | import com.thalossphere.register.center.selector.InstanceSelector; 5 | import com.netflix.loadbalancer.Server; 6 | import lombok.extern.slf4j.Slf4j; 7 | 8 | import java.util.Map; 9 | 10 | @Slf4j 11 | public class NacosSelector extends InstanceSelector { 12 | 13 | private static final NacosSelector INSTANCE = new NacosSelector(); 14 | 15 | public static NacosSelector getInstance() { 16 | return INSTANCE; 17 | } 18 | 19 | 20 | @Override 21 | public Map getMetadata(Server server) { 22 | if (server instanceof NacosServer) { 23 | NacosServer nacosServer = (NacosServer) server; 24 | return nacosServer.getMetadata(); 25 | } 26 | return null; 27 | } 28 | 29 | @Override 30 | public boolean isValidServer(Server server) { 31 | return server instanceof NacosServer && new NacosServerPredicate().test((NacosServer) server); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-removal/src/main/java/com/thalossphere/feature/removal/ServiceNode.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.removal; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.concurrent.atomic.AtomicBoolean; 6 | import java.util.concurrent.atomic.AtomicInteger; 7 | 8 | @Data 9 | public class ServiceNode { 10 | 11 | /** 12 | * 请求数 13 | */ 14 | private AtomicInteger requestNum = new AtomicInteger(0); 15 | 16 | /** 17 | * 失败请求数 18 | */ 19 | private AtomicInteger requestFailNum = new AtomicInteger(0); 20 | 21 | /** 22 | * 隔离状态 23 | */ 24 | private AtomicBoolean removalStatus = new AtomicBoolean(false); 25 | 26 | /** 27 | * 隔离时间 28 | */ 29 | private long removalTime; 30 | 31 | /** 32 | * 恢复时间 33 | */ 34 | private long recoveryTime; 35 | 36 | /** 37 | * ip地址 38 | */ 39 | private String ip; 40 | 41 | /** 42 | * 端口 43 | */ 44 | private int port; 45 | 46 | /** 47 | * 最后调用时间 48 | */ 49 | private long lastInvokeTime; 50 | 51 | /** 52 | * 错误率 53 | */ 54 | private double errorRate; 55 | 56 | } 57 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-fegin/src/main/resources/feign-agent.yaml: -------------------------------------------------------------------------------- 1 | pointcutConfigs: 2 | - className: org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient 3 | methodPointcutConfigs: 4 | - methodName: execute 5 | type: instant 6 | interceptorName: com.thalossphere.agent.plugin.feign.LoadBalancerFeignClientInterceptor 7 | - className: org.springframework.cloud.openfeign.support.SpringMvcContract 8 | methodPointcutConfigs: 9 | - methodName: parseAndValidateMetadata 10 | type: instant 11 | interceptorName: com.thalossphere.agent.plugin.feign.SpringMvcContractInterceptor 12 | - className: org.springframework.cloud.openfeign.ribbon.FeignLoadBalancer 13 | methodPointcutConfigs: 14 | - methodName: execute 15 | type: instant 16 | interceptorName: com.thalossphere.agent.plugin.feign.FeignLoadBalancerInterceptor 17 | - className: com.netflix.loadbalancer.DynamicServerListLoadBalancer 18 | methodPointcutConfigs: 19 | - methodName: updateListOfServers 20 | type: instant 21 | interceptorName: com.thalossphere.agent.plugin.feign.DynamicServerListLoadBalancerInterceptor -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-rocketmq4/src/main/resources/rocketmq4-agent.yaml: -------------------------------------------------------------------------------- 1 | pointcutConfigs: 2 | - className: org.apache.rocketmq.client.producer.DefaultMQProducer 3 | methodPointcutConfigs: 4 | - methodName: send 5 | type: instant 6 | interceptorName: com.thalossphere.agent.plugin.rocketmq.producer.DefaultMQProducerInterceptor 7 | - className: org.apache.rocketmq.client.latency.MQFaultStrategy 8 | methodPointcutConfigs: 9 | - methodName: selectOneMessageQueue 10 | type: instant 11 | interceptorName: com.thalossphere.agent.plugin.rocketmq.producer.MQFaultStrategyInterceptor 12 | - className: org.apache.rocketmq.client.ClientConfig 13 | methodPointcutConfigs: 14 | - methodName: getInstanceName 15 | type: instant 16 | interceptorName: com.thalossphere.agent.plugin.rocketmq.consumer.ClientConfigInterceptor 17 | - className: org.apache.rocketmq.client.consumer.DefaultMQPushConsumer 18 | methodPointcutConfigs: 19 | - methodName: getAllocateMessageQueueStrategy 20 | type: instant 21 | interceptorName: com.thalossphere.agent.plugin.rocketmq.consumer.DefaultMQPushConsumerInterceptor 22 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-a-example/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8082 3 | spring: 4 | datasource: 5 | driver-class-name: com.mysql.cj.jdbc.Driver 6 | url: jdbc:mysql://localhost:3306/thalossphere_example?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai 7 | username: root 8 | password: root 9 | jpa: 10 | database-platform: org.hibernate.dialect.MySQLDialect 11 | application: 12 | name: service-a 13 | cloud: 14 | # consul: 15 | # host: localhost 16 | # port: 8500 17 | # discovery: 18 | # heartbeat: 19 | # enabled: true 20 | nacos: 21 | config: 22 | file-extension: yaml 23 | server-addr: localhost:8848 24 | # zookeeper: 25 | # connect-string: 127.0.0.1:2181 26 | #eureka: 27 | # client: 28 | # service-url: 29 | # defaultZone: http://${eureka.host:127.0.0.1}:${eureka.port:8189}/eureka/ 30 | # nacos: 31 | discovery: 32 | server-addr: localhost:8848 33 | enabled: true 34 | username: nacos 35 | password: nacos 36 | 37 | thalossphere: 38 | instantInitEnabled: true -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-a1-example/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 3 | spring: 4 | datasource: 5 | driver-class-name: com.mysql.cj.jdbc.Driver 6 | url: jdbc:mysql://localhost:3306/thalossphere_example?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai 7 | username: root 8 | password: root 9 | jpa: 10 | database-platform: org.hibernate.dialect.MySQLDialect 11 | application: 12 | name: service-a 13 | cloud: 14 | # consul: 15 | # host: localhost 16 | # port: 8500 17 | # discovery: 18 | # heartbeat: 19 | # enabled: true 20 | nacos: 21 | config: 22 | file-extension: yaml 23 | server-addr: localhost:8848 24 | discovery: 25 | server-addr: localhost:8848 26 | enabled: true 27 | username: nacos 28 | password: nacos 29 | # zookeeper: 30 | # connect-string: 127.0.0.1:2181 31 | #eureka: 32 | # client: 33 | # service-url: 34 | # defaultZone: http://${eureka.host:127.0.0.1}:${eureka.port:8189}/eureka/ 35 | # nacos: 36 | thalossphere: 37 | instantInitEnabled: true 38 | 39 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-zookeeper/src/main/java/com/thalossphere/agent/plugin/zookeeper/ZookeeperServerPredicate.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.zookeeper; 2 | 3 | import com.thalossphere.common.constant.CommonConstant; 4 | import com.thalossphere.common.tag.context.TagContext; 5 | import com.google.common.base.Strings; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.cloud.zookeeper.discovery.ZookeeperServer; 8 | 9 | import java.util.function.Predicate; 10 | 11 | @Slf4j 12 | public class ZookeeperServerPredicate implements Predicate { 13 | 14 | @Override 15 | public boolean test(ZookeeperServer zookeeperServer) { 16 | String serverTag = zookeeperServer.getInstance().getPayload() 17 | .getMetadata().get(CommonConstant.SERVER_TAG); 18 | String tag = TagContext.get(); 19 | if (log.isDebugEnabled()) { 20 | log.debug("[thalossphere] zookeeper predicate zk tag={}", tag); 21 | } 22 | if (!Strings.isNullOrEmpty(tag) && !tag.equals(serverTag) && !Strings.isNullOrEmpty(serverTag)) { 23 | return false; 24 | } 25 | return true; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-eureka/src/main/java/com/thalossphere/agent/plugin/eureka/EurekaSelector.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.eureka; 2 | 3 | import com.thalossphere.register.center.selector.InstanceSelector; 4 | import com.netflix.loadbalancer.Server; 5 | import com.netflix.niws.loadbalancer.DiscoveryEnabledServer; 6 | 7 | import java.util.Map; 8 | 9 | public class EurekaSelector extends InstanceSelector { 10 | 11 | private static final EurekaSelector INSTANCE = new EurekaSelector(); 12 | 13 | public static EurekaSelector getInstance() { 14 | return INSTANCE; 15 | } 16 | 17 | @Override 18 | public Map getMetadata(Server server) { 19 | if (server instanceof DiscoveryEnabledServer) { 20 | DiscoveryEnabledServer discoveryEnabledServer = (DiscoveryEnabledServer) server; 21 | return discoveryEnabledServer.getInstanceInfo().getMetadata(); 22 | } 23 | return null; 24 | } 25 | 26 | @Override 27 | public boolean isValidServer(Server server) { 28 | return server instanceof DiscoveryEnabledServer && new EurekaServerPredicate().test((DiscoveryEnabledServer) server); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-rocketmq4/src/main/java/com/thalossphere/agent/plugin/rocketmq/consumer/DefaultMQPushConsumerInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.rocketmq.consumer; 2 | 3 | import com.thalossphere.agent.core.context.CustomContextAccessor; 4 | import com.thalossphere.agent.core.interceptor.template.InstantMethodInterceptorResult; 5 | import com.thalossphere.agent.core.interceptor.type.InstantMethodInterceptor; 6 | import com.thalossphere.common.utils.JacksonUtils; 7 | import lombok.extern.slf4j.Slf4j; 8 | 9 | import java.lang.reflect.Method; 10 | import java.util.concurrent.Callable; 11 | 12 | @Slf4j 13 | public class DefaultMQPushConsumerInterceptor implements InstantMethodInterceptor { 14 | 15 | @Override 16 | public void beforeMethod(CustomContextAccessor customContextAccessor, Object[] allArguments, Callable callable, Method method, InstantMethodInterceptorResult instantMethodInterceptorResult) { 17 | AllocateMessageQueueGray allocateMessageQueueGray = new AllocateMessageQueueGray(); 18 | instantMethodInterceptorResult.setContinue(false); 19 | instantMethodInterceptorResult.setResult(allocateMessageQueueGray); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-zookeeper/src/main/java/com/thalossphere/agent/plugin/zookeeper/ZookeeperSelector.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.zookeeper; 2 | 3 | import com.thalossphere.register.center.selector.InstanceSelector; 4 | import com.netflix.loadbalancer.Server; 5 | import org.springframework.cloud.zookeeper.discovery.ZookeeperServer; 6 | 7 | import java.util.Map; 8 | 9 | public class ZookeeperSelector extends InstanceSelector { 10 | 11 | private static final ZookeeperSelector INSTANCE = new ZookeeperSelector(); 12 | 13 | public static ZookeeperSelector getInstance() { 14 | return INSTANCE; 15 | } 16 | 17 | @Override 18 | public Map getMetadata(Server server) { 19 | if (server instanceof ZookeeperServer){ 20 | ZookeeperServer zookeeperServer = (ZookeeperServer) server; 21 | return zookeeperServer.getInstance().getPayload().getMetadata(); 22 | } 23 | return null; 24 | } 25 | 26 | @Override 27 | public boolean isValidServer(Server server) { 28 | return server instanceof ZookeeperServer && new ZookeeperServerPredicate().test((ZookeeperServer) server); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-sentinel/src/main/java/com/thalossphere/feature/sentinel/init/SentinelInit.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.sentinel.init; 2 | 3 | import com.thalossphere.common.config.YamlAgentConfig; 4 | import com.thalossphere.common.init.CoreInit; 5 | import com.thalossphere.extension.datasource.enums.PluginConfigDataSourceTypeEnum; 6 | import com.thalossphere.feature.sentinel.datasource.SentinelDataSourceRuleLoaderManager; 7 | 8 | import java.lang.instrument.Instrumentation; 9 | 10 | public class SentinelInit implements CoreInit { 11 | 12 | @Override 13 | public void init(YamlAgentConfig yamlAgentConfig, ClassLoader classLoader, Instrumentation inst) { 14 | if (!yamlAgentConfig.isSentinelEnabled() || PluginConfigDataSourceTypeEnum.LOCAL.getType() 15 | .equals(yamlAgentConfig.getPluginConfigDataSource().getType())) { 16 | return; 17 | } 18 | SentinelDataSourceRuleLoaderManager.getLoader(yamlAgentConfig.getPluginConfigDataSource().getType()) 19 | .load(yamlAgentConfig.getPluginConfigDataSource()); 20 | } 21 | 22 | @Override 23 | public int getOrder() { 24 | return 2; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /thalossphere-test/src/main/java/com/thalossphere/test/classloader/AgentClassLoaderTest.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.test.classloader; 2 | 3 | import com.thalossphere.agent.core.classloader.AgentClassLoader; 4 | import com.thalossphere.agent.core.classloader.PluginsJarLoader; 5 | import com.thalossphere.agent.core.utils.URLUtils; 6 | import com.thalossphere.test.interceptor.CustomInterceptor; 7 | import org.junit.jupiter.api.Test; 8 | 9 | import java.util.List; 10 | import java.util.jar.JarFile; 11 | 12 | import static org.junit.jupiter.api.Assertions.assertNotNull; 13 | 14 | 15 | public class AgentClassLoaderTest { 16 | 17 | 18 | @Test 19 | public void loadTest() throws ClassNotFoundException, InstantiationException, IllegalAccessException { 20 | List jarFileList = PluginsJarLoader.getJarFileList(URLUtils.getPluginURL()); 21 | AgentClassLoader classLoader = new AgentClassLoader(AgentClassLoaderTest.class.getClassLoader(), jarFileList); 22 | 23 | CustomInterceptor methodInterceptor = (CustomInterceptor) Class.forName("com.thalossphere.test.interceptor.CustomInterceptor", true, classLoader).newInstance(); 24 | assertNotNull(methodInterceptor); 25 | } 26 | 27 | 28 | } -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/java/com/thalossphere/extension/datasource/support/nacos/NacosConfigListener.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.extension.datasource.support.nacos; 2 | 3 | import com.alibaba.nacos.api.config.listener.Listener; 4 | import com.thalossphere.common.concurrent.NamedThreadFactory; 5 | import com.thalossphere.common.utils.JacksonUtils; 6 | import com.thalossphere.extension.datasource.cache.PluginConfigCache; 7 | import com.thalossphere.extension.datasource.entity.PluginConfig; 8 | 9 | import java.util.concurrent.*; 10 | 11 | public class NacosConfigListener implements Listener { 12 | 13 | private static final ExecutorService POOL = new ThreadPoolExecutor(1, 1, 0, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1), new NamedThreadFactory("thalossphere-nacos-ds-update", true), new ThreadPoolExecutor.DiscardOldestPolicy()); 14 | 15 | @Override 16 | public Executor getExecutor() { 17 | return POOL; 18 | } 19 | 20 | @Override 21 | public void receiveConfigInfo(String config) { 22 | PluginConfig pluginConfig = JacksonUtils.toObj(config, PluginConfig.class); 23 | PluginConfigCache.put(pluginConfig); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/AgentListener.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core; 2 | 3 | import net.bytebuddy.agent.builder.AgentBuilder; 4 | import net.bytebuddy.description.type.TypeDescription; 5 | import net.bytebuddy.dynamic.DynamicType; 6 | import net.bytebuddy.utility.JavaModule; 7 | 8 | public class AgentListener implements AgentBuilder.Listener { 9 | 10 | @Override 11 | public void onDiscovery(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded) { 12 | 13 | } 14 | 15 | @Override 16 | public void onTransformation(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, boolean loaded, DynamicType dynamicType) { 17 | 18 | } 19 | 20 | @Override 21 | public void onIgnored(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, boolean loaded) { 22 | 23 | } 24 | 25 | @Override 26 | public void onError(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded, Throwable throwable) { 27 | 28 | } 29 | 30 | @Override 31 | public void onComplete(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded) { 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/java/com/thalossphere/extension/datasource/entity/SentinelConfig.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.extension.datasource.entity; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | @Data 9 | public class SentinelConfig { 10 | 11 | private String dataId; 12 | 13 | private String groupId; 14 | 15 | private String ruleKey; 16 | 17 | /** 18 | * application 19 | */ 20 | private String namespace; 21 | 22 | private boolean resourceLimitEnabled; 23 | 24 | private boolean circuitBreakerEnabled; 25 | 26 | private HttpApiLimitConfig httpApiLimitConfig; 27 | 28 | private MybatisApiLimitConfig mybatisApiLimitConfig; 29 | 30 | private Map limitReturnResult; 31 | 32 | 33 | @Data 34 | public static class HttpApiLimitConfig { 35 | 36 | private boolean allUrlLimitEnabled; 37 | 38 | private List excludeLimitUrlList; 39 | 40 | } 41 | 42 | @Data 43 | public static class MybatisApiLimitConfig { 44 | 45 | private boolean allMethodLimitEnabled; 46 | 47 | private List excludeLimitMethodList; 48 | 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-register-center/src/main/java/com/thalossphere/register/center/listener/RefreshServerListListener.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.register.center.listener; 2 | 3 | import com.thalossphere.common.eventbus.event.RefreshServerListEvent; 4 | import com.thalossphere.common.utils.DynamicServerListLoadBalancerCache; 5 | import com.google.common.eventbus.Subscribe; 6 | import com.netflix.loadbalancer.DynamicServerListLoadBalancer; 7 | import lombok.extern.slf4j.Slf4j; 8 | 9 | import java.util.Objects; 10 | 11 | @Slf4j 12 | public class RefreshServerListListener { 13 | 14 | @Subscribe 15 | public void listener(RefreshServerListEvent refreshServerListEvent) { 16 | Object result = DynamicServerListLoadBalancerCache.get(refreshServerListEvent.getApplicationName()); 17 | if (Objects.isNull(result)) { 18 | log.info("[RefreshServerListListener] applicationName={} get dynamicServerListLoadBalancer is null", refreshServerListEvent.getApplicationName()); 19 | return; 20 | } 21 | DynamicServerListLoadBalancer dynamicServerListLoadBalancer = (DynamicServerListLoadBalancer) result; 22 | dynamicServerListLoadBalancer.updateListOfServers(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-fegin/src/main/java/com/thalossphere/agent/plugin/feign/DynamicServerListLoadBalancerInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.feign; 2 | 3 | import com.thalossphere.agent.core.context.CustomContextAccessor; 4 | import com.thalossphere.agent.core.interceptor.template.InstantMethodInterceptorResult; 5 | import com.thalossphere.agent.core.interceptor.type.InstantMethodInterceptor; 6 | import com.thalossphere.common.utils.DynamicServerListLoadBalancerCache; 7 | import com.netflix.loadbalancer.DynamicServerListLoadBalancer; 8 | 9 | import java.lang.reflect.Method; 10 | import java.util.concurrent.Callable; 11 | 12 | public class DynamicServerListLoadBalancerInterceptor implements InstantMethodInterceptor { 13 | 14 | @Override 15 | public void beforeMethod(CustomContextAccessor customContextAccessor, Object[] allArguments, Callable callable, Method method, InstantMethodInterceptorResult instantMethodInterceptorResult) { 16 | DynamicServerListLoadBalancer dynamicServerListLoadBalancer = (DynamicServerListLoadBalancer) customContextAccessor; 17 | DynamicServerListLoadBalancerCache.add(dynamicServerListLoadBalancer.getName(), dynamicServerListLoadBalancer); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/tag/extract/AbstractTagExtract.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.tag.extract; 2 | 3 | import com.thalossphere.common.loadbalance.ArrayWeightRandom; 4 | import com.thalossphere.common.loadbalance.InstantWeight; 5 | import com.thalossphere.common.loadbalance.TagWeight; 6 | import com.thalossphere.common.request.AbstractAttributeResolver; 7 | import com.thalossphere.common.tag.context.TagContext; 8 | import lombok.extern.slf4j.Slf4j; 9 | 10 | import java.util.List; 11 | 12 | @Slf4j 13 | public abstract class AbstractTagExtract implements TagExtract { 14 | 15 | @Override 16 | public String extract(InstantWeight instantWeight, AbstractAttributeResolver attributeResolver) { 17 | List tagWeight = getTagWeight(instantWeight); 18 | ArrayWeightRandom arrayWeightRandom = new ArrayWeightRandom(tagWeight); 19 | String tag = (String) arrayWeightRandom.choose(); 20 | TagContext.set(tag); 21 | if (log.isDebugEnabled()) { 22 | log.debug("[thalossphere] spring-cloud-gateway choose tag={}", tag); 23 | } 24 | return tag; 25 | } 26 | 27 | public abstract List getTagWeight(InstantWeight instantWeight); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-resttemplate/src/main/java/com/thalossphere/plugin/resttemplate/HttpAccessorInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.plugin.resttemplate; 2 | 3 | import com.thalossphere.agent.core.context.CustomContextAccessor; 4 | import com.thalossphere.agent.core.interceptor.type.InstantMethodInterceptor; 5 | import com.thalossphere.common.constant.CommonConstant; 6 | import com.thalossphere.common.tag.context.TagContext; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.http.client.ClientHttpRequest; 9 | 10 | import java.lang.reflect.Method; 11 | import java.util.concurrent.Callable; 12 | 13 | @Slf4j 14 | public class HttpAccessorInterceptor implements InstantMethodInterceptor { 15 | 16 | @Override 17 | public void afterMethod(CustomContextAccessor customContextAccessor, Object[] allArguments, Callable callable, Method method, Object instantMethodInterceptorResult) { 18 | ClientHttpRequest request = (ClientHttpRequest) instantMethodInterceptorResult; 19 | if (log.isDebugEnabled()) { 20 | log.info("[thalossphere] restTemplate tag={}", TagContext.get()); 21 | } 22 | request.getHeaders().add(CommonConstant.TAG, TagContext.get()); 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/java/com/thalossphere/extension/datasource/loader/PluginConfigLoaderManager.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.extension.datasource.loader; 2 | 3 | 4 | import com.thalossphere.extension.datasource.enums.PluginConfigDataSourceTypeEnum; 5 | import com.thalossphere.extension.datasource.support.apollo.ApolloPluginConfigLoader; 6 | import com.thalossphere.extension.datasource.support.local.LocalPluginConfigLoader; 7 | import com.thalossphere.extension.datasource.support.nacos.NacosPluginConfigLoader; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | public class PluginConfigLoaderManager { 13 | 14 | private static final Map LOADER_MAP = new HashMap<>(); 15 | 16 | static { 17 | LOADER_MAP.put(PluginConfigDataSourceTypeEnum.NACOS.getType(), new NacosPluginConfigLoader()); 18 | LOADER_MAP.put(PluginConfigDataSourceTypeEnum.LOCAL.getType(), new LocalPluginConfigLoader()); 19 | LOADER_MAP.put(PluginConfigDataSourceTypeEnum.APOLLO.getType(), new ApolloPluginConfigLoader()); 20 | } 21 | 22 | 23 | public static PluginConfigLoader getPluginConfigLoader(String key) { 24 | return LOADER_MAP.get(key); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-removal/src/main/java/com/thalossphere/feature/removal/RemovalInit.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.removal; 2 | 3 | import com.thalossphere.common.config.YamlAgentConfig; 4 | import com.thalossphere.common.init.CoreInit; 5 | import com.thalossphere.extension.datasource.cache.PluginConfigCache; 6 | import com.thalossphere.extension.datasource.entity.PluginConfig; 7 | import com.thalossphere.extension.datasource.entity.RemovalConfig; 8 | 9 | import java.lang.instrument.Instrumentation; 10 | import java.util.Objects; 11 | 12 | public class RemovalInit implements CoreInit { 13 | 14 | @Override 15 | public void init(YamlAgentConfig yamlAgentConfig, ClassLoader classLoader, Instrumentation inst) { 16 | PluginConfig pluginConfig = PluginConfigCache.get(); 17 | RemovalConfig removalConfig = pluginConfig.getRemovalConfig(); 18 | if (Objects.isNull(removalConfig)) { 19 | return; 20 | } 21 | RemovalTask removalTask = new RemovalTask(); 22 | removalTask.start(); 23 | Runtime.getRuntime().addShutdownHook(new Thread(() -> removalTask.stop())); 24 | } 25 | 26 | @Override 27 | public int getOrder() { 28 | return 4; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-sentinel/src/main/java/com/thalossphere/feature/sentinel/limiter/support/SlowRatioCircuitBreakerLimiter.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.sentinel.limiter.support; 2 | 3 | import com.alibaba.csp.sentinel.Entry; 4 | import com.alibaba.csp.sentinel.SphU; 5 | import com.thalossphere.extension.datasource.entity.PluginConfig; 6 | import com.thalossphere.feature.sentinel.limiter.AbstractSentinelLimiter; 7 | import com.thalossphere.feature.sentinel.limiter.SentinelResource; 8 | import lombok.SneakyThrows; 9 | 10 | public class SlowRatioCircuitBreakerLimiter extends AbstractSentinelLimiter { 11 | 12 | private static final SlowRatioCircuitBreakerLimiter INSTANT = new SlowRatioCircuitBreakerLimiter(); 13 | 14 | public static SlowRatioCircuitBreakerLimiter getInstance() { 15 | return INSTANT; 16 | } 17 | 18 | @SneakyThrows 19 | @Override 20 | public Entry getEntry(SentinelResource sentinelResource) { 21 | return SphU.entry(sentinelResource.getResourceName()); 22 | } 23 | 24 | @Override 25 | public boolean needLimit(SentinelResource sentinelResource, PluginConfig pluginConfig) { 26 | return pluginConfig.getSentinelConfig().isCircuitBreakerEnabled(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-springmvc/src/main/java/com/thalossphere/agent/plugin/spring/mvc/RequestMappingHandlerMappingInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.spring.mvc; 2 | 3 | import com.thalossphere.agent.core.context.CustomContextAccessor; 4 | import com.thalossphere.agent.core.interceptor.template.InstantMethodInterceptorResult; 5 | import com.thalossphere.agent.core.interceptor.type.InstantMethodInterceptor; 6 | import com.thalossphere.feature.discovery.binder.ProviderInterfaceManager; 7 | import org.springframework.web.servlet.mvc.method.RequestMappingInfo; 8 | 9 | import java.lang.reflect.Method; 10 | import java.util.concurrent.Callable; 11 | 12 | public class RequestMappingHandlerMappingInterceptor implements InstantMethodInterceptor { 13 | 14 | @Override 15 | public void beforeMethod(CustomContextAccessor customContextAccessor, Object[] allArguments, Callable callable, Method method, InstantMethodInterceptorResult instantMethodInterceptorResult) { 16 | RequestMappingInfo requestMappingInfo = (RequestMappingInfo) allArguments[2]; 17 | for (String url : requestMappingInfo.getPatternsCondition().getPatterns()) { 18 | ProviderInterfaceManager.addInterfaceUrl(url); 19 | } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /thalossphere-test/src/main/java/com/thalossphere/test/request/HeaderResolverTest.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.test.request; 2 | 3 | import com.thalossphere.common.constant.CommonConstant; 4 | import com.thalossphere.common.request.*; 5 | import com.google.common.collect.ImmutableMap; 6 | import org.junit.jupiter.api.Assertions; 7 | import org.junit.jupiter.api.Test; 8 | import org.mockito.Mockito; 9 | 10 | public class HeaderResolverTest { 11 | 12 | @Test 13 | public void headerResolverTest(){ 14 | HttpRequest httpRequest = Mockito.mock(HttpRequest.class); 15 | Mockito.when(httpRequest.getHeaders()).thenReturn(ImmutableMap.of( 16 | CommonConstant.TAG, "tagA", 17 | CommonConstant.USER_ID, "123", 18 | CommonConstant.REGION, "111" 19 | )); 20 | 21 | RequestResolver requestResolver = new SimpleRequestResolver(httpRequest); 22 | HeaderResolver headerResolver = new HeaderResolver() { 23 | }; 24 | Assertions.assertTrue(headerResolver.getUserId(requestResolver).equals("123")); 25 | Assertions.assertTrue(headerResolver.getRegion(requestResolver).equals("111")); 26 | Assertions.assertTrue(headerResolver.getTag(requestResolver).equals("tagA")); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/tag/extract/UserIdTagExtract.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.tag.extract; 2 | 3 | import com.thalossphere.common.request.AbstractAttributeResolver; 4 | import com.thalossphere.common.request.HeaderResolver; 5 | import com.thalossphere.common.loadbalance.InstantWeight; 6 | import com.thalossphere.common.loadbalance.TagWeight; 7 | import com.thalossphere.common.loadbalance.UserWeight; 8 | 9 | import java.util.List; 10 | import java.util.Objects; 11 | 12 | public class UserIdTagExtract extends AbstractTagExtract { 13 | 14 | @Override 15 | public List getTagWeight(InstantWeight instantWeight) { 16 | return instantWeight.getUserWeight().getTagWeights(); 17 | } 18 | 19 | @Override 20 | public boolean match(InstantWeight instantWeight, AbstractAttributeResolver attributeResolver) { 21 | UserWeight userWeight = instantWeight.getUserWeight(); 22 | if (Objects.isNull(userWeight) || Objects.isNull(userWeight.getUserIds()) || Objects.isNull(userWeight.getTagWeights())) { 23 | return false; 24 | } 25 | if (userWeight.getUserIds().contains(attributeResolver.getUserId())) { 26 | return true; 27 | } 28 | return false; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/builder/MultiThreadMethodInterceptorBuilder.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.builder; 2 | 3 | import com.thalossphere.agent.core.interceptor.MultiThreadConstructorInterceptor; 4 | import com.thalossphere.agent.core.interceptor.MultiThreadMethodInterceptor; 5 | import com.thalossphere.agent.core.matcher.MultiThreadMethodMatch; 6 | import net.bytebuddy.description.NamedElement; 7 | import net.bytebuddy.dynamic.DynamicType; 8 | import net.bytebuddy.implementation.MethodDelegation; 9 | import net.bytebuddy.implementation.SuperMethodCall; 10 | import net.bytebuddy.matcher.ElementMatchers; 11 | 12 | public class MultiThreadMethodInterceptorBuilder implements InterceptorBuilder { 13 | 14 | @Override 15 | public DynamicType.Builder intercept(DynamicType.Builder builder) { 16 | return builder 17 | .method(new MultiThreadMethodMatch()) 18 | .intercept(MethodDelegation.withDefaultConfiguration().to(new MultiThreadMethodInterceptor())) 19 | .constructor(ElementMatchers.isConstructor()) 20 | .intercept(SuperMethodCall.INSTANCE.andThen(MethodDelegation.withDefaultConfiguration().to(new MultiThreadConstructorInterceptor()))); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-rocketmq-example/src/main/java/com/thalossphere/rocketmq/example/controller/RocketMQController.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.rocketmq.example.controller; 2 | 3 | import org.apache.rocketmq.client.producer.DefaultMQProducer; 4 | import org.apache.rocketmq.client.producer.SendResult; 5 | import org.apache.rocketmq.common.message.Message; 6 | import org.apache.rocketmq.remoting.common.RemotingHelper; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | @RequestMapping 13 | @RestController 14 | public class RocketMQController { 15 | 16 | @Autowired 17 | private DefaultMQProducer defaultMQProducer; 18 | 19 | @GetMapping("/myRocketMQ") 20 | public String myRocketMQ(String str) throws Exception { 21 | Message msg = new Message("TopicTest", 22 | "tagA", 23 | // "OrderID188", 24 | str.getBytes(RemotingHelper.DEFAULT_CHARSET)); 25 | msg.putUserProperty("user", "zhangsan"); 26 | SendResult sendResult = defaultMQProducer.send(msg); 27 | return "ok"; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-discovery-binder/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | io.github.thalossphere-projects 7 | thalossphere-features 8 | 1.5.0.RELEASE 9 | 10 | thalossphere-feature-discovery-binder 11 | thalossphere-feature-discovery-binder 12 | thalossphere-feature-discovery-binder 13 | 14 | 8 15 | 16 | 17 | 18 | 19 | 20 | ${project.groupId} 21 | thalossphere-agent-core 22 | 23 | 24 | 25 | ${project.groupId} 26 | thalossphere-extension-datasource 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-rocketmq4/src/main/java/com/thalossphere/agent/plugin/rocketmq/consumer/ClientConfigInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.rocketmq.consumer; 2 | 3 | import com.thalossphere.agent.core.context.CustomContextAccessor; 4 | import com.thalossphere.agent.core.interceptor.template.InstantMethodInterceptorResult; 5 | import com.thalossphere.agent.core.interceptor.type.InstantMethodInterceptor; 6 | import com.thalossphere.common.tag.context.TagManager; 7 | import com.thalossphere.common.utils.StringUtils; 8 | 9 | import java.lang.reflect.Method; 10 | import java.util.UUID; 11 | import java.util.concurrent.Callable; 12 | 13 | public class ClientConfigInterceptor implements InstantMethodInterceptor { 14 | 15 | @Override 16 | public void beforeMethod(CustomContextAccessor customContextAccessor, Object[] allArguments, Callable callable, Method method, InstantMethodInterceptorResult instantMethodInterceptorResult) { 17 | String systemTag = TagManager.getSystemTag(); 18 | if (StringUtils.isNotEmpty(systemTag)) { 19 | instantMethodInterceptorResult.setContinue(false); 20 | instantMethodInterceptorResult.setResult(systemTag + "@" + UUID.randomUUID().toString().replace("-", "")); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /thalossphere-test/src/main/java/com/thalossphere/test/request/ParameterResolverTest.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.test.request; 2 | 3 | import com.thalossphere.common.constant.CommonConstant; 4 | import com.thalossphere.common.request.*; 5 | import com.google.common.collect.ImmutableMap; 6 | import org.junit.jupiter.api.Assertions; 7 | import org.junit.jupiter.api.Test; 8 | import org.mockito.Mockito; 9 | 10 | public class ParameterResolverTest { 11 | 12 | @Test 13 | public void parameterResolverTest(){ 14 | HttpRequest httpRequest = Mockito.mock(HttpRequest.class); 15 | Mockito.when(httpRequest.getParameters()).thenReturn(ImmutableMap.of( 16 | CommonConstant.TAG, "tagA", 17 | CommonConstant.USER_ID, "123", 18 | CommonConstant.REGION, "111" 19 | )); 20 | 21 | RequestResolver requestResolver = new SimpleRequestResolver(httpRequest); 22 | ParameterResolver parameterResolver = new ParameterResolver() { 23 | }; 24 | Assertions.assertTrue(parameterResolver.getUserId(requestResolver).equals("123")); 25 | Assertions.assertTrue(parameterResolver.getRegion(requestResolver).equals("111")); 26 | Assertions.assertTrue(parameterResolver.getTag(requestResolver).equals("tagA")); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /thalossphere-test/src/main/java/com/thalossphere/test/interceptor/CustomInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.test.interceptor; 2 | 3 | 4 | import com.thalossphere.agent.core.context.CustomContextAccessor; 5 | import com.thalossphere.agent.core.interceptor.template.InstantMethodInterceptorResult; 6 | import com.thalossphere.agent.core.interceptor.type.InstantMethodInterceptor; 7 | 8 | import java.lang.reflect.Method; 9 | import java.util.concurrent.Callable; 10 | 11 | public class CustomInterceptor implements InstantMethodInterceptor { 12 | 13 | @Override 14 | public void beforeMethod(CustomContextAccessor customContextAccessor, Object[] allArguments, Callable callable, Method method, InstantMethodInterceptorResult instantMethodInterceptorResult) { 15 | System.out.println("进入拦截器beforeMethod"); 16 | } 17 | 18 | @Override 19 | public void afterMethod(CustomContextAccessor customContextAccessor, Object[] allArguments, Callable callable, Method method, Object result) { 20 | System.out.println("进入拦截器afterMethod"); 21 | } 22 | 23 | @Override 24 | public void exceptionMethod(CustomContextAccessor customContextAccessor, Object[] allArguments, Callable callable, Method method, Throwable e) { 25 | System.out.println("进入拦截器exceptionMethod"); 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/tag/extract/RegionTagExtract.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.tag.extract; 2 | 3 | import com.thalossphere.common.request.AbstractAttributeResolver; 4 | import com.thalossphere.common.request.HeaderResolver; 5 | import com.thalossphere.common.loadbalance.InstantWeight; 6 | import com.thalossphere.common.loadbalance.RegionWeight; 7 | import com.thalossphere.common.loadbalance.TagWeight; 8 | 9 | import java.util.List; 10 | import java.util.Objects; 11 | 12 | public class RegionTagExtract extends AbstractTagExtract { 13 | 14 | @Override 15 | public List getTagWeight(InstantWeight instantWeight) { 16 | return instantWeight.getRegionWeight().getTagWeights(); 17 | } 18 | 19 | 20 | 21 | @Override 22 | public boolean match(InstantWeight instantWeight, AbstractAttributeResolver attributeResolver) { 23 | RegionWeight regionWeight = instantWeight.getRegionWeight(); 24 | if (Objects.isNull(regionWeight) || Objects.isNull(regionWeight.getRegions()) || Objects.isNull(regionWeight.getTagWeights())) { 25 | return false; 26 | } 27 | if (regionWeight.getRegions().contains(attributeResolver.getRegion())) { 28 | return true; 29 | } 30 | return false; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-mybatis/src/main/java/com/thalossphere/plugin/mybatis/BaseExecutorInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.plugin.mybatis; 2 | 3 | import com.thalossphere.agent.core.context.CustomContextAccessor; 4 | import com.thalossphere.agent.core.interceptor.template.InstantMethodInterceptorResult; 5 | import com.thalossphere.agent.core.interceptor.type.InstantMethodInterceptor; 6 | import com.thalossphere.feature.sentinel.limiter.SentinelResource; 7 | import com.thalossphere.plugin.mybatis.flow.MybatisLimiter; 8 | import org.apache.ibatis.mapping.MappedStatement; 9 | 10 | import java.lang.reflect.Method; 11 | import java.util.concurrent.Callable; 12 | 13 | public class BaseExecutorInterceptor implements InstantMethodInterceptor { 14 | 15 | @Override 16 | public void beforeMethod(CustomContextAccessor customContextAccessor, Object[] allArguments, Callable callable, Method method, InstantMethodInterceptorResult instantMethodInterceptorResult) { 17 | MappedStatement ms = (MappedStatement) allArguments[0]; 18 | Object result = MybatisLimiter.getInstance().limit(new SentinelResource().setResourceName(ms.getId()), callable); 19 | instantMethodInterceptorResult.setContinue(false); 20 | instantMethodInterceptorResult.setResult(result); 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-mybatis/src/main/java/com/thalossphere/plugin/mybatis/flow/MybatisLimiter.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.plugin.mybatis.flow; 2 | 3 | import com.thalossphere.extension.datasource.entity.PluginConfig; 4 | import com.thalossphere.extension.datasource.entity.SentinelConfig; 5 | import com.thalossphere.feature.sentinel.limiter.AbstractSentinelLimiter; 6 | import com.thalossphere.feature.sentinel.limiter.SentinelResource; 7 | 8 | import java.util.Objects; 9 | 10 | public class MybatisLimiter extends AbstractSentinelLimiter { 11 | 12 | private final static MybatisLimiter INSTANT = new MybatisLimiter(); 13 | 14 | public static MybatisLimiter getInstance() { 15 | return INSTANT; 16 | } 17 | 18 | @Override 19 | public boolean needLimit(SentinelResource sentinelResource, PluginConfig pluginConfig) { 20 | SentinelConfig.MybatisApiLimitConfig mybatisApiLimitConfig = pluginConfig.getSentinelConfig().getMybatisApiLimitConfig(); 21 | if (Objects.isNull(mybatisApiLimitConfig)) { 22 | return false; 23 | } 24 | return mybatisApiLimitConfig.isAllMethodLimitEnabled() || mybatisApiLimitConfig.getExcludeLimitMethodList().stream() 25 | .anyMatch(method -> method.equals(sentinelResource.getResourceName())); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-eureka/src/main/java/com/thalossphere/agent/plugin/eureka/EurekaServerPredicate.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.eureka; 2 | 3 | import com.thalossphere.common.constant.CommonConstant; 4 | import com.thalossphere.common.tag.context.TagContext; 5 | import com.google.common.base.Strings; 6 | import com.netflix.appinfo.InstanceInfo; 7 | import com.netflix.niws.loadbalancer.DiscoveryEnabledServer; 8 | import lombok.extern.slf4j.Slf4j; 9 | 10 | import java.util.Map; 11 | import java.util.function.Predicate; 12 | 13 | @Slf4j 14 | public class EurekaServerPredicate implements Predicate { 15 | 16 | @Override 17 | public boolean test(DiscoveryEnabledServer discoveryEnabledServer) { 18 | InstanceInfo instanceInfo = discoveryEnabledServer.getInstanceInfo(); 19 | Map metadata = instanceInfo.getMetadata(); 20 | String serverTag = metadata.get(CommonConstant.SERVER_TAG); 21 | String tag = TagContext.get(); 22 | if (log.isDebugEnabled()) { 23 | log.debug("[thalossphere] eureka tag={}", tag); 24 | } 25 | if (!Strings.isNullOrEmpty(tag) && tag.equals(serverTag) && !Strings.isNullOrEmpty(serverTag)) { 26 | return true; 27 | } 28 | return false; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-removal/src/main/java/com/thalossphere/feature/removal/RemovalTask.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.removal; 2 | 3 | import com.thalossphere.extension.datasource.cache.PluginConfigCache; 4 | import com.thalossphere.extension.datasource.entity.PluginConfig; 5 | import com.thalossphere.extension.datasource.entity.RemovalConfig; 6 | 7 | import java.util.Objects; 8 | import java.util.concurrent.ScheduledThreadPoolExecutor; 9 | import java.util.concurrent.TimeUnit; 10 | 11 | public class RemovalTask { 12 | 13 | private ScheduledThreadPoolExecutor scheduledThreadPoolExecutor; 14 | 15 | public void start() { 16 | PluginConfig pluginConfig = PluginConfigCache.get(); 17 | RemovalConfig removalConfig = pluginConfig.getRemovalConfig(); 18 | if (Objects.isNull(removalConfig)) { 19 | return; 20 | } 21 | scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); 22 | scheduledThreadPoolExecutor.scheduleWithFixedDelay(new RemovalThread(), removalConfig.getWindowsTime(), 23 | removalConfig.getWindowsTime(), TimeUnit.MILLISECONDS); 24 | } 25 | 26 | public void stop() { 27 | if (scheduledThreadPoolExecutor != null) { 28 | scheduledThreadPoolExecutor.shutdown(); 29 | } 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/interceptor/MultiThreadMethodInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.interceptor; 2 | 3 | import com.thalossphere.agent.core.context.CustomContext; 4 | import com.thalossphere.agent.core.context.CustomContextAccessor; 5 | import com.thalossphere.common.tag.context.TagContext; 6 | import net.bytebuddy.implementation.bind.annotation.*; 7 | 8 | import java.lang.reflect.Method; 9 | import java.util.Objects; 10 | import java.util.concurrent.Callable; 11 | 12 | public class MultiThreadMethodInterceptor { 13 | 14 | @RuntimeType 15 | public Object instantMethodIntercept(@This Object obj, @AllArguments Object[] allArguments, @SuperCall Callable callable, @Origin Method method) throws Exception { 16 | try { 17 | CustomContextAccessor customContextAccessor = (CustomContextAccessor) obj; 18 | Object object = customContextAccessor.getCustomContext(); 19 | if (Objects.nonNull(object) && object instanceof CustomContext) { 20 | CustomContext customContext = (CustomContext) object; 21 | TagContext.set(customContext.getTag()); 22 | } 23 | Object result = callable.call(); 24 | return result; 25 | } finally { 26 | TagContext.remove(); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /thalossphere-features/thalossphere-feature-sentinel/src/main/java/com/thalossphere/feature/sentinel/limiter/support/DynamicMachineIndicatorsLimiter.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.feature.sentinel.limiter.support; 2 | 3 | import com.alibaba.csp.sentinel.Entry; 4 | import com.alibaba.csp.sentinel.EntryType; 5 | import com.alibaba.csp.sentinel.SphU; 6 | import com.thalossphere.extension.datasource.entity.PluginConfig; 7 | import com.thalossphere.feature.sentinel.limiter.AbstractSentinelLimiter; 8 | import com.thalossphere.feature.sentinel.limiter.SentinelResource; 9 | import lombok.SneakyThrows; 10 | 11 | /** 12 | * 实现动态限流根据CPU/内存 13 | */ 14 | public class DynamicMachineIndicatorsLimiter extends AbstractSentinelLimiter { 15 | 16 | private final static DynamicMachineIndicatorsLimiter INSTANTCE = new DynamicMachineIndicatorsLimiter(); 17 | 18 | public static DynamicMachineIndicatorsLimiter getInstance() { 19 | return INSTANTCE; 20 | } 21 | 22 | @Override 23 | public boolean needLimit(SentinelResource sentinelResource, PluginConfig pluginConfig) { 24 | return pluginConfig.getSentinelConfig().isResourceLimitEnabled(); 25 | } 26 | 27 | @SneakyThrows 28 | @Override 29 | public Entry getEntry(SentinelResource sentinelResource) { 30 | return SphU.entry(sentinelResource.getResourceName(), EntryType.IN); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/utils/NetUtils.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.utils; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.net.Inet4Address; 6 | import java.net.InetAddress; 7 | import java.net.NetworkInterface; 8 | import java.util.Enumeration; 9 | 10 | @Slf4j 11 | public class NetUtils { 12 | 13 | public static String getIpAddress() { 14 | try { 15 | Enumeration allNetInterfaces = NetworkInterface.getNetworkInterfaces(); 16 | InetAddress ip; 17 | while (allNetInterfaces.hasMoreElements()) { 18 | NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement(); 19 | if (!netInterface.isLoopback() && !netInterface.isVirtual() && netInterface.isUp()) { 20 | Enumeration addresses = netInterface.getInetAddresses(); 21 | while (addresses.hasMoreElements()) { 22 | ip = addresses.nextElement(); 23 | if (ip instanceof Inet4Address) { 24 | return ip.getHostAddress(); 25 | } 26 | } 27 | } 28 | } 29 | } catch (Exception e) { 30 | log.error("", e); 31 | } 32 | return ""; 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-consul/src/main/java/com/thalossphere/agent/plugin/consul/ConsulDiscoveryPropertiesInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.consul; 2 | 3 | import com.thalossphere.agent.core.context.CustomContextAccessor; 4 | import com.thalossphere.agent.core.interceptor.template.InstantMethodInterceptorResult; 5 | import com.thalossphere.agent.core.interceptor.type.InstantMethodInterceptor; 6 | import com.thalossphere.common.constant.CommonConstant; 7 | import com.thalossphere.common.tag.context.TagManager; 8 | import lombok.SneakyThrows; 9 | 10 | import java.lang.reflect.Method; 11 | import java.util.List; 12 | import java.util.concurrent.Callable; 13 | 14 | public class ConsulDiscoveryPropertiesInterceptor implements InstantMethodInterceptor { 15 | 16 | @SneakyThrows 17 | @Override 18 | public void beforeMethod(CustomContextAccessor customContextAccessor, Object[] allArguments, Callable callable, Method method, InstantMethodInterceptorResult instantMethodInterceptorResult) { 19 | List tags = (List) callable.call(); 20 | tags.add(CommonConstant.SERVER_TAG + "=" + TagManager.getSystemTag()); 21 | tags.add(CommonConstant.TIMESTAMP + "=" + System.currentTimeMillis()); 22 | instantMethodInterceptorResult.setContinue(false); 23 | instantMethodInterceptorResult.setResult(tags); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-zookeeper/src/main/java/com/thalossphere/agent/plugin/zookeeper/ZookeeperDiscoveryPropertiesInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.zookeeper; 2 | 3 | import com.thalossphere.agent.core.context.CustomContextAccessor; 4 | import com.thalossphere.agent.core.interceptor.template.InstantMethodInterceptorResult; 5 | import com.thalossphere.agent.core.interceptor.type.InstantMethodInterceptor; 6 | import com.thalossphere.common.constant.CommonConstant; 7 | import com.thalossphere.common.tag.context.TagManager; 8 | import lombok.SneakyThrows; 9 | 10 | import java.lang.reflect.Method; 11 | import java.util.Map; 12 | import java.util.concurrent.Callable; 13 | 14 | public class ZookeeperDiscoveryPropertiesInterceptor implements InstantMethodInterceptor { 15 | 16 | @SneakyThrows 17 | @Override 18 | public void beforeMethod(CustomContextAccessor customContextAccessor, Object[] allArguments, Callable callable, Method method, InstantMethodInterceptorResult instantMethodInterceptorResult) { 19 | Map metadata = (Map) callable.call(); 20 | metadata.put(CommonConstant.SERVER_TAG, TagManager.getSystemTag()); 21 | metadata.put(CommonConstant.TIMESTAMP, String.valueOf(System.currentTimeMillis())); 22 | instantMethodInterceptorResult.setContinue(false); 23 | instantMethodInterceptorResult.setResult(metadata); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-eureka/src/main/java/com/thalossphere/agent/plugin/eureka/EurekaInstanceConfigBeanInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.eureka; 2 | 3 | import com.thalossphere.agent.core.context.CustomContextAccessor; 4 | import com.thalossphere.agent.core.interceptor.template.InstantMethodInterceptorResult; 5 | import com.thalossphere.agent.core.interceptor.type.InstantMethodInterceptor; 6 | import com.thalossphere.common.constant.CommonConstant; 7 | import com.thalossphere.common.tag.context.TagManager; 8 | import lombok.SneakyThrows; 9 | 10 | import java.lang.reflect.Method; 11 | import java.util.Map; 12 | import java.util.concurrent.Callable; 13 | 14 | public class EurekaInstanceConfigBeanInterceptor implements InstantMethodInterceptor { 15 | 16 | @SneakyThrows 17 | @Override 18 | public void beforeMethod(CustomContextAccessor customContextAccessor, Object[] allArguments, Callable callable, Method method, InstantMethodInterceptorResult instantMethodInterceptorResult) { 19 | Object callResult = callable.call(); 20 | Map result = (Map) callResult; 21 | result.put(CommonConstant.SERVER_TAG, TagManager.getSystemTag()); 22 | result.put(CommonConstant.TIMESTAMP, String.valueOf(System.currentTimeMillis())); 23 | instantMethodInterceptorResult.setContinue(false); 24 | instantMethodInterceptorResult.setResult(result); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/java/com/thalossphere/extension/datasource/support/apollo/ApolloPluginConfigLoader.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.extension.datasource.support.apollo; 2 | 3 | import com.ctrip.framework.apollo.Config; 4 | import com.ctrip.framework.apollo.ConfigService; 5 | import com.thalossphere.common.utils.JacksonUtils; 6 | import com.thalossphere.extension.datasource.entity.PluginConfig; 7 | import com.thalossphere.extension.datasource.loader.PluginConfigLoader; 8 | import com.google.common.collect.Sets; 9 | 10 | import java.util.Properties; 11 | 12 | import static com.thalossphere.extension.datasource.support.apollo.ApolloConfigConstant.*; 13 | 14 | public class ApolloPluginConfigLoader implements PluginConfigLoader { 15 | 16 | @Override 17 | public PluginConfig load(ClassLoader classLoader, Properties properties) { 18 | 19 | System.setProperty("env", (String) properties.get(ENV)); 20 | System.setProperty("app.id", String.valueOf(properties.get(APP_ID))); 21 | System.setProperty("apollo.meta", (String) properties.get(APOLLO_META)); 22 | 23 | Config config = ConfigService.getAppConfig(); 24 | String json = config.getProperty(FLOW_SPHERE_CONFIG_JSON, null); 25 | config.addChangeListener(new ApolloConfigListener(), Sets.newHashSet(new String[]{FLOW_SPHERE_CONFIG_JSON})); 26 | return JacksonUtils.toObj(json, PluginConfig.class); 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /thalossphere-test/src/main/java/com/thalossphere/test/request/CookieResolverTest.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.test.request; 2 | 3 | import com.thalossphere.common.constant.CommonConstant; 4 | import com.thalossphere.common.request.CookieResolver; 5 | import com.thalossphere.common.request.HttpRequest; 6 | import com.thalossphere.common.request.RequestResolver; 7 | import com.thalossphere.common.request.SimpleRequestResolver; 8 | import com.google.common.collect.ImmutableMap; 9 | import org.junit.jupiter.api.Assertions; 10 | import org.junit.jupiter.api.Test; 11 | import org.mockito.Mockito; 12 | 13 | public class CookieResolverTest { 14 | 15 | @Test 16 | public void resolverTest() { 17 | HttpRequest httpRequest = Mockito.mock(HttpRequest.class); 18 | Mockito.when(httpRequest.getCookies()).thenReturn(ImmutableMap.of( 19 | CommonConstant.TAG, "tagA", 20 | CommonConstant.USER_ID, "123", 21 | CommonConstant.REGION, "111" 22 | )); 23 | 24 | RequestResolver requestResolver = new SimpleRequestResolver(httpRequest); 25 | CookieResolver cookieResolver = new CookieResolver() { 26 | }; 27 | Assertions.assertTrue(cookieResolver.getUserId(requestResolver).equals("123")); 28 | Assertions.assertTrue(cookieResolver.getRegion(requestResolver).equals("111")); 29 | Assertions.assertTrue(cookieResolver.getTag(requestResolver).equals("tagA")); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-elasticjob-example/src/main/java/com/thalossphere/elasticjob/example/config/JobEventConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2015 dangdang.com. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *

16 | */ 17 | 18 | package com.thalossphere.elasticjob.example.config; 19 | 20 | import com.dangdang.ddframe.job.event.JobEventConfiguration; 21 | import com.dangdang.ddframe.job.event.rdb.JobEventRdbConfiguration; 22 | import org.springframework.context.annotation.Bean; 23 | import org.springframework.context.annotation.Configuration; 24 | 25 | import javax.annotation.Resource; 26 | import javax.sql.DataSource; 27 | 28 | @Configuration 29 | public class JobEventConfig { 30 | 31 | @Resource 32 | private DataSource dataSource; 33 | 34 | @Bean 35 | public JobEventConfiguration jobEventConfiguration() { 36 | return new JobEventRdbConfiguration(dataSource); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-rocketmq-example/src/main/java/com/thalossphere/rocketmq/example/MyTest.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.rocketmq.example; 2 | 3 | import org.apache.rocketmq.client.exception.MQBrokerException; 4 | import org.apache.rocketmq.client.exception.MQClientException; 5 | import org.apache.rocketmq.client.producer.DefaultMQProducer; 6 | import org.apache.rocketmq.client.producer.SendResult; 7 | import org.apache.rocketmq.common.message.Message; 8 | import org.apache.rocketmq.remoting.common.RemotingHelper; 9 | import org.apache.rocketmq.remoting.exception.RemotingException; 10 | 11 | import java.io.UnsupportedEncodingException; 12 | 13 | public class MyTest { 14 | 15 | public static void main(String[] args) throws MQClientException, UnsupportedEncodingException, MQBrokerException, RemotingException, InterruptedException { 16 | DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupN123ame"); 17 | producer.setNamesrvAddr("127.0.0.1:9876"); 18 | producer.start(); 19 | Message msg = new Message("TopicTest", 20 | "tagA", 21 | // "OrderID188", 22 | "ttsar".getBytes(RemotingHelper.DEFAULT_CHARSET)); 23 | msg.putUserProperty("user", "zhangsan1"); 24 | SendResult sendResult = producer.send(msg); 25 | System.out.println(sendResult.getMessageQueue()); 26 | System.out.println(sendResult.getSendStatus()); 27 | producer.shutdown(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-springmvc/src/main/resources/springmvc-agent.yaml: -------------------------------------------------------------------------------- 1 | pointcutConfigs: 2 | - className: org.springframework.web.filter.RequestContextFilter 3 | methodPointcutConfigs: 4 | - methodName: doFilterInternal 5 | type: instant 6 | interceptorName: com.thalossphere.agent.plugin.spring.mvc.RequestContextFilterInterceptor 7 | - className: org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController 8 | methodPointcutConfigs: 9 | - methodName: error 10 | type: instant 11 | interceptorName: com.thalossphere.agent.plugin.spring.mvc.BasicErrorControllerInterceptor 12 | - className: org.springframework.web.filter.CorsFilter 13 | methodPointcutConfigs: 14 | - methodName: doFilterInternal 15 | type: instant 16 | interceptorName: com.thalossphere.agent.plugin.spring.mvc.DynamicMachineIndicatorsLimiterInterceptor 17 | - className: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping 18 | methodPointcutConfigs: 19 | - methodName: registerHandlerMethod 20 | type: instant 21 | interceptorName: com.thalossphere.agent.plugin.spring.mvc.RequestMappingHandlerMappingInterceptor 22 | - className: org.springframework.boot.context.event.EventPublishingRunListener 23 | methodPointcutConfigs: 24 | - methodName: running 25 | type: instant 26 | interceptorName: com.thalossphere.agent.plugin.spring.mvc.ApplicationContextInterceptor 27 | -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/thalossphere-springcloud-service-api-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | io.github.thalossphere-projects 7 | thalossphere-springcloud-example 8 | 1.5.0.RELEASE 9 | 10 | 11 | thalossphere-springcloud-service-api-example 12 | thalossphere-springcloud-service-api-example 13 | thalossphere-springcloud-service-api-example 14 | 15 | 1.8 16 | 17 | 1.8 18 | 1.8 19 | 20 | 21 | 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-openfeign 26 | 27 | 28 | 29 | io.github.thalossphere-projects 30 | thalossphere-common 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /thalossphere-extensions/thalossphere-extension-datasource/src/main/java/com/thalossphere/extension/datasource/support/local/LocalPluginConfigLoader.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.extension.datasource.support.local; 2 | 3 | 4 | import com.thalossphere.agent.core.utils.AgentPath; 5 | import com.thalossphere.common.yaml.YamlConstructor; 6 | import com.thalossphere.extension.datasource.entity.PluginConfig; 7 | import com.thalossphere.extension.datasource.loader.PluginConfigLoader; 8 | import lombok.SneakyThrows; 9 | import org.yaml.snakeyaml.Yaml; 10 | 11 | import java.io.File; 12 | import java.io.InputStream; 13 | import java.nio.file.Files; 14 | import java.nio.file.Paths; 15 | import java.util.Properties; 16 | 17 | public class LocalPluginConfigLoader implements PluginConfigLoader { 18 | 19 | @Override 20 | public PluginConfig load(ClassLoader classLoader, Properties properties) { 21 | YamlPluginConfig yamlPluginConfig = parsePluginConfig(classLoader); 22 | return yamlPluginConfig.getPluginConfig(); 23 | } 24 | 25 | @SneakyThrows 26 | public YamlPluginConfig parsePluginConfig(ClassLoader classLoader) { 27 | File path = AgentPath.getPath(); 28 | File file = new File(path, "config/plugin-config.yaml"); 29 | try (InputStream agentYamlInputStream = Files.newInputStream(Paths.get(file.toURI()))) { 30 | return new Yaml(new YamlConstructor(YamlPluginConfig.class)).loadAs(agentYamlInputStream, YamlPluginConfig.class); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /thalossphere-test/src/main/java/com/thalossphere/test/request/SimpleRequestResolverTest.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.test.request; 2 | 3 | import com.thalossphere.common.constant.CommonConstant; 4 | import com.thalossphere.common.request.HttpRequest; 5 | import com.thalossphere.common.request.SimpleRequestResolver; 6 | import com.google.common.collect.ImmutableMap; 7 | import org.junit.jupiter.api.Assertions; 8 | import org.junit.jupiter.api.Test; 9 | import org.mockito.Mockito; 10 | 11 | public class SimpleRequestResolverTest { 12 | 13 | @Test 14 | public void requestResolverTest() { 15 | HttpRequest httpRequest = Mockito.mock(HttpRequest.class); 16 | Mockito.when(httpRequest.getParameters()).thenReturn(ImmutableMap.of( 17 | CommonConstant.TAG, "tagA" 18 | )); 19 | Mockito.when(httpRequest.getHeaders()).thenReturn(ImmutableMap.of( 20 | CommonConstant.TAG, "tagA" 21 | )); 22 | Mockito.when(httpRequest.getCookies()).thenReturn(ImmutableMap.of( 23 | CommonConstant.TAG, "tagA" 24 | )); 25 | SimpleRequestResolver simpleRequestResolver = new SimpleRequestResolver(httpRequest); 26 | Assertions.assertTrue(simpleRequestResolver.getParameters(CommonConstant.TAG).equals("tagA")); 27 | Assertions.assertTrue(simpleRequestResolver.getHeader(CommonConstant.TAG).equals("tagA")); 28 | Assertions.assertTrue(simpleRequestResolver.getCookie(CommonConstant.TAG).equals("tagA")); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/interceptor/MethodInterceptorManager.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core.interceptor; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | public class MethodInterceptorManager { 8 | 9 | private static final Map METHOD_INTERCEPTOR_MAP = new HashMap<>(); 10 | 11 | public static MethodInterceptor getMethodInterceptor(String methodInterceptorClassName, ClassLoader classLoader) { 12 | return METHOD_INTERCEPTOR_MAP.computeIfAbsent(methodInterceptorClassName, key -> createMethodInterceptor(methodInterceptorClassName, classLoader)); 13 | } 14 | 15 | private static MethodInterceptor createMethodInterceptor(String methodInterceptorClassName, ClassLoader classLoader) { 16 | try { 17 | return (MethodInterceptor) Class.forName(methodInterceptorClassName, true, classLoader).getDeclaredConstructor().newInstance(); 18 | } catch (InstantiationException e) { 19 | throw new RuntimeException(e); 20 | } catch (IllegalAccessException e) { 21 | throw new RuntimeException(e); 22 | } catch (InvocationTargetException e) { 23 | throw new RuntimeException(e); 24 | } catch (NoSuchMethodException e) { 25 | throw new RuntimeException(e); 26 | } catch (ClassNotFoundException e) { 27 | throw new RuntimeException(e); 28 | } 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /thalossphere-plugins/thalossphere-plugin-rocketmq4/src/main/java/com/thalossphere/agent/plugin/rocketmq/producer/DefaultMQProducerInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.plugin.rocketmq.producer; 2 | 3 | import com.thalossphere.agent.core.context.CustomContextAccessor; 4 | import com.thalossphere.agent.core.interceptor.template.InstantMethodInterceptorResult; 5 | import com.thalossphere.agent.core.interceptor.type.InstantMethodInterceptor; 6 | import com.thalossphere.common.constant.CommonConstant; 7 | import com.thalossphere.common.tag.context.TagManager; 8 | import org.apache.rocketmq.common.message.Message; 9 | 10 | import java.lang.reflect.Method; 11 | import java.util.concurrent.Callable; 12 | 13 | public class DefaultMQProducerInterceptor implements InstantMethodInterceptor { 14 | 15 | @Override 16 | public void beforeMethod(CustomContextAccessor customContextAccessor, Object[] allArguments, Callable callable, Method method, InstantMethodInterceptorResult instantMethodInterceptorResult) { 17 | Message message = (Message) allArguments[0]; 18 | message.putUserProperty(CommonConstant.TAG, TagManager.getTag()); 19 | } 20 | 21 | @Override 22 | public void afterMethod(CustomContextAccessor customContextAccessor, Object[] allArguments, Callable callable, Method method, Object result) { 23 | 24 | } 25 | 26 | @Override 27 | public void exceptionMethod(CustomContextAccessor customContextAccessor, Object[] allArguments, Callable callable, Method method, Throwable e) { 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /thalossphere-agent-core/src/main/java/com/thalossphere/agent/core/AgentBootstrap.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.agent.core; 2 | 3 | import com.thalossphere.agent.core.config.PointcutConfigLoader; 4 | import com.thalossphere.agent.core.config.yaml.YamlClassPointcutConfig; 5 | import com.thalossphere.agent.core.config.yaml.YamlMethodPointcutConfig; 6 | import lombok.extern.slf4j.Slf4j; 7 | 8 | import java.util.*; 9 | 10 | @Slf4j 11 | public class AgentBootstrap { 12 | 13 | public static Map> loadPlugins(List pluginNameList, ClassLoader classLoader) { 14 | 15 | Map> methodPointcutConfigMap = new HashMap<>(); 16 | for (String pluginName : pluginNameList) { 17 | List classPointcutConfigs = PointcutConfigLoader.load(pluginName, classLoader); 18 | for (YamlClassPointcutConfig classPointcutConfig : classPointcutConfigs) { 19 | Collection yamlMethodPointcutConfigs = methodPointcutConfigMap.get(classPointcutConfig.getClassName()); 20 | if (yamlMethodPointcutConfigs == null) { 21 | yamlMethodPointcutConfigs = new ArrayList<>(); 22 | } 23 | yamlMethodPointcutConfigs.addAll(classPointcutConfig.getMethodPointcutConfigs()); 24 | methodPointcutConfigMap.put(classPointcutConfig.getClassName(), yamlMethodPointcutConfigs); 25 | } 26 | } 27 | return methodPointcutConfigMap; 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /thalossphere-common/src/main/java/com/thalossphere/common/config/YamlAgentConfigCache.java: -------------------------------------------------------------------------------- 1 | package com.thalossphere.common.config; 2 | 3 | import com.github.benmanes.caffeine.cache.CacheLoader; 4 | import com.github.benmanes.caffeine.cache.Caffeine; 5 | import com.github.benmanes.caffeine.cache.LoadingCache; 6 | 7 | import java.util.concurrent.TimeUnit; 8 | 9 | public class YamlAgentConfigCache { 10 | 11 | private static final String CACHE_KEY = "thalossphereYamlAgentConfigCacheKey"; 12 | 13 | private static final LoadingCache CAHCE; 14 | 15 | static { 16 | CAHCE = Caffeine.newBuilder() 17 | .expireAfterWrite(365 * 100, TimeUnit.DAYS) 18 | .initialCapacity(2) 19 | .maximumSize(10) 20 | .recordStats() 21 | .build(new CacheLoader() { 22 | @Override 23 | public YamlAgentConfig load(String key) throws Exception { 24 | return null; 25 | } 26 | }); 27 | } 28 | 29 | public static boolean put(YamlAgentConfig ruleEntity) { 30 | CAHCE.put(CACHE_KEY, ruleEntity); 31 | return Boolean.TRUE; 32 | } 33 | 34 | public static YamlAgentConfig get() { 35 | try { 36 | return CAHCE.get(CACHE_KEY); 37 | } catch (Exception e) { 38 | return null; 39 | } 40 | } 41 | 42 | public static boolean clear() { 43 | CAHCE.invalidate(CACHE_KEY); 44 | return Boolean.TRUE; 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /thalossphere-examples/thalossphere-springcloud-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | io.github.thalossphere-projects 8 | thalossphere-examples 9 | 1.5.0.RELEASE 10 | 11 | 12 | thalossphere-springcloud-example 13 | 1.5.0.RELEASE 14 | pom 15 | thalossphere-springcloud-example 16 | Demo project for Spring Boot 17 | 18 | 19 | thalossphere-springcloud-gateway-example 20 | thalossphere-springcloud-service-a-example 21 | thalossphere-springcloud-service-a1-example 22 | thalossphere-springcloud-service-b-example 23 | thalossphere-springcloud-service-b1-example 24 | thalossphere-springcloud-service-c-example 25 | thalossphere-springcloud-service-c1-example 26 | thalossphere-springcloud-eureka-server 27 | thalossphere-springcloud-zuul-example 28 | thalossphere-springcloud-service-api-example 29 | 30 | 31 | 32 | --------------------------------------------------------------------------------