Skip to content

Conversation

@JasonXuDeveloper
Copy link
Contributor

Overview

Part 2 of 4 PRs implementing executor pattern architecture. See issue #219 for full context.

This PR implements the core executor pattern for mode-specific execution strategies and adapter pattern for request builders, enabling clean separation and extensibility.

Changes

New Executor Pattern (request/executor/)

  • executor.go: Executor interface and metadata types
  • factory.go: Registry-based factory for creating executors
  • weighted_random.go: WeightedRandomExecutor with rate limiting
  • timeseries.go: TimeSeriesExecutor for audit log replay

Request Builder Adapters (request/builders.go)

  • CreateRequestBuilderFromWeighted(): Converts WeightedRequest → RESTRequestBuilder
  • CreateRequestBuilderFromExact(): Converts ExactRequest → RESTRequestBuilder
  • Centralized factory registration functions
  • No unnecessary type conversions

Refactored Scheduler (request/schedule.go)

  • Uses executor pattern instead of hardcoded mode logic
  • Mode-agnostic scheduling
  • Executors manage their own rate limiting

Simplified Random Module (request/random.go)

  • Removed WeightedRandomRequests() function
  • Kept individual request builder functions
  • Cleaner separation of concerns

Benefits

  • Each executor is self-contained and testable
  • Easy to add new execution modes
  • No coupling between scheduler and mode-specific logic
  • Clean adapter pattern for different request types

Dependencies

Next PRs

  • PR 3/4: Mode-agnostic CLI tools
  • PR 4/4: Time-series benchmark example

Related to #219

Add ModeConfig interface to enable self-configuring execution modes
and provide backward compatibility for legacy LoadProfile format.

## Changes

### New files:
- api/types/mode_config.go: ModeConfig interface and helpers
- api/types/weighted_random_config.go: WeightedRandomConfig implementation
- api/types/timeseries_config.go: TimeSeriesConfig implementation
- Split test files for better organization

### Modified files:
- api/types/load_traffic.go:
  - Add ExecutionMode type
  - Update LoadProfileSpec with Mode and ModeConfig fields
  - Add UnmarshalYAML/UnmarshalJSON for backward compatibility
  - Fix typo: RequestList.Selector (was "seletor")
  - Update Validate() method

## Features

**ModeConfig Interface:**
- Self-configuring modes declare their own overridable fields
- Automatic CLI override extraction via BuildOverridesFromCLI()
- Mode-specific validation and client configuration
- Clean separation between mode logic and CLI tools

**Backward Compatibility:**
- Legacy format (rate/total/requests fields) auto-migrates to weighted-random mode
- Both YAML and JSON unmarshaling supported
- Existing load profiles continue to work without changes

## Testing

All tests pass including:
- Polymorphic deserialization tests
- Backward compatibility tests for legacy format
- CLI override extraction tests
- Mode-specific configuration tests
Implement executor pattern for mode-specific execution strategies and
adapter pattern for request builders, enabling clean separation and
extensibility.

## Changes

### New Executor Pattern (request/executor/)
- **executor.go**: Executor interface and metadata types
- **factory.go**: Registry-based factory for creating executors
- **weighted_random.go**: WeightedRandomExecutor with rate limiting
- **timeseries.go**: TimeSeriesExecutor for audit log replay

### Request Builder Adapters (request/builders.go)
- CreateRequestBuilderFromWeighted(): Converts WeightedRequest → RESTRequestBuilder
- CreateRequestBuilderFromExact(): Converts ExactRequest → RESTRequestBuilder
- Centralized factory registration functions
- No unnecessary type conversions

### Refactored Scheduler (request/schedule.go)
- Uses executor pattern instead of hardcoded mode logic
- Mode-agnostic scheduling
- Executors manage their own rate limiting

### Simplified Random Module (request/random.go)
- Removed WeightedRandomRequests() function
- Kept individual request builder functions
- Cleaner separation of concerns

## Benefits

- Each executor is self-contained and testable
- Easy to add new execution modes
- No coupling between scheduler and mode-specific logic
- Clean adapter pattern for different request types

## Depends On

- PR1: mode-config-interface (ModeConfig interface must exist first)
The interval field in TimeSeriesConfig is redundant since timing is
already specified via StartTime in each RequestBucket. Removing it
simplifies the configuration.

## Changes

- Remove Interval field from TimeSeriesConfig struct
- Update GetOverridableFields() to return empty array (no CLI overrides)
- Update ApplyOverrides() to reject any override attempts
- Update all tests to remove interval references
- Update comment examples to remove interval mentions

## Benefits

- Simpler configuration
- Less redundant data
- Timing is determined by bucket StartTime values
- Update runner command to access Rate/Total/Duration via WeightedRandomConfig type assertion
- Remove interval field reference from TimeSeriesExecutor metadata
- Ensure PR builds independently
@JasonXuDeveloper
Copy link
Contributor Author

see #219

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant