Apache Dubbo-Go-Pixiu

repository·develop·Indexed 19 days ago

https://github.com/apache/dubbo-go-pixiu

A high-performance AI and API Gateway that unifies access to LLMs, MCP services, and traditional microservices. It bridges HTTP, gRPC, and Dubbo protocols while providing traffic governance, security, and observability. Features include a management platform (Pixiu-Admin), an MCP intelligent tool router for governing tool access via policies, and integration support for SpringCloud and Nacos.

Tokens
69.6K
Snippets
184
Records
266
Agent score
61%

What's inside dubbo-go-pixiu

  1. Overview of Dubbo-Go-Pixiu AI and API Gateway

    develop

    Dubbo-Go-Pixiu is a high-performance AI and API gateway built on Dubbo-go. It serves two primary purposes:

    1. AI Gateway: Provides a unified interface to access Large Language Models (LLMs) and Model Context Protocol (MCP) services. It supports public cloud providers and self-hosted models, offering features like token billing, cost management, and model orchestration via a plugin system.
    2. API Gateway: Bridges external protocols (HTTP, gRPC, Dubbo2, and Triple) to internal Dubbo clusters. It acts as a sidecar solution to connect non-Java applications (Go, Python, Node.js, etc.) to Dubbo services.

    Key capabilities include:

    • Protocol Transformation: Proxying and converting between HTTP, gRPC, Dubbo2, and Triple.
    • Security: Support for HTTPS, JWT, and OAuth2.
    • Service Discovery: Integration with Zookeeper and Nacos.
    • Traffic Governance: Integration with Sentinel for rate limiting, circuit breaking, and traffic shaping.
    • Observability: Support for OpenTelemetry and Jaeger for tracing, metrics, and logging.
    • Kubernetes Native: Functions as a Kubernetes Ingress Controller using declarative routing.
  2. Overview of Dubbo-Go-Pixiu

    develop

    Dubbo-Go-Pixiu is a high-performance AI and API Gateway built on Dubbo-go. It serves two primary purposes:

    1. AI Gateway: Provides unified access to LLMs (OpenAI, Anthropic, or custom/on-prem models) and MCP (Model Context Protocol) services. It allows you to expose HTTP APIs as MCP Servers and manage AI workloads with plugins for authentication, rate-limiting, and model orchestration.
    2. API Gateway: Bridges external protocols (HTTP, gRPC) with internal Dubbo clusters (Dubbo2, Triple). It acts as a sidecar solution for connecting non-Java applications (Go, Python, Node.js) to Dubbo services.

    Additionally, Pixiu functions as a Kubernetes Ingress Controller, allowing for declarative traffic governance and routing via Kubernetes APIs.

  3. Use the gRPC Proxy Filter (dgp.filter.grpc.proxy)

    develop

    The dgp.filter.grpc.proxy filter provides gRPC proxy capabilities for the Pixiu gateway. It supports gRPC Server Reflection, allowing the gateway to dynamically parse and inspect message content at runtime without requiring pre-compiled .proto files.

    Core Capabilities

    • Dynamic Message Decoding: Parse and inspect gRPC messages on the fly.
    • Protocol Detection: Supports both standard gRPC and the Dubbo Triple protocol.
    • Descriptor Caching: Uses a TTL-based cache for method descriptors to improve performance.
    • Graceful Degradation: The hybrid mode allows automatic fallback to passthrough if reflection fails.
    grpc_filters:
      - name: dgp.filter.grpc.proxy
        config: {} # Defaults to passthrough mode
  4. Access the Pixiu User Guide

    develop

    The Pixiu User Guide provides comprehensive documentation for getting started, understanding the API model, managing responses, installing the gateway, and configuring specific filters like OpenAPI Request Validation and SAML Auth.

    Key topics include:

    • Quick Start: Initial setup and first steps.
    • Api Model: Understanding how APIs are defined and structured in Pixiu.
    • Response: Managing and customizing API responses.
    • Installation: Procedures for deploying Pixiu.
    • Filters: Detailed guides for implementing security and validation logic, such as OpenAPI Request Validation Filter and SAML Auth Filter.
  5. AI Gateway and LLM Integration Features in v1.1.0

    develop

    As of version 1.1.0, Dubbo-Go-Pixiu provides advanced capabilities for managing Large Language Model (LLM) traffic through its AI Gateway features:

    • LLM Proxy: Supports retry mechanisms with configurable strategy abstractions and failure fallback capabilities.
    • Token Management: Includes a Token billing/statistics Filter and a Tokenizer Filter that supports Content-Encoding.
    • Streaming Support: Full support for HTTP/SSE streaming inference, suitable for long-connection data pipelines.
    • LLM Configuration: A new LLMMeta field is available to simplify LLM Endpoint configurations.
    • LLM Service Discovery: Supports using Nacos as an LLM registry center.
    • Observability: Enhanced upstream tracing and metric collection for model services.
  6. Configure retry policies for LLM endpoints

    develop

    Retry behavior is defined by combining llm-meta.retry_policy.name and llm-meta.retry_policy.config (a JSON string).

    1. CountBased

    Retries a fixed number of times.

    • Name: CountBased
    • Config Keys:
      • times (integer): Number of retry attempts.
    • Example Config: {"times": 2}

    2. ExponentialBackoff

    Retries with increasing delays between attempts.

    • Name: ExponentialBackoff
    • Config Keys:
      • times (integer): Number of retries.
      • initialInterval (string): Initial wait duration (e.g., "200ms").
      • maxInterval (string): Maximum wait duration (e.g., "5s").
      • multiplier (float): The factor to multiply the delay by each time.
    • Example Config: {"times": 3, "initialInterval": "200ms", "maxInterval": "5s", "multiplier": 2.0}

    3. NoRetry

    No retry attempts are made.

    • Name: NoRetry
    • Config: No configuration required.
  7. Use `llm_meta` for LLM-specific behavior

    develop

    The llm_meta block allows you to customize how the gateway handles specific LLM upstream endpoints. It supports the following fields:

    • fallback (boolean): If true, the gateway attempts the next endpoint in the cluster if all retries on the current endpoint fail. If false, the gateway stops and returns the last error to the client.
    • api_key (string): The API key injected into the request headers when forwarding to the LLM service.
    • retry_policy (object): Defines the retry strategy for the endpoint. It requires a name (case-insensitive) and a config object containing policy-specific parameters.
  8. How the OpenAPI Request Validation Flow works

    develop

    The OpenAPI validation process follows these steps at runtime:

    1. Startup: Pixiu loads the OpenAPI file and builds an SDK validator using libopenapi.
    2. Entry: A request enters the openapi.Decode() stage.
    3. Matching: Pixiu checks if the OpenAPI document contains the specific path and method of the request.
    4. Decision:
      • If not declared: Validation is skipped; the request continues to the next filter.
      • If declared: The request is validated via libopenapi-validator.
    5. Outcome:
      • Success: The request continues to subsequent filters.
      • Failure: Pixiu immediately returns a 400 Bad Request to the client.
  9. Extract parameters from URI and Query Strings in Pixiu

    develop

    Pixiu allows you to map incoming request data from different sources—such as URI path parameters, query strings, or the request body—to the downstream integration request.

    • Query Strings: Defined in inboundRequest.queryStrings. You can mark them as required: true.
    • URI Path Parameters: Defined using the restful resource type. Parameters in the path (e.g., /:name) are accessible via the uri prefix (e.g., uri.name).
    • Mapping: Use mappingParams in the integrationRequest section to transfer values from the inbound request to the downstream request. You can map from uri.*, queryStrings.*, or requestBody.* to target fields in the downstream request.
  10. Configure Claim-based Rules in the MCP Router

    develop

    The MCP router can consume JWT claims (such as tenant or agent_role) to implement isolation and specific workflows.

    Important Requirements:

    • The router does not re-validate tokens. It consumes claims that have already been validated by the MCP auth filter earlier in the filter chain.
    • For claim-based rules to work, the auth filter must be present in the chain and must successfully populate the JWT claims.
    • Unconditional rules (rules that do not require specific claims) will work even without an auth filter.
  11. Understand the Pixiu configuration abstraction

    develop

    Pixiu uses a configuration model inspired by Envoy, centered around static_resources. The core abstractions are:

    • listener: Defines external network servers (e.g., HTTP, HTTP2, TCP) that listen on a specific host and port.
    • filter: Provides request handling via filter chains. Filters process requests in a specific order: client -> listener -> network filter (e.g., httpconnectionmanager) -> http filter chain.
      • network filter: Handles the base protocol (e.g., dgp.filter.httpconnectionmanager for HTTP).
      • http filter: Protocol-specific transformation filters (e.g., dgp.filter.http.httpproxy for HTTP-to-Dubbo) or built-in utility filters (e.g., dgp.filter.http.response for CORS, metrics, ratelimiting, or timeouts).
    • route: Defines rules for forwarding requests to upstream clusters based on matches like path prefix, method, or headers.
    • cluster: Represents a group of service instances (upstream servers) and specifies their connection info and load balancing policy.

    Additionally, Pixiu supports a Dubbo-specific api_config which allows the dubbo-filter to transform HTTP requests into Dubbo generic calls.

    static_resources:
      listeners:
        - name: "net/http"
          protocol_type: "HTTP"
          address:
            socket_address:
              address: "0.0.0.0"
              port: 8888
          filter_chains:
            filters:
              - name: dgp.filter.httpconnectionmanager
                config:
                  route_config:
                    routes:
                      - match:
                          prefix: "/user"
                        route:
                          cluster: "user"
                          cluster_not_found_response_code: 505
                  http_filters:
                    - name: dgp.filter.http.httpproxy
                      config:
                    - name: dgp.filter.http.response
                      config:
      clusters:
        - name: "user"
          lb_policy: "lb"
          endpoints:
            - id: 1
              socket_address:
                address: 127.0.0.1
                port: 1314
  12. Configure OPA Policies

    develop
    Pixiu-Admin provides a menu to manage Open Policy Agent (OPA) policies. You can modify the policy_id, synchronize policies, and write Rego policy content directly in the web editor. Changes can be submitted to OPA by clicking 'Save' or removed by clicking 'Delete'.