Documentation
¶
Index ¶
- Constants
- type AttackConfiguration
- type AttackJobHandler
- type AttackJobPayload
- type AttackResult
- type BatchAttackPayload
- type DefaultLogger
- type ExecutionResult
- type Job
- type JobHandler
- type JobStatus
- type Logger
- type Provider
- type ProviderManager
- type QueueMetrics
- type RedisJobQueue
- func (q *RedisJobQueue) AddWorker(handler JobHandler) (*Worker, error)
- func (q *RedisJobQueue) CompleteJob(job *Job, result interface{}) error
- func (q *RedisJobQueue) Dequeue(queueName string) (*Job, error)
- func (q *RedisJobQueue) Enqueue(job *Job) error
- func (q *RedisJobQueue) FailJob(job *Job, err error) error
- func (q *RedisJobQueue) GetJob(jobID string) (*Job, error)
- func (q *RedisJobQueue) GetMetrics() *QueueMetrics
- func (q *RedisJobQueue) GetQueueLength(queueName string) (int64, error)
- func (q *RedisJobQueue) GetWorkerMetrics() []*WorkerMetrics
- func (q *RedisJobQueue) Start() error
- func (q *RedisJobQueue) Stop() error
- type RedisQueueConfig
- type Worker
- type WorkerMetrics
Constants ¶
const ( JobTypeAttack = "attack" JobTypeBatchAttack = "batch_attack" JobTypeTemplateValidation = "template_validation" JobTypeProviderTest = "provider_test" JobTypeComplianceCheck = "compliance_check" )
JobType constants
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AttackConfiguration ¶
type AttackConfiguration struct {
MaxRetries int `json:"max_retries"`
Timeout time.Duration `json:"timeout"`
RateLimit int `json:"rate_limit"`
ConcurrentLimit int `json:"concurrent_limit"`
StopOnSuccess bool `json:"stop_on_success"`
CollectMetrics bool `json:"collect_metrics"`
}
AttackConfiguration defines configuration for attack execution
type AttackJobHandler ¶
type AttackJobHandler struct {
// contains filtered or unexported fields
}
AttackJobHandler handles attack execution jobs
func NewAttackJobHandler ¶
func NewAttackJobHandler( providerManager ProviderManager, templateManager interfaces.TemplateManager, logger Logger, ) *AttackJobHandler
NewAttackJobHandler creates a new attack job handler
func (*AttackJobHandler) GetJobTypes ¶
func (h *AttackJobHandler) GetJobTypes() []string
GetJobTypes returns the job types this handler can process
func (*AttackJobHandler) ProcessJob ¶
func (h *AttackJobHandler) ProcessJob(ctx context.Context, job *Job) error
ProcessJob processes a job based on its type
type AttackJobPayload ¶
type AttackJobPayload struct {
ProviderType core.ProviderType `json:"provider_type"`
Model string `json:"model"`
TemplateID string `json:"template_id"`
Parameters map[string]interface{} `json:"parameters"`
Configuration AttackConfiguration `json:"configuration"`
Metadata map[string]interface{} `json:"metadata"`
}
AttackJobPayload defines the payload for attack jobs
type AttackResult ¶
type AttackResult struct {
JobID string `json:"job_id"`
Success bool `json:"success"`
Response string `json:"response"`
Confidence float64 `json:"confidence"`
AttackType string `json:"attack_type"`
ProviderType core.ProviderType `json:"provider_type"`
Model string `json:"model"`
ExecutionTime time.Duration `json:"execution_time"`
TokensUsed int `json:"tokens_used"`
Cost float64 `json:"cost"`
Metadata map[string]interface{} `json:"metadata"`
Error string `json:"error,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
AttackResult defines the result of attack execution
type BatchAttackPayload ¶
type BatchAttackPayload struct {
Attacks []*AttackJobPayload `json:"attacks"`
Configuration AttackConfiguration `json:"configuration"`
}
BatchAttackPayload defines payload for batch attacks
type DefaultLogger ¶
type DefaultLogger struct {
// contains filtered or unexported fields
}
DefaultLogger provides a simple logger implementation
func NewDefaultLogger ¶
func NewDefaultLogger() *DefaultLogger
NewDefaultLogger creates a new default logger
func (*DefaultLogger) Debug ¶
func (l *DefaultLogger) Debug(msg string, args ...interface{})
func (*DefaultLogger) Error ¶
func (l *DefaultLogger) Error(msg string, args ...interface{})
func (*DefaultLogger) Info ¶
func (l *DefaultLogger) Info(msg string, args ...interface{})
func (*DefaultLogger) Warn ¶
func (l *DefaultLogger) Warn(msg string, args ...interface{})
type ExecutionResult ¶ added in v0.8.0
type ExecutionResult struct {
Success bool `json:"success"`
Response string `json:"response"`
Confidence float64 `json:"confidence"`
TokensUsed int `json:"tokens_used"`
Cost float64 `json:"cost"`
Metadata map[string]interface{} `json:"metadata"`
}
ExecutionResult represents the result of template execution
type Job ¶
type Job struct {
ID string `json:"id"`
Type string `json:"type"`
Queue string `json:"queue"`
Priority int `json:"priority"`
Payload map[string]interface{} `json:"payload"`
CreatedAt time.Time `json:"created_at"`
ScheduledAt time.Time `json:"scheduled_at"`
StartedAt *time.Time `json:"started_at,omitempty"`
CompletedAt *time.Time `json:"completed_at,omitempty"`
FailedAt *time.Time `json:"failed_at,omitempty"`
Attempts int `json:"attempts"`
MaxRetries int `json:"max_retries"`
Error string `json:"error,omitempty"`
Result interface{} `json:"result,omitempty"`
Status JobStatus `json:"status"`
}
Job represents a job in the queue
type JobHandler ¶
type JobHandler interface {
ProcessJob(ctx context.Context, job *Job) error
GetJobTypes() []string
}
JobHandler processes a job
type Logger ¶
type Logger interface {
Info(msg string, args ...interface{})
Warn(msg string, args ...interface{})
Error(msg string, args ...interface{})
Debug(msg string, args ...interface{})
}
Logger interface for queue logging
type Provider ¶ added in v0.8.0
type Provider interface {
GetModels(ctx context.Context) ([]string, error)
Execute(ctx context.Context, request map[string]interface{}) (*ExecutionResult, error)
GetName() string
}
Provider defines the interface for LLM providers
type ProviderManager ¶ added in v0.8.0
type ProviderManager interface {
GetProvider(providerType core.ProviderType) (Provider, error)
ListProviders() []string
}
ProviderManager defines the interface for managing providers
type QueueMetrics ¶
type QueueMetrics struct {
JobsEnqueued int64 `json:"jobs_enqueued"`
JobsProcessed int64 `json:"jobs_processed"`
JobsFailed int64 `json:"jobs_failed"`
JobsRetried int64 `json:"jobs_retried"`
ActiveWorkers int64 `json:"active_workers"`
QueueLength int64 `json:"queue_length"`
AverageLatency time.Duration `json:"average_latency"`
ThroughputRPS float64 `json:"throughput_rps"`
}
QueueMetrics tracks queue performance
type RedisJobQueue ¶
type RedisJobQueue struct {
// contains filtered or unexported fields
}
RedisJobQueue implements a persistent job queue using Redis
func NewRedisJobQueue ¶
func NewRedisJobQueue(config RedisQueueConfig, logger Logger) (*RedisJobQueue, error)
NewRedisJobQueue creates a new Redis job queue
func (*RedisJobQueue) AddWorker ¶
func (q *RedisJobQueue) AddWorker(handler JobHandler) (*Worker, error)
AddWorker adds a worker to process jobs
func (*RedisJobQueue) CompleteJob ¶
func (q *RedisJobQueue) CompleteJob(job *Job, result interface{}) error
CompleteJob marks a job as completed
func (*RedisJobQueue) Dequeue ¶
func (q *RedisJobQueue) Dequeue(queueName string) (*Job, error)
Dequeue removes and returns the next job from the queue
func (*RedisJobQueue) Enqueue ¶
func (q *RedisJobQueue) Enqueue(job *Job) error
Enqueue adds a job to the queue
func (*RedisJobQueue) FailJob ¶
func (q *RedisJobQueue) FailJob(job *Job, err error) error
FailJob marks a job as failed and potentially retries it
func (*RedisJobQueue) GetJob ¶
func (q *RedisJobQueue) GetJob(jobID string) (*Job, error)
GetJob retrieves a job by ID
func (*RedisJobQueue) GetMetrics ¶
func (q *RedisJobQueue) GetMetrics() *QueueMetrics
GetMetrics returns current queue metrics
func (*RedisJobQueue) GetQueueLength ¶
func (q *RedisJobQueue) GetQueueLength(queueName string) (int64, error)
GetQueueLength returns the number of jobs in a queue
func (*RedisJobQueue) GetWorkerMetrics ¶
func (q *RedisJobQueue) GetWorkerMetrics() []*WorkerMetrics
GetWorkerMetrics returns metrics for all workers
func (*RedisJobQueue) Start ¶
func (q *RedisJobQueue) Start() error
Start starts the job queue and workers
func (*RedisJobQueue) Stop ¶
func (q *RedisJobQueue) Stop() error
Stop stops the job queue and all workers
type RedisQueueConfig ¶
type RedisQueueConfig struct {
// Redis connection
RedisAddr string `json:"redis_addr"`
RedisPassword string `json:"redis_password"`
RedisDB int `json:"redis_db"`
// Queue configuration
QueuePrefix string `json:"queue_prefix"`
DefaultPriority int `json:"default_priority"`
MaxRetries int `json:"max_retries"`
RetryDelay time.Duration `json:"retry_delay"`
JobTimeout time.Duration `json:"job_timeout"`
VisibilityTimeout time.Duration `json:"visibility_timeout"`
// Worker configuration
WorkerCount int `json:"worker_count"`
PollInterval time.Duration `json:"poll_interval"`
BatchSize int `json:"batch_size"`
// Performance settings
EnablePipelining bool `json:"enable_pipelining"`
PoolSize int `json:"pool_size"`
MinIdleConns int `json:"min_idle_conns"`
MaxConnAge time.Duration `json:"max_conn_age"`
// Monitoring
EnableMetrics bool `json:"enable_metrics"`
MetricsInterval time.Duration `json:"metrics_interval"`
}
RedisQueueConfig defines configuration for Redis job queue
func DefaultQueueConfig ¶
func DefaultQueueConfig() RedisQueueConfig
DefaultQueueConfig returns default configuration
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker processes jobs from the queue
type WorkerMetrics ¶
type WorkerMetrics struct {
WorkerID string `json:"worker_id"`
JobsProcessed int64 `json:"jobs_processed"`
JobsFailed int64 `json:"jobs_failed"`
AverageLatency time.Duration `json:"average_latency"`
LastActive time.Time `json:"last_active"`
Status string `json:"status"`
}
WorkerMetrics tracks individual worker performance