CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-netflix-hystrix--hystrix-metrics-event-stream

A Netflix Hystrix module that exposes circuit breaker and thread pool metrics in Server-Sent Events format for real-time monitoring and dashboard integration

Pending
Overview
Eval results
Files

request-events-streaming.mddocs/

Request Events Streaming

Servlet that streams individual Hystrix request events as they occur, providing detailed information about each request execution including events, latencies, and collapser information.

Capabilities

HystrixRequestEventsSseServlet

Servlet that writes SSE JSON data every time a Hystrix request is made, providing detailed execution information.

/**
 * Servlet that writes SSE JSON every time a request is made
 * Provides detailed request execution information including events and latencies
 */
public class HystrixRequestEventsSseServlet extends HystrixSampleSseServlet {
    
    /**
     * Default constructor using HystrixRequestEventsStream and default delay
     */
    public HystrixRequestEventsSseServlet();
    
    /**
     * Package-private constructor for testing with custom stream and delay
     * @param sampleStream Observable stream of request events
     * @param pausePollerThreadDelayInMs Delay between polling cycles in milliseconds
     */
    HystrixRequestEventsSseServlet(Observable<HystrixRequestEvents> sampleStream, int pausePollerThreadDelayInMs);
    
    /**
     * Returns maximum number of concurrent connections allowed
     * @return Maximum concurrent connections (default: 5)
     */
    protected int getMaxNumberConcurrentConnectionsAllowed();
    
    /**
     * Returns current number of active connections
     * @return Current connection count
     */
    protected int getNumberCurrentConnections();
    
    /**
     * Atomically increments and returns current concurrent connection count
     * @return New connection count after increment
     */
    protected int incrementAndGetCurrentConcurrentConnections();
    
    /**
     * Atomically decrements current concurrent connection count
     */
    protected void decrementCurrentConcurrentConnections();
}

HystrixRequestEventsJsonStream (Deprecated)

Legacy JSON stream utility for converting request events to JSON format.

/**
 * Stream that converts HystrixRequestEvents into JSON
 * @deprecated Since 1.5.4 - prefer mapping serialization on HystrixRequestEventsStream.observe()
 */
@Deprecated
public class HystrixRequestEventsJsonStream {
    
    /**
     * Get the underlying request events stream
     * @return Observable stream of request events
     */
    public Observable<HystrixRequestEvents> getStream();
    
    /**
     * Convert collection of request events to JSON string
     * @param requests Collection of request events to convert
     * @return JSON string representation
     * @throws IOException if JSON generation fails
     */
    public static String convertRequestsToJson(Collection<HystrixRequestEvents> requests) throws IOException;
    
    /**
     * Convert single request event to JSON string
     * @param request Request event to convert
     * @return JSON string representation
     * @throws IOException if JSON generation fails
     */
    public static String convertRequestToJson(HystrixRequestEvents request) throws IOException;
    
    /**
     * Write request as JSON to a JsonGenerator
     * @param json JsonGenerator to write to
     * @param request Request event to write
     * @throws IOException if JSON writing fails
     */
    private static void writeRequestAsJson(JsonGenerator json, HystrixRequestEvents request) throws IOException;
    
    /**
     * Convert execution signature to JSON
     * @param json JsonGenerator to write to
     * @param executionSignature Execution signature containing command details
     * @param latencies List of execution latencies in milliseconds
     * @throws IOException if JSON writing fails
     */
    private static void convertExecutionToJson(JsonGenerator json, HystrixRequestEvents.ExecutionSignature executionSignature, List<Integer> latencies) throws IOException;
}

/**
 * Request events types for detailed request information
 */
public interface HystrixRequestEvents.ExecutionSignature {
    String getCommandName();
    ExecutionResult.EventCounts getEventCounts();
    int getCachedCount();
    HystrixCollapserKey getCollapserKey();
    int getCollapserBatchSize();
}

Web.xml Configuration:

<servlet>
  <servlet-name>HystrixRequestEventsSseServlet</servlet-name>
  <servlet-class>com.netflix.hystrix.contrib.requests.stream.HystrixRequestEventsSseServlet</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>HystrixRequestEventsSseServlet</servlet-name>
  <url-pattern>/hystrix/requests.stream</url-pattern>
</servlet-mapping>

Usage Examples:

// Deploy servlet via web.xml configuration
// Access stream endpoint
curl http://localhost:8080/app/hystrix/requests.stream

// Custom request events processing (using deprecated API)
HystrixRequestEventsJsonStream stream = new HystrixRequestEventsJsonStream();
stream.getStream().subscribe(requestEvents -> {
    String json = HystrixRequestEventsJsonStream.convertRequestToJson(requestEvents);
    System.out.println("Request event: " + json);
});

Data Format

The servlet outputs detailed request execution information:

Request Events Structure

data: [
  {
    "name": "GetUser",
    "events": [
      "SUCCESS"
    ],
    "latencies": [45],
    "cached": 0
  },
  {
    "name": "GetUserPreferences", 
    "events": [
      "TIMEOUT",
      "FALLBACK_SUCCESS"
    ],
    "latencies": [800],
    "cached": 0
  },
  {
    "name": "GetUserProfile",
    "events": [
      {
        "name": "FAILURE",
        "count": 3
      },
      "FALLBACK_SUCCESS"
    ],
    "latencies": [23, 45, 67],
    "cached": 2,
    "collapsed": {
      "name": "UserDataCollapser",
      "count": 5
    }
  }
]

Event Types

Common Hystrix event types that appear in request events:

  • SUCCESS - Command executed successfully
  • FAILURE - Command execution failed
  • TIMEOUT - Command execution timed out
  • SHORT_CIRCUITED - Circuit breaker short-circuited the request
  • THREAD_POOL_REJECTED - Thread pool rejected the request
  • SEMAPHORE_REJECTED - Semaphore rejected the request
  • FALLBACK_SUCCESS - Fallback executed successfully
  • FALLBACK_FAILURE - Fallback execution failed
  • FALLBACK_REJECTION - Fallback was rejected
  • FALLBACK_MISSING - No fallback was implemented
  • EXCEPTION_THROWN - Exception was thrown during execution
  • RESPONSE_FROM_CACHE - Response served from cache
  • COLLAPSED - Request was collapsed (batched)
  • EMIT - Observable emitted a value
  • BAD_REQUEST - Request was considered bad/invalid

Field Descriptions

  • name - Command name that was executed
  • events - Array of events that occurred during execution (strings or objects with count)
  • latencies - Array of execution latencies in milliseconds
  • cached - Number of cached responses (if > 0)
  • collapsed - Information about request collapsing/batching (if present)
    • name - Name of the collapser that batched the request
    • count - Size of the batch this request was part of

Connection Management

Uses the same connection management pattern as other SSE servlets:

// Configuration property for max concurrent connections
public static final String MAX_CONCURRENT_CONNECTIONS_PROPERTY = "hystrix.config.stream.maxConcurrentConnections";
public static final int DEFAULT_MAX_CONCURRENT_CONNECTIONS = 5;

Migration from Deprecated API

// Old approach (deprecated)
HystrixRequestEventsJsonStream jsonStream = new HystrixRequestEventsJsonStream();
jsonStream.getStream().subscribe(events -> {
    String json = HystrixRequestEventsJsonStream.convertRequestToJson(events);
    // process json
});

// New approach (recommended)
HystrixRequestEventsStream.getInstance()
    .observe()
    .map(SerialHystrixRequestEvents::toJsonString)
    .subscribe(json -> {
        // process json
    });

Install with Tessl CLI

npx tessl i tessl/maven-com-netflix-hystrix--hystrix-metrics-event-stream

docs

base-sse-servlet.md

configuration-streaming.md

index.md

legacy-metrics-polling.md

metrics-streaming.md

request-events-streaming.md

utilization-streaming.md

tile.json