Sentinel

repository·1.8·Indexed 12 days ago

https://github.com/alibaba/sentinel

A high-availability flow control component for microservices providing capabilities for flow control, traffic shaping, concurrency limiting, circuit breaking, and system adaptive overload protection. It includes a real-time monitoring dashboard and adapters for Apache Dubbo (2.7.x, 3.0.5+), Apache HttpClient, and Apache HttpClient 5.x.

Tokens
45K
Snippets
147
Records
207
Agent score
91%

What's inside Sentinel

  1. Overview of Sentinel Transport module

    1.8

    The sentinel-transport module defines the core interfaces for communication between Sentinel monitoring components. It provides the abstractions necessary for a Sentinel monitoring API server and client to interact.

    Key abstractions include:

    • CommandCenter: The interface for the monitoring API server.
    • HeartbeatSender: The interface for sending heartbeat signals from clients.

    The module includes various implementations of these interfaces using different protocols and libraries to facilitate monitoring and control in microservice environments.

  2. Overview of Sentinel Cluster Flow Control implementation

    1.8

    Sentinel provides a default implementation for cluster-level flow control, which allows for distributed traffic management across multiple service instances. The implementation is divided into three core modules:

    • sentinel-cluster-common-default: Contains the common logic, transport protocols, and shared functions used by both clients and servers.
    • sentinel-cluster-client-default: The client-side module that integrates with your application. It uses Netty as the underlying transport library to communicate with the cluster server.
    • sentinel-cluster-server-default: The server-side module that manages the cluster state and coordinates flow control rules across clients.
  3. Explore Sentinel usage examples

    1.8

    The sentinel-demo repository provides comprehensive examples for integrating Sentinel into various environments and extending its functionality. You can use these examples to learn how to implement:

    • Core Features: Flow control, circuit breaking, and load protection.
    • Data Source Extensions: Configuring Sentinel to use external data sources like File, Nacos, or ZooKeeper for rule management.
    • Framework Integrations: Using Sentinel with Dubbo or the Apache RocketMQ client.
    • Annotation Support: Leveraging Sentinel's annotation-based configuration.
    • Custom Logic: Extending Sentinel's processing pipeline by implementing the Slot Chain SPI to add custom logic.
  4. Clean and Unify URLs with UrlCleaner

    1.8

    The UrlCleaner interface is used to normalize URLs to prevent resource exhaustion in Sentinel.

    • For REST APIs: You must clean dynamic URLs (e.g., converting /foo/1 and /foo/2 into a unified pattern like /foo/:id).
    • To exclude URLs: To prevent certain URLs from being recorded as Sentinel resources, implement UrlCleaner and return an empty string "" or null for those URLs (supported since version 1.6.3).
  5. Perform flow control based on Dubbo caller (origin)

    1.8

    The Sentinel Dubbo Adapter automatically resolves the Dubbo consumer's application name as the caller's name (origin). This allows you to apply flow rules to specific callers.

    • Global Flow Control: If the limitApp field in a Sentinel flow rule is set to default, the rule applies to all callers.
    • Caller-Specific Flow Control: If limitApp is set to a specific identifier (e.g., the service name of consumer B), the rule will only trigger for that specific caller.

    Customization: You can customize how the origin is parsed by implementing the DubboOriginParser interface and registering it to DubboAdapterGlobalConfig.

  6. Perform flow control based on caller (origin)

    1.8

    The adapter automatically resolves the SOFARPC consumer's application name as the caller's name (origin). This allows you to apply flow control rules to specific callers using the limitApp field in a Sentinel flow rule.

    • Default Behavior: If limitApp is not configured (set to default), flow control applies to all callers.
    • Caller-Specific Behavior: If limitApp is set to a specific service name (e.g., service-b), the flow rule will only apply to requests originating from that specific service.
  7. Understand Dubbo Resource Naming

    1.8

    Sentinel protects Dubbo resources at two levels of granularity. When defining rules in Sentinel, use the following resourceName formats:

    1. Service Interface: Use the fully qualified interface name.
      • Format: interfaceName
      • Example: com.alibaba.csp.sentinel.demo.dubbo.FooService
    2. Service Method: Use the interface name combined with the method signature.
      • Format: interfaceName:methodSignature
      • Example: com.alibaba.csp.sentinel.demo.dubbo.FooService:sayHello(java.lang.String)
  8. Flow Control Based on Caller (Origin)

    1.8

    Sentinel Dubbo Adapter allows you to limit traffic from specific callers by setting the limitApp field in your flow rules.

    How it works

    • The adapter automatically resolves the Dubbo consumer's application name as the caller's name (origin).
    • If limitApp is set to default, the rule applies to all callers.
    • If limitApp is set to a specific identifier (e.g., a service name), the rule applies only to that caller.

    Manual Application Name Passing

    If a Dubbo consumer does not provide its application name during RPC, you must ensure the name is passed in the Dubbo attachment.

    • Using Sentinel Dubbo Adapter: The DubboAppContextFilter automatically carries the application name from consumer to provider.
    • Manual implementation: If the consumer does not use the Sentinel adapter but you still need caller-based flow control, manually put the application name into the attachment using the key dubboApplication.

    Customizing Origin Parsing

    Since version 1.8.0, you can customize how the origin is parsed by registering your own DubboOriginParser implementation to DubboAdapterGlobalConfig.

  9. Understand the Sentinel Dashboard workflow

    1.8

    The Sentinel Dashboard serves as the central entry point for configuring and managing flow control and circuit breaking rules. The standard operational workflow for using the dashboard is:

    1. Client Integration: Connect your microservices to Sentinel.
    2. Machine Discovery: The dashboard automatically detects connected machines.
    3. View Resource Chains: Inspect the automatically discovered resource call chains.
    4. Configure Flow Control Rules: Set rules to protect your services.
    5. Monitor Effects: Observe the real-time impact of the configured rules.