├── doc
└── img
│ ├── 1-1-1.jpg
│ └── 1-1-2.jpg
├── femas-example
├── femas-example-springcloud-2020-consumer
│ └── src
│ │ └── main
│ │ ├── resources
│ │ ├── application.yaml
│ │ ├── femas.conf
│ │ ├── bootstrap.yaml
│ │ ├── nacos
│ │ │ └── bootstrap.yaml
│ │ └── consul
│ │ │ └── bootstrap.yaml
│ │ └── java
│ │ └── com
│ │ └── femas
│ │ └── example
│ │ └── springcloud2020
│ │ └── consumer
│ │ ├── proxy
│ │ └── service
│ │ │ └── ProviderService.java
│ │ └── TestFilter.java
├── femas-example-springcloud-2020-provider
│ └── src
│ │ └── main
│ │ ├── resources
│ │ ├── application.yaml
│ │ ├── femas.conf
│ │ ├── bootstrap.yaml
│ │ └── nacos
│ │ │ └── bootstrap.yaml
│ │ └── java
│ │ └── com
│ │ └── femas
│ │ └── example
│ │ └── springcloud2020
│ │ └── provider
│ │ └── ProviderService.java
├── femas-example-springcloud-greenwich-gateway
│ └── src
│ │ └── main
│ │ ├── resources
│ │ ├── application.yaml
│ │ └── femas.conf
│ │ └── java
│ │ └── com
│ │ └── tencent
│ │ └── tsf
│ │ └── femas
│ │ └── example
│ │ └── gateway
│ │ └── springcloud
│ │ └── filter
│ │ └── TestFilter.java
├── femas-example-springcloud-greenwich-zuul
│ └── src
│ │ └── main
│ │ ├── resources
│ │ ├── application.yaml
│ │ └── femas.conf
│ │ └── java
│ │ └── com
│ │ └── tencent
│ │ └── tsf
│ │ └── femas
│ │ └── example
│ │ └── gateway
│ │ └── zuul
│ │ └── ZuulApplication.java
├── femas-example-springcloud-greenwich-consumer
│ └── src
│ │ └── main
│ │ ├── resources
│ │ ├── application.yaml
│ │ ├── femas.conf
│ │ ├── nacos
│ │ │ └── bootstrap.yaml
│ │ ├── consul
│ │ │ └── bootstrap.yaml
│ │ └── bootstrap.yaml
│ │ └── java
│ │ └── com
│ │ └── tencent
│ │ └── tsf
│ │ └── femas
│ │ └── example
│ │ └── springcloud
│ │ ├── proxy
│ │ └── service
│ │ │ └── ProviderService.java
│ │ └── TestFilter.java
└── femas-example-springcloud-greenwich-provider
│ └── src
│ └── main
│ ├── resources
│ ├── application.yaml
│ ├── bootstrap.yaml
│ ├── nacos
│ │ └── bootstrap.yaml
│ ├── femas.conf
│ └── consul
│ │ └── bootstrap.yaml
│ └── java
│ └── com
│ └── tencent
│ └── tsf
│ └── femas
│ └── example
│ └── springcloud
│ └── ProviderService.java
├── femas-common
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── tencent
│ │ └── tsf
│ │ └── femas
│ │ └── common
│ │ ├── rule
│ │ ├── Rule.java
│ │ └── AbstractRuleManager.java
│ │ ├── annotation
│ │ ├── SPI.java
│ │ ├── AdaptorComponent.java
│ │ ├── VisibleForTesting.java
│ │ └── ThreadSafe.java
│ │ ├── context
│ │ ├── RpcInfoEnum.java
│ │ └── RpcContext.java
│ │ ├── callback
│ │ ├── SendableResponseCallback.java
│ │ └── FemasCallback.java
│ │ ├── version
│ │ └── Version.java
│ │ ├── base
│ │ ├── Sortable.java
│ │ └── Initializable.java
│ │ ├── spi
│ │ ├── SpiExtensionClass.java
│ │ └── SpiService.java
│ │ ├── httpclient
│ │ ├── HttpClientRequest.java
│ │ ├── factory
│ │ │ └── HttpClientFactory.java
│ │ ├── client
│ │ │ ├── FemasHttpClient.java
│ │ │ └── LongPullingApacheHttpRestClient.java
│ │ └── wrapper
│ │ │ └── Body2StringResultWrapper.java
│ │ ├── util
│ │ ├── id
│ │ │ ├── KeyGenerator.java
│ │ │ ├── GeneratorEnum.java
│ │ │ ├── UIdGenerator.java
│ │ │ └── KeyGeneratorFactory.java
│ │ ├── PositiveAtomicCounter.java
│ │ ├── HttpResult.java
│ │ ├── CollectionUtil.java
│ │ ├── HttpHeaderKeys.java
│ │ ├── PropertiesUtil.java
│ │ ├── ConfigUtils.java
│ │ ├── GsonUtil.java
│ │ └── IOUtils.java
│ │ ├── tag
│ │ ├── TagRuleGroup.java
│ │ ├── exception
│ │ │ └── TagEngineException.java
│ │ ├── TagExpression.java
│ │ └── constant
│ │ │ └── TagConstant.java
│ │ ├── statistic
│ │ ├── Measurement.java
│ │ ├── SecondsSlidingTimeWindowMetrics.java
│ │ ├── TotalAggregation.java
│ │ ├── Metrics.java
│ │ └── PartialAggregation.java
│ │ ├── invoke
│ │ └── Invoker.java
│ │ ├── serialize
│ │ └── Serializer.java
│ │ ├── exception
│ │ ├── FemasRuntimeException.java
│ │ ├── FemasRegisterDescribeException.java
│ │ └── ErrorCode.java
│ │ ├── entity
│ │ └── EndpointStatus.java
│ │ └── codec
│ │ └── EscapeNonAsciiWriter.java
│ └── test
│ └── java
│ └── com
│ └── tencent
│ └── tsf
│ └── femas
│ └── common
│ └── statistic
│ └── SecondsSlidingTimeWindowMetricsTest.java
├── femas-governance-impl
└── src
│ ├── main
│ ├── resources
│ │ └── META-INF
│ │ │ └── services
│ │ │ ├── com.tencent.tsf.femas.governance.lane.LaneFilter
│ │ │ ├── com.tencent.tsf.femas.governance.auth.IAuthentication
│ │ │ ├── com.tencent.tsf.femas.governance.plugin.ConfigProvider
│ │ │ ├── com.tencent.tsf.femas.governance.plugin.PluginProvider
│ │ │ ├── com.tencent.tsf.femas.governance.route.Router
│ │ │ ├── com.tencent.tsf.femas.governance.ratelimit.RateLimiter
│ │ │ ├── com.tencent.tsf.femas.governance.circuitbreaker.ICircuitBreakerService
│ │ │ ├── com.tencent.tsf.femas.governance.metrics.MetricsTransformer
│ │ │ ├── com.tencent.tsf.femas.governance.metrics.MetricsExporter
│ │ │ ├── com.tencent.tsf.femas.governance.loadbalance.Loadbalancer
│ │ │ └── com.tencent.tsf.femas.governance.metrics.IMeterRegistry
│ └── java
│ │ └── com
│ │ └── tencent
│ │ └── tsf
│ │ └── femas
│ │ └── governance
│ │ ├── ratelimit
│ │ ├── impl
│ │ │ ├── AdaptiveRateLimiter.java
│ │ │ ├── SemaphoreBasedRateLimiter.java
│ │ │ ├── AccessTokenClusterRateLimiter.java
│ │ │ └── AssignTokenClusterRateLimiter.java
│ │ ├── entity
│ │ │ ├── RateLimiterRuleGroup.java
│ │ │ └── RateLimitRuleConfig.java
│ │ ├── constant
│ │ │ └── RateLimiterConstant.java
│ │ └── RateLimiterManager.java
│ │ ├── api
│ │ └── entity
│ │ │ ├── OpenApiPath.java
│ │ │ ├── OpenApiEntity.java
│ │ │ ├── OpenApiParameters.java
│ │ │ ├── OpenApiResponse.java
│ │ │ └── ServiceApiRequest.java
│ │ ├── event
│ │ └── EventTypeEnum.java
│ │ ├── auth
│ │ ├── constant
│ │ │ └── AuthConstant.java
│ │ ├── entity
│ │ │ ├── AuthRuleConfig.java
│ │ │ └── AuthRuleGroup.java
│ │ └── AuthorizationManager.java
│ │ ├── loadbalance
│ │ ├── exception
│ │ │ └── FemasNoAvailableInstanceException.java
│ │ ├── LoadbalancerManager.java
│ │ └── impl
│ │ │ ├── RandomLoadbalancer.java
│ │ │ └── AbstractLoadbalancer.java
│ │ ├── circuitbreaker
│ │ ├── core
│ │ │ ├── StateTransitionCallback.java
│ │ │ ├── utils
│ │ │ │ └── MetricNames.java
│ │ │ ├── internal
│ │ │ │ └── SchedulerFactory.java
│ │ │ └── IllegalStateTransitionException.java
│ │ ├── rule
│ │ │ └── CircuitBreakerApi.java
│ │ └── constant
│ │ │ └── FemasCircuitBreakerConstant.java
│ │ ├── metrics
│ │ └── micrometer
│ │ │ ├── exporter
│ │ │ ├── PrometheusPropertiesConfigAdapter.java
│ │ │ └── logger
│ │ │ │ └── LoggerFormatter.java
│ │ │ ├── meter
│ │ │ ├── MicroDistributionSummary.java
│ │ │ ├── MicroCounter.java
│ │ │ └── MicroLongTaskTimer.java
│ │ │ ├── ModuleEnum.java
│ │ │ └── registry
│ │ │ ├── RpcMeterRegistry.java
│ │ │ └── GovernanceMeterRegistry.java
│ │ ├── trace
│ │ └── TraceAdapter.java
│ │ ├── config
│ │ └── FemasTypeProviders.java
│ │ ├── lane
│ │ ├── MockLaneFilter.java
│ │ └── LaneService.java
│ │ └── route
│ │ ├── RouterRuleManager.java
│ │ └── entity
│ │ ├── RouteDest.java
│ │ └── RouteRule.java
│ └── test
│ └── java
│ └── com
│ └── tencent
│ └── tsf
│ └── femas
│ └── governance
│ └── circuitbreaker
│ └── core
│ ├── mockservice
│ ├── HelloWorldException.java
│ └── AsyncHelloWorldService.java
│ ├── internal
│ └── SchedulerFactoryTest.java
│ ├── IllegalStateTransitionExceptionTest.java
│ ├── CallNotPermittedExceptionTest.java
│ └── CircuitBreakerOpenExceptionTest.java
├── femas-benchmark
└── src
│ └── test
│ └── java
│ └── com
│ └── tencent
│ └── tsf
│ └── femas
│ └── benchmark
│ └── ClientBenchMark.java
├── femas-config-impl
├── femas-config-paas
│ └── src
│ │ └── main
│ │ ├── resources
│ │ └── META-INF
│ │ │ └── services
│ │ │ └── com.tencent.tsf.femas.config.ConfigFactory
│ │ └── java
│ │ └── com
│ │ └── tencent
│ │ └── tsf
│ │ └── femas
│ │ └── config
│ │ └── impl
│ │ └── paas
│ │ ├── PaasConfigFactory.java
│ │ ├── PaasConstants.java
│ │ └── GetValue.java
├── femas-config-consul
│ └── src
│ │ └── main
│ │ ├── resources
│ │ └── META-INF
│ │ │ └── services
│ │ │ └── com.tencent.tsf.femas.config.ConfigFactory
│ │ └── java
│ │ └── com
│ │ └── tencent
│ │ └── tsf
│ │ └── femas
│ │ └── config
│ │ └── impl
│ │ └── consul
│ │ ├── ConsulConstants.java
│ │ └── ConsulConfigFactory.java
└── femas-config-nacos
│ └── src
│ └── main
│ ├── resources
│ └── META-INF
│ │ └── services
│ │ ├── com.tencent.tsf.femas.config.ConfigFactory
│ │ └── com.tencent.tsf.femas.config.FemasConfigManager
│ └── java
│ └── com
│ └── tencent
│ └── tsf
│ └── femas
│ └── config
│ └── impl
│ └── nacos
│ ├── SpringApplicationContextUtil.java
│ └── FemasNacosConfigManager.java
├── PULL_REQUEST_TEMPLATE.md
├── femas-adaptor
├── femas-adaptor-opensource-admin
│ └── src
│ │ └── main
│ │ ├── resources
│ │ └── META-INF
│ │ │ └── services
│ │ │ ├── com.tencent.tsf.femas.common.context.Context
│ │ │ ├── com.tencent.tsf.femas.common.context.ContextConstant
│ │ │ ├── com.tencent.tsf.femas.config.AbstractConfigHttpClientManager
│ │ │ ├── com.tencent.tsf.femas.governance.ratelimit.RateLimiter
│ │ │ ├── com.tencent.tsf.femas.common.serviceregistry.AbstractServiceRegistryMetadata
│ │ │ └── com.tencent.tsf.femas.governance.plugin.config.ConfigHandler
│ │ └── java
│ │ └── com
│ │ └── tencent
│ │ └── tsf
│ │ └── femas
│ │ └── adaptor
│ │ └── paas
│ │ ├── governance
│ │ ├── lane
│ │ │ └── RuleTagRelationship.java
│ │ └── circuitbreaker
│ │ │ └── event
│ │ │ └── EventResponse.java
│ │ ├── logger
│ │ ├── ConverterBase.java
│ │ └── LogbackTraceConverter.java
│ │ └── config
│ │ └── FemasPaasConfigManager.java
└── pom.xml
├── femas-registry-impl
├── femas-registry-k8s
│ └── src
│ │ └── main
│ │ ├── resources
│ │ └── META-INF
│ │ │ └── services
│ │ │ ├── com.tencent.tsf.femas.common.discovery.ServiceDiscoveryFactory
│ │ │ └── com.tencent.tsf.femas.common.serviceregistry.ServiceRegistryFactory
│ │ └── java
│ │ └── com
│ │ └── tencent
│ │ └── tsf
│ │ └── femas
│ │ └── registry
│ │ └── impl
│ │ └── k8s
│ │ ├── serviceregistry
│ │ ├── K8sServiceRegistryFactory.java
│ │ └── K8sServiceRegistry.java
│ │ └── discovery
│ │ └── K8sServiceDiscoveryFactory.java
├── femas-registry-consul
│ └── src
│ │ └── main
│ │ ├── resources
│ │ └── META-INF
│ │ │ └── services
│ │ │ ├── com.tencent.tsf.femas.common.discovery.ServiceDiscoveryFactory
│ │ │ └── com.tencent.tsf.femas.common.serviceregistry.ServiceRegistryFactory
│ │ └── java
│ │ └── com
│ │ └── tencent
│ │ └── tsf
│ │ └── femas
│ │ └── registry
│ │ └── impl
│ │ └── consul
│ │ ├── serviceregistry
│ │ └── ConsulServiceRegistryFactory.java
│ │ ├── discovery
│ │ └── ConsulServiceDiscoveryFactory.java
│ │ └── util
│ │ └── NormalizeUtil.java
├── femas-registry-eureka
│ └── src
│ │ └── main
│ │ ├── resources
│ │ └── META-INF
│ │ │ └── services
│ │ │ ├── com.tencent.tsf.femas.common.discovery.ServiceDiscoveryFactory
│ │ │ └── com.tencent.tsf.femas.common.serviceregistry.ServiceRegistryFactory
│ │ └── java
│ │ └── com
│ │ └── tencent
│ │ └── tsf
│ │ └── femas
│ │ └── registry
│ │ └── impl
│ │ └── eureka
│ │ ├── serviceregistry
│ │ └── EurekaServiceRegistryFactory.java
│ │ └── discovery
│ │ └── EurekaServiceDiscoveryFactory.java
├── femas-registry-nacos
│ └── src
│ │ └── main
│ │ ├── resources
│ │ └── META-INF
│ │ │ └── services
│ │ │ ├── com.tencent.tsf.femas.common.discovery.ServiceDiscoveryFactory
│ │ │ └── com.tencent.tsf.femas.common.serviceregistry.ServiceRegistryFactory
│ │ └── java
│ │ └── com
│ │ └── tencent
│ │ └── tsf
│ │ └── femas
│ │ └── registry
│ │ └── impl
│ │ └── nacos
│ │ ├── serviceregistry
│ │ └── NacosServiceRegistryFactory.java
│ │ └── discovery
│ │ └── NacosServiceDiscoveryFactory.java
└── femas-registry-polaris
│ └── pom.xml
├── femas-config
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── tencent
│ │ └── tsf
│ │ └── femas
│ │ └── config
│ │ ├── enums
│ │ ├── PropertyChangeType.java
│ │ └── FemasConfigTypeEnum.java
│ │ ├── ConfigFactory.java
│ │ ├── util
│ │ └── parser
│ │ │ └── ParserException.java
│ │ ├── exception
│ │ └── FemasConfigException.java
│ │ ├── ConfigName.java
│ │ ├── ConfigChangeListener.java
│ │ ├── Config.java
│ │ ├── FemasConfigManager.java
│ │ └── ConfigService.java
│ └── resources
│ └── femas-default.conf
├── Code-of-Conduct-zh.md
├── entrypoint.sh
├── femas-extensions
├── femas-extension-springcloud
│ ├── femas-extension-springcloud-greenwich-zuul
│ │ └── src
│ │ │ └── main
│ │ │ └── resources
│ │ │ └── META-INF
│ │ │ └── spring.factories
│ ├── femas-extension-springcloud-greenwich-gateway
│ │ └── src
│ │ │ └── main
│ │ │ ├── resources
│ │ │ └── META-INF
│ │ │ │ └── spring.factories
│ │ │ └── java
│ │ │ └── com
│ │ │ └── tencent
│ │ │ └── tsf
│ │ │ └── femas
│ │ │ └── springcloud
│ │ │ └── gateway
│ │ │ └── filter
│ │ │ └── AbstractGlobalFilter.java
│ ├── femas-extension-springcloud-2020.0-ilford
│ │ └── src
│ │ │ └── main
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── tencent
│ │ │ │ └── tsf
│ │ │ │ └── femas
│ │ │ │ └── extension
│ │ │ │ └── springcloud
│ │ │ │ └── ilford
│ │ │ │ └── discovery
│ │ │ │ └── loadbalancer
│ │ │ │ └── FemasServiceFilterLoadBalancer.java
│ │ │ └── resources
│ │ │ └── META-INF
│ │ │ └── spring.factories
│ ├── femas-extension-springcloud-greenwich
│ │ └── src
│ │ │ └── main
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── tencent
│ │ │ │ └── tsf
│ │ │ │ └── femas
│ │ │ │ └── extension
│ │ │ │ └── springcloud
│ │ │ │ └── discovery
│ │ │ │ ├── ribbon
│ │ │ │ └── FemasServiceFilterLoadBalancer.java
│ │ │ │ └── eureka
│ │ │ │ └── FemasEurekaRegistrationCustomizer.java
│ │ │ └── resources
│ │ │ └── META-INF
│ │ │ └── spring.factories
│ └── femas-extension-springcloud-common
│ │ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── tencent
│ │ └── tsf
│ │ └── femas
│ │ └── extension
│ │ └── springcloud
│ │ └── common
│ │ ├── discovery
│ │ ├── loadbalancer
│ │ │ └── BaseDiscoveryServerConverter.java
│ │ └── nacos
│ │ │ ├── NacosEnv.java
│ │ │ └── FemasNacosRegistrationCustomizer.java
│ │ └── instrumentation
│ │ └── feign
│ │ └── FeignHeaderUtils.java
└── pom.xml
├── femas-registry
└── src
│ └── main
│ └── java
│ └── com
│ └── tencent
│ └── tsf
│ └── femas
│ └── common
│ ├── RegistryEnum.java
│ ├── serviceregistry
│ ├── ServiceRegistryFactory.java
│ └── AbstractServiceRegistryMetadata.java
│ ├── discovery
│ ├── ServiceNotifyListener.java
│ ├── ServerUpdater.java
│ ├── ServiceDiscoveryClient.java
│ ├── ServiceDiscoveryFactory.java
│ └── DiscoveryService.java
│ ├── RegistryConstants.java
│ └── RegistryBuilder.java
├── femas-governance
└── src
│ └── main
│ └── java
│ └── com
│ └── tencent
│ └── tsf
│ └── femas
│ └── governance
│ ├── metrics
│ ├── DistributionSummary.java
│ ├── LongTaskTimer.java
│ ├── Counter.java
│ ├── Meter.java
│ ├── Timer.java
│ ├── MetricsTransformer.java
│ ├── MetricsConstant.java
│ ├── MeterEnum.java
│ └── MetricsExporter.java
│ ├── circuitbreaker
│ └── FemasCircuitBreakerIsolationLevelEnum.java
│ ├── lane
│ └── LaneFilter.java
│ ├── plugin
│ ├── config
│ │ ├── gov
│ │ │ ├── MetricsTransformerConfig.java
│ │ │ ├── AuthenticateConfig.java
│ │ │ ├── LaneConfig.java
│ │ │ ├── RateLimitConfig.java
│ │ │ ├── MetricsConfig.java
│ │ │ ├── LoadBalanceConfig.java
│ │ │ └── MetricsExporterConfig.java
│ │ ├── global
│ │ │ ├── SystemConfig.java
│ │ │ └── GlobalConfig.java
│ │ └── verify
│ │ │ └── Verifier.java
│ ├── context
│ │ └── ConfigContext.java
│ ├── ConfigProvider.java
│ ├── Lifecycle.java
│ └── PluginProvider.java
│ ├── ratelimit
│ └── RateLimiter.java
│ ├── loadbalance
│ └── Loadbalancer.java
│ ├── route
│ └── Router.java
│ └── auth
│ └── IAuthentication.java
├── Code-of-Conduct.md
├── femas-helm
├── templates
│ ├── serviceaccount.yaml
│ ├── tests
│ │ └── test-connection.yaml
│ ├── service.yaml
│ └── hpa.yaml
├── .helmignore
└── Chart.yaml
├── femas-api
└── src
│ └── main
│ └── java
│ └── com
│ └── tencent
│ └── tsf
│ └── femas
│ └── api
│ └── ExtensionManager.java
├── .gitignore
├── Dockerfile
├── Makefile
└── femas-starters
└── pom.xml
/doc/img/1-1-1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tencent/Femas/HEAD/doc/img/1-1-1.jpg
--------------------------------------------------------------------------------
/doc/img/1-1-2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tencent/Femas/HEAD/doc/img/1-1-2.jpg
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-2020-consumer/src/main/resources/application.yaml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-2020-provider/src/main/resources/application.yaml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-gateway/src/main/resources/application.yaml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-zuul/src/main/resources/application.yaml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-consumer/src/main/resources/application.yaml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-provider/src/main/resources/application.yaml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/rule/Rule.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.rule;
2 |
3 | public interface Rule {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/resources/META-INF/services/com.tencent.tsf.femas.governance.lane.LaneFilter:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.governance.lane.MockLaneFilter
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/resources/META-INF/services/com.tencent.tsf.femas.governance.auth.IAuthentication:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.governance.auth.Authentication
--------------------------------------------------------------------------------
/femas-benchmark/src/test/java/com/tencent/tsf/femas/benchmark/ClientBenchMark.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.benchmark;
2 |
3 | public class ClientBenchMark {
4 | }
5 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/annotation/SPI.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.annotation;
2 |
3 | public @interface SPI {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/context/RpcInfoEnum.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.context;
2 |
3 | public enum RpcInfoEnum {
4 | }
5 |
--------------------------------------------------------------------------------
/femas-config-impl/femas-config-paas/src/main/resources/META-INF/services/com.tencent.tsf.femas.config.ConfigFactory:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.config.impl.paas.PaasConfigFactory
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/resources/META-INF/services/com.tencent.tsf.femas.governance.plugin.ConfigProvider:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.governance.config.FemasConfigProviders
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/resources/META-INF/services/com.tencent.tsf.femas.governance.plugin.PluginProvider:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.governance.config.FemasTypeProviders
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/resources/META-INF/services/com.tencent.tsf.femas.governance.route.Router:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.governance.route.FemasDefaultRouteRuleRouter
--------------------------------------------------------------------------------
/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## What is the purpose of the change
2 |
3 | XXXXX
4 |
5 | ## Brief changelog
6 |
7 | XX
8 |
9 | ## Verifying this change
10 |
11 | XXXX
--------------------------------------------------------------------------------
/femas-adaptor/femas-adaptor-opensource-admin/src/main/resources/META-INF/services/com.tencent.tsf.femas.common.context.Context:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.common.context.FemasContext
--------------------------------------------------------------------------------
/femas-config-impl/femas-config-consul/src/main/resources/META-INF/services/com.tencent.tsf.femas.config.ConfigFactory:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.config.impl.consul.ConsulConfigFactory
--------------------------------------------------------------------------------
/femas-config-impl/femas-config-nacos/src/main/resources/META-INF/services/com.tencent.tsf.femas.config.ConfigFactory:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.config.impl.nacos.FemasNacosConfigFactory
--------------------------------------------------------------------------------
/femas-config-impl/femas-config-nacos/src/main/resources/META-INF/services/com.tencent.tsf.femas.config.FemasConfigManager:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.config.impl.nacos.FemasNacosConfigManager
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/resources/META-INF/services/com.tencent.tsf.femas.governance.ratelimit.RateLimiter:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.governance.ratelimit.impl.SlidingWindowRateLimiter
--------------------------------------------------------------------------------
/femas-adaptor/femas-adaptor-opensource-admin/src/main/resources/META-INF/services/com.tencent.tsf.femas.common.context.ContextConstant:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.adaptor.paas.common.FemasConstant
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/resources/META-INF/services/com.tencent.tsf.femas.governance.circuitbreaker.ICircuitBreakerService:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.governance.circuitbreaker.service.CircuitBreakerService
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/resources/META-INF/services/com.tencent.tsf.femas.governance.metrics.MetricsTransformer:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.governance.metrics.micrometer.transformer.FemasMetricsTransformer
--------------------------------------------------------------------------------
/femas-adaptor/femas-adaptor-opensource-admin/src/main/resources/META-INF/services/com.tencent.tsf.femas.config.AbstractConfigHttpClientManager:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.adaptor.paas.config.FemasConfigHttpClientManager
--------------------------------------------------------------------------------
/femas-adaptor/femas-adaptor-opensource-admin/src/main/resources/META-INF/services/com.tencent.tsf.femas.governance.ratelimit.RateLimiter:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.adaptor.paas.governance.ratelimiter.FemasRateLimiter
--------------------------------------------------------------------------------
/femas-adaptor/femas-adaptor-opensource-admin/src/main/resources/META-INF/services/com.tencent.tsf.femas.common.serviceregistry.AbstractServiceRegistryMetadata:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.adaptor.paas.registry.FemasRegistry
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-k8s/src/main/resources/META-INF/services/com.tencent.tsf.femas.common.discovery.ServiceDiscoveryFactory:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.registry.impl.k8s.discovery.K8sServiceDiscoveryFactory
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-consul/src/main/resources/META-INF/services/com.tencent.tsf.femas.common.discovery.ServiceDiscoveryFactory:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.registry.impl.consul.discovery.ConsulServiceDiscoveryFactory
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-eureka/src/main/resources/META-INF/services/com.tencent.tsf.femas.common.discovery.ServiceDiscoveryFactory:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.registry.impl.eureka.discovery.EurekaServiceDiscoveryFactory
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-nacos/src/main/resources/META-INF/services/com.tencent.tsf.femas.common.discovery.ServiceDiscoveryFactory:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.registry.impl.nacos.discovery.NacosServiceDiscoveryFactory
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/ratelimit/impl/AdaptiveRateLimiter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.ratelimit.impl;
2 |
3 | public class AdaptiveRateLimiter {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-k8s/src/main/resources/META-INF/services/com.tencent.tsf.femas.common.serviceregistry.ServiceRegistryFactory:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.registry.impl.k8s.serviceregistry.K8sServiceRegistryFactory
--------------------------------------------------------------------------------
/femas-common/src/test/java/com/tencent/tsf/femas/common/statistic/SecondsSlidingTimeWindowMetricsTest.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.statistic;
2 |
3 | public class SecondsSlidingTimeWindowMetricsTest {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/femas-config/src/main/java/com/tencent/tsf/femas/config/enums/PropertyChangeType.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.config.enums;
2 |
3 | public enum PropertyChangeType {
4 | ADDED,
5 | MODIFIED,
6 | DELETED
7 | }
8 |
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-consul/src/main/resources/META-INF/services/com.tencent.tsf.femas.common.serviceregistry.ServiceRegistryFactory:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.registry.impl.consul.serviceregistry.ConsulServiceRegistryFactory
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-eureka/src/main/resources/META-INF/services/com.tencent.tsf.femas.common.serviceregistry.ServiceRegistryFactory:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.registry.impl.eureka.serviceregistry.EurekaServiceRegistryFactory
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-nacos/src/main/resources/META-INF/services/com.tencent.tsf.femas.common.serviceregistry.ServiceRegistryFactory:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.registry.impl.nacos.serviceregistry.NacosServiceRegistryFactory
--------------------------------------------------------------------------------
/Code-of-Conduct-zh.md:
--------------------------------------------------------------------------------
1 | # Femas社区行为准则
2 |
3 | **Femas社区成员和参与其中的每个人都遵守[CNCF行为准则](https://github.com/cncf/foundation/blob/master/code-of-conduct.md)。**
4 |
5 | 如果遇到辱骂、骚扰或其他不可接受的行为,可以通过电子邮件联系 Femas 行为准则委员会报告,
6 | 邮箱地址:femas_community@qq.com
--------------------------------------------------------------------------------
/entrypoint.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 | cd /usr/local/src/femas
5 | BOOTSTRAP=$(find /usr/local/src/femas -regex ".*/femas-admin-starter-.*/startup.sh$")
6 | bash ${BOOTSTRAP}
7 | tail -f $(dirname ${BOOTSTRAP})/../logs/*.out
8 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/ratelimit/impl/SemaphoreBasedRateLimiter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.ratelimit.impl;
2 |
3 | public class SemaphoreBasedRateLimiter {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/ratelimit/impl/AccessTokenClusterRateLimiter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.ratelimit.impl;
2 |
3 | public class AccessTokenClusterRateLimiter {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/ratelimit/impl/AssignTokenClusterRateLimiter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.ratelimit.impl;
2 |
3 | public class AssignTokenClusterRateLimiter {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/annotation/AdaptorComponent.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.annotation;
2 |
3 | /**
4 | * 此注解用来标示该类需要再Adaptor层进行封装与适配
5 | */
6 | public @interface AdaptorComponent {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/femas-extensions/femas-extension-springcloud/femas-extension-springcloud-greenwich-zuul/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2 | com.tencent.tsf.femas.extension.zuul.filter.FemasRibbonRoutingFilter
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/resources/META-INF/services/com.tencent.tsf.femas.governance.metrics.MetricsExporter:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.governance.metrics.micrometer.exporter.logger.LoggerMeterExporter
2 | com.tencent.tsf.femas.governance.metrics.micrometer.exporter.PrometheusMeterExporter
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/callback/SendableResponseCallback.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.callback;
2 |
3 | /**
4 | * 表示是一个异步可链路返回的Callback
5 | *
6 | */
7 | public interface SendableResponseCallback extends FemasCallback {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/version/Version.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.version;
2 |
3 |
4 | public final class Version {
5 |
6 | /**
7 | * 当前RPC版本,例如: 5.6.7
8 | */
9 | public static final String RPC_VERSION = "0.0.1";
10 | }
11 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/base/Sortable.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.base;
2 |
3 | /**
4 | * 可排序的接口
5 | */
6 | public interface Sortable {
7 |
8 | /**
9 | * 得到顺序
10 | *
11 | * @return 顺序
12 | */
13 | int getOrder();
14 | }
15 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/api/entity/OpenApiPath.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.api.entity;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public class OpenApiPath {
7 |
8 | public Map post = new HashMap();
9 | }
10 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/api/entity/OpenApiEntity.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.api.entity;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public class OpenApiEntity {
7 |
8 | public Map paths = new HashMap();
9 | }
10 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/api/entity/OpenApiParameters.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.api.entity;
2 |
3 | public class OpenApiParameters {
4 |
5 | public String name;
6 | public String in = "query";
7 | public boolean required = true;
8 | }
9 |
--------------------------------------------------------------------------------
/femas-config/src/main/resources/femas-default.conf:
--------------------------------------------------------------------------------
1 | femas_registry_ip: 127.0.0.1
2 | femas_registry_port: 8500
3 | femas_registry_type: consul
4 | #paas_server_address: http://127.0.0.1:8080
5 | monitor.log.path: /data/femas_apm/monitor/logs
6 | trace.log.path: /data/femas_apm/trace/logs
7 | femas.sdk.client.version: 1.0.0
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/spi/SpiExtensionClass.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.spi;
2 |
3 | public interface SpiExtensionClass {
4 |
5 | String getType();
6 |
7 | default String getName() {
8 | return this.getClass().getName();
9 | }
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/httpclient/HttpClientRequest.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.httpclient;
2 |
3 | /**
4 | * @Author leoziltong
5 | * @Description //TODO
6 | * @Date: 2021/3/29 11:21
7 | * @Version 1.0
8 | */
9 | public interface HttpClientRequest {
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/resources/META-INF/services/com.tencent.tsf.femas.governance.loadbalance.Loadbalancer:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.governance.loadbalance.impl.RandomLoadbalancer
2 | com.tencent.tsf.femas.governance.loadbalance.impl.RoundRobinLoadbalancer
3 | com.tencent.tsf.femas.governance.loadbalance.impl.TagBasedLoadbalancer
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/util/id/KeyGenerator.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.util.id;
2 |
3 | /**
4 | * @Author leoziltong
5 | * @Description //TODO
6 | * @Date: 2021/3/31 15:13
7 | * @Version 1.0
8 | */
9 | public interface KeyGenerator {
10 |
11 | long generate();
12 | }
13 |
--------------------------------------------------------------------------------
/femas-registry/src/main/java/com/tencent/tsf/femas/common/RegistryEnum.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common;
2 |
3 | /**
4 | * @Author leoziltong
5 | * @Description //TODO
6 | * @Date: 2021/3/23 20:36
7 | * @Version 1.0
8 | */
9 | public enum RegistryEnum {
10 | CONSUL, EUREKA, NACOS, KUBERNETES, POLARIS;
11 | }
12 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/resources/META-INF/services/com.tencent.tsf.femas.governance.metrics.IMeterRegistry:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.governance.metrics.micrometer.registry.GovernanceMeterRegistry
2 | com.tencent.tsf.femas.governance.metrics.micrometer.registry.JmxMeterRegistry
3 | com.tencent.tsf.femas.governance.metrics.micrometer.registry.RpcMeterRegistry
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/metrics/DistributionSummary.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.metrics;
2 |
3 | /**
4 | * @Author p_mtluo
5 | * @Date 2021-08-17 20:05
6 | * @Description TODO
7 | **/
8 | public interface DistributionSummary extends Meter {
9 |
10 | void record(double amount);
11 | }
12 |
--------------------------------------------------------------------------------
/Code-of-Conduct.md:
--------------------------------------------------------------------------------
1 | # Femas Community Code of Conduct
2 |
3 | **Femas and everyone participating in it follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).**
4 |
5 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the Femas Code of Conduct Committee via email:femas_community@qq.com
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/metrics/LongTaskTimer.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.metrics;
2 |
3 | /**
4 | * @Author p_mtluo
5 | * @Date 2021-08-17 20:12
6 | * @Description TODO
7 | **/
8 | public interface LongTaskTimer extends Meter {
9 |
10 | N start();
11 |
12 | long stop(long task);
13 | }
14 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/api/entity/OpenApiResponse.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.api.entity;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | /**
7 | * TODO
8 | *
9 | * need refactor
10 | */
11 | public class OpenApiResponse {
12 |
13 | public Map responses = new HashMap();
14 | }
15 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/metrics/Counter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.metrics;
2 |
3 | /**
4 | * @Author p_mtluo
5 | * @Date 2021-08-17 20:09
6 | * @Description TODO
7 | **/
8 | public interface Counter extends Meter {
9 |
10 | void increment(double amount);
11 |
12 | void increment();
13 | }
14 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/metrics/Meter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.metrics;
2 |
3 | /**
4 | * @Author p_mtluo
5 | * @Date 2021-08-17 17:06
6 | * @Description TODO
7 | **/
8 | public interface Meter {
9 |
10 | T getMeter();
11 |
12 | MeterEnum getMeterType();
13 |
14 | String getMeterName();
15 | }
16 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/tag/TagRuleGroup.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.tag;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * TODO
7 | * 暂时又各个治理模块自己实现
8 | */
9 | public class TagRuleGroup {
10 |
11 | List rules;
12 |
13 | /**
14 | * 规则运算表达式
15 | * 默认是或
16 | */
17 | private String expression;
18 | }
19 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/util/id/GeneratorEnum.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.util.id;
2 |
3 | /**
4 | * @Author leoziltong
5 | * @Description //TODO
6 | * @Date: 2021/3/31 15:13
7 | * @Version 1.0
8 | */
9 | public enum GeneratorEnum {
10 |
11 | IP,
12 | HOST,
13 | IP_SECTION;
14 |
15 | GeneratorEnum() {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/metrics/Timer.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.metrics;
2 |
3 | import java.util.concurrent.TimeUnit;
4 |
5 | /**
6 | * @Author p_mtluo
7 | * @Date 2021-08-17 17:55
8 | * @Description TODO
9 | **/
10 | public interface Timer extends Meter {
11 |
12 | void record(long amount, TimeUnit unit);
13 | }
14 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/ratelimit/entity/RateLimiterRuleGroup.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.ratelimit.entity;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 |
6 | public class RateLimiterRuleGroup implements Serializable {
7 |
8 | /**
9 | * 规则列表
10 | */
11 | private List rules;
12 | }
13 |
--------------------------------------------------------------------------------
/femas-config/src/main/java/com/tencent/tsf/femas/config/ConfigFactory.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.config;
2 |
3 | import com.tencent.tsf.femas.common.annotation.SPI;
4 | import com.tencent.tsf.femas.common.spi.SpiExtensionClass;
5 | import java.util.Map;
6 |
7 | @SPI
8 | public interface ConfigFactory extends SpiExtensionClass {
9 |
10 | Config create(Map configMap);
11 | }
12 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/statistic/Measurement.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.statistic;
2 |
3 | class Measurement extends AbstractAggregation {
4 |
5 | void reset() {
6 | this.totalDurationInMillis = 0;
7 | this.numberOfSlowCalls.reset();
8 | this.numberOfFailedCalls.reset();
9 | this.numberOfCalls.reset();
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/tag/exception/TagEngineException.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.tag.exception;
2 |
3 | import java.text.MessageFormat;
4 |
5 | public class TagEngineException extends RuntimeException {
6 |
7 | public TagEngineException(String messageFmt, Object... args) {
8 | super(new MessageFormat(messageFmt).format(args));
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/femas-config/src/main/java/com/tencent/tsf/femas/config/util/parser/ParserException.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.config.util.parser;
2 |
3 | public class ParserException extends Exception {
4 |
5 | public ParserException(String message) {
6 | super(message);
7 | }
8 |
9 | public ParserException(String message, Throwable cause) {
10 | super(message, cause);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/femas-config-impl/femas-config-consul/src/main/java/com/tencent/tsf/femas/config/impl/consul/ConsulConstants.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.config.impl.consul;
2 |
3 | public class ConsulConstants {
4 |
5 | public static final String REGISTRY_HOST = "registryHost";
6 | public static final String REGISTRY_PORT = "registryPort";
7 | public static final String CONSUL_ACCESS_TOKEN = "consulAccessToken";
8 | }
9 |
--------------------------------------------------------------------------------
/femas-helm/templates/serviceaccount.yaml:
--------------------------------------------------------------------------------
1 | {{- if .Values.serviceAccount.create -}}
2 | apiVersion: v1
3 | kind: ServiceAccount
4 | metadata:
5 | name: {{ include "femas-helm.serviceAccountName" . }}
6 | labels:
7 | {{- include "femas-helm.labels" . | nindent 4 }}
8 | {{- with .Values.serviceAccount.annotations }}
9 | annotations:
10 | {{- toYaml . | nindent 4 }}
11 | {{- end }}
12 | {{- end }}
13 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/tag/TagExpression.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.tag;
2 |
3 | /**
4 | * 与逻辑
5 | * 或逻辑
6 | * 复合自定义逻辑
7 | * 暂不支持
8 | */
9 | public class TagExpression {
10 |
11 | public static final String RELATION_AND = "and";
12 |
13 | public static final String RELATION_OR = "or";
14 |
15 | public static final String RELATION_COMPOSITE = "composite";
16 | }
17 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/circuitbreaker/FemasCircuitBreakerIsolationLevelEnum.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.circuitbreaker;
2 |
3 |
4 | /**
5 | * 熔断级别
6 | *
7 | * @author zhixinzxliu
8 | */
9 | public enum FemasCircuitBreakerIsolationLevelEnum {
10 | // 服务级别熔断
11 | SERVICE,
12 |
13 | // API级别熔断
14 | API,
15 |
16 | // 实例级别熔断
17 | INSTANCE
18 | }
19 |
--------------------------------------------------------------------------------
/femas-adaptor/femas-adaptor-opensource-admin/src/main/java/com/tencent/tsf/femas/adaptor/paas/governance/lane/RuleTagRelationship.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.adaptor.paas.governance.lane;
2 |
3 | /**
4 | * User: MackZhang
5 | * Date: 2020/2/12
6 | */
7 | public enum RuleTagRelationship {
8 | /**
9 | * 与
10 | */
11 | RELEATION_AND,
12 |
13 | /**
14 | * 或
15 | */
16 | RELEATION_OR;
17 | }
18 |
--------------------------------------------------------------------------------
/femas-config/src/main/java/com/tencent/tsf/femas/config/exception/FemasConfigException.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.config.exception;
2 |
3 | public class FemasConfigException extends RuntimeException {
4 |
5 | public FemasConfigException(String message) {
6 | super(message);
7 | }
8 |
9 | public FemasConfigException(String message, Throwable cause) {
10 | super(message, cause);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/invoke/Invoker.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.invoke;
2 |
3 | import com.tencent.tsf.femas.common.entity.Request;
4 | import com.tencent.tsf.femas.common.entity.Response;
5 |
6 | public interface Invoker {
7 |
8 | /**
9 | * 执行调用
10 | *
11 | * @param request 请求
12 | * @return Response 响应
13 | */
14 | Response invoke(Request request);
15 | }
16 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/metrics/MetricsTransformer.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.metrics;
2 |
3 | import com.tencent.tsf.femas.governance.plugin.Plugin;
4 |
5 | /**
6 | * @Author p_mtluo
7 | * @Date 2021-11-09 11:33
8 | * @Description metrics transformer
9 | **/
10 | public interface MetricsTransformer extends Plugin {
11 |
12 | default void transform() {
13 |
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/test/java/com/tencent/tsf/femas/governance/circuitbreaker/core/mockservice/HelloWorldException.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.circuitbreaker.core.mockservice;
2 |
3 | public class HelloWorldException extends RuntimeException {
4 |
5 | public HelloWorldException() {
6 | super("BAM!");
7 | }
8 |
9 | public HelloWorldException(String message) {
10 | super(message);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/event/EventTypeEnum.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.event;
2 |
3 |
4 | public enum EventTypeEnum {
5 |
6 | /**
7 | * 熔断事件
8 | */
9 | CIRCUITBREAKER,
10 |
11 | /**
12 | * 熔断事件
13 | */
14 | RATELIMIT,
15 |
16 | /**
17 | * 熔断事件
18 | */
19 | AUTH,
20 |
21 | /**
22 | * 熔断事件
23 | */
24 | ROUTER
25 | }
26 |
--------------------------------------------------------------------------------
/femas-extensions/femas-extension-springcloud/femas-extension-springcloud-greenwich-gateway/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2 | com.tencent.tsf.femas.springcloud.gateway.config.FemasDiscoveryAutoConfiguration,\
3 | com.tencent.tsf.femas.extension.springcloud.common.instrumentation.config.FemasGovernanceAutoConfiguration,\
4 | com.tencent.tsf.femas.springcloud.gateway.config.GatewayAutoConfiguration
--------------------------------------------------------------------------------
/femas-helm/.helmignore:
--------------------------------------------------------------------------------
1 | # Patterns to ignore when building packages.
2 | # This supports shell glob matching, relative path matching, and
3 | # negation (prefixed with !). Only one pattern per line.
4 | .DS_Store
5 | # Common VCS dirs
6 | .git/
7 | .gitignore
8 | .bzr/
9 | .bzrignore
10 | .hg/
11 | .hgignore
12 | .svn/
13 | # Common backup files
14 | *.swp
15 | *.bak
16 | *.tmp
17 | *.orig
18 | *~
19 | # Various IDEs
20 | .project
21 | .idea/
22 | *.tmproj
23 | .vscode/
24 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/httpclient/factory/HttpClientFactory.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.httpclient.factory;
2 |
3 | import com.tencent.tsf.femas.common.httpclient.client.AbstractHttpClient;
4 |
5 |
6 | /**
7 | * @Author leoziltong
8 | * @Description //TODO
9 | * @Date: 2021/3/29 11:03
10 | * @Version 1.0
11 | */
12 | public interface HttpClientFactory {
13 |
14 | AbstractHttpClient createHttpClient();
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/util/id/UIdGenerator.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.util.id;
2 |
3 | /**
4 | * @Author leoziltong
5 | * @Description //TODO
6 | * @Date: 2021/4/6 14:52
7 | * @Version 1.0
8 | */
9 | public class UIdGenerator {
10 |
11 | public static String generateUid() {
12 | //默认IP_SECTION方式
13 | return String.valueOf(KeyGeneratorFactory.gen(GeneratorEnum.IP_SECTION).generate());
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/femas-helm/templates/tests/test-connection.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Pod
3 | metadata:
4 | name: "{{ include "femas-helm.fullname" . }}-test-connection"
5 | labels:
6 | {{- include "femas-helm.labels" . | nindent 4 }}
7 | annotations:
8 | "helm.sh/hook": test
9 | spec:
10 | containers:
11 | - name: wget
12 | image: busybox
13 | command: ['wget']
14 | args: ['{{ include "femas-helm.fullname" . }}:{{ .Values.service.port }}']
15 | restartPolicy: Never
16 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/auth/constant/AuthConstant.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.auth.constant;
2 |
3 | public class AuthConstant {
4 |
5 | /**
6 | * 黑名单模式
7 | */
8 | public static final String BLACK_LIST = "B";
9 |
10 | /**
11 | * 白名单模式
12 | */
13 | public static final String WHITE_LIST = "W";
14 |
15 | /**
16 | * 不启用
17 | */
18 | public static final String DISABLED = "D";
19 | }
20 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/serialize/Serializer.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.serialize;
2 |
3 | /**
4 | * leoziltong
5 | * 序列化接口类
6 | */
7 | public interface Serializer {
8 |
9 |
10 | byte[] serialize(Object obj);
11 |
12 | /**
13 | * 二进制转换成 java 对象
14 | */
15 | T deserialize(Class clazz, byte[] bytes);
16 |
17 | String serializeStr(Object obj);
18 |
19 | T deserializeStr(Class clazz, String bytes);
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/femas-helm/templates/service.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Service
3 | metadata:
4 | name: {{ include "femas-helm.fullname" . }}
5 | labels:
6 | {{- include "femas-helm.labels" . | nindent 4 }}
7 | spec:
8 | type: {{ .Values.service.type }}
9 | ports:
10 | - port: {{ .Values.service.port }}
11 | targetPort: http
12 | nodePort: {{ .Values.service.port }}
13 | protocol: TCP
14 | name: http
15 | selector:
16 | {{- include "femas-helm.selectorLabels" . | nindent 4 }}
17 |
--------------------------------------------------------------------------------
/femas-config/src/main/java/com/tencent/tsf/femas/config/ConfigName.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.config;
2 |
3 | import java.lang.annotation.Documented;
4 | import java.lang.annotation.ElementType;
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.lang.annotation.Target;
8 |
9 | @Target({ElementType.TYPE, ElementType.METHOD})
10 | @Retention(RetentionPolicy.RUNTIME)
11 | @Documented
12 | public @interface ConfigName {
13 |
14 | String value() default "";
15 | }
--------------------------------------------------------------------------------
/femas-adaptor/femas-adaptor-opensource-admin/src/main/resources/META-INF/services/com.tencent.tsf.femas.governance.plugin.config.ConfigHandler:
--------------------------------------------------------------------------------
1 | com.tencent.tsf.femas.adaptor.paas.governance.auth.FemasAuthHandler
2 | com.tencent.tsf.femas.adaptor.paas.governance.circuitbreaker.FemasCircuitBreakerHandler
3 | com.tencent.tsf.femas.adaptor.paas.governance.loadbalance.FemasLoadBalancerHandler
4 | com.tencent.tsf.femas.adaptor.paas.governance.ratelimiter.FemasRateLimiterHandler
5 | com.tencent.tsf.femas.adaptor.paas.governance.router.FemasRouterHandler
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/ratelimit/constant/RateLimiterConstant.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.ratelimit.constant;
2 |
3 | public class RateLimiterConstant {
4 |
5 | public static final int RATE_LIMITER_TYPE_QPS = 0;
6 | public static final int RATE_LIMITER_TYPE_WARM_UP = 1;
7 | public static final int RATE_LIMITER_TYPE_STEADY = 2;
8 | public static final int CONTROL_BEHAVIOR_WARM_UP_QPS = 3;
9 | public static final int CONTROL_BEHAVIOR_WARM_UP_STEADY = 4;
10 | }
11 |
--------------------------------------------------------------------------------
/femas-registry/src/main/java/com/tencent/tsf/femas/common/serviceregistry/ServiceRegistryFactory.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.serviceregistry;
2 |
3 | import com.tencent.tsf.femas.common.annotation.SPI;
4 | import com.tencent.tsf.femas.common.spi.SpiExtensionClass;
5 | import java.util.Map;
6 |
7 | /**
8 | * 通过SPI注册的注册中心生成
9 | *
10 | * @author zhixinzxliu
11 | */
12 | @SPI
13 | public interface ServiceRegistryFactory extends SpiExtensionClass {
14 |
15 | ServiceRegistry getServiceRegistry(Map configMap);
16 | }
17 |
--------------------------------------------------------------------------------
/femas-extensions/femas-extension-springcloud/femas-extension-springcloud-2020.0-ilford/src/main/java/com/tencent/tsf/femas/extension/springcloud/ilford/discovery/loadbalancer/FemasServiceFilterLoadBalancer.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.extension.springcloud.ilford.discovery.loadbalancer;
2 |
3 | import org.springframework.cloud.client.ServiceInstance;
4 |
5 |
6 | public interface FemasServiceFilterLoadBalancer {
7 |
8 | void beforeChooseServer(Object key);
9 |
10 | void afterChooseServer(ServiceInstance server, Object key);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/lane/LaneFilter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.lane;
2 |
3 | import com.tencent.tsf.femas.common.entity.Service;
4 | import com.tencent.tsf.femas.common.entity.ServiceInstance;
5 | import com.tencent.tsf.femas.governance.plugin.Plugin;
6 | import java.util.List;
7 |
8 | public interface LaneFilter extends Plugin {
9 |
10 | void preProcessLaneId();
11 |
12 | List filterInstancesWithLane(Service service, List serviceInstances);
13 | }
14 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/plugin/config/gov/MetricsTransformerConfig.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.plugin.config.gov;
2 |
3 | import com.tencent.tsf.femas.governance.plugin.config.PluginConfig;
4 | import com.tencent.tsf.femas.governance.plugin.config.verify.Verifier;
5 |
6 | /**
7 | * @Author p_mtluo
8 | * @Date 2021-11-09 16:26
9 | * @Description metrics transformer config
10 | **/
11 | public interface MetricsTransformerConfig extends PluginConfig, Verifier {
12 |
13 | String getType();
14 | }
15 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/test/java/com/tencent/tsf/femas/governance/circuitbreaker/core/mockservice/AsyncHelloWorldService.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.circuitbreaker.core.mockservice;
2 |
3 | import java.util.concurrent.CompletionStage;
4 |
5 | public interface AsyncHelloWorldService {
6 |
7 | CompletionStage returnHelloWorld();
8 |
9 | CompletionStage returnHelloWorldWithName(String name);
10 |
11 | CompletionStage sayHelloWorld();
12 |
13 | CompletionStage sayHelloWorldWithName(String name);
14 | }
15 |
--------------------------------------------------------------------------------
/femas-adaptor/femas-adaptor-opensource-admin/src/main/java/com/tencent/tsf/femas/adaptor/paas/logger/ConverterBase.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.adaptor.paas.logger;
2 |
3 | public interface ConverterBase {
4 |
5 | /**
6 | * MDC Map为空时的默认值
7 | */
8 | String DEFAULT_VALUE = "[,,,]";
9 |
10 | /**
11 | * value为空时的默认值
12 | */
13 | String DEFAULT_SINGLE_VALUE = "";
14 |
15 | /**
16 | * MDC中获取traceid、spanid、span-export的key
17 | */
18 | String[] MDC_KEYS = new String[]{"X-B3-TraceId", "X-B3-SpanId", "X-Span-Export"};
19 | }
20 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-provider/src/main/resources/bootstrap.yaml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 19001
3 | spring:
4 | application:
5 | name: femas-springcloud-provider
6 | cloud:
7 | nacos:
8 | discovery:
9 | server-addr: 127.0.0.1:8848
10 | username: nacos
11 | password: nacos
12 | config:
13 | server-addr: 127.0.0.1:8848
14 |
15 | management:
16 | endpoints:
17 | web:
18 | exposure:
19 | include: '*'
20 |
21 | logging:
22 | file: ./log/femas/${spring.application.name}/${spring.application.name}
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/ratelimit/RateLimiter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.ratelimit;
2 |
3 |
4 | import com.tencent.tsf.femas.common.entity.Service;
5 | import com.tencent.tsf.femas.governance.plugin.Plugin;
6 |
7 | public interface RateLimiter extends Plugin {
8 |
9 | public boolean acquire();
10 |
11 | public void buildCollector(Service service);
12 |
13 | public boolean acquire(int permits);
14 |
15 | public void update(T rule);
16 |
17 | public void setInsId(String insId);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-gateway/src/main/resources/femas.conf:
--------------------------------------------------------------------------------
1 | serviceRouter:
2 | chain:
3 | - FemasDefaultRoute
4 | loadbalancer:
5 | type: random
6 | circuitBreaker:
7 | enable: true
8 | chain:
9 | - femasCircuitBreaker
10 | # plugin:
11 | # femasCircuitBreaker:
12 | # continuousErrorThreshold: 10
13 | # metricStatTimeWindow: 1s
14 | # requestCountAfterHalfOpen: 3
15 | # sleepWindow: 5s
16 | # successCountAfterHalfOpen: 2
17 |
18 | rateLimit:
19 | type: femasRateLimit
20 | authenticate:
21 | type: femasAuthenticate
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-provider/src/main/resources/nacos/bootstrap.yaml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 19001
3 | spring:
4 | application:
5 | name: femas-springcloud-provider
6 | cloud:
7 | nacos:
8 | discovery:
9 | server-addr: 127.0.0.1:8848
10 | username: nacos
11 | password: nacos
12 | config:
13 | server-addr: 127.0.0.1:8848
14 |
15 | management:
16 | endpoints:
17 | web:
18 | exposure:
19 | include: '*'
20 |
21 | logging:
22 | file: ./log/femas/${spring.application.name}/${spring.application.name}
--------------------------------------------------------------------------------
/femas-extensions/femas-extension-springcloud/femas-extension-springcloud-greenwich/src/main/java/com/tencent/tsf/femas/extension/springcloud/discovery/ribbon/FemasServiceFilterLoadBalancer.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.extension.springcloud.discovery.ribbon;
2 |
3 | import com.netflix.loadbalancer.Server;
4 | import java.util.List;
5 |
6 |
7 | public interface FemasServiceFilterLoadBalancer {
8 |
9 | void beforeChooseServer(Object key);
10 |
11 | void afterChooseServer(Server server, Object key);
12 |
13 | List filterAllServer(List servers);
14 | }
15 |
--------------------------------------------------------------------------------
/femas-registry/src/main/java/com/tencent/tsf/femas/common/discovery/ServiceNotifyListener.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.discovery;
2 |
3 | import com.tencent.tsf.femas.common.entity.Service;
4 | import com.tencent.tsf.femas.common.entity.ServiceInstance;
5 | import java.util.List;
6 |
7 | public interface ServiceNotifyListener {
8 |
9 | void notify(Service service, List instances);
10 |
11 | void notifyOnRemoved(Service service, List instances);
12 |
13 | void notifyOnAdded(Service service, List instances);
14 | }
15 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/exception/FemasRuntimeException.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.exception;
2 |
3 | public class FemasRuntimeException extends RuntimeException {
4 |
5 | protected FemasRuntimeException() {
6 |
7 | }
8 |
9 | public FemasRuntimeException(String message) {
10 | super(message);
11 | }
12 |
13 | public FemasRuntimeException(String message, Throwable cause) {
14 | super(message, cause);
15 | }
16 |
17 | public FemasRuntimeException(Throwable cause) {
18 | super(cause);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-2020-consumer/src/main/resources/femas.conf:
--------------------------------------------------------------------------------
1 | serviceRouter:
2 | chain:
3 | - FemasDefaultRoute
4 |
5 | rateLimit:
6 | type: femasRateLimit
7 |
8 | authenticate:
9 | type: femasAuthenticate
10 |
11 | loadbalancer:
12 | type: random
13 |
14 | circuitBreaker:
15 | enable: true
16 | chain:
17 | - femasCircuitBreaker
18 |
19 | # plugin:
20 | # femasCircuitBreaker:
21 | # continuousErrorThreshold: 10
22 | # metricStatTimeWindow: 1s
23 | # requestCountAfterHalfOpen: 3
24 | # sleepWindow: 5s
25 | # successCountAfterHalfOpen: 2
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-2020-provider/src/main/resources/femas.conf:
--------------------------------------------------------------------------------
1 | serviceRouter:
2 | chain:
3 | - FemasDefaultRoute
4 |
5 | rateLimit:
6 | type: femasRateLimit
7 |
8 | authenticate:
9 | type: femasAuthenticate
10 |
11 | loadbalancer:
12 | type: random
13 |
14 | circuitBreaker:
15 | enable: true
16 | chain:
17 | - femasCircuitBreaker
18 |
19 | # plugin:
20 | # femasCircuitBreaker:
21 | # continuousErrorThreshold: 10
22 | # metricStatTimeWindow: 1s
23 | # requestCountAfterHalfOpen: 3
24 | # sleepWindow: 5s
25 | # successCountAfterHalfOpen: 2
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/loadbalance/Loadbalancer.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.loadbalance;
2 |
3 | import com.tencent.tsf.femas.common.entity.ServiceInstance;
4 | import com.tencent.tsf.femas.governance.plugin.Plugin;
5 | import java.util.List;
6 |
7 | /**
8 | * @author zhixinzxliu
9 | */
10 | public interface Loadbalancer extends Plugin {
11 |
12 | /**
13 | * 给定一组服务节点,根据负载算法,选择一台服务节点
14 | *
15 | * @param serviceInstances
16 | * @return
17 | */
18 | ServiceInstance select(List serviceInstances);
19 | }
20 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/annotation/VisibleForTesting.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.annotation;
2 |
3 | import java.lang.annotation.Documented;
4 | import java.lang.annotation.ElementType;
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.lang.annotation.Target;
8 |
9 | /**
10 | * 代表这个只是为了测试用例才开放的
11 | */
12 | @Documented
13 | @Retention(RetentionPolicy.SOURCE)
14 | @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR})
15 | public @interface VisibleForTesting {
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/loadbalance/exception/FemasNoAvailableInstanceException.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.loadbalance.exception;
2 |
3 | public class FemasNoAvailableInstanceException extends RuntimeException {
4 |
5 | public FemasNoAvailableInstanceException() {
6 | super();
7 | }
8 |
9 | public FemasNoAvailableInstanceException(String message) {
10 | super(message);
11 | }
12 |
13 | public FemasNoAvailableInstanceException(String message, Throwable cause) {
14 | super(message, cause);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/plugin/context/ConfigContext.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.plugin.context;
2 |
3 | import com.tencent.tsf.femas.governance.plugin.config.Configuration;
4 |
5 | /**
6 | * 插件初始化相关的上下文接口
7 | *
8 | * @author leoziltong
9 | */
10 | public class ConfigContext extends ContextAware {
11 |
12 | private final Configuration config;
13 |
14 | public ConfigContext(Configuration config) {
15 | this.config = config;
16 | }
17 |
18 | public Configuration getConfig() {
19 | return config;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/statistic/SecondsSlidingTimeWindowMetrics.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.statistic;
2 |
3 | public class SecondsSlidingTimeWindowMetrics extends SlidingTimeWindowMetrics {
4 |
5 | /**
6 | * Creates a new {@link SecondsSlidingTimeWindowMetrics} with the given clock and window of time.
7 | *
8 | * @param timeWindowSizeInSeconds the window time size in seconds
9 | */
10 | public SecondsSlidingTimeWindowMetrics(int timeWindowSizeInSeconds) {
11 | super(timeWindowSizeInSeconds, timeWindowSizeInSeconds * 1000);
12 | }
13 | }
--------------------------------------------------------------------------------
/femas-registry/src/main/java/com/tencent/tsf/femas/common/RegistryConstants.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common;
2 |
3 | /**
4 | * @Author leoziltong
5 | * @Description //TODO
6 | * @Date: 2021/3/24 15:31
7 | * @Version 1.0
8 | */
9 | public class RegistryConstants {
10 |
11 | public static final String REGISTRY_HOST = "registryHost";
12 |
13 | public static final String REGISTRY_PORT = "registryPort";
14 |
15 | public static final String REGISTRY_TYPE = "registryType";
16 |
17 |
18 | public static final int DEFAULT_THREAD_POOL_SIZE = Runtime.getRuntime().availableProcessors();
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/femas-api/src/main/java/com/tencent/tsf/femas/api/ExtensionManager.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.api;
2 |
3 | import com.tencent.tsf.femas.common.context.ContextConstant;
4 | import com.tencent.tsf.femas.common.context.factory.ContextFactory;
5 |
6 | public class ExtensionManager {
7 |
8 | private static volatile ContextConstant contextConstant = ContextFactory.getContextConstantInstance();
9 | // 后续支持扩展
10 | private static IExtensionLayer extensionLayer = new CommonExtensionLayer();
11 |
12 | public static IExtensionLayer getExtensionLayer() {
13 | return extensionLayer;
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/femas-config-impl/femas-config-paas/src/main/java/com/tencent/tsf/femas/config/impl/paas/PaasConfigFactory.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.config.impl.paas;
2 |
3 | import com.tencent.tsf.femas.config.Config;
4 | import com.tencent.tsf.femas.config.ConfigFactory;
5 | import java.util.Map;
6 |
7 | /**
8 | * @author zhixinzxliu
9 | */
10 | public class PaasConfigFactory implements ConfigFactory {
11 |
12 | @Override
13 | public String getType() {
14 | return "paas";
15 | }
16 |
17 | @Override
18 | public Config create(Map configMap) {
19 | return new PaasConfig(configMap);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/plugin/ConfigProvider.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.plugin;
2 |
3 | import com.tencent.tsf.femas.common.annotation.SPI;
4 | import com.tencent.tsf.femas.common.spi.SpiExtensionClass;
5 | import com.tencent.tsf.femas.governance.plugin.context.ConfigContext;
6 |
7 | /**
8 | * @Author leoziltong
9 | * @Date: 2021/5/25 19:11
10 | */
11 | @SPI
12 | public interface ConfigProvider extends SpiExtensionClass {
13 |
14 | ConfigContext getPluginConfigs();
15 |
16 | /**
17 | * 插件归属
18 | *
19 | * @return
20 | */
21 | Attribute getAttr();
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # IntelliJ project files
2 | .factorypath
3 | .idea/
4 | *.iml
5 | out
6 | gen
7 |
8 | # Maven
9 | target/
10 | pom.xml.tag
11 | pom.xml.releaseBackup
12 | pom.xml.versionsBackup
13 | pom.xml.next
14 | release.properties
15 | dependency-reduced-pom.xml
16 | buildNumber.properties
17 | .mvn/timing.properties
18 | !/.mvn/wrapper/maven-wrapper.jar
19 | */.flattened-pom.xml
20 | .flattened-pom.xml
21 |
22 | # Eclipse
23 | .classpath
24 | .settings/
25 | .project
26 |
27 | /logs
28 | */logs
29 | *.log
30 |
31 | env.sh
32 |
33 | # System related
34 | *.DS_Store
35 | Thumbs.db
36 |
37 |
38 | # Atom console
39 | node_modules
40 | dist
41 | .vscode
42 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM hub.grepcode.cn:55582/basic/ubuntu:20.04
2 |
3 | LABEL maintainer "minghhou "
4 |
5 | ENV BUILD_MODE="docker"
6 |
7 | RUN sed -i 's/archive.ubuntu.com/mirrors.tencent.com/g' /etc/apt/sources.list && \
8 | sed -i 's/security.ubuntu.com/mirrors.tencent.com/g' /etc/apt/sources.list
9 |
10 | RUN apt update && apt install openjdk-8-jdk maven iproute2 -y
11 |
12 | COPY ./ /usr/local/src/femas
13 |
14 | RUN echo "start build docker" && cd /usr/local/src/femas && mvn -Dmaven.test.skip=true clean install -U
15 |
16 | COPY ./entrypoint.sh /entrypoint.sh
17 |
18 | RUN chmod +x /entrypoint.sh
19 |
20 | ENTRYPOINT /entrypoint.sh
21 |
22 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/exception/FemasRegisterDescribeException.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.exception;
2 |
3 | public class FemasRegisterDescribeException extends RuntimeException {
4 |
5 |
6 | protected FemasRegisterDescribeException() {
7 |
8 | }
9 |
10 | public FemasRegisterDescribeException(String message) {
11 | super(message);
12 | }
13 |
14 | public FemasRegisterDescribeException(String message, Throwable cause) {
15 | super(message, cause);
16 | }
17 |
18 | public FemasRegisterDescribeException(Throwable cause) {
19 | super(cause);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/circuitbreaker/core/StateTransitionCallback.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.circuitbreaker.core;
2 |
3 | import com.tencent.tsf.femas.governance.circuitbreaker.ICircuitBreakerService;
4 | import com.tencent.tsf.femas.governance.circuitbreaker.core.internal.CircuitBreakerMetrics;
5 |
6 | public abstract class StateTransitionCallback {
7 |
8 | public abstract void onTransition(ICircuitBreakerService.State from, ICircuitBreakerService.State to,
9 | Object circuitBreakerObject, CircuitBreakerMetrics metrics,
10 | CircuitBreaker circuitBreaker);
11 | }
12 |
--------------------------------------------------------------------------------
/femas-config-impl/femas-config-consul/src/main/java/com/tencent/tsf/femas/config/impl/consul/ConsulConfigFactory.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.config.impl.consul;
2 |
3 | import com.tencent.tsf.femas.config.Config;
4 | import com.tencent.tsf.femas.config.ConfigFactory;
5 | import java.util.Map;
6 |
7 | /**
8 | * @author zhixinzxliu
9 | */
10 | public class ConsulConfigFactory implements ConfigFactory {
11 |
12 | @Override
13 | public String getType() {
14 | return "consul";
15 | }
16 |
17 | @Override
18 | public Config create(Map configMap) {
19 | return new ConsulConfig(configMap);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-consumer/src/main/resources/femas.conf:
--------------------------------------------------------------------------------
1 |
2 | # paas_server_address: http://localhost:8080
3 |
4 | rateLimit:
5 | type: femasRateLimit
6 |
7 | authenticate:
8 | type: femasAuthenticate
9 |
10 | serviceRouter:
11 | chain:
12 | - FemasDefaultRoute
13 |
14 |
15 | loadbalancer:
16 | type: random
17 |
18 | circuitBreaker:
19 | enable: true
20 | chain:
21 | - femasCircuitBreaker
22 | # plugin:
23 | # femasCircuitBreaker:
24 | # continuousErrorThreshold: 10
25 | # metricStatTimeWindow: 1s
26 | # requestCountAfterHalfOpen: 3
27 | # sleepWindow: 5s
28 | # successCountAfterHalfOpen: 2
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-provider/src/main/resources/femas.conf:
--------------------------------------------------------------------------------
1 |
2 | # paas_server_address: http://localhost:8080
3 |
4 | rateLimit:
5 | type: femasRateLimit
6 |
7 | authenticate:
8 | type: femasAuthenticate
9 |
10 | serviceRouter:
11 | chain:
12 | - FemasDefaultRoute
13 |
14 |
15 | loadbalancer:
16 | type: random
17 |
18 | circuitBreaker:
19 | enable: true
20 | chain:
21 | - femasCircuitBreaker
22 | # plugin:
23 | # femasCircuitBreaker:
24 | # continuousErrorThreshold: 10
25 | # metricStatTimeWindow: 1s
26 | # requestCountAfterHalfOpen: 3
27 | # sleepWindow: 5s
28 | # successCountAfterHalfOpen: 2
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-zuul/src/main/resources/femas.conf:
--------------------------------------------------------------------------------
1 |
2 | # paas_server_address: http://localhost:8080
3 |
4 | rateLimit:
5 | type: femasRateLimit
6 |
7 | authenticate:
8 | type: femasAuthenticate
9 |
10 | serviceRouter:
11 | chain:
12 | - FemasDefaultRoute
13 | -
14 |
15 | loadbalancer:
16 | type: random
17 |
18 | circuitBreaker:
19 | enable: true
20 | chain:
21 | - femasCircuitBreaker
22 | # plugin:
23 | # femasCircuitBreaker:
24 | # continuousErrorThreshold: 10
25 | # metricStatTimeWindow: 1s
26 | # requestCountAfterHalfOpen: 3
27 | # sleepWindow: 5s
28 | # successCountAfterHalfOpen: 2
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/metrics/micrometer/exporter/PrometheusPropertiesConfigAdapter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.metrics.micrometer.exporter;
2 |
3 | import io.micrometer.prometheus.PrometheusConfig;
4 |
5 | /**
6 | * @Author p_mtluo
7 | * @Date 2021-08-18 16:54
8 | * @Description prometheus 配置类
9 | **/
10 | public class PrometheusPropertiesConfigAdapter implements PrometheusConfig {
11 |
12 | @Override
13 | public String get(String key) {
14 | return null;
15 | }
16 |
17 | @Override
18 | public String prefix() {
19 | return "femas.metrics.export.prometheus";
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/femas-config-impl/femas-config-paas/src/main/java/com/tencent/tsf/femas/config/impl/paas/PaasConstants.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.config.impl.paas;
2 |
3 | public class PaasConstants {
4 |
5 | /**
6 | * 不建议中间件地址配置成IP PORT形式,建议直接配置域名,防止IP漂移。
7 | */
8 | public static final String PAAS_SERVER_ADDRESS = "paas_server_address";
9 | public static final String SDK_CLIENT_VERSION = "femas.sdk.client.version";
10 |
11 | public static final String KEY = "key";
12 | public static final String NAMESPACE_ID = "namespaceId";
13 | public static final String SERVICE_NAME = "serviceName";
14 | public static final String GROUP_NAME = "groupName";
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-provider/src/main/resources/consul/bootstrap.yaml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 19001
3 | spring:
4 | application:
5 | name: femas-springcloud-provider
6 | cloud:
7 | consul:
8 | host: 127.0.0.1
9 | port: 8500
10 | discovery:
11 | serviceName: femas-springcloud-provider
12 | instanceId: ${spring.application.name}-${server.port}-${spring.cloud.client.hostname}
13 | heartbeat:
14 | enabled: true
15 |
16 | management:
17 | endpoints:
18 | web:
19 | exposure:
20 | include: '*'
21 |
22 | logging:
23 | file: ./log/femas/${spring.application.name}/${spring.application.name}
--------------------------------------------------------------------------------
/femas-adaptor/femas-adaptor-opensource-admin/src/main/java/com/tencent/tsf/femas/adaptor/paas/governance/circuitbreaker/event/EventResponse.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.adaptor.paas.governance.circuitbreaker.event;
2 |
3 | public class EventResponse {
4 |
5 | private Integer retCode;
6 | private String retMsg;
7 |
8 | public Integer getRetCode() {
9 | return retCode;
10 | }
11 |
12 | public void setRetCode(Integer retCode) {
13 | this.retCode = retCode;
14 | }
15 |
16 | public String getRetMsg() {
17 | return retMsg;
18 | }
19 |
20 | public void setRetMsg(String retMsg) {
21 | this.retMsg = retMsg;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/femas-extensions/femas-extension-springcloud/femas-extension-springcloud-common/src/main/java/com/tencent/tsf/femas/extension/springcloud/common/discovery/loadbalancer/BaseDiscoveryServerConverter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.extension.springcloud.common.discovery.loadbalancer;/*
2 | /**
3 | * 所有spring cloud版本通用的converter转换器里的方法
4 | *
5 | * @Author juanyinyang
6 | */
7 |
8 | public interface BaseDiscoveryServerConverter {
9 |
10 | default String getNamespace() {
11 | return null;
12 | }
13 |
14 | default String getServiceName() {
15 | return null;
16 | }
17 |
18 | default String getVersion() {
19 | return null;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/metrics/MetricsConstant.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.metrics;
2 |
3 | /**
4 | * @Author p_mtluo
5 | * @Date 2021-08-18 01:30
6 | * @Description TODO
7 | **/
8 | public class MetricsConstant {
9 |
10 | public static final String FEMAS_HTTP_SERVER_REQUESTS = "femas.http.server.requests";
11 | public static final String FEMAS_HTTP_CLIENT_REQUESTS = "femas.http.client.requests";
12 | public static final String FEMAS_HTTP_RATELIMIT_COUNT = "femas.http.ratelimit.count";
13 |
14 | public static final String KIND_SERVER = "SERVER";
15 | public static final String KIND_CLIENT = "CLIENT";
16 | }
17 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/plugin/Lifecycle.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.plugin;
2 |
3 | import com.tencent.tsf.femas.common.exception.FemasRuntimeException;
4 | import com.tencent.tsf.femas.governance.plugin.context.ConfigContext;
5 |
6 | /**
7 | * @Author leoziltong
8 | * @Date: 2021/4/19 17:19
9 | * @Version 1.0
10 | */
11 | public interface Lifecycle {
12 |
13 | /**
14 | * 根据配置初始化配置
15 | *
16 | * @param conf
17 | * @throws FemasRuntimeException
18 | */
19 | void init(final ConfigContext conf) throws FemasRuntimeException;
20 |
21 | /**
22 | * 释放资源
23 | */
24 | void destroy();
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/plugin/PluginProvider.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.plugin;
2 |
3 | import com.tencent.tsf.femas.common.annotation.SPI;
4 | import com.tencent.tsf.femas.common.spi.SpiExtensionClass;
5 | import java.util.List;
6 |
7 | /**
8 | * @Author leoziltong
9 | * @Date: 2021/5/25 19:11
10 | */
11 | @SPI
12 | public interface PluginProvider extends SpiExtensionClass {
13 |
14 | /**
15 | * 实现充分的灵活性,实现层提供插件列表,femas不指定插件列表
16 | *
17 | * @return
18 | */
19 | List> getPluginTypes();
20 |
21 | /**
22 | * 插件归属
23 | *
24 | * @return
25 | */
26 | Attribute getAttr();
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/rule/AbstractRuleManager.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.rule;
2 |
3 | import com.tencent.tsf.femas.common.context.Context;
4 |
5 | public abstract class AbstractRuleManager {
6 |
7 | /**
8 | * 根据Rule Id匹配对象
9 | *
10 | * @param ruleId
11 | * @return
12 | */
13 | protected abstract T match(String ruleId);
14 |
15 | /**
16 | * 根据上下文Context匹配对象
17 | *
18 | * @param context
19 | * @return
20 | */
21 | protected abstract T match(Context context);
22 |
23 | /**
24 | * 将Rule装载到manager中
25 | *
26 | * @param rule
27 | */
28 | protected abstract void load(Rule rule);
29 | }
30 |
--------------------------------------------------------------------------------
/femas-config/src/main/java/com/tencent/tsf/femas/config/ConfigChangeListener.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.config;
2 |
3 | import com.tencent.tsf.femas.config.model.ConfigChangeEvent;
4 | import java.util.List;
5 |
6 | public interface ConfigChangeListener {
7 |
8 | /**
9 | * Invoked when there is any config change for the namespace.
10 | *
11 | * @param changeEvents the events for this change
12 | */
13 | void onChange(List> changeEvents);
14 |
15 | /**
16 | * Invoked when there is any config change for the namespace.
17 | *
18 | * @param changeEvent the events for this change
19 | */
20 | void onChange(ConfigChangeEvent changeEvent);
21 | }
22 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/statistic/TotalAggregation.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.statistic;
2 |
3 | class TotalAggregation extends AbstractAggregation {
4 |
5 | void removeBucket(AbstractAggregation bucket) {
6 | this.totalDurationInMillis -= bucket.totalDurationInMillis;
7 | this.numberOfSlowCalls.add(-bucket.numberOfSlowCalls.intValue());
8 | this.numberOfSlowFailedCalls.add(-bucket.numberOfSlowFailedCalls.intValue());
9 | this.numberOfFailedCalls.add(-bucket.numberOfFailedCalls.intValue());
10 | this.numberOfBlockCalls.add(-bucket.numberOfBlockCalls.intValue());
11 | this.numberOfCalls.add(-bucket.numberOfCalls.intValue());
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-consumer/src/main/resources/nacos/bootstrap.yaml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 18001
3 | spring:
4 | application:
5 | name: femas-springcloud-consumer
6 | cloud:
7 | nacos:
8 | discovery:
9 | server-addr: 127.0.0.1:8848
10 | username: nacos
11 | password: nacos
12 | config:
13 | server-addr: 127.0.0.1:8848
14 |
15 | ribbon:
16 | ReadTimeout: 10000
17 | ConnectTimeout: 10000
18 | MaxAutoRetries: 0
19 | # 同一个微服务其他实例的最大重试次数,不包括第一次调用的实例。默认值为1
20 | MaxAutoRetriesNextServer: 0
21 | # 是否所有操作(GET、POST等)都允许重试。默认值为false
22 | OkToRetryOnAllOperations: false
23 |
24 | logging:
25 | file: ./log/femas/${spring.application.name}/${spring.application.name}
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/httpclient/client/FemasHttpClient.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.httpclient.client;
2 |
3 |
4 | import com.tencent.tsf.femas.common.httpclient.wrapper.Body2StringResultWrapper;
5 | import com.tencent.tsf.femas.common.httpclient.wrapper.ResultWrapper;
6 |
7 |
8 | /**
9 | * @Author leoziltong
10 | * @Description //TODO
11 | * @Date: 2021/3/29 20:58
12 | * @Version 1.0
13 | */
14 | public interface FemasHttpClient {
15 |
16 | void registerWrapper(String var, ResultWrapper wrapper);
17 |
18 | ResultWrapper getOneResultWrapper(String key);
19 |
20 | default ResultWrapper getDefaultWrapper() {
21 | return new Body2StringResultWrapper();
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/httpclient/client/LongPullingApacheHttpRestClient.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.httpclient.client;
2 |
3 | import org.apache.http.impl.client.CloseableHttpClient;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 |
7 |
8 | /**
9 | * @Author leoziltong
10 | * @Description //TODO
11 | * @Date: 2021/3/30 11:21
12 | * @Version 1.0
13 | */
14 | public class LongPullingApacheHttpRestClient extends FemasApacheHttpRestClient {
15 |
16 | private final static Logger logger = LoggerFactory.getLogger(LongPullingApacheHttpRestClient.class);
17 |
18 | public LongPullingApacheHttpRestClient(CloseableHttpClient client) {
19 | super(client);
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/statistic/Metrics.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.statistic;
2 |
3 | import java.util.concurrent.TimeUnit;
4 |
5 | public interface Metrics {
6 |
7 | /**
8 | * Records a call.
9 | *
10 | * @param duration the duration of the call
11 | * @param durationUnit the time unit of the duration
12 | * @param outcome the outcome of the call
13 | */
14 | Snapshot record(long duration, TimeUnit durationUnit, Outcome outcome);
15 |
16 | /**
17 | * Returns a snapshot.
18 | *
19 | * @return a snapshot
20 | */
21 | Snapshot getSnapshot();
22 |
23 | enum Outcome {
24 | SUCCESS, ERROR, SLOW_SUCCESS, SLOW_ERROR, BLOCK
25 | }
26 |
27 | }
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/statistic/PartialAggregation.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.statistic;
2 |
3 | public class PartialAggregation extends AbstractAggregation {
4 |
5 | private long epochMillis;
6 |
7 | PartialAggregation(long epochMillis) {
8 | this.epochMillis = epochMillis;
9 | }
10 |
11 | void reset(long epochMillis) {
12 | this.epochMillis = epochMillis;
13 | this.totalDurationInMillis = 0;
14 | this.numberOfSlowCalls.reset();
15 | this.numberOfFailedCalls.reset();
16 | this.numberOfCalls.reset();
17 | this.numberOfBlockCalls.reset();
18 | }
19 |
20 | public long getEpochMillis() {
21 | return epochMillis;
22 | }
23 | }
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/util/id/KeyGeneratorFactory.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.util.id;
2 |
3 | /**
4 | * @Author leoziltong
5 | * @Description //TODO
6 | * @Date: 2021/3/31 15:13
7 | * @Version 1.0
8 | */
9 | public class KeyGeneratorFactory {
10 |
11 | public static KeyGenerator gen(GeneratorEnum type) {
12 | if (GeneratorEnum.HOST.equals(type)) {
13 | return new HostNameKeyGenerator();
14 | }
15 | if (GeneratorEnum.IP.equals(type)) {
16 | return new IPKeyGenerator();
17 | }
18 | if (GeneratorEnum.IP_SECTION.equals(type)) {
19 | return new IPSectionKeyGenerator();
20 | }
21 | return new IPKeyGenerator();
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/auth/entity/AuthRuleConfig.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.auth.entity;
2 |
3 | /**
4 | * @author Cody
5 | * @date 2021 2021/10/13 3:12 下午
6 | */
7 | public class AuthRuleConfig {
8 |
9 | private String serviceName;
10 |
11 | private AuthRuleGroup authRuleGroup;
12 |
13 | public String getServiceName() {
14 | return serviceName;
15 | }
16 |
17 | public void setServiceName(String serviceName) {
18 | this.serviceName = serviceName;
19 | }
20 |
21 | public AuthRuleGroup getAuthRuleGroup() {
22 | return authRuleGroup;
23 | }
24 |
25 | public void setAuthRuleGroup(AuthRuleGroup authRuleGroup) {
26 | this.authRuleGroup = authRuleGroup;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 |
2 | REG ?= registry.tce.com
3 |
4 | PROJECT_NAME := femas
5 |
6 | APP_NAME := all
7 |
8 | TAG = $(shell git rev-parse --short HEAD)
9 |
10 | PORT ?= 8708
11 |
12 | VERSION ?= $(TAG)
13 |
14 | build-image:
15 | docker build -f Dockerfile -t ${REG}/${PROJECT_NAME}/${APP_NAME}:${VERSION} .
16 |
17 | push-image:
18 | docker push ${REG}/${PROJECT_NAME}/${APP_NAME}:${VERSION}
19 |
20 | run-image:
21 | docker run -d --name femas-runner -w /usr/local/src/femas \
22 | -p ${PORT}:8080 \
23 | -e VERSION=${VERSION} \
24 | -v $(shell pwd)/logs:/usr/local/src/femas/femas-admin-starter/target/femas-admin-starter-0.3.0-${VERSION}/femas-admin/logs ${REG}/${PROJECT_NAME}/${APP_NAME}:${VERSION}
25 |
26 | run-helm:
27 | helm install femas-helm ./femas-helm
28 |
29 | reset-helm:
30 | helm uninstall femas-helm
31 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/util/PositiveAtomicCounter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.util;
2 |
3 | import java.util.concurrent.atomic.AtomicInteger;
4 |
5 | /**
6 | * 计数器,从0开始,保证正数。
7 | *
8 | * @author zhixinzxliu
9 | */
10 | public class PositiveAtomicCounter {
11 |
12 | private static final int MASK = 0x7FFFFFFF;
13 | private final AtomicInteger atom;
14 |
15 | public PositiveAtomicCounter() {
16 | atom = new AtomicInteger(0);
17 | }
18 |
19 | public final int incrementAndGet() {
20 | return atom.incrementAndGet() & MASK;
21 | }
22 |
23 | public final int getAndIncrement() {
24 | return atom.getAndIncrement() & MASK;
25 | }
26 |
27 | public int get() {
28 | return atom.get() & MASK;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/util/HttpResult.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.util;
2 |
3 |
4 | import java.util.Map;
5 |
6 | /**
7 | * @Author leoziltong
8 | * @Description //TODO
9 | * @Date: 2021/3/29 21:33
10 | * @Version 1.0
11 | */
12 | public class HttpResult extends Result {
13 |
14 | private Map headers;
15 |
16 | public HttpResult() {
17 | }
18 |
19 | public HttpResult(Map headers, String code, T data, String message) {
20 | super(code, message, data);
21 | this.headers = headers;
22 | }
23 |
24 | public Map getHeader() {
25 | return headers;
26 | }
27 |
28 | public void setHeader(Map header) {
29 | this.headers = header;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/femas-extensions/femas-extension-springcloud/femas-extension-springcloud-greenwich/src/main/java/com/tencent/tsf/femas/extension/springcloud/discovery/eureka/FemasEurekaRegistrationCustomizer.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.extension.springcloud.discovery.eureka;
2 |
3 | import com.tencent.tsf.femas.common.serviceregistry.AbstractServiceRegistryMetadata;
4 | import com.tencent.tsf.femas.common.serviceregistry.AbstractServiceRegistryMetadataFactory;
5 |
6 | /**
7 | * TODO 实现待定,eureka 可能没有 RegistrationCustomizer 机制
8 | */
9 | public class FemasEurekaRegistrationCustomizer {
10 |
11 | private volatile AbstractServiceRegistryMetadata serviceRegistryMetadata = AbstractServiceRegistryMetadataFactory
12 | .getServiceRegistryMetadata();
13 |
14 | public FemasEurekaRegistrationCustomizer() {
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-consumer/src/main/resources/consul/bootstrap.yaml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 18001
3 | spring:
4 | application:
5 | name: femas-springcloud-consumer
6 | cloud:
7 | consul:
8 | host: 127.0.0.1
9 | port: 8500
10 | discovery:
11 | serviceName: femas-springcloud-consumer
12 | instanceId: ${spring.application.name}-${server.port}-${spring.cloud.client.hostname}
13 | heartbeat:
14 | enabled: true
15 |
16 | ribbon:
17 | ReadTimeout: 10000
18 | ConnectTimeout: 10000
19 | MaxAutoRetries: 0
20 | # 同一个微服务其他实例的最大重试次数,不包括第一次调用的实例。默认值为1
21 | MaxAutoRetriesNextServer: 0
22 | # 是否所有操作(GET、POST等)都允许重试。默认值为false
23 | OkToRetryOnAllOperations: false
24 |
25 | logging:
26 | file: ./log/femas/${spring.application.name}/${spring.application.name}
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/loadbalance/LoadbalancerManager.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.loadbalance;
2 |
3 | import com.tencent.tsf.femas.common.entity.ServiceInstance;
4 | import com.tencent.tsf.femas.governance.config.FemasPluginContext;
5 | import java.util.List;
6 |
7 | /**
8 | * @author leoziltong
9 | */
10 | public class LoadbalancerManager {
11 |
12 | // 根据用户配置选取
13 | private static volatile Loadbalancer loadbalancer = FemasPluginContext.getLoadBalancer();
14 |
15 | public static ServiceInstance select(List serviceInstances) {
16 | return loadbalancer.select(serviceInstances);
17 | }
18 |
19 | public static void update(Loadbalancer loadbalancer) {
20 | LoadbalancerManager.loadbalancer = loadbalancer;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-k8s/src/main/java/com/tencent/tsf/femas/registry/impl/k8s/serviceregistry/K8sServiceRegistryFactory.java:
--------------------------------------------------------------------------------
1 |
2 | package com.tencent.tsf.femas.registry.impl.k8s.serviceregistry;
3 |
4 | import com.tencent.tsf.femas.common.RegistryEnum;
5 | import com.tencent.tsf.femas.common.serviceregistry.ServiceRegistry;
6 | import com.tencent.tsf.femas.common.serviceregistry.ServiceRegistryFactory;
7 |
8 | import java.util.Map;
9 |
10 | /**
11 | * @author leo
12 | */
13 | public class K8sServiceRegistryFactory implements ServiceRegistryFactory {
14 | @Override
15 | public ServiceRegistry getServiceRegistry(Map configMap) {
16 | return new K8sServiceRegistry(configMap);
17 | }
18 |
19 | @Override
20 | public String getType() {
21 | return RegistryEnum.KUBERNETES.name();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-nacos/src/main/java/com/tencent/tsf/femas/registry/impl/nacos/serviceregistry/NacosServiceRegistryFactory.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.registry.impl.nacos.serviceregistry;
2 |
3 | import com.tencent.tsf.femas.common.RegistryEnum;
4 | import com.tencent.tsf.femas.common.serviceregistry.ServiceRegistry;
5 | import com.tencent.tsf.femas.common.serviceregistry.ServiceRegistryFactory;
6 | import java.util.Map;
7 |
8 | /**
9 | * @author leo
10 | */
11 | public class NacosServiceRegistryFactory implements ServiceRegistryFactory {
12 |
13 | @Override
14 | public ServiceRegistry getServiceRegistry(Map configMap) {
15 | return new NacosServiceRegistry(configMap);
16 | }
17 |
18 | @Override
19 | public String getType() {
20 | return RegistryEnum.NACOS.name();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-eureka/src/main/java/com/tencent/tsf/femas/registry/impl/eureka/serviceregistry/EurekaServiceRegistryFactory.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.registry.impl.eureka.serviceregistry;
2 |
3 | import com.tencent.tsf.femas.common.RegistryEnum;
4 | import com.tencent.tsf.femas.common.serviceregistry.ServiceRegistry;
5 | import com.tencent.tsf.femas.common.serviceregistry.ServiceRegistryFactory;
6 | import java.util.Map;
7 |
8 | /**
9 | * @author leo
10 | */
11 | public class EurekaServiceRegistryFactory implements ServiceRegistryFactory {
12 |
13 | @Override
14 | public ServiceRegistry getServiceRegistry(Map configMap) {
15 | return new EurekaServiceRegistry(configMap);
16 | }
17 |
18 | @Override
19 | public String getType() {
20 | return RegistryEnum.EUREKA.name();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-consul/src/main/java/com/tencent/tsf/femas/registry/impl/consul/serviceregistry/ConsulServiceRegistryFactory.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.registry.impl.consul.serviceregistry;
2 |
3 | import com.tencent.tsf.femas.common.RegistryEnum;
4 | import com.tencent.tsf.femas.common.serviceregistry.ServiceRegistry;
5 | import com.tencent.tsf.femas.common.serviceregistry.ServiceRegistryFactory;
6 | import java.util.Map;
7 |
8 | /**
9 | * @author zhixinzxliu
10 | */
11 | public class ConsulServiceRegistryFactory implements ServiceRegistryFactory {
12 |
13 | @Override
14 | public ServiceRegistry getServiceRegistry(Map configMap) {
15 | return new ConsulServiceRegistry(configMap);
16 | }
17 |
18 | @Override
19 | public String getType() {
20 | return RegistryEnum.CONSUL.name();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/ratelimit/entity/RateLimitRuleConfig.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.ratelimit.entity;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * @author Cody
7 | * @date 2021 2021/10/14 10:35 上午
8 | */
9 | public class RateLimitRuleConfig {
10 |
11 | private List limitRuleGroup;
12 |
13 | private String serviceName;
14 |
15 | public List getLimitRuleGroup() {
16 | return limitRuleGroup;
17 | }
18 |
19 | public void setLimitRuleGroup(List limitRuleGroup) {
20 | this.limitRuleGroup = limitRuleGroup;
21 | }
22 |
23 | public String getServiceName() {
24 | return serviceName;
25 | }
26 |
27 | public void setServiceName(String serviceName) {
28 | this.serviceName = serviceName;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/httpclient/wrapper/Body2StringResultWrapper.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.httpclient.wrapper;
2 |
3 | import com.tencent.tsf.femas.common.httpclient.HttpClientResponse;
4 | import com.tencent.tsf.femas.common.util.HttpResult;
5 | import com.tencent.tsf.femas.common.util.IOTinyUtils;
6 |
7 | /**
8 | * @Author leoziltong
9 | * @Description //TODO
10 | * @Date: 2021/3/31 14:52
11 | * @Version 1.0
12 | */
13 | public class Body2StringResultWrapper implements ResultWrapper {
14 |
15 | @Override
16 | public HttpResult dealWithResponse(HttpClientResponse response) throws Exception {
17 | String stringBody = IOTinyUtils.toString(response.getBody(), response.getCharset());
18 | return new HttpResult(response.getHeaders(), response.getStatusCode(), stringBody, null);
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/util/CollectionUtil.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.util;
2 |
3 | import java.util.Collection;
4 | import java.util.List;
5 |
6 | public class CollectionUtil {
7 |
8 | public static boolean isEmpty(Collection> collection) {
9 | return (collection == null || collection.isEmpty());
10 | }
11 |
12 | public static boolean isNotEmpty(Collection> collection) {
13 | return !(collection == null || collection.isEmpty());
14 | }
15 |
16 | public static boolean hasString(List list, String target) {
17 | if (isEmpty(list) || StringUtils.isEmpty(target)) {
18 | return false;
19 | }
20 | for (String str : list) {
21 | if (target.equals(str)) {
22 | return true;
23 | }
24 | }
25 | return false;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/circuitbreaker/core/utils/MetricNames.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.circuitbreaker.core.utils;
2 |
3 | public class MetricNames {
4 |
5 | public static final String DEFAULT_PREFIX = "resilience4j.circuitbreaker";
6 | public static final String SUCCESSFUL = "successful";
7 | public static final String FAILED = "failed";
8 | public static final String SLOW = "slow";
9 | public static final String SLOW_SUCCESS = "slow_successful";
10 | public static final String SLOW_FAILED = "slow_failed";
11 | public static final String NOT_PERMITTED = "not_permitted";
12 | public static final String BUFFERED = "buffered";
13 | public static final String STATE = "state";
14 | public static final String FAILURE_RATE = "failure_rate";
15 | public static final String SLOW_CALL_RATE = "slow_call_rate";
16 | }
17 |
--------------------------------------------------------------------------------
/femas-registry/src/main/java/com/tencent/tsf/femas/common/discovery/ServerUpdater.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.discovery;
2 |
3 | import java.util.concurrent.ScheduledFuture;
4 |
5 | /**
6 | * @Author leoziltong
7 | * @Description //TODO
8 | * @Date: 2021/3/23 18:01
9 | * @Version 1.0
10 | */
11 | public interface ServerUpdater {
12 |
13 | ScheduledFuture> start(ServerUpdater.UpdateAction action);
14 |
15 | void stop(ScheduledFuture scheduledFuture);
16 |
17 | /**
18 | * 不必要继承接口
19 | *
20 | * @return
21 | */
22 | default String getLastUpdate() {
23 | return null;
24 | }
25 |
26 | default long getDurationSinceLastUpdateMs() {
27 | return 0L;
28 | }
29 |
30 | default int getCoreThreads() {
31 | return 0;
32 | }
33 |
34 | interface UpdateAction {
35 |
36 | void doUpdate();
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/callback/FemasCallback.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.callback;
2 |
3 | import com.tencent.tsf.femas.common.entity.RequestBase;
4 |
5 | public interface FemasCallback {
6 |
7 | /**
8 | * will callback this method when server return response success
9 | *
10 | * @param appResponse response object
11 | * @param methodName the invoked method
12 | * @param request the invoked request object
13 | */
14 | void onSuccess(Object appResponse, String methodName, RequestBase request);
15 |
16 | /**
17 | * will callback this method when server meet exception
18 | *
19 | * @param throwable app's exception
20 | * @param methodName the invoked method
21 | * @param request the invoked request
22 | */
23 | void onException(Throwable throwable, String methodName, RequestBase request);
24 | }
25 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/route/Router.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.route;
2 |
3 | import com.tencent.tsf.femas.common.entity.Service;
4 | import com.tencent.tsf.femas.common.entity.ServiceInstance;
5 | import com.tencent.tsf.femas.governance.plugin.Plugin;
6 | import java.util.Collection;
7 |
8 | /**
9 | * 路由器
10 | *
11 | * @author zhixinzxliu
12 | */
13 | public interface Router extends Plugin {
14 |
15 | /**
16 | * 给定一组服务节点,返回零个或多个服务节点
17 | *
18 | * @param serviceInstances
19 | * @return
20 | */
21 | Collection route(Service service, Collection serviceInstances);
22 |
23 | /**
24 | * 返回该Router对应的名称
25 | *
26 | * @return
27 | */
28 | String name();
29 |
30 | /**
31 | * 返回该路由器的优先级
32 | *
33 | * @return
34 | */
35 | int priority();
36 | }
37 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/entity/EndpointStatus.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.entity;
2 |
3 | /**
4 | * 节点状态
5 | *
6 | * @author zhixinzxliu
7 | */
8 | public enum EndpointStatus {
9 | /**
10 | * 启动中
11 | */
12 | UP,
13 |
14 | /**
15 | * 正在初始化
16 | */
17 | INITIALIZING,
18 |
19 | /**
20 | * 正在关闭
21 | * 优雅关闭使用,不接受新流量
22 | */
23 | CLOSING,
24 |
25 | /**
26 | * 服务下线
27 | */
28 | DOWN,
29 |
30 | /**
31 | * 与注册中心失联
32 | */
33 | OUT_OF_CONTACT,
34 |
35 | UNKNOWN;
36 |
37 |
38 | public static EndpointStatus getTypeByName(String var) {
39 | for (EndpointStatus status : EndpointStatus.values()) {
40 | if (var.equalsIgnoreCase(status.name())) {
41 | return status;
42 | }
43 | }
44 | return UNKNOWN;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/femas-config-impl/femas-config-nacos/src/main/java/com/tencent/tsf/femas/config/impl/nacos/SpringApplicationContextUtil.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.config.impl.nacos;
2 |
3 | import org.springframework.beans.BeansException;
4 | import org.springframework.context.ApplicationContext;
5 | import org.springframework.context.ApplicationContextAware;
6 | import org.springframework.stereotype.Component;
7 |
8 | @Component
9 | public class SpringApplicationContextUtil implements ApplicationContextAware {
10 |
11 | private static ApplicationContext applicationContext;
12 |
13 | public static T getBean(Class clazz) {
14 | return applicationContext.getBean(clazz);
15 | }
16 |
17 | @Override
18 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
19 | SpringApplicationContextUtil.applicationContext = applicationContext;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/femas-registry/src/main/java/com/tencent/tsf/femas/common/RegistryBuilder.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common;
2 |
3 | import com.tencent.tsf.femas.common.exception.FemasRegisterDescribeException;
4 | import java.util.function.Supplier;
5 |
6 | /**
7 | * @Author leoziltong
8 | * @Description //TODO
9 | * @Date: 2021/3/24 11:06
10 | * @Version 1.0
11 | */
12 | public interface RegistryBuilder {
13 |
14 | T describeClient(Supplier serverAddressSupplier, String namespace, boolean certificate, Object... var) throws FemasRegisterDescribeException;
15 |
16 | T build(Supplier serverAddressSupplier, String namespace);
17 |
18 | T certificateClient(Supplier serverAddressSupplier, String namespace, Object... var);
19 |
20 | default String getKey(Supplier serverAddressSupplier) {
21 | String key = serverAddressSupplier.get();
22 | return key;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/annotation/ThreadSafe.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.annotation;
2 |
3 | import java.lang.annotation.Documented;
4 | import java.lang.annotation.ElementType;
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.lang.annotation.Target;
8 |
9 | /**
10 | * ThreadSafe
11 | *
12 | * The class to which this annotation is applied is thread-safe. This means that
13 | * no sequences of accesses (reads and writes to public fields, calls to public
14 | * methods) may put the object into an invalid state, regardless of the
15 | * interleaving of those actions by the runtime, and without requiring any
16 | * additional synchronization or coordination on the part of the caller.
17 | */
18 | @Documented
19 | @Target(ElementType.TYPE)
20 | @Retention(RetentionPolicy.CLASS)
21 | public @interface ThreadSafe {
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/femas-config-impl/femas-config-nacos/src/main/java/com/tencent/tsf/femas/config/impl/nacos/FemasNacosConfigManager.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.config.impl.nacos;
2 |
3 | import com.tencent.tsf.femas.config.Config;
4 | import com.tencent.tsf.femas.config.ConfigService;
5 | import com.tencent.tsf.femas.config.FemasConfigManager;
6 | import com.tencent.tsf.femas.config.enums.FemasConfigTypeEnum;
7 |
8 | public class FemasNacosConfigManager extends FemasConfigManager {
9 |
10 | private volatile static FemasNacosConfig CONFIG;
11 |
12 | public Config getConfig() {
13 | if (CONFIG == null) {
14 | synchronized (FemasNacosConfigManager.class) {
15 | if (CONFIG == null) {
16 | CONFIG = (FemasNacosConfig) ConfigService.createConfig(FemasConfigTypeEnum.NACOS.getType(), null);
17 | }
18 | }
19 | }
20 | return CONFIG;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-2020-consumer/src/main/resources/bootstrap.yaml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 18001
3 | spring:
4 | application:
5 | name: femas-example-springcloud2020-consumer
6 | cloud:
7 | nacos:
8 | discovery:
9 | server-addr: 127.0.0.1:8848
10 | username: nacos
11 | password: nacos
12 | config:
13 | server-addr: 127.0.0.1:8848
14 | # consul:
15 | # host: 127.0.0.1
16 | # port: 8500
17 | # discovery:
18 | # serviceName: femas-springcloud-consumer
19 | # instanceId: ${spring.application.name}-${server.port}-${spring.cloud.client.hostname}
20 | # heartbeat:
21 | # enabled: true
22 |
23 | ribbon:
24 | ReadTimeout: 10000
25 | ConnectTimeout: 10000
26 | MaxAutoRetries: 0
27 | # 同一个微服务其他实例的最大重试次数,不包括第一次调用的实例。默认值为1
28 | MaxAutoRetriesNextServer: 0
29 | # 是否所有操作(GET、POST等)都允许重试。默认值为false
30 | OkToRetryOnAllOperations: false
31 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-zuul/src/main/java/com/tencent/tsf/femas/example/gateway/zuul/ZuulApplication.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.example.gateway.zuul;
2 |
3 | import com.tencent.tsf.femas.example.gateway.zuul.filter.TestFilter;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
7 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
8 | import org.springframework.context.annotation.Bean;
9 |
10 | @SpringBootApplication
11 | @EnableDiscoveryClient
12 | @EnableZuulProxy
13 | public class ZuulApplication {
14 |
15 | public static void main(String[] args) {
16 | SpringApplication.run(ZuulApplication.class, args);
17 | }
18 |
19 |
20 | @Bean
21 | public TestFilter testFilter() {
22 | return new TestFilter();
23 | }
24 | }
--------------------------------------------------------------------------------
/femas-config/src/main/java/com/tencent/tsf/femas/config/Config.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.config;
2 |
3 | import com.google.common.base.Function;
4 | import com.tencent.tsf.femas.config.model.ConfigChangeEvent;
5 |
6 | import java.util.List;
7 |
8 |
9 | public interface Config {
10 |
11 | boolean publishConfig(Object[] params);
12 |
13 | T getProperty(String key, T defaultValue);
14 |
15 | V getProperty(String key, Function function, V defaultValue);
16 |
17 | void subscribe(String key, ConfigChangeListener listener);
18 |
19 | /**
20 | * zk,consul,etcd等支持该API
21 | * Apollo,redis等不支持
22 | *
23 | * throws unsupport
24 | */
25 | void subscribeDirectory(String key, ConfigChangeListener listener);
26 |
27 | List> getDirectory(String key);
28 |
29 | void unsubscribe(String key);
30 |
31 | void unsubscribe(String key, ConfigChangeListener listener);
32 | }
33 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/util/HttpHeaderKeys.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.util;
2 |
3 | /**
4 | * @Author leoziltong
5 | * @Description //TODO
6 | * @Date: 2021/3/31 15:13
7 | * @Version 1.0
8 | */
9 | public final class HttpHeaderKeys {
10 |
11 | public final static String USER_AGENT_HEADER = "User-Agent";
12 | public final static String CONTENT_TYPE = "Content-Type";
13 | public final static String CONTENT_LENGTH = "Content-Length";
14 | public final static String ACCEPT_CHARSET = "Accept-Charset";
15 | public final static String ACCEPT_ENCODING = "Accept-Encoding";
16 | public final static String CONTENT_ENCODING = "Content-Encoding";
17 | public final static String REQUEST_ID = "RequestId";
18 | public static final String DEFAULT_ENCODE = "UTF-8";
19 | public static final String CONNECTION = "Connection";
20 | public static final String CLIENT_VERSION_HEADER = "Client-Version";
21 |
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/trace/TraceAdapter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.trace;
2 |
3 | import com.tencent.tsf.femas.common.context.RpcContext;
4 | import io.opentelemetry.api.trace.Span;
5 |
6 | /**
7 | * @Author p_mtluo
8 | * @Date 2021-12-13 18:04
9 | * @Description test
10 | **/
11 | public class TraceAdapter {
12 |
13 |
14 | public static void setSpanAttribute(RpcContext rpcContext) {
15 | Span span = Span.current();
16 | if (rpcContext.getTracingContext() != null && rpcContext.getTracingContext().getLocalPort() != null) {
17 | span.setAttribute("http.port", rpcContext.getTracingContext().getLocalPort());
18 | }
19 | if (rpcContext.getTracingContext() != null && rpcContext.getTracingContext().getRemoteServiceName() != null) {
20 | span.setAttribute("net.peer.service", rpcContext.getTracingContext().getRemoteServiceName());
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/femas-registry/src/main/java/com/tencent/tsf/femas/common/discovery/ServiceDiscoveryClient.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.discovery;
2 |
3 | import com.tencent.tsf.femas.common.entity.Service;
4 | import com.tencent.tsf.femas.common.entity.ServiceInstance;
5 | import java.util.List;
6 |
7 | /**
8 | * @author zhixinzxliu
9 | */
10 | public interface ServiceDiscoveryClient {
11 |
12 | /**
13 | * Get all ServiceInstances associated with a particular service
14 | *
15 | * @param service the service to query
16 | * @return a List of ServiceInstance
17 | */
18 | List getInstances(Service service);
19 |
20 | /**
21 | * 订阅服务
22 | */
23 | void subscribe(Service service);
24 |
25 | void addNotifyListener(ServiceNotifyListener listener);
26 |
27 | /**
28 | * 取消订阅
29 | */
30 | void unsubscribe(Service service);
31 |
32 | void removeNotifyListener(ServiceNotifyListener listener);
33 | }
34 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/util/PropertiesUtil.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.util;
2 |
3 | public class PropertiesUtil {
4 |
5 | /**
6 | * 参考Spring的优先级
7 | * -D优先级高于Env
8 | *
9 | * @param propertyName
10 | * @return
11 | */
12 | public static String getFromEnvAndProperty(String propertyName) {
13 | return getFromEnvAndProperty(propertyName, null);
14 | }
15 |
16 | public static String getFromEnvAndProperty(String propertyName, String defaultValue) {
17 | String result = System.getProperty(propertyName);
18 |
19 | if (result == null || result.isEmpty()) {
20 | String envName = propertyName.replace('.', '_');
21 | envName = envName.replace('-', '_');
22 | result = System.getenv(envName);
23 | }
24 |
25 | if (result == null) {
26 | return defaultValue;
27 | }
28 |
29 | return result;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/femas-config-impl/femas-config-paas/src/main/java/com/tencent/tsf/femas/config/impl/paas/GetValue.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.config.impl.paas;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 | import java.nio.charset.Charset;
5 |
6 | /**
7 | * @Author leoziltong
8 | * @Description //TODO
9 | * @Date: 2021/4/1 16:30
10 | * @Version 1.0
11 | */
12 | public class GetValue {
13 |
14 | private static final Charset UTF_8 = Charset.forName("UTF-8");
15 |
16 | @SerializedName("Key")
17 | private String key;
18 | @SerializedName("Value")
19 | private String value;
20 |
21 | public GetValue() {
22 | }
23 |
24 | public String getKey() {
25 | return this.key;
26 | }
27 |
28 | public void setKey(String key) {
29 | this.key = key;
30 | }
31 |
32 | public String getValue() {
33 | return this.value;
34 | }
35 |
36 | public void setValue(String value) {
37 | this.value = value;
38 | }
39 |
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/circuitbreaker/rule/CircuitBreakerApi.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.circuitbreaker.rule;
2 |
3 | import java.io.Serializable;
4 | import org.apache.commons.lang3.StringUtils;
5 |
6 | /**
7 | * @author zhixinzxliu
8 | */
9 | public class CircuitBreakerApi implements Serializable {
10 |
11 | /**
12 | * 这里如果是Http的话,需要自行将method和path组合起来
13 | */
14 | private String method;
15 |
16 | public String getMethod() {
17 | return method;
18 | }
19 |
20 | public void setMethod(final String method) {
21 | this.method = method;
22 | }
23 |
24 | public boolean validate() {
25 | if (StringUtils.isBlank(method)) {
26 | return false;
27 | }
28 |
29 | return true;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return "CircuitBreakerApi{" +
35 | "method='" + method + '\'' +
36 | '}';
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-consumer/src/main/resources/bootstrap.yaml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 18001
3 | spring:
4 | application:
5 | name: femas-springcloud-consumer
6 | cloud:
7 | nacos:
8 | discovery:
9 | server-addr: 127.0.0.1:8848
10 | username: nacos
11 | password: nacos
12 | config:
13 | server-addr: 127.0.0.1:8848
14 | # consul:
15 | # host: 127.0.0.1
16 | # port: 8500
17 | # discovery:
18 | # serviceName: femas-springcloud-consumer
19 | # instanceId: ${spring.application.name}-${server.port}-${spring.cloud.client.hostname}
20 | # heartbeat:
21 | # enabled: true
22 |
23 | ribbon:
24 | ReadTimeout: 10000
25 | ConnectTimeout: 10000
26 | MaxAutoRetries: 0
27 | # 同一个微服务其他实例的最大重试次数,不包括第一次调用的实例。默认值为1
28 | MaxAutoRetriesNextServer: 0
29 | # 是否所有操作(GET、POST等)都允许重试。默认值为false
30 | OkToRetryOnAllOperations: false
31 |
32 | logging:
33 | file: ./log/femas/${spring.application.name}/${spring.application.name}
--------------------------------------------------------------------------------
/femas-adaptor/femas-adaptor-opensource-admin/src/main/java/com/tencent/tsf/femas/adaptor/paas/logger/LogbackTraceConverter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.adaptor.paas.logger;
2 |
3 | import ch.qos.logback.classic.pattern.ClassicConverter;
4 | import ch.qos.logback.classic.spi.ILoggingEvent;
5 | import java.util.Map;
6 |
7 | public class LogbackTraceConverter extends ClassicConverter implements ConverterBase {
8 |
9 | @Override
10 | public String convert(ILoggingEvent event) {
11 | Map mdcPropertyMap = event.getMDCPropertyMap();
12 |
13 | if (mdcPropertyMap == null) {
14 | return DEFAULT_VALUE;
15 | }
16 |
17 | StringBuffer stringBuffer = new StringBuffer("[");
18 | for (String key : MDC_KEYS) {
19 | String value = mdcPropertyMap.get(key);
20 | stringBuffer.append(",").append(value == null ? DEFAULT_SINGLE_VALUE : value);
21 | }
22 | stringBuffer.append("]");
23 | return stringBuffer.toString();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/context/RpcContext.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.context;
2 |
3 | import com.tencent.tsf.femas.common.entity.ErrorStatus;
4 | import com.tencent.tsf.femas.common.statistic.Metrics;
5 |
6 | public class RpcContext {
7 |
8 | private ErrorStatus errorStatus;
9 | private Metrics metrics;
10 | private TracingContext tracingContext;
11 |
12 | public ErrorStatus getErrorStatus() {
13 | return errorStatus;
14 | }
15 |
16 | public void setErrorStatus(ErrorStatus errorStatus) {
17 | this.errorStatus = errorStatus;
18 | }
19 |
20 | public Metrics getMetrics() {
21 | return metrics;
22 | }
23 |
24 | public void setMetrics(Metrics metrics) {
25 | this.metrics = metrics;
26 | }
27 |
28 | public TracingContext getTracingContext() {
29 | return tracingContext;
30 | }
31 |
32 | public void setTracingContext(TracingContext tracingContext) {
33 | this.tracingContext = tracingContext;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/femas-extensions/femas-extension-springcloud/femas-extension-springcloud-greenwich/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2 | com.tencent.tsf.femas.extension.springcloud.discovery.FemasDiscoveryAutoConfiguration,\
3 | com.tencent.tsf.femas.extension.springcloud.common.discovery.FemasDiscoveryCommonAutoConfiguration,\
4 | com.tencent.tsf.femas.extension.springcloud.discovery.ribbon.config.FemasRibbonAutoConfiguration,\
5 | com.tencent.tsf.femas.extension.springcloud.instrumentation.feign.FemasFeignInterceptorAutoConfiguration,\
6 | com.tencent.tsf.femas.extension.springcloud.common.instrumentation.config.FemasGovernanceAutoConfiguration,\
7 | com.tencent.tsf.femas.extension.springcloud.common.instrumentation.restapi.FemasSwaggerAutoConfiguration,\
8 | com.tencent.tsf.femas.extension.springcloud.common.instrumentation.metrics.PrometheusConfig
9 | org.springframework.context.ApplicationListener=\
10 | com.tencent.tsf.femas.extension.springcloud.common.instrumentation.restapi.FemasSwaggerApplicationListener
--------------------------------------------------------------------------------
/femas-helm/templates/hpa.yaml:
--------------------------------------------------------------------------------
1 | {{- if .Values.autoscaling.enabled }}
2 | apiVersion: autoscaling/v2beta1
3 | kind: HorizontalPodAutoscaler
4 | metadata:
5 | name: {{ include "femas-helm.fullname" . }}
6 | labels:
7 | {{- include "femas-helm.labels" . | nindent 4 }}
8 | spec:
9 | scaleTargetRef:
10 | apiVersion: apps/v1
11 | kind: Deployment
12 | name: {{ include "femas-helm.fullname" . }}
13 | minReplicas: {{ .Values.autoscaling.minReplicas }}
14 | maxReplicas: {{ .Values.autoscaling.maxReplicas }}
15 | metrics:
16 | {{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
17 | - type: Resource
18 | resource:
19 | name: cpu
20 | targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
21 | {{- end }}
22 | {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
23 | - type: Resource
24 | resource:
25 | name: memory
26 | targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
27 | {{- end }}
28 | {{- end }}
29 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/config/FemasTypeProviders.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.config;
2 |
3 | import com.tencent.tsf.femas.governance.plugin.Attribute;
4 | import com.tencent.tsf.femas.governance.plugin.Plugin;
5 | import com.tencent.tsf.femas.governance.plugin.PluginProvider;
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | public class FemasTypeProviders implements PluginProvider {
10 |
11 | @Override
12 | public List> getPluginTypes() {
13 | List> types = new ArrayList<>();
14 | for (SPIPluginType type : SPIPluginType.values()) {
15 | types.add(type.getInterfaces());
16 | }
17 | return types;
18 | }
19 |
20 | @Override
21 | public Attribute getAttr() {
22 | return new Attribute(Attribute.Implement.FEMAS, "femasPluginMenu");
23 | }
24 |
25 | @Override
26 | public String getType() {
27 | return this.getClass().getTypeName();
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-2020-provider/src/main/java/com/femas/example/springcloud2020/provider/ProviderService.java:
--------------------------------------------------------------------------------
1 | package com.femas.example.springcloud2020.provider;
2 |
3 | import org.springframework.cloud.openfeign.FeignClient;
4 | import org.springframework.web.bind.annotation.PathVariable;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestMethod;
7 |
8 | @FeignClient(name = "femas-example-springcloud2020-provider")
9 | public interface ProviderService {
10 |
11 | @RequestMapping(value = "/hello", method = RequestMethod.GET)
12 | String hello();
13 |
14 | @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
15 | String echo(@PathVariable("str") String str);
16 |
17 | @RequestMapping(value = "/echo/error/{str}", method = RequestMethod.GET)
18 | String echoError(@PathVariable("str") String str);
19 |
20 | @RequestMapping(value = "/echo/slow/{str}", method = RequestMethod.GET)
21 | String echoSlow(@PathVariable("str") String str);
22 | }
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/circuitbreaker/constant/FemasCircuitBreakerConstant.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.circuitbreaker.constant;
2 |
3 | public class FemasCircuitBreakerConstant {
4 |
5 | //统计滚动的时间窗口
6 | public static final Integer MAX_SLIDING_WINDOW_SIZE = 9999;
7 | public static final Integer MIN_SLIDING_WINDOW_SIZE = 1;
8 |
9 | // 失败请求比例
10 | public static final Integer MAX_FAILURE_RATE_THRESHOLD = 100;
11 | public static final Integer MIN_FAILURE_RATE_THRESHOLD = 1;
12 |
13 | // 失败请求比例
14 | public static final Integer MAX_EJECTION_RATE_THRESHOLD = 100;
15 | public static final Integer MIN_EJECTION_RATE_THRESHOLD = 0;
16 |
17 | // 熔断开启到半开间隔
18 | public static final Integer MAX_WAIT_DURATION_IN_OPEN_STATE = 9999;
19 | public static final Integer MIN_WAIT_DURATION_IN_OPEN_STATE = 1;
20 |
21 | // 最小失败请求数
22 | public static final Integer MINIMUN_NUMBER_OF_CALLS = 1;
23 |
24 | public static final RuntimeException MOCK_EXCEPTION = new RuntimeException();
25 | }
26 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/metrics/micrometer/exporter/logger/LoggerFormatter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.metrics.micrometer.exporter.logger;
2 |
3 | import java.io.PrintWriter;
4 | import java.io.StringWriter;
5 | import java.util.logging.Formatter;
6 | import java.util.logging.LogRecord;
7 |
8 | /**
9 | * @Author p_mtluo
10 | * @Date 2021-11-09 18:16
11 | * @Description LoggerFormatter
12 | **/
13 | public class LoggerFormatter extends Formatter {
14 |
15 | @Override
16 | public String format(LogRecord record) {
17 | String var3 = this.formatMessage(record);
18 | String var4 = "";
19 | if (record.getThrown() != null) {
20 | StringWriter var5 = new StringWriter();
21 | PrintWriter var6 = new PrintWriter(var5);
22 | var6.println();
23 | record.getThrown().printStackTrace(var6);
24 | var6.close();
25 | var4 = var5.toString();
26 | }
27 | return String.format("%1$s%2$s%n", var3, var4);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/circuitbreaker/core/internal/SchedulerFactory.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.circuitbreaker.core.internal;
2 |
3 | import io.vavr.Lazy;
4 | import java.util.concurrent.Executors;
5 | import java.util.concurrent.ScheduledExecutorService;
6 |
7 | public class SchedulerFactory {
8 |
9 | private static Lazy lazyInstance = Lazy.of(SchedulerFactory::new);
10 | private Lazy lazyScheduler = Lazy
11 | .of(() -> Executors.newSingleThreadScheduledExecutor(threadTask -> {
12 | Thread thread = new Thread(threadTask, "CircuitBreakerAutoTransitionThread");
13 | thread.setDaemon(true);
14 | return thread;
15 | }));
16 |
17 | private SchedulerFactory() {
18 | }
19 |
20 | public static SchedulerFactory getInstance() {
21 | return lazyInstance.get();
22 | }
23 |
24 | public ScheduledExecutorService getScheduler() {
25 | return lazyScheduler.get();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-2020-provider/src/main/resources/bootstrap.yaml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 19001
3 | spring:
4 | application:
5 | name: femas-example-springcloud2020-provider
6 | cloud:
7 | nacos:
8 | discovery:
9 | server-addr: 127.0.0.1:8848
10 | username: nacos
11 | password: nacos
12 | config:
13 | server-addr: 127.0.0.1:8848
14 | # file-extension: properties
15 | # refresh-enabled: true
16 | # namespace: ns-mldqvo58
17 | # shared-configs[0]:
18 | # data-id: testDataId
19 | # refresh: true
20 | # group: DEFAULT_GROUP
21 | # consul:
22 | # host: 127.0.0.1
23 | # port: 8500
24 | # discovery:
25 | # serviceName: femas-example-springcloud2020-provider
26 | # instanceId: ${spring.application.name}-${server.port}-${spring.cloud.client.hostname}
27 | # heartbeat:
28 | # enabled: true
29 |
30 | management:
31 | endpoints:
32 | web:
33 | exposure:
34 | include: '*'
35 |
36 | logging:
37 | level:
38 | root: info
--------------------------------------------------------------------------------
/femas-extensions/femas-extension-springcloud/femas-extension-springcloud-common/src/main/java/com/tencent/tsf/femas/extension/springcloud/common/discovery/nacos/NacosEnv.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.extension.springcloud.common.discovery.nacos;
2 |
3 | import com.tencent.tsf.femas.common.context.Context;
4 | import com.tencent.tsf.femas.common.context.ContextConstant;
5 | import com.tencent.tsf.femas.common.context.factory.ContextFactory;
6 | import com.tencent.tsf.femas.common.util.StringUtils;
7 |
8 | public class NacosEnv {
9 |
10 | private static volatile ContextConstant contextConstant = ContextFactory.getContextConstantInstance();
11 |
12 | public static void init() {
13 | // 需要优先于 NacosDiscoveryEndpointAutoConfiguration 进行环境变量设置
14 | String namespace = Context.getSystemTag(contextConstant.getNamespaceId());
15 | if (StringUtils.isNotEmpty(namespace)) {
16 | System.setProperty("spring.cloud.nacos.discovery.namespace", namespace);
17 | System.setProperty("spring.cloud.nacos.config.namespace", namespace);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/codec/EscapeNonAsciiWriter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.codec;
2 |
3 | import java.io.IOException;
4 | import java.io.Writer;
5 |
6 | /**
7 | * copy from FEMAS LANE
8 | */
9 | // 测试过这个类,对中文有效,对处于 Plane 1 的字符(如 𐀀)也有效
10 | public class EscapeNonAsciiWriter extends Writer {
11 |
12 | private final Writer out;
13 |
14 | public EscapeNonAsciiWriter(Writer out) {
15 | this.out = out;
16 | }
17 |
18 | @Override
19 | public void write(char[] buffer, int offset, int count) throws IOException {
20 | for (int i = 0; i < count; i++) {
21 | char c = buffer[i + offset];
22 | if (c <= 0x7f) {
23 | out.write(c);
24 | } else {
25 | out.write(String.format("\\u%04x", (int) c));
26 | }
27 | }
28 | }
29 |
30 | @Override
31 | public void flush() throws IOException {
32 | out.flush();
33 | }
34 |
35 | @Override
36 | public void close() throws IOException {
37 | out.close();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/femas-extensions/femas-extension-springcloud/femas-extension-springcloud-common/src/main/java/com/tencent/tsf/femas/extension/springcloud/common/instrumentation/feign/FeignHeaderUtils.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.extension.springcloud.common.instrumentation.feign;
2 |
3 | import com.tencent.tsf.femas.common.header.AbstractRequestMetaUtils;
4 | import feign.Request;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 |
8 | /**
9 | * 由于 feign-core 从 10.12 开始不能通过 feignRequest.headers() 来修改 header,
10 | * 统一改为从 FeignHeaderInterceptor 设置。preprocess 和 setRequestMeta 空实现
11 | */
12 | public class FeignHeaderUtils extends AbstractRequestMetaUtils {
13 |
14 | private static final Logger logger = LoggerFactory.getLogger(FemasFeignClientWrapper.class);
15 |
16 | private Request feignRequest;
17 |
18 | public FeignHeaderUtils(Request feignRequest) {
19 | this.feignRequest = feignRequest;
20 | }
21 |
22 | @Override
23 | public void preprocess() {
24 |
25 | }
26 |
27 | @Override
28 | public void setRequestMeta(String name, String value) {
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-provider/src/main/java/com/tencent/tsf/femas/example/springcloud/ProviderService.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.example.springcloud;
2 |
3 | import org.springframework.cloud.openfeign.FeignClient;
4 | import org.springframework.web.bind.annotation.PathVariable;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestMethod;
7 |
8 | @FeignClient(name = "femas-springcloud-provider")
9 | //@FeignClient(name = "provider-demo", url = "127.0.0.1:19001")
10 | public interface ProviderService {
11 |
12 | @RequestMapping(value = "/hello", method = RequestMethod.GET)
13 | String hello();
14 |
15 | @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
16 | String echo(@PathVariable("str") String str);
17 |
18 | @RequestMapping(value = "/echo/error/{str}", method = RequestMethod.GET)
19 | String echoError(@PathVariable("str") String str);
20 |
21 | @RequestMapping(value = "/echo/slow/{str}", method = RequestMethod.GET)
22 | String echoSlow(@PathVariable("str") String str);
23 | }
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/base/Initializable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.common.base;
19 |
20 | /**
21 | * 可初始化的接口
22 | */
23 | public interface Initializable {
24 |
25 | /**
26 | * 初始化
27 | */
28 | void init();
29 | }
30 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/test/java/com/tencent/tsf/femas/governance/circuitbreaker/core/internal/SchedulerFactoryTest.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.circuitbreaker.core.internal;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 |
5 | import java.util.concurrent.ScheduledExecutorService;
6 | import org.junit.Test;
7 |
8 | public class SchedulerFactoryTest {
9 |
10 | @Test
11 | public void shouldBeSameSchedulerFactoryInstance() {
12 | SchedulerFactory instance = SchedulerFactory.getInstance();
13 | SchedulerFactory instance2 = SchedulerFactory.getInstance();
14 | assertThat(instance).isEqualTo(instance2);
15 | }
16 |
17 | @Test
18 | public void shouldBeSameScheduledExecutorServiceInstance() {
19 | ScheduledExecutorService scheduledExecutorService = SchedulerFactory.getInstance()
20 | .getScheduler();
21 | ScheduledExecutorService scheduledExecutorService2 = SchedulerFactory.getInstance()
22 | .getScheduler();
23 | assertThat(scheduledExecutorService).isEqualTo(scheduledExecutorService2);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/femas-registry/src/main/java/com/tencent/tsf/femas/common/discovery/ServiceDiscoveryFactory.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.discovery;
2 |
3 | import static com.tencent.tsf.femas.common.RegistryConstants.REGISTRY_HOST;
4 | import static com.tencent.tsf.femas.common.RegistryConstants.REGISTRY_PORT;
5 | import static com.tencent.tsf.femas.common.util.CommonUtils.checkNotNull;
6 |
7 | import com.tencent.tsf.femas.common.annotation.SPI;
8 | import com.tencent.tsf.femas.common.spi.SpiExtensionClass;
9 | import java.util.Map;
10 |
11 | /**
12 | * @author zhixinzxliu
13 | */
14 | @SPI
15 | public interface ServiceDiscoveryFactory extends SpiExtensionClass {
16 |
17 | ServiceDiscoveryClient getServiceDiscovery(Map configMap);
18 |
19 | default String getKey(Map configMap) {
20 | String host = checkNotNull(REGISTRY_HOST, configMap.get(REGISTRY_HOST));
21 | String portString = checkNotNull(REGISTRY_PORT, configMap.get(REGISTRY_PORT));
22 | Integer port = Integer.parseInt(portString);
23 | String key = host + ":" + port;
24 | return key;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/spi/SpiService.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.spi;
2 |
3 | import java.util.HashMap;
4 | import java.util.Iterator;
5 | import java.util.Map;
6 | import java.util.ServiceLoader;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 |
10 | public class SpiService {
11 |
12 | private static final Logger logger = LoggerFactory.getLogger(SpiService.class);
13 |
14 | public static Map init(Class spiExtensionClass) {
15 | ServiceLoader registryFactoryServiceLoader = ServiceLoader.load(spiExtensionClass);
16 | Iterator it = registryFactoryServiceLoader.iterator();
17 |
18 | Map typeMap = new HashMap<>();
19 | while (it.hasNext()) {
20 | T klassInstance = it.next();
21 | typeMap.put(klassInstance.getType(), klassInstance);
22 | logger.info("Load SPI Service, Type :" + klassInstance.getType() + ", Class :" + klassInstance.getClass()
23 | .getCanonicalName());
24 | }
25 | return typeMap;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-2020-consumer/src/main/java/com/femas/example/springcloud2020/consumer/proxy/service/ProviderService.java:
--------------------------------------------------------------------------------
1 | package com.femas.example.springcloud2020.consumer.proxy.service;
2 |
3 | import org.springframework.cloud.openfeign.FeignClient;
4 | import org.springframework.web.bind.annotation.PathVariable;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestMethod;
7 |
8 | @FeignClient(name = "femas-example-springcloud2020-provider")
9 | //@FeignClient(name = "provider-demo", url = "127.0.0.1:19001")
10 | public interface ProviderService {
11 |
12 | @RequestMapping(value = "/hello", method = RequestMethod.GET)
13 | String hello();
14 |
15 | @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
16 | String echo(@PathVariable("str") String str);
17 |
18 | @RequestMapping(value = "/echo/error/{str}", method = RequestMethod.GET)
19 | String echoError(@PathVariable("str") String str);
20 |
21 | @RequestMapping(value = "/echo/slow/{str}", method = RequestMethod.GET)
22 | String echoSlow(@PathVariable("str") String str);
23 | }
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-consumer/src/main/java/com/tencent/tsf/femas/example/springcloud/proxy/service/ProviderService.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.example.springcloud.proxy.service;
2 |
3 | import org.springframework.cloud.openfeign.FeignClient;
4 | import org.springframework.web.bind.annotation.PathVariable;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestMethod;
7 |
8 | @FeignClient(name = "femas-springcloud-provider")
9 | //@FeignClient(name = "femas-springcloud-provider", url = "127.0.0.1:19001")
10 | public interface ProviderService {
11 |
12 | @RequestMapping(value = "/hello", method = RequestMethod.GET)
13 | String hello();
14 |
15 | @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
16 | String echo(@PathVariable("str") String str);
17 |
18 | @RequestMapping(value = "/echo/error/{str}", method = RequestMethod.GET)
19 | String echoError(@PathVariable("str") String str);
20 |
21 | @RequestMapping(value = "/echo/slow/{str}", method = RequestMethod.GET)
22 | String echoSlow(@PathVariable("str") String str);
23 | }
--------------------------------------------------------------------------------
/femas-extensions/femas-extension-springcloud/femas-extension-springcloud-2020.0-ilford/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2 | com.tencent.tsf.femas.extension.springcloud.ilford.discovery.FemasDiscoveryAutoConfiguration,\
3 | com.tencent.tsf.femas.extension.springcloud.common.discovery.FemasDiscoveryCommonAutoConfiguration,\
4 | com.tencent.tsf.femas.extension.springcloud.common.instrumentation.config.FemasGovernanceAutoConfiguration,\
5 | com.tencent.tsf.femas.extension.springcloud.ilford.discovery.loadbalancer.config.FemasLoadBalancerAutoConfiguration,\
6 | com.tencent.tsf.femas.extension.springcloud.common.instrumentation.restapi.FemasSwaggerAutoConfiguration,\
7 | com.tencent.tsf.femas.extension.springcloud.ilford.discovery.FemasFeignInterceptorAutoConfiguration,\
8 | com.tencent.tsf.femas.extension.springcloud.common.instrumentation.metrics.PrometheusConfig,\
9 | com.tencent.tsf.femas.extension.springcloud.ilford.common.config.FemasContextConfiguration
10 | org.springframework.context.ApplicationListener=\
11 | com.tencent.tsf.femas.extension.springcloud.common.instrumentation.restapi.FemasSwaggerApplicationListener
--------------------------------------------------------------------------------
/femas-adaptor/femas-adaptor-opensource-admin/src/main/java/com/tencent/tsf/femas/adaptor/paas/config/FemasPaasConfigManager.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.adaptor.paas.config;
2 |
3 | import com.tencent.tsf.femas.adaptor.paas.common.FemasConstant;
4 | import com.tencent.tsf.femas.common.context.FemasContext;
5 | import com.tencent.tsf.femas.config.ConfigService;
6 | import com.tencent.tsf.femas.config.impl.paas.PaasConfig;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 |
10 | public class FemasPaasConfigManager {
11 |
12 | private final static Logger logger = LoggerFactory.getLogger(FemasPaasConfigManager.class);
13 |
14 | private static volatile PaasConfig PAAS_CONFIG;
15 |
16 | public static PaasConfig getConfig() {
17 | if (PAAS_CONFIG == null) {
18 | synchronized (FemasPaasConfigManager.class) {
19 | if (PAAS_CONFIG == null) {
20 | PAAS_CONFIG = (PaasConfig) ConfigService
21 | .createConfig(FemasConstant.FEMAS_CONFIG_PAAS, FemasContext.REGISTRY_CONFIG_MAP);
22 | }
23 | }
24 | }
25 | return PAAS_CONFIG;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/api/entity/ServiceApiRequest.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.api.entity;
2 |
3 | public class ServiceApiRequest {
4 |
5 | private String namespaceId;
6 |
7 | private String serviceName;
8 |
9 | private String applicationVersion;
10 |
11 | private String data;
12 |
13 | public String getNamespaceId() {
14 | return namespaceId;
15 | }
16 |
17 | public void setNamespaceId(String namespaceId) {
18 | this.namespaceId = namespaceId;
19 | }
20 |
21 | public String getServiceName() {
22 | return serviceName;
23 | }
24 |
25 | public void setServiceName(String serviceName) {
26 | this.serviceName = serviceName;
27 | }
28 |
29 | public String getApplicationVersion() {
30 | return applicationVersion;
31 | }
32 |
33 | public void setApplicationVersion(String applicationVersion) {
34 | this.applicationVersion = applicationVersion;
35 | }
36 |
37 | public String getData() {
38 | return data;
39 | }
40 |
41 | public void setData(String data) {
42 | this.data = data;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/lane/MockLaneFilter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.lane;
2 |
3 | import com.tencent.tsf.femas.common.entity.Service;
4 | import com.tencent.tsf.femas.common.entity.ServiceInstance;
5 | import com.tencent.tsf.femas.common.exception.FemasRuntimeException;
6 | import com.tencent.tsf.femas.governance.plugin.context.ConfigContext;
7 | import java.util.List;
8 |
9 | public class MockLaneFilter implements LaneFilter {
10 |
11 | @Override
12 | public String getType() {
13 | // 可能暂时不用
14 | return null;
15 | }
16 |
17 | @Override
18 | public String getName() {
19 | return "mockLane";
20 | }
21 |
22 | @Override
23 | public void preProcessLaneId() {
24 |
25 | }
26 |
27 | @Override
28 | public List filterInstancesWithLane(Service service, List serviceInstances) {
29 | // 直接返回
30 | return serviceInstances;
31 | }
32 |
33 | @Override
34 | public void init(ConfigContext conf) throws FemasRuntimeException {
35 |
36 | }
37 |
38 | @Override
39 | public void destroy() {
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/tag/constant/TagConstant.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.tag.constant;
2 |
3 | /**
4 | * 标签常量
5 | *
6 | * @author zhixinzxliu
7 | */
8 | public class TagConstant {
9 |
10 | /**
11 | * 标签类型
12 | */
13 | public static class TYPE {
14 |
15 | /**
16 | * 系统标签
17 | */
18 | public static final String SYSTEM = "S";
19 |
20 | /**
21 | * 用户自定义标签
22 | */
23 | public static final String CUSTOM = "U";
24 | }
25 |
26 | /**
27 | * 操作符
28 | */
29 | public static class OPERATOR {
30 |
31 | /**
32 | * 包含
33 | */
34 | public static final String IN = "IN";
35 | /**
36 | * 不包含
37 | */
38 | public static final String NOT_IN = "NOT_IN";
39 | /**
40 | * 等于
41 | */
42 | public static final String EQUAL = "EQUAL";
43 | /**
44 | * 不等于
45 | */
46 | public static final String NOT_EQUAL = "NOT_EQUAL";
47 | /**
48 | * 正则
49 | */
50 | public static final String REGEX = "REGEX";
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/test/java/com/tencent/tsf/femas/governance/circuitbreaker/core/IllegalStateTransitionExceptionTest.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.circuitbreaker.core;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 |
5 | import com.tencent.tsf.femas.governance.circuitbreaker.ICircuitBreakerService;
6 | import org.junit.Test;
7 |
8 | public class IllegalStateTransitionExceptionTest {
9 |
10 | @Test
11 | public void shouldReturnCorrectMessage() {
12 | IllegalStateTransitionException illegalStateTransitionException = new IllegalStateTransitionException(
13 | "testName", ICircuitBreakerService.State.OPEN,
14 | ICircuitBreakerService.State.CLOSED);
15 | assertThat(illegalStateTransitionException.getMessage()).isEqualTo(
16 | "CircuitBreaker 'testName' tried an illegal state transition from OPEN to CLOSED");
17 | assertThat(illegalStateTransitionException.getFromState())
18 | .isEqualTo(ICircuitBreakerService.State.OPEN);
19 | assertThat(illegalStateTransitionException.getToState())
20 | .isEqualTo(ICircuitBreakerService.State.CLOSED);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/ratelimit/RateLimiterManager.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.ratelimit;
2 |
3 | import com.tencent.tsf.femas.common.entity.Service;
4 | import java.util.Map;
5 | import java.util.concurrent.ConcurrentHashMap;
6 |
7 | /**
8 | * TODO 后续所有治理相关模块的使用可能会从静态方法变成类方法,以实现用户自己在需要的地方进行治理的能力
9 | */
10 | public class RateLimiterManager {
11 |
12 | public static Map RATE_LIMITERS = new ConcurrentHashMap<>();
13 |
14 | public static boolean acquire(Service service) {
15 | if (service == null) {
16 | return true;
17 | }
18 |
19 | RateLimiter rateLimiter = RATE_LIMITERS.get(service);
20 | // RATE_LIMITER 不为空,且Tag规则命中,且限流不通过
21 | if (rateLimiter != null && !rateLimiter.acquire()) {
22 | return false;
23 | }
24 |
25 | return true;
26 | }
27 |
28 | public static void refreshRateLimiter(Service service, RateLimiter rateLimiter) {
29 | RATE_LIMITERS.put(service, rateLimiter);
30 | }
31 |
32 | public static RateLimiter getRateLimiter(Service service) {
33 | return RATE_LIMITERS.get(service);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-2020-consumer/src/main/resources/nacos/bootstrap.yaml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 18001
3 | spring:
4 | application:
5 | name: femas-example-springcloud2020-consumer
6 | cloud:
7 | nacos:
8 | discovery:
9 | server-addr: 127.0.0.1:8848
10 | username: nacos
11 | password: nacos
12 | config:
13 | server-addr: 127.0.0.1:8848
14 |
15 | ribbon:
16 | ReadTimeout: 10000
17 | ConnectTimeout: 10000
18 | MaxAutoRetries: 0
19 | # 同一个微服务其他实例的最大重试次数,不包括第一次调用的实例。默认值为1
20 | MaxAutoRetriesNextServer: 0
21 | # 是否所有操作(GET、POST等)都允许重试。默认值为false
22 | OkToRetryOnAllOperations: false
23 |
24 | serviceRouter:
25 | chain:
26 | - FemasDefaultRoute
27 | loadbalancer:
28 | type: random
29 | circuitBreaker:
30 | enable: true
31 | chain:
32 | - femasCircuitBreaker
33 | # plugin:
34 | # femasCircuitBreaker:
35 | # continuousErrorThreshold: 10
36 | # metricStatTimeWindow: 1s
37 | # requestCountAfterHalfOpen: 3
38 | # sleepWindow: 5s
39 | # successCountAfterHalfOpen: 2
40 |
41 | rateLimit:
42 | type: femasRateLimit
43 | authenticate:
44 | type: femasAuthenticate
45 |
46 | paas_server_address: http://127.0.0.1:8080
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/plugin/config/global/SystemConfig.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Tencent is pleased to support the open source community by making Polaris available.
3 | *
4 | * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5 | *
6 | * Licensed under the BSD 3-Clause License (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://opensource.org/licenses/BSD-3-Clause
11 | *
12 | * Unless required by applicable law or agreed to in writing, software distributed
13 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.governance.plugin.config.global;
19 |
20 |
21 | import com.tencent.tsf.femas.governance.plugin.config.verify.Verifier;
22 |
23 | /**
24 | * api相关的配置对象
25 | *
26 | * @author andrewshan
27 | * @date 2019/8/20
28 | */
29 | public interface SystemConfig extends Verifier {
30 |
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/loadbalance/impl/RandomLoadbalancer.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.loadbalance.impl;
2 |
3 | import com.tencent.tsf.femas.common.entity.ServiceInstance;
4 | import com.tencent.tsf.femas.common.exception.FemasRuntimeException;
5 | import com.tencent.tsf.femas.governance.plugin.context.ConfigContext;
6 | import java.util.List;
7 | import java.util.Random;
8 |
9 | /**
10 | *
11 | */
12 | public class RandomLoadbalancer extends AbstractLoadbalancer {
13 |
14 | private final Random random = new Random(System.currentTimeMillis());
15 |
16 | @Override
17 | public ServiceInstance doSelect(List serviceInstances) {
18 | int size = serviceInstances.size(); // 总个数
19 | return serviceInstances.get(random.nextInt(size));
20 | }
21 |
22 | @Override
23 | public String getType() {
24 | return null;
25 | }
26 |
27 | @Override
28 | public void init(ConfigContext conf) throws FemasRuntimeException {
29 |
30 | }
31 |
32 | @Override
33 | public String getName() {
34 | return "random";
35 | }
36 |
37 | @Override
38 | public void destroy() {
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/femas-config/src/main/java/com/tencent/tsf/femas/config/FemasConfigManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Tencent is pleased to support the open source community by making Femas available.
3 | *
4 | * Copyright (C) 2021, a Tencent company. All rights reserved.
5 | *
6 | * Licensed under the BSD 3-Clause License (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://opensource.org/licenses/BSD-3-Clause
11 | *
12 | * Unless required by applicable law or agreed to in writing, software distributed
13 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.config;
19 |
20 | import com.tencent.tsf.femas.common.annotation.AdaptorComponent;
21 |
22 | /**
23 | *
24 | * 文件名称:FemasConfigManager.java
25 | * 创建时间:Aug 11, 2021 4:46:04 PM
26 | * @author juanyinyang
27 | * 类说明:
28 | */
29 | @AdaptorComponent
30 | public abstract class FemasConfigManager {
31 |
32 | public abstract Config getConfig();
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/femas-helm/Chart.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v2
2 | name: femas-helm
3 | description: A Helm chart for Kubernetes
4 |
5 | # A chart can be either an 'application' or a 'library' chart.
6 | #
7 | # Application charts are a collection of templates that can be packaged into versioned archives
8 | # to be deployed.
9 | #
10 | # Library charts provide useful utilities or functions for the chart developer. They're included as
11 | # a dependency of application charts to inject those utilities and functions into the rendering
12 | # pipeline. Library charts do not define any templates and therefore cannot be deployed.
13 | type: application
14 |
15 | # This is the chart version. This version number should be incremented each time you make changes
16 | # to the chart and its templates, including the app version.
17 | # Versions are expected to follow Semantic Versioning (https://semver.org/)
18 | version: 0.1.0
19 |
20 | # This is the version number of the application being deployed. This version number should be
21 | # incremented each time you make changes to the application. Versions are not expected to
22 | # follow Semantic Versioning. They should reflect the version the application is using.
23 | # It is recommended to use it with quotes.
24 | appVersion: "1.16.0"
25 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-2020-consumer/src/main/java/com/femas/example/springcloud2020/consumer/TestFilter.java:
--------------------------------------------------------------------------------
1 | package com.femas.example.springcloud2020.consumer;
2 |
3 |
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.core.Ordered;
7 | import org.springframework.core.annotation.Order;
8 | import org.springframework.web.filter.OncePerRequestFilter;
9 |
10 | import javax.servlet.FilterChain;
11 | import javax.servlet.ServletException;
12 | import javax.servlet.http.HttpServletRequest;
13 | import javax.servlet.http.HttpServletResponse;
14 | import java.io.IOException;
15 |
16 |
17 | @Order(TestFilter.ORDER)
18 | public class TestFilter extends OncePerRequestFilter {
19 |
20 | public static final int ORDER = Ordered.HIGHEST_PRECEDENCE;
21 | private static final Logger LOG = LoggerFactory.getLogger(TestFilter.class);
22 |
23 | @Override
24 | protected void doFilterInternal(final HttpServletRequest request,
25 | final HttpServletResponse response,
26 | final FilterChain filterChain)
27 | throws ServletException, IOException {
28 | // LOG.info("Hello World");
29 | filterChain.doFilter(request, response);
30 | }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-consumer/src/main/java/com/tencent/tsf/femas/example/springcloud/TestFilter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.example.springcloud;
2 |
3 |
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.core.Ordered;
7 | import org.springframework.core.annotation.Order;
8 | import org.springframework.web.filter.OncePerRequestFilter;
9 |
10 | import javax.servlet.FilterChain;
11 | import javax.servlet.ServletException;
12 | import javax.servlet.http.HttpServletRequest;
13 | import javax.servlet.http.HttpServletResponse;
14 | import java.io.IOException;
15 |
16 |
17 | @Order(TestFilter.ORDER)
18 | public class TestFilter extends OncePerRequestFilter {
19 |
20 | public static final int ORDER = Ordered.HIGHEST_PRECEDENCE;
21 | private static final Logger LOG = LoggerFactory.getLogger(TestFilter.class);
22 |
23 | @Override
24 | protected void doFilterInternal(final HttpServletRequest request,
25 | final HttpServletResponse response,
26 | final FilterChain filterChain)
27 | throws ServletException, IOException {
28 | // LOG.info("Hello World");
29 | filterChain.doFilter(request, response);
30 | }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-greenwich-gateway/src/main/java/com/tencent/tsf/femas/example/gateway/springcloud/filter/TestFilter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.example.gateway.springcloud.filter;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.cloud.gateway.filter.GatewayFilterChain;
6 | import org.springframework.cloud.gateway.filter.GlobalFilter;
7 | import org.springframework.cloud.gateway.support.ServerWebExchangeUtils;
8 | import org.springframework.core.Ordered;
9 | import org.springframework.stereotype.Component;
10 | import org.springframework.web.server.ServerWebExchange;
11 | import reactor.core.publisher.Mono;
12 |
13 | @Component
14 | public class TestFilter implements GlobalFilter, Ordered {
15 |
16 | private static final Logger LOG = LoggerFactory.getLogger(TestFilter.class);
17 |
18 | @Override
19 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) {
20 | LOG.info(exchange.getAttributes().get(ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR).toString());
21 | return chain.filter(exchange);
22 | }
23 |
24 | @Override
25 | public int getOrder() {
26 | return Ordered.LOWEST_PRECEDENCE;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/femas-config/src/main/java/com/tencent/tsf/femas/config/ConfigService.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.config;
2 |
3 | import com.tencent.tsf.femas.common.spi.SpiService;
4 | import java.util.Map;
5 |
6 | /**
7 | * Entry point for client config use
8 | *
9 | * @author Jason Song(song_s@ctrip.com)
10 | */
11 | public class ConfigService {
12 |
13 | /**
14 | * key是注册中心的类型
15 | * value是注册中心的类别
16 | */
17 | private static Map CONFIG_FACTORIES;
18 |
19 | /**
20 | * 创建新的Registry然后返回
21 | * 请自行保存返回后的Config并且复用,请勿每次调用获取该对象
22 | *
23 | * @param type
24 | * @param configs
25 | * @return
26 | */
27 | public static synchronized Config createConfig(String type, Map configs) {
28 | if (CONFIG_FACTORIES == null) {
29 | CONFIG_FACTORIES = SpiService.init(ConfigFactory.class);
30 | }
31 |
32 | ConfigFactory configFactory = CONFIG_FACTORIES.get(type);
33 | if (configFactory == null) {
34 | throw new IllegalArgumentException("Invalid type " + type + ". ConfigFactory : Type not registered.");
35 | }
36 |
37 | Config config = configFactory.create(configs);
38 | return config;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/metrics/micrometer/meter/MicroDistributionSummary.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.metrics.micrometer.meter;
2 |
3 | import com.tencent.tsf.femas.governance.metrics.MeterEnum;
4 | import io.micrometer.core.instrument.DistributionSummary;
5 | import io.micrometer.core.instrument.MeterRegistry;
6 | import io.micrometer.core.instrument.Tag;
7 | import java.util.List;
8 |
9 | /**
10 | * @Author p_mtluo
11 | * @Date 2021-08-17 20:07
12 | * @Description DistributionSummary
13 | **/
14 | public class MicroDistributionSummary extends MicroMeter
15 | implements com.tencent.tsf.femas.governance.metrics.DistributionSummary {
16 |
17 |
18 | public MicroDistributionSummary(MeterRegistry registry, MeterEnum meterType, String meterName, List tagList) {
19 | super(registry, meterType, meterName, tagList);
20 | }
21 |
22 | @Override
23 | public DistributionSummary createMeter() {
24 | return this.registry.summary(this.meterName, this.tagList);
25 | }
26 |
27 | @Override
28 | public void record(double amount) {
29 | this.meter.record(amount);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/metrics/micrometer/meter/MicroCounter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.metrics.micrometer.meter;
2 |
3 | import com.tencent.tsf.femas.governance.metrics.MeterEnum;
4 | import io.micrometer.core.instrument.Counter;
5 | import io.micrometer.core.instrument.MeterRegistry;
6 | import io.micrometer.core.instrument.Tag;
7 | import java.util.List;
8 |
9 | /**
10 | * @Author p_mtluo
11 | * @Date 2021-08-17 20:10
12 | * @Description counter
13 | **/
14 | public class MicroCounter extends MicroMeter
15 | implements com.tencent.tsf.femas.governance.metrics.Counter {
16 |
17 |
18 | public MicroCounter(MeterRegistry registry, MeterEnum meterType, String meterName, List tagList) {
19 | super(registry, meterType, meterName, tagList);
20 | }
21 |
22 | @Override
23 | public Counter createMeter() {
24 | return this.registry.counter(this.meterName, this.tagList);
25 | }
26 |
27 | @Override
28 | public void increment(double amount) {
29 | this.meter.increment(amount);
30 | }
31 |
32 | @Override
33 | public void increment() {
34 | this.meter.increment();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-consul/src/main/java/com/tencent/tsf/femas/registry/impl/consul/discovery/ConsulServiceDiscoveryFactory.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.registry.impl.consul.discovery;
2 |
3 | import com.tencent.tsf.femas.common.RegistryEnum;
4 | import com.tencent.tsf.femas.common.discovery.ServiceDiscoveryClient;
5 | import com.tencent.tsf.femas.common.discovery.ServiceDiscoveryFactory;
6 | import java.util.Map;
7 | import java.util.concurrent.ConcurrentHashMap;
8 |
9 |
10 | /**
11 | * @author zhixinzxliu
12 | */
13 | public class ConsulServiceDiscoveryFactory implements ServiceDiscoveryFactory {
14 |
15 | private static Map clientMap = new ConcurrentHashMap<>();
16 |
17 | @Override
18 | public String getType() {
19 | return RegistryEnum.CONSUL.name();
20 | }
21 |
22 | @Override
23 | public ServiceDiscoveryClient getServiceDiscovery(Map configMap) {
24 | String key = getKey(configMap);
25 | if (!clientMap.containsKey(key)) {
26 | ServiceDiscoveryClient client = new ConsulServiceDiscoveryClient(configMap);
27 | clientMap.putIfAbsent(key, client);
28 | }
29 | return clientMap.get(key);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/femas-registry/src/main/java/com/tencent/tsf/femas/common/serviceregistry/AbstractServiceRegistryMetadata.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Tencent is pleased to support the open source community by making Femas available.
3 | *
4 | * Copyright (C) 2021, a Tencent company. All rights reserved.
5 | *
6 | * Licensed under the BSD 3-Clause License (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://opensource.org/licenses/BSD-3-Clause
11 | *
12 | * Unless required by applicable law or agreed to in writing, software distributed
13 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.common.serviceregistry;
19 |
20 | import java.util.Map;
21 |
22 | /**
23 | *
24 | * 文件名称:AbstractServiceRegistryMetadata.java
25 | * 创建时间:Jul 31, 2021 7:21:13 PM
26 | * @author juanyinyang
27 | * 类说明:
28 | */
29 | public abstract class AbstractServiceRegistryMetadata {
30 |
31 | public abstract Map getRegisterMetadataMap();
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/metrics/micrometer/ModuleEnum.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.governance.metrics.micrometer;
19 |
20 | /**
21 | * @Author leoziltong
22 | * @Date: 2021/7/14 16:59
23 | * @Version 1.0
24 | */
25 | public enum ModuleEnum {
26 |
27 | /**
28 | * 模块类型
29 | */
30 | AUTH,
31 | RATE_LIMIT,
32 | CIRCUIT_BREAKER;
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/auth/entity/AuthRuleGroup.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.auth.entity;
2 |
3 | import com.tencent.tsf.femas.common.tag.TagRule;
4 | import java.io.Serializable;
5 | import java.util.List;
6 |
7 | public class AuthRuleGroup implements Serializable {
8 |
9 | /**
10 | * serialVersionUID
11 | */
12 | private static final long serialVersionUID = 1643183648126834802L;
13 |
14 | /**
15 | * 规则列表
16 | */
17 | private List rules;
18 |
19 | /**
20 | * 鉴权类型,黑名单/白名单
21 | */
22 | private String type;
23 |
24 | public List getRules() {
25 | return rules;
26 | }
27 |
28 | public void setRules(List rules) {
29 | this.rules = rules;
30 | }
31 |
32 | public String getType() {
33 | return type;
34 | }
35 |
36 | public void setType(String type) {
37 | this.type = type;
38 | }
39 |
40 | @Override
41 | public String toString() {
42 | final StringBuffer sb = new StringBuffer("AuthRuleGroup{");
43 | sb.append("rules=").append(rules);
44 | sb.append(", type='").append(type).append('\'');
45 | sb.append('}');
46 | return sb.toString();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-k8s/src/main/java/com/tencent/tsf/femas/registry/impl/k8s/serviceregistry/K8sServiceRegistry.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.registry.impl.k8s.serviceregistry;
2 |
3 | import com.tencent.tsf.femas.common.entity.EndpointStatus;
4 | import com.tencent.tsf.femas.common.entity.ServiceInstance;
5 | import com.tencent.tsf.femas.common.serviceregistry.AbstractServiceRegistry;
6 |
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 |
10 | import java.util.Map;
11 |
12 |
13 | /**
14 | * @author leo
15 | */
16 | public class K8sServiceRegistry extends AbstractServiceRegistry {
17 | private static final Logger logger = LoggerFactory.getLogger(K8sServiceRegistry.class);
18 |
19 |
20 | public K8sServiceRegistry(Map configMap) {
21 | }
22 |
23 | @Override
24 | protected void doRegister(ServiceInstance serviceInstance) {
25 |
26 | }
27 |
28 | @Override
29 | protected void doDeregister(ServiceInstance serviceInstance) {
30 |
31 | }
32 |
33 |
34 | @Override
35 | public void setStatus(ServiceInstance serviceInstance, EndpointStatus status) {
36 |
37 | }
38 |
39 | @Override
40 | public EndpointStatus getStatus(ServiceInstance serviceInstance) {
41 | return null;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/femas-registry/src/main/java/com/tencent/tsf/femas/common/discovery/DiscoveryService.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.discovery;
2 |
3 | import com.tencent.tsf.femas.common.spi.SpiService;
4 | import java.util.Map;
5 |
6 | public class DiscoveryService {
7 |
8 | /**
9 | * key是注册中心的类型
10 | * value是注册中心的类别
11 | */
12 | private static Map DISCOVERY_FACTORIES;
13 |
14 | /**
15 | * 创建新的Discovery然后返回
16 | *
17 | * @param type
18 | * @param configs
19 | * @return
20 | */
21 | public static synchronized ServiceDiscoveryClient createDiscoveryClient(String type, Map configs) {
22 | if (DISCOVERY_FACTORIES == null) {
23 | DISCOVERY_FACTORIES = SpiService.init(ServiceDiscoveryFactory.class);
24 | }
25 |
26 | ServiceDiscoveryFactory discoveryFactory = DISCOVERY_FACTORIES.get(type.toUpperCase());
27 | if (discoveryFactory == null) {
28 | throw new IllegalArgumentException(
29 | "Invalid type " + type + ". ServiceDiscoveryFactory : Type not registered.");
30 | }
31 |
32 | ServiceDiscoveryClient discoveryClient = discoveryFactory.getServiceDiscovery(configs);
33 | return discoveryClient;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/test/java/com/tencent/tsf/femas/governance/circuitbreaker/core/CallNotPermittedExceptionTest.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.circuitbreaker.core;
2 |
3 | import static com.tencent.tsf.femas.governance.circuitbreaker.core.CallNotPermittedException.createCallNotPermittedException;
4 | import static org.assertj.core.api.Assertions.assertThat;
5 |
6 | import org.junit.Test;
7 |
8 | public class CallNotPermittedExceptionTest {
9 |
10 | @Test
11 | public void shouldReturnCorrectMessageWhenStateIsOpen() {
12 | CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults("testName");
13 | circuitBreaker.transitionToOpenState();
14 | assertThat(createCallNotPermittedException(circuitBreaker).getMessage())
15 | .isEqualTo("CircuitBreaker 'testName' is OPEN and does not permit further calls");
16 | }
17 |
18 | @Test
19 | public void shouldReturnCorrectMessageWhenStateIsForcedOpen() {
20 | CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults("testName");
21 | circuitBreaker.transitionToForcedOpenState();
22 | assertThat(createCallNotPermittedException(circuitBreaker).getMessage()).isEqualTo(
23 | "CircuitBreaker 'testName' is FORCED_OPEN and does not permit further calls");
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/test/java/com/tencent/tsf/femas/governance/circuitbreaker/core/CircuitBreakerOpenExceptionTest.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.circuitbreaker.core;
2 |
3 | import static com.tencent.tsf.femas.governance.circuitbreaker.core.CallNotPermittedException.createCallNotPermittedException;
4 | import static org.assertj.core.api.Assertions.assertThat;
5 |
6 | import org.junit.Test;
7 |
8 | public class CircuitBreakerOpenExceptionTest {
9 |
10 | @Test
11 | public void shouldReturnCorrectMessageWhenStateIsOpen() {
12 | CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults("testName");
13 | circuitBreaker.transitionToOpenState();
14 | assertThat(createCallNotPermittedException(circuitBreaker).getMessage())
15 | .isEqualTo("CircuitBreaker 'testName' is OPEN and does not permit further calls");
16 | }
17 |
18 | @Test
19 | public void shouldReturnCorrectMessageWhenStateIsForcedOpen() {
20 | CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults("testName");
21 | circuitBreaker.transitionToForcedOpenState();
22 | assertThat(createCallNotPermittedException(circuitBreaker).getMessage()).isEqualTo(
23 | "CircuitBreaker 'testName' is FORCED_OPEN and does not permit further calls");
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-2020-consumer/src/main/resources/consul/bootstrap.yaml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 18001
3 | spring:
4 | application:
5 | name: femas-example-springcloud2020-consumer
6 | cloud:
7 | consul:
8 | host: 127.0.0.1
9 | port: 8500
10 | discovery:
11 | serviceName: femas-example-springcloud2020-consumer
12 | instanceId: ${spring.application.name}-${server.port}-${spring.cloud.client.hostname}
13 | heartbeat:
14 | enabled: true
15 |
16 | ribbon:
17 | ReadTimeout: 10000
18 | ConnectTimeout: 10000
19 | MaxAutoRetries: 0
20 | # 同一个微服务其他实例的最大重试次数,不包括第一次调用的实例。默认值为1
21 | MaxAutoRetriesNextServer: 0
22 | # 是否所有操作(GET、POST等)都允许重试。默认值为false
23 | OkToRetryOnAllOperations: false
24 |
25 | serviceRouter:
26 | chain:
27 | - FemasDefaultRoute
28 | loadbalancer:
29 | type: random
30 | circuitBreaker:
31 | enable: true
32 | chain:
33 | - femasCircuitBreaker
34 | # plugin:
35 | # femasCircuitBreaker:
36 | # continuousErrorThreshold: 10
37 | # metricStatTimeWindow: 1s
38 | # requestCountAfterHalfOpen: 3
39 | # sleepWindow: 5s
40 | # successCountAfterHalfOpen: 2
41 |
42 | rateLimit:
43 | type: femasRateLimit
44 | authenticate:
45 | type: femasAuthenticate
46 |
47 | paas_server_address: http://127.0.0.1:8080
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-k8s/src/main/java/com/tencent/tsf/femas/registry/impl/k8s/discovery/K8sServiceDiscoveryFactory.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.registry.impl.k8s.discovery;
2 |
3 | import com.tencent.tsf.femas.common.RegistryEnum;
4 | import com.tencent.tsf.femas.common.discovery.ServiceDiscoveryClient;
5 | import com.tencent.tsf.femas.common.discovery.ServiceDiscoveryFactory;
6 |
7 | import java.util.Map;
8 | import java.util.concurrent.ConcurrentHashMap;
9 |
10 |
11 | /**
12 | * @Author leoziltong
13 | * @Description //TODO
14 | * @Date: 2021/3/24 15:25
15 | * @Version 1.0
16 | */
17 | public class K8sServiceDiscoveryFactory implements ServiceDiscoveryFactory {
18 |
19 | private static Map clientMap = new ConcurrentHashMap<>();
20 |
21 | @Override
22 | public ServiceDiscoveryClient getServiceDiscovery(Map configMap) {
23 | String key = getKey(configMap);
24 | if (!clientMap.containsKey(key)) {
25 | ServiceDiscoveryClient client = new K8sServiceDiscoveryClient(configMap);
26 | clientMap.putIfAbsent(key, client);
27 | }
28 | return clientMap.get(key);
29 | }
30 |
31 | @Override
32 | public String getType() {
33 | return RegistryEnum.KUBERNETES.name();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-nacos/src/main/java/com/tencent/tsf/femas/registry/impl/nacos/discovery/NacosServiceDiscoveryFactory.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.registry.impl.nacos.discovery;
2 |
3 | import com.tencent.tsf.femas.common.RegistryEnum;
4 | import com.tencent.tsf.femas.common.discovery.ServiceDiscoveryClient;
5 | import com.tencent.tsf.femas.common.discovery.ServiceDiscoveryFactory;
6 | import java.util.Map;
7 | import java.util.concurrent.ConcurrentHashMap;
8 |
9 |
10 | /**
11 | * @Author leoziltong
12 | * @Description //TODO
13 | * @Date: 2021/3/24 15:25
14 | * @Version 1.0
15 | */
16 | public class NacosServiceDiscoveryFactory implements ServiceDiscoveryFactory {
17 |
18 | private static Map clientMap = new ConcurrentHashMap<>();
19 |
20 | @Override
21 | public ServiceDiscoveryClient getServiceDiscovery(Map configMap) {
22 | String key = getKey(configMap);
23 | if (!clientMap.containsKey(key)) {
24 | ServiceDiscoveryClient client = new NacosServiceDiscoveryClient(configMap);
25 | clientMap.putIfAbsent(key, client);
26 | }
27 | return clientMap.get(key);
28 | }
29 |
30 | @Override
31 | public String getType() {
32 | return RegistryEnum.NACOS.name();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/femas-extensions/femas-extension-springcloud/femas-extension-springcloud-common/src/main/java/com/tencent/tsf/femas/extension/springcloud/common/discovery/nacos/FemasNacosRegistrationCustomizer.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.extension.springcloud.common.discovery.nacos;
2 |
3 | import com.alibaba.cloud.nacos.registry.NacosRegistration;
4 | import com.alibaba.cloud.nacos.registry.NacosRegistrationCustomizer;
5 | import com.tencent.tsf.femas.common.serviceregistry.AbstractServiceRegistryMetadata;
6 | import com.tencent.tsf.femas.common.serviceregistry.AbstractServiceRegistryMetadataFactory;
7 | import java.util.Map;
8 |
9 | /**
10 | * @author juanyinyang
11 | */
12 | public class FemasNacosRegistrationCustomizer implements NacosRegistrationCustomizer {
13 |
14 | private volatile AbstractServiceRegistryMetadata serviceRegistryMetadata = AbstractServiceRegistryMetadataFactory
15 | .getServiceRegistryMetadata();
16 |
17 | public FemasNacosRegistrationCustomizer() {
18 | }
19 |
20 | @Override
21 | public void customize(NacosRegistration registration) {
22 | Map registerMetadataMap = serviceRegistryMetadata.getRegisterMetadataMap();
23 | registerMetadataMap.put("protocol", "spring-cloud-nacos");
24 | registration.getMetadata().putAll(registerMetadataMap);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/util/ConfigUtils.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.util;
2 |
3 | import org.apache.commons.collections.MapUtils;
4 | import org.apache.commons.lang3.StringUtils;
5 | import org.yaml.snakeyaml.Yaml;
6 |
7 | import java.io.File;
8 | import java.io.IOException;
9 | import java.util.Map;
10 |
11 | public class ConfigUtils {
12 |
13 | public static Map loadRelativeConfig(String fileName) {
14 | String content = null;
15 | try {
16 | content = FileUtils.file2String(fileName, "UTF-8");
17 | } catch (IOException e) {
18 | e.printStackTrace();
19 | }
20 | return content2Map(content);
21 | }
22 |
23 | public static Map loadAbsoluteConfig(File file) {
24 | String content = null;
25 | try {
26 | content = FileUtils.file2String(file);
27 | } catch (IOException e) {
28 | e.printStackTrace();
29 | }
30 | return content2Map(content);
31 | }
32 |
33 | public static Map content2Map(String content) {
34 | if (StringUtils.isNotEmpty(content)) {
35 | Yaml yaml = new Yaml();
36 | return yaml.load(content);
37 | }
38 | return MapUtils.EMPTY_MAP;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/loadbalance/impl/AbstractLoadbalancer.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.loadbalance.impl;
2 |
3 | import com.tencent.tsf.femas.common.context.Context;
4 | import com.tencent.tsf.femas.common.entity.Request;
5 | import com.tencent.tsf.femas.common.entity.ServiceInstance;
6 | import com.tencent.tsf.femas.common.util.CollectionUtil;
7 | import com.tencent.tsf.femas.governance.loadbalance.Loadbalancer;
8 | import com.tencent.tsf.femas.governance.loadbalance.exception.FemasNoAvailableInstanceException;
9 | import java.util.List;
10 |
11 | public abstract class AbstractLoadbalancer implements Loadbalancer {
12 |
13 | @Override
14 | public ServiceInstance select(List serviceInstances) {
15 | if (CollectionUtil.isEmpty(serviceInstances)) {
16 | Request request = Context.getRpcInfo().getRequest();
17 | throw new FemasNoAvailableInstanceException("No available instances. Request : " + request);
18 | }
19 |
20 | if (serviceInstances.size() == 1) {
21 | return serviceInstances.iterator().next();
22 | } else {
23 | return doSelect(serviceInstances);
24 | }
25 | }
26 |
27 | public abstract ServiceInstance doSelect(List serviceInstances);
28 | }
29 |
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-eureka/src/main/java/com/tencent/tsf/femas/registry/impl/eureka/discovery/EurekaServiceDiscoveryFactory.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.registry.impl.eureka.discovery;
2 |
3 | import com.tencent.tsf.femas.common.RegistryEnum;
4 | import com.tencent.tsf.femas.common.discovery.ServiceDiscoveryClient;
5 | import com.tencent.tsf.femas.common.discovery.ServiceDiscoveryFactory;
6 | import java.util.Map;
7 | import java.util.concurrent.ConcurrentHashMap;
8 |
9 |
10 | /**
11 | * @Author leoziltong
12 | * @Description //TODO
13 | * @Date: 2021/3/24 15:25
14 | * @Version 1.0
15 | */
16 | public class EurekaServiceDiscoveryFactory implements ServiceDiscoveryFactory {
17 |
18 |
19 | private static Map clientMap = new ConcurrentHashMap<>();
20 |
21 | @Override
22 | public ServiceDiscoveryClient getServiceDiscovery(Map configMap) {
23 | String key = getKey(configMap);
24 | if (!clientMap.containsKey(key)) {
25 | ServiceDiscoveryClient client = new EurekaServiceDiscoveryClient(configMap);
26 | clientMap.putIfAbsent(key, client);
27 | }
28 | return clientMap.get(key);
29 | }
30 |
31 | @Override
32 | public String getType() {
33 | return RegistryEnum.EUREKA.name();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/route/RouterRuleManager.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.route;
2 |
3 | import com.google.common.collect.Maps;
4 | import com.tencent.tsf.femas.common.entity.Service;
5 | import com.tencent.tsf.femas.governance.route.entity.RouteRuleGroup;
6 | import java.util.Map;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 |
10 | public class RouterRuleManager {
11 |
12 | private static final Logger LOGGER = LoggerFactory.getLogger(RouterRuleManager.class);
13 |
14 | private static Map routeRuleMap = Maps.newConcurrentMap();
15 |
16 | public static RouteRuleGroup getRouteRuleGroup(Service service) {
17 | return routeRuleMap.get(service);
18 | }
19 |
20 | public static void refreshRouteRule(Service service, RouteRuleGroup routeRuleGroup) {
21 | if (routeRuleGroup == null) {
22 | routeRuleMap.remove(service);
23 | }
24 |
25 | routeRuleMap.put(service, routeRuleGroup);
26 | LOGGER.info("Refresh router rule. Service : " + service + ", rule " + routeRuleGroup);
27 | }
28 |
29 | public static void removeRouteRule(Service service) {
30 | routeRuleMap.remove(service);
31 | LOGGER.info("Remove router rule. Service : " + service);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/metrics/micrometer/meter/MicroLongTaskTimer.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.metrics.micrometer.meter;
2 |
3 | import com.tencent.tsf.femas.governance.metrics.MeterEnum;
4 | import io.micrometer.core.instrument.LongTaskTimer;
5 | import io.micrometer.core.instrument.MeterRegistry;
6 | import io.micrometer.core.instrument.Tag;
7 | import java.util.List;
8 |
9 | /**
10 | * @Author p_mtluo
11 | * @Date 2021-08-17 20:12
12 | * @Description long task timer
13 | **/
14 | public class MicroLongTaskTimer extends MicroMeter
15 | implements com.tencent.tsf.femas.governance.metrics.LongTaskTimer {
16 |
17 | public MicroLongTaskTimer(MeterRegistry registry, MeterEnum meterType, String meterName, List tagList) {
18 | super(registry, meterType, meterName, tagList);
19 | }
20 |
21 | @Override
22 | public LongTaskTimer createMeter() {
23 | return this.registry.more().longTaskTimer(this.meterName, this.tagList);
24 | }
25 |
26 | @Override
27 | public LongTaskTimer.Sample start() {
28 | return this.meter.start();
29 | }
30 |
31 | @Override
32 | public long stop(long task) {
33 | return this.meter.stop(task);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/util/GsonUtil.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.util;
2 |
3 | import com.google.gson.Gson;
4 | import com.google.gson.GsonBuilder;
5 | import com.tencent.tsf.femas.common.codec.EscapeNonAsciiWriter;
6 | import java.io.StringWriter;
7 | import org.apache.commons.lang3.StringUtils;
8 |
9 | public class GsonUtil {
10 |
11 | private static Gson DESERIALIZE_GSON = new GsonBuilder().disableHtmlEscaping().create();
12 | private static Gson SERIALIZE_GSON = new GsonBuilder().disableHtmlEscaping().excludeFieldsWithoutExposeAnnotation()
13 | .create();
14 |
15 |
16 | public static T deserialize(String content, Class clazz) {
17 | if (StringUtils.isBlank(content)) {
18 | return null;
19 | }
20 |
21 | return DESERIALIZE_GSON.fromJson(content, clazz);
22 | }
23 |
24 | // TODO 编写一个可复用的Writer(reset byte数组)
25 | public static String serializeToJson(T object) {
26 | StringWriter writer = new StringWriter();
27 | EscapeNonAsciiWriter escapeWriter = new EscapeNonAsciiWriter(writer);
28 |
29 | SERIALIZE_GSON.toJson(object, escapeWriter);
30 | return writer.toString();
31 | }
32 |
33 | public static String toJson(T object) {
34 | return SERIALIZE_GSON.toJson(object);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/femas-starters/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | com.tencent.tsf
9 | femas-parent
10 | ${revision}
11 |
12 |
13 | femas-starters
14 | pom
15 | femas-starters
16 |
17 |
18 | femas-springcloud-starters
19 |
20 |
21 |
22 |
23 |
24 | org.apache.maven.plugins
25 | maven-jar-plugin
26 |
27 |
28 |
29 | ${project.version}
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/femas-extensions/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | com.tencent.tsf
9 | femas-parent
10 | ${revision}
11 |
12 |
13 | femas-extensions
14 | pom
15 | femas-extensions
16 |
17 |
18 | femas-extension-springcloud
19 |
20 |
21 |
22 |
23 |
24 | org.apache.maven.plugins
25 | maven-jar-plugin
26 |
27 |
28 |
29 | ${project.version}
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/metrics/MeterEnum.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.governance.metrics;
19 |
20 | /**
21 | * @Author leoziltong
22 | * @Date: 2021/7/14 16:59
23 | * @Version 1.0
24 | */
25 | public enum MeterEnum {
26 |
27 | /**
28 | * 指标类型
29 | */
30 | TIMER,
31 | COUNTER,
32 | FUNCTION_COUNTER,
33 | FUNCTION_TIMER,
34 | LONG_TASK_TIMER,
35 | GAUGE,
36 | TIME_GAUGE,
37 | DISTRIBUTION_SUMMARY;
38 |
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/plugin/config/gov/AuthenticateConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.governance.plugin.config.gov;
19 |
20 | import com.tencent.tsf.femas.governance.plugin.config.PluginConfig;
21 | import com.tencent.tsf.femas.governance.plugin.config.verify.Verifier;
22 |
23 | /**
24 | * @Author leoziltong
25 | * @Date: 2021/6/2 20:51
26 | */
27 | public interface AuthenticateConfig extends PluginConfig, Verifier {
28 |
29 | String getType();
30 | }
31 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/exception/ErrorCode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.common.exception;
19 |
20 | /**
21 | * @Author leoziltong
22 | * @Date: 2021/5/25 16:30
23 | */
24 | public enum ErrorCode {
25 | /**
26 | * 获取插件失败
27 | */
28 | PLUGIN_NOT_FOUND(1003),
29 | /**
30 | * 插件初始化错误
31 | */
32 | PLUGIN_INIT_ERROR(1004);
33 |
34 | int code;
35 |
36 | ErrorCode(int code) {
37 | this.code = code;
38 | }
39 |
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/plugin/config/gov/LaneConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.governance.plugin.config.gov;
19 |
20 | import com.tencent.tsf.femas.governance.plugin.config.PluginConfig;
21 | import com.tencent.tsf.femas.governance.plugin.config.verify.Verifier;
22 |
23 | /**
24 | * @Author leoziltong
25 | * @Date: 2021/5/25 20:51
26 | * @Version 1.0
27 | */
28 | public interface LaneConfig extends PluginConfig, Verifier {
29 |
30 | String getType();
31 | }
32 |
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-consul/src/main/java/com/tencent/tsf/femas/registry/impl/consul/util/NormalizeUtil.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.registry.impl.consul.util;
2 |
3 | import com.tencent.tsf.femas.registry.impl.consul.ConsulConstants;
4 |
5 | public class NormalizeUtil {
6 |
7 | /**
8 | * copy from Spring
9 | *
10 | * @param s
11 | * @return
12 | */
13 | public static String normalizeForDns(String s) {
14 | // tsf not check consul service instance id start with letter and end with
15 | // letter or digit
16 | if (s == null) {
17 | throw new IllegalArgumentException("Consul service ids must not be empty");
18 | }
19 |
20 | StringBuilder normalized = new StringBuilder();
21 | Character prev = null;
22 | for (char curr : s.toCharArray()) {
23 | Character toAppend = null;
24 | if (Character.isLetterOrDigit(curr)) {
25 | toAppend = curr;
26 | } else if (prev == null || !(prev == ConsulConstants.SEPARATOR)) {
27 | toAppend = ConsulConstants.SEPARATOR;
28 | }
29 | if (toAppend != null) {
30 | normalized.append(toAppend);
31 | prev = toAppend;
32 | }
33 | }
34 |
35 | return normalized.toString();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/plugin/config/verify/Verifier.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Tencent is pleased to support the open source community by making Polaris available.
3 | *
4 | * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5 | *
6 | * Licensed under the BSD 3-Clause License (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://opensource.org/licenses/BSD-3-Clause
11 | *
12 | * Unless required by applicable law or agreed to in writing, software distributed
13 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.governance.plugin.config.verify;
19 |
20 | /**
21 | * 检验SDK配置
22 | *
23 | * @author andrewshan
24 | * @author leoziltong
25 | * @date 2019/8/20
26 | */
27 | public interface Verifier {
28 |
29 | /**
30 | * 执行校验操作,参数校验失败会抛出IllegalArgumentException
31 | */
32 | void verify() throws IllegalArgumentException;
33 |
34 | /**
35 | * TODO 设置默认值信息,直接放默认值;还是优先使用用户配置,用户没有配置才使用默认配置
36 | */
37 | void setDefault();
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/plugin/config/gov/RateLimitConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.governance.plugin.config.gov;
19 |
20 | import com.tencent.tsf.femas.governance.plugin.config.PluginConfig;
21 | import com.tencent.tsf.femas.governance.plugin.config.verify.Verifier;
22 |
23 | /**
24 | * @Author leoziltong
25 | * @Date: 2021/5/25 20:51
26 | * @Version 1.0
27 | */
28 | public interface RateLimitConfig extends PluginConfig, Verifier {
29 |
30 | String getType();
31 | }
32 |
--------------------------------------------------------------------------------
/femas-extensions/femas-extension-springcloud/femas-extension-springcloud-greenwich-gateway/src/main/java/com/tencent/tsf/femas/springcloud/gateway/filter/AbstractGlobalFilter.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.springcloud.gateway.filter;
2 |
3 | import com.tencent.tsf.femas.api.ExtensionManager;
4 | import com.tencent.tsf.femas.api.IExtensionLayer;
5 | import org.springframework.cloud.gateway.filter.GatewayFilterChain;
6 | import org.springframework.cloud.gateway.filter.GlobalFilter;
7 | import org.springframework.core.Ordered;
8 | import org.springframework.web.server.ServerWebExchange;
9 | import reactor.core.publisher.Mono;
10 |
11 | public abstract class AbstractGlobalFilter implements GlobalFilter, Ordered {
12 |
13 | protected final IExtensionLayer extensionLayer = ExtensionManager.getExtensionLayer();
14 |
15 | @Override
16 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) {
17 | if (shouldFilter(exchange, chain)) {
18 | return doFilter(exchange, chain);
19 | } else {
20 | return chain.filter(exchange);
21 | }
22 | }
23 |
24 | @Override
25 | abstract public int getOrder();
26 |
27 | abstract public boolean shouldFilter(ServerWebExchange exchange, GatewayFilterChain chain);
28 |
29 | abstract public Mono doFilter(ServerWebExchange exchange, GatewayFilterChain chain);
30 | }
--------------------------------------------------------------------------------
/femas-example/femas-example-springcloud-2020-provider/src/main/resources/nacos/bootstrap.yaml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 19001
3 | spring:
4 | application:
5 | name: femas-example-springcloud2020-provider
6 | cloud:
7 | nacos:
8 | discovery:
9 | server-addr: 127.0.0.1:8848
10 | username: nacos
11 | password: nacos
12 | config:
13 | server-addr: 127.0.0.1:8848
14 | # file-extension: properties
15 | # refresh-enabled: true
16 | # namespace: ns-mldqvo58
17 | # shared-configs[0]:
18 | # data-id: testDataId
19 | # refresh: true
20 | # group: DEFAULT_GROUP
21 |
22 | serviceRouter:
23 | chain:
24 | - FemasDefaultRoute
25 | -
26 | loadbalancer:
27 | type: random
28 | circuitBreaker:
29 | enable: true
30 | chain:
31 | - femasCircuitBreaker
32 | # plugin:
33 | # femasCircuitBreaker:
34 | # continuousErrorThreshold: 10
35 | # metricStatTimeWindow: 1s
36 | # requestCountAfterHalfOpen: 3
37 | # sleepWindow: 5s
38 | # successCountAfterHalfOpen: 2
39 |
40 | management:
41 | endpoints:
42 | web:
43 | exposure:
44 | include: '*'
45 |
46 |
47 | rateLimit:
48 | type: femasRateLimit
49 |
50 |
51 | authenticate:
52 | type: femasAuthenticate
53 |
54 | paas_server_address: http://127.0.0.1:8080
55 |
56 |
57 | logging:
58 | level:
59 | root: info
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/plugin/config/gov/MetricsConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.governance.plugin.config.gov;
19 |
20 | import com.tencent.tsf.femas.governance.plugin.config.PluginConfig;
21 | import com.tencent.tsf.femas.governance.plugin.config.verify.Verifier;
22 | import java.util.List;
23 |
24 | /**
25 | * @Author leoziltong
26 | * @Date: 2021/6/2 20:51
27 | */
28 | public interface MetricsConfig extends PluginConfig, Verifier {
29 |
30 | List getChain();
31 | }
32 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/metrics/micrometer/registry/RpcMeterRegistry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.governance.metrics.micrometer.registry;
19 |
20 | import com.tencent.tsf.femas.governance.metrics.micrometer.MicrometerMeterRegistry;
21 |
22 | /**
23 | * @Author leoziltong
24 | * @Date: 2021/7/26 16:43
25 | */
26 | public class RpcMeterRegistry extends MicrometerMeterRegistry {
27 |
28 | @Override
29 | public String getName() {
30 | return "rpcMeter";
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/femas-registry-impl/femas-registry-polaris/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | com.tencent.tsf
9 | femas-registry-impl
10 | ${revision}
11 | ../pom.xml
12 |
13 |
14 | femas-registry-polaris
15 | jar
16 |
17 |
18 |
19 | com.tencent.tsf
20 | femas-registry
21 |
22 |
23 | com.tencent.polaris
24 | polaris-discovery-factory
25 |
26 |
27 |
28 |
29 |
30 |
31 | org.apache.maven.plugins
32 | maven-jar-plugin
33 |
34 |
35 |
36 | ${project.version}
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/femas-common/src/main/java/com/tencent/tsf/femas/common/util/IOUtils.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.common.util;
2 |
3 | import java.io.Closeable;
4 | import java.net.ServerSocket;
5 | import java.net.Socket;
6 |
7 | /**
8 | * IO工具类
9 | */
10 | public class IOUtils {
11 |
12 | /**
13 | * 静默关闭
14 | *
15 | * @param closeable 可关闭的
16 | */
17 | public static void closeQuietly(Closeable closeable) {
18 | if (closeable != null) {
19 | try {
20 | closeable.close();
21 | } catch (Exception ignore) {
22 | // NOPMD
23 | }
24 | }
25 | }
26 |
27 | /**
28 | * 静默关闭 for jdk6
29 | *
30 | * @param closeable 可关闭的
31 | */
32 | public static void closeQuietly(ServerSocket closeable) {
33 | if (closeable != null) {
34 | try {
35 | closeable.close();
36 | } catch (Exception ignore) {
37 | // NOPMD
38 | }
39 | }
40 | }
41 |
42 | /**
43 | * 静默关闭 for jdk6
44 | *
45 | * @param closeable 可关闭的
46 | */
47 | public static void closeQuietly(Socket closeable) {
48 | if (closeable != null) {
49 | try {
50 | closeable.close();
51 | } catch (Exception ignore) {
52 | // NOPMD
53 | }
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/auth/AuthorizationManager.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.auth;
2 |
3 | import com.tencent.tsf.femas.common.entity.Service;
4 | import com.tencent.tsf.femas.governance.auth.entity.AuthRuleGroup;
5 | import com.tencent.tsf.femas.governance.config.FemasPluginContext;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 |
9 |
10 | /**
11 | * Auth服务权限管理客户端
12 | */
13 | public class AuthorizationManager {
14 |
15 | private static final Logger LOGGER = LoggerFactory.getLogger(AuthorizationManager.class);
16 |
17 | private static final IAuthentication authentication = FemasPluginContext.getAuthentication();
18 |
19 | /**
20 | * 鉴权
21 | */
22 | public static Boolean authenticate(Service service) {
23 | return authentication.authenticate(service);
24 | }
25 |
26 | public static void refreshAuthRuleGroup(Service service, AuthRuleGroup authRuleGroup) {
27 | authentication.refreshAuthRuleGroup(service, authRuleGroup);
28 | LOGGER.info("Refresh auth rule group. Service : " + service + ", authRuleGroup : " + authRuleGroup);
29 | }
30 |
31 | public static void disableAuthRuleGroup(Service service) {
32 | authentication.disableAuthRuleGroup(service);
33 | LOGGER.info("Disable auth rule group. Service : " + service);
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/circuitbreaker/core/IllegalStateTransitionException.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.circuitbreaker.core;
2 |
3 | import com.tencent.tsf.femas.governance.circuitbreaker.ICircuitBreakerService;
4 |
5 | /**
6 | * A {@link IllegalStateTransitionException} signals that someone tried to trigger an illegal state
7 | * transition..
8 | */
9 | public class IllegalStateTransitionException extends RuntimeException {
10 |
11 | private final String name;
12 | private final ICircuitBreakerService.State fromState;
13 | private final ICircuitBreakerService.State toState;
14 |
15 | IllegalStateTransitionException(String name, ICircuitBreakerService.State fromState,
16 | ICircuitBreakerService.State toState) {
17 | super(String
18 | .format("CircuitBreaker '%s' tried an illegal state transition from %s to %s", name,
19 | fromState.toString(), toState.toString()));
20 | this.name = name;
21 | this.fromState = fromState;
22 | this.toState = toState;
23 | }
24 |
25 | public ICircuitBreakerService.State getFromState() {
26 | return fromState;
27 | }
28 |
29 | public ICircuitBreakerService.State getToState() {
30 | return toState;
31 | }
32 |
33 | public String getName() {
34 | return name;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/plugin/config/gov/LoadBalanceConfig.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Tencent is pleased to support the open source community by making Polaris available.
3 | *
4 | * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5 | *
6 | * Licensed under the BSD 3-Clause License (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://opensource.org/licenses/BSD-3-Clause
11 | *
12 | * Unless required by applicable law or agreed to in writing, software distributed
13 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.governance.plugin.config.gov;
19 |
20 |
21 | import com.tencent.tsf.femas.governance.plugin.config.PluginConfig;
22 | import com.tencent.tsf.femas.governance.plugin.config.verify.Verifier;
23 |
24 | /**
25 | * 负载均衡相关配置项
26 | *
27 | * @author andrewshan
28 | * @date 2019/8/20
29 | */
30 | public interface LoadBalanceConfig extends PluginConfig, Verifier {
31 |
32 | /**
33 | * 负载均衡类型
34 | *
35 | * @return String
36 | */
37 | String getType();
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/femas-adaptor/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | com.tencent.tsf
9 | femas-parent
10 | ${revision}
11 |
12 |
13 | femas-adaptor
14 | pom
15 | The adaptor of femas
16 |
17 |
18 | femas-adaptor-opensource-admin
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | org.apache.maven.plugins
28 | maven-jar-plugin
29 |
30 |
31 |
32 | ${project.version}
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/plugin/config/gov/MetricsExporterConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.governance.plugin.config.gov;
19 |
20 | import com.tencent.tsf.femas.governance.plugin.config.PluginConfig;
21 | import com.tencent.tsf.femas.governance.plugin.config.verify.Verifier;
22 |
23 | /**
24 | * @Author leoziltong
25 | * @Date: 2021/6/2 20:51
26 | */
27 | public interface MetricsExporterConfig extends PluginConfig, Verifier {
28 |
29 | String getType();
30 |
31 | String getExporterAddr();
32 |
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/metrics/micrometer/registry/GovernanceMeterRegistry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.governance.metrics.micrometer.registry;
19 |
20 | import com.tencent.tsf.femas.governance.metrics.micrometer.MicrometerMeterRegistry;
21 |
22 |
23 | /**
24 | * @Author leoziltong
25 | * @Date: 2021/7/26 16:43
26 | */
27 | public class GovernanceMeterRegistry extends MicrometerMeterRegistry {
28 |
29 | @Override
30 | public String getName() {
31 | return "microMeter";
32 | }
33 |
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/metrics/MetricsExporter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.governance.metrics;
19 |
20 | import com.tencent.tsf.femas.governance.plugin.Plugin;
21 | import java.time.Duration;
22 |
23 | /**
24 | * @Author leoziltong
25 | * @Date: 2021/7/13 20:52
26 | */
27 | public interface MetricsExporter extends Plugin {
28 |
29 | /**
30 | * metrics插件上报
31 | */
32 | void report();
33 |
34 | /**
35 | * 上报间隔
36 | *
37 | * @return
38 | */
39 | Duration step();
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/plugin/config/global/GlobalConfig.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Tencent is pleased to support the open source community by making Polaris available.
3 | *
4 | * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5 | *
6 | * Licensed under the BSD 3-Clause License (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://opensource.org/licenses/BSD-3-Clause
11 | *
12 | * Unless required by applicable law or agreed to in writing, software distributed
13 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.governance.plugin.config.global;
19 |
20 |
21 | import com.tencent.tsf.femas.governance.plugin.config.verify.Verifier;
22 |
23 | /**
24 | * 全局配置对象
25 | *
26 | * @author andrewshan
27 | * @date 2019/8/20
28 | */
29 | public interface GlobalConfig extends Verifier {
30 |
31 | SystemConfig getSystem();
32 |
33 | /**
34 | * services.global.serverConnector前缀开头的所有配置项
35 | *
36 | * @return ServerConnectorConfig
37 | */
38 | ServerConnectorConfig getServerConnector();
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/lane/LaneService.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.lane;
2 |
3 | import com.tencent.tsf.femas.common.entity.Service;
4 | import com.tencent.tsf.femas.common.entity.ServiceInstance;
5 | import com.tencent.tsf.femas.governance.config.FemasPluginContext;
6 | import java.util.List;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 |
10 | /**
11 | * 泳道能力是给全链路灰度发布来使用的
12 | * 需要搭配控制台来发布规则
13 | *
14 | * 目前要订阅消费全局泳道,性能有点差,等待优化
15 | * 暂时不支持单个应用使用
16 | */
17 | public class LaneService {
18 |
19 | private static final Logger LOGGER = LoggerFactory.getLogger(LaneService.class);
20 |
21 | private static volatile LaneFilter LANE_FILTER = FemasPluginContext.getLaneFilter();
22 |
23 | public static void headerPreprocess() {
24 | if (LANE_FILTER != null) {
25 | LANE_FILTER.preProcessLaneId();
26 | }
27 | }
28 |
29 | public static List filterInstancesWithLane(Service service,
30 | List serviceInstances) {
31 | // RATE_LIMITER 不为空,且Tag规则命中,且限流不通过
32 | if (LANE_FILTER != null) {
33 | return LANE_FILTER.filterInstancesWithLane(service, serviceInstances);
34 | }
35 |
36 | return serviceInstances;
37 | }
38 |
39 | public static void refreshLaneFilter(LaneFilter laneFilter) {
40 | LANE_FILTER = laneFilter;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/route/entity/RouteDest.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.route.entity;
2 |
3 | import com.tencent.tsf.femas.common.tag.TagRule;
4 | import java.io.Serializable;
5 |
6 | /**
7 | *
8 | */
9 | public class RouteDest implements Serializable {
10 |
11 | /**
12 | * serialVersionUID
13 | */
14 | private static final long serialVersionUID = 984582541720418394L;
15 | /**
16 | * 路由目标权重
17 | */
18 | private Integer destWeight;
19 | /**
20 | * 路由目标匹配条件列表
21 | */
22 | private TagRule destItemList;
23 |
24 | /**
25 | * 空构造函数
26 | */
27 | public RouteDest() {
28 | }
29 |
30 | public Integer getDestWeight() {
31 | return destWeight;
32 | }
33 |
34 | public void setDestWeight(Integer destWeight) {
35 | this.destWeight = destWeight;
36 | }
37 |
38 | public TagRule getDestItemList() {
39 | return destItemList;
40 | }
41 |
42 | public void setDestItemList(TagRule destItemList) {
43 | this.destItemList = destItemList;
44 | }
45 |
46 | @Override
47 | public String toString() {
48 | final StringBuffer sb = new StringBuffer("RouteDest{");
49 | sb.append(", destWeight=").append(destWeight);
50 | sb.append(", destItemList=").append(destItemList);
51 | sb.append('}');
52 | return sb.toString();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/femas-governance/src/main/java/com/tencent/tsf/femas/governance/auth/IAuthentication.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.governance.auth;
19 |
20 | import com.tencent.tsf.femas.common.entity.Service;
21 | import com.tencent.tsf.femas.governance.plugin.Plugin;
22 |
23 | /**
24 | * @Author leoziltong
25 | * @Date: 2021/6/2 17:31
26 | */
27 | public interface IAuthentication extends Plugin {
28 |
29 | Boolean authenticate(Service service);
30 |
31 | void refreshAuthRuleGroup(Service service, T authRuleGroup);
32 |
33 | void disableAuthRuleGroup(Service service);
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/femas-config/src/main/java/com/tencent/tsf/femas/config/enums/FemasConfigTypeEnum.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Tencent is pleased to support the open source community by making Femas available.
3 | *
4 | * Copyright (C) 2021, a Tencent company. All rights reserved.
5 | *
6 | * Licensed under the BSD 3-Clause License (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://opensource.org/licenses/BSD-3-Clause
11 | *
12 | * Unless required by applicable law or agreed to in writing, software distributed
13 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.tencent.tsf.femas.config.enums;
19 |
20 | /**
21 | *
22 | * 文件名称:FemasConfigTypeEnum.java
23 | * 创建时间:Aug 11, 2021 9:06:38 PM
24 | * @author juanyinyang
25 | * 类说明:
26 | */
27 | public enum FemasConfigTypeEnum {
28 |
29 | CONSUL("consul"),
30 | PAAS("paas"),
31 | NACOS("nacos");
32 |
33 | private String type;
34 |
35 | FemasConfigTypeEnum(String type) {
36 | this.type = type;
37 | }
38 |
39 | public String getType() {
40 | return type;
41 | }
42 |
43 | public void setType(String type) {
44 | this.type = type;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/femas-governance-impl/src/main/java/com/tencent/tsf/femas/governance/route/entity/RouteRule.java:
--------------------------------------------------------------------------------
1 | package com.tencent.tsf.femas.governance.route.entity;
2 |
3 | import com.tencent.tsf.femas.common.tag.TagRule;
4 | import java.io.Serializable;
5 | import java.util.List;
6 |
7 | /**
8 | * 路由规则
9 | */
10 | public class RouteRule implements Serializable {
11 |
12 | /**
13 | * serialVersionUID
14 | */
15 | private static final long serialVersionUID = -1886125299472426511L;
16 | /**
17 | * 路由规则项包含的匹配条件列表
18 | */
19 | private TagRule tagRule;
20 | /**
21 | * 路由规则项包含的目的列表
22 | */
23 | private List destList;
24 |
25 | /**
26 | * 空构造函数
27 | */
28 | public RouteRule() {
29 | }
30 |
31 | public TagRule getTagRule() {
32 | return tagRule;
33 | }
34 |
35 | public void setTagRule(TagRule tagRule) {
36 | this.tagRule = tagRule;
37 | }
38 |
39 | public List getDestList() {
40 | return destList;
41 | }
42 |
43 | public void setDestList(List destList) {
44 | this.destList = destList;
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | final StringBuffer sb = new StringBuffer("RouteRule{");
50 | sb.append(", tagRule=").append(tagRule);
51 | sb.append(", destList=").append(destList);
52 | sb.append('}');
53 | return sb.toString();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------