Documentation
¶
Overview ¶
Package pipeline provides async pipeline for separating scan and upload.
Index ¶
- type Pipeline
- func (p *Pipeline) Flush(ctx context.Context) error
- func (p *Pipeline) GetStats() *Stats
- func (p *Pipeline) QueueLength() int
- func (p *Pipeline) Start(ctx context.Context) error
- func (p *Pipeline) Stop(ctx context.Context) error
- func (p *Pipeline) Submit(report *ctis.Report, opts ...SubmitOption) (string, error)
- type PipelineConfig
- type QueueItem
- type Result
- type Stats
- type SubmitOption
- type Uploader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline manages async upload of scan results. This allows scans to complete immediately while uploads happen in background.
func NewPipeline ¶
func NewPipeline(config *PipelineConfig, uploader Uploader) *Pipeline
NewPipeline creates a new upload pipeline.
func (*Pipeline) QueueLength ¶
QueueLength returns the current queue length.
type PipelineConfig ¶
type PipelineConfig struct {
// QueueSize is the maximum number of pending uploads.
// Default: 1000
QueueSize int
// Workers is the number of concurrent upload workers.
// Default: 3
Workers int
// RetryAttempts is the number of retry attempts for failed uploads.
// Default: 3
RetryAttempts int
// RetryDelay is the base delay between retries.
// Default: 5 seconds (exponential backoff applied)
RetryDelay time.Duration
// UploadTimeout is the timeout for each upload attempt.
// Default: 2 minutes
UploadTimeout time.Duration
// OnSubmitted is called when a report is queued.
OnSubmitted func(item *QueueItem)
// OnCompleted is called when an upload completes.
OnCompleted func(item *QueueItem, result *Result)
// OnFailed is called when an upload fails after all retries.
OnFailed func(item *QueueItem, err error)
// Verbose enables debug logging.
Verbose bool
}
PipelineConfig configures the upload pipeline.
func DefaultPipelineConfig ¶
func DefaultPipelineConfig() *PipelineConfig
DefaultPipelineConfig returns sensible defaults.
type QueueItem ¶
type QueueItem struct {
ID string `json:"id"`
Report *ctis.Report `json:"-"` // Not serialized
ReportJSON []byte `json:"report_json,omitempty"`
JobID string `json:"job_id,omitempty"`
TenantID string `json:"tenant_id,omitempty"`
ToolName string `json:"tool_name"`
SubmittedAt time.Time `json:"submitted_at"`
Attempts int `json:"attempts"`
LastError string `json:"last_error,omitempty"`
Priority int `json:"priority"` // Higher = more urgent
}
QueueItem represents a pending upload.
type Result ¶
type Result struct {
ID string `json:"id"`
ReportID string `json:"report_id"`
Status string `json:"status"` // pending, uploading, completed, failed
FindingsCreated int `json:"findings_created"`
AssetsCreated int `json:"assets_created"`
Error string `json:"error,omitempty"`
SubmittedAt time.Time `json:"submitted_at"`
CompletedAt time.Time `json:"completed_at,omitempty"`
DurationMs int64 `json:"duration_ms,omitempty"`
}
Result represents an upload result.
type Stats ¶
type Stats struct {
Submitted int64 `json:"submitted"`
Completed int64 `json:"completed"`
Failed int64 `json:"failed"`
InProgress int `json:"in_progress"`
QueueLength int `json:"queue_length"`
TotalBytes int64 `json:"total_bytes"`
}
Stats returns pipeline statistics.
type SubmitOption ¶
type SubmitOption func(*QueueItem)
SubmitOption is an option for Submit.
func WithPriority ¶
func WithPriority(priority int) SubmitOption
WithPriority sets the priority (higher = more urgent).
func WithTenantID ¶
func WithTenantID(tenantID string) SubmitOption
WithTenantID sets the tenant ID.
Click to show internal directories.
Click to hide internal directories.