metrics

package
v0.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package metrics provides build performance tracking and metrics collection.

Package metrics provides build performance tracking and metrics collection.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNilMetrics is returned when nil metrics are provided.
	ErrNilMetrics = errors.New("metrics cannot be nil")

	// ErrEmptyBuildID is returned when an empty build ID is provided.
	ErrEmptyBuildID = errors.New("build ID cannot be empty")

	// ErrMetricsNotFound is returned when metrics for a build are not found.
	ErrMetricsNotFound = errors.New("metrics not found for build")
)

Functions

This section is empty.

Types

type AggregateMetrics

type AggregateMetrics struct {
	TotalBuilds      int           `json:"total_builds"`
	SuccessfulBuilds int           `json:"successful_builds"`
	FailedBuilds     int           `json:"failed_builds"`
	CacheHits        int           `json:"cache_hits"`
	OCIRetries       int           `json:"oci_retries"`
	SuccessRate      float64       `json:"success_rate"`
	CacheHitRate     float64       `json:"cache_hit_rate"`
	AvgBuildTime     time.Duration `json:"avg_build_time"`
	AvgTotalTime     time.Duration `json:"avg_total_time"`
	MaxBuildTime     time.Duration `json:"max_build_time"`
	MinBuildTime     time.Duration `json:"min_build_time"`

	// Breakdown by strategy
	ByStrategy map[models.BuildStrategy]*StrategyMetrics `json:"by_strategy,omitempty"`

	// Breakdown by language
	ByLanguage map[string]*LanguageMetrics `json:"by_language,omitempty"`
}

AggregateMetrics contains aggregated build metrics for analysis.

type BuildMetrics

type BuildMetrics struct {
	BuildID   string               `json:"build_id"`
	Strategy  models.BuildStrategy `json:"strategy"`
	Language  string               `json:"language"`
	Framework string               `json:"framework"`

	// Timing
	DetectionTime time.Duration `json:"detection_time"`
	TemplateTime  time.Duration `json:"template_time"`
	HashCalcTime  time.Duration `json:"hash_calc_time"`
	BuildTime     time.Duration `json:"build_time"`
	PushTime      time.Duration `json:"push_time"`
	TotalTime     time.Duration `json:"total_time"`

	// Resource usage
	CPUUsage    float64 `json:"cpu_usage"`
	MemoryUsage int64   `json:"memory_usage"`
	DiskUsage   int64   `json:"disk_usage"`

	// Outcome
	Success      bool `json:"success"`
	CacheHit     bool `json:"cache_hit"`
	RetriedAsOCI bool `json:"retried_as_oci"`

	// Timestamps
	StartedAt   time.Time  `json:"started_at"`
	CompletedAt *time.Time `json:"completed_at,omitempty"`
}

BuildMetrics contains build performance data.

type BuildMetricsCollector

type BuildMetricsCollector interface {
	// RecordMetrics records metrics for a completed build.
	RecordMetrics(ctx context.Context, metrics *BuildMetrics) error

	// GetMetrics retrieves metrics for a build.
	GetMetrics(ctx context.Context, buildID string) (*BuildMetrics, error)

	// GetAggregateMetrics retrieves aggregate metrics for analysis.
	GetAggregateMetrics(ctx context.Context, filter MetricsFilter) (*AggregateMetrics, error)
}

BuildMetricsCollector tracks build performance data.

type Collector

type Collector struct {
	// contains filtered or unexported fields
}

Collector implements the BuildMetricsCollector interface.

func NewCollector

func NewCollector() *Collector

NewCollector creates a new Collector with default settings.

func NewCollectorWithOptions

func NewCollectorWithOptions(opts ...CollectorOption) *Collector

NewCollectorWithOptions creates a new Collector with custom options.

func (*Collector) CleanupExpired

func (c *Collector) CleanupExpired(ctx context.Context) int

CleanupExpired removes metrics older than the retention period.

func (*Collector) DeleteMetrics

func (c *Collector) DeleteMetrics(ctx context.Context, buildID string) error

DeleteMetrics removes metrics for a specific build.

func (*Collector) GetAggregateMetrics

func (c *Collector) GetAggregateMetrics(ctx context.Context, filter MetricsFilter) (*AggregateMetrics, error)

GetAggregateMetrics retrieves aggregate metrics for analysis.

func (*Collector) GetMetrics

func (c *Collector) GetMetrics(ctx context.Context, buildID string) (*BuildMetrics, error)

GetMetrics retrieves metrics for a build.

func (*Collector) GetStats

func (c *Collector) GetStats(ctx context.Context) *CollectorStats

GetStats returns statistics about the metrics collector.

func (*Collector) ListBuildIDs

func (c *Collector) ListBuildIDs(ctx context.Context) []string

ListBuildIDs returns all build IDs with recorded metrics.

func (*Collector) RecordMetrics

func (c *Collector) RecordMetrics(ctx context.Context, metrics *BuildMetrics) error

RecordMetrics records metrics for a completed build.

func (*Collector) UpdateMetrics

func (c *Collector) UpdateMetrics(ctx context.Context, buildID string, update func(*BuildMetrics)) error

UpdateMetrics updates existing metrics for a build.

type CollectorOption

type CollectorOption func(*Collector)

CollectorOption is a functional option for configuring Collector.

func WithRetentionPeriod

func WithRetentionPeriod(period time.Duration) CollectorOption

WithRetentionPeriod sets the retention period for metrics.

type CollectorStats

type CollectorStats struct {
	TotalMetrics    int           `json:"total_metrics"`
	RetentionPeriod time.Duration `json:"retention_period"`
}

CollectorStats contains statistics about the metrics collector.

type LanguageMetrics

type LanguageMetrics struct {
	TotalBuilds      int           `json:"total_builds"`
	SuccessfulBuilds int           `json:"successful_builds"`
	AvgBuildTime     time.Duration `json:"avg_build_time"`
}

LanguageMetrics contains metrics for a specific language.

type MetricsFilter

type MetricsFilter struct {
	Strategy  models.BuildStrategy `json:"strategy,omitempty"`
	Language  string               `json:"language,omitempty"`
	Framework string               `json:"framework,omitempty"`
	StartTime *time.Time           `json:"start_time,omitempty"`
	EndTime   *time.Time           `json:"end_time,omitempty"`
	Success   *bool                `json:"success,omitempty"`
}

MetricsFilter defines criteria for filtering aggregate metrics.

type StrategyMetrics

type StrategyMetrics struct {
	TotalBuilds      int           `json:"total_builds"`
	SuccessfulBuilds int           `json:"successful_builds"`
	AvgBuildTime     time.Duration `json:"avg_build_time"`
}

StrategyMetrics contains metrics for a specific build strategy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL