metrics

package
v0.0.0-...-483a4a2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	CIOperatorMetricsJSON = "ci-operator-metrics.json"
	CIWorkloadLabel       = "ci-workload"
	MachineAPINamespace   = "openshift-machine-api"
	MachineSetLabel       = "machine.openshift.io/cluster-api-machineset"
)
View Source
const (
	BuildsPluginName = "openshift_builds"
)
View Source
const (
	EventsPluginName = "events"
)
View Source
const (
	ImagesPluginName = "images"
)
View Source
const (
	InsightsPluginName = "test_platform_insights"
)
View Source
const NodeEventsName = "nodes"

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoscalerInfo

type AutoscalerInfo struct {
	Name string `json:"name"`
	Min  int    `json:"min"`
	Max  int    `json:"max"`
}

type BuildEvent

type BuildEvent struct {
	Namespace         string         `json:"namespace"`
	Name              string         `json:"name"`
	StartTime         time.Time      `json:"start_time"`
	CompletionTime    time.Time      `json:"completion_time"`
	DurationSeconds   int            `json:"duration_seconds"`
	Status            string         `json:"status"`
	Reason            string         `json:"reason,omitempty"`
	OutputImage       string         `json:"output_image,omitempty"`
	AdditionalContext map[string]any `json:"additional_context,omitempty"`
	Timestamp         time.Time      `json:"timestamp"`
	ForImage          string         `json:"for_image,omitempty"`
}

BuildEvent defines a build event for the metrics system.

func NewBuildEvent

func NewBuildEvent(name, namespace, forImage string) *BuildEvent

NewBuildEvent constructs a BuildEvent.

func (*BuildEvent) SetTimestamp

func (be *BuildEvent) SetTimestamp(t time.Time)

SetTimestamp sets the timestamp of the event.

type ClusterProfileForTarget

type ClusterProfileForTarget struct {
	Target      string `json:"target,omitempty"`
	ProfileName string `json:"profile_name,omitempty"`
}

type Context

type Context map[string]any

type Event

type Event struct {
	Level     EventLevel   `json:"level"`
	Source    string       `json:"source"`
	Locator   EventLocator `json:"locator"`
	Message   EventMessage `json:"message"`
	From      time.Time    `json:"from"`
	To        time.Time    `json:"to"`
	Timestamp time.Time    `json:"timestamp"`
}

func NewEvent

func NewEvent(level EventLevel, locator EventLocator, message EventMessage, source string, from, to time.Time) *Event

func (*Event) SetTimestamp

func (e *Event) SetTimestamp(t time.Time)

type EventLevel

type EventLevel string
const (
	EventLevelInfo    EventLevel = "Info"
	EventLevelWarning EventLevel = "Warning"
	EventLevelError   EventLevel = "Error"
)

type EventLocator

type EventLocator struct {
	Type      string         `json:"type"`
	Name      string         `json:"name"`
	Container *string        `json:"container,omitempty"`
	Keys      map[string]any `json:"keys,omitempty"`
}

type EventMessage

type EventMessage struct {
	Reason       string         `json:"reason"`
	Cause        string         `json:"cause"`
	HumanMessage string         `json:"humanMessage"`
	Annotations  map[string]any `json:"annotations,omitempty"`
}

type ImageStreamEvent

type ImageStreamEvent struct {
	Namespace          string         `json:"namespace"`
	ImageStreamName    string         `json:"image_stream_name"`
	FullName           string         `json:"full_name"`
	Success            bool           `json:"success"`
	Error              string         `json:"error,omitempty"`
	ImageStreamDetails map[string]any `json:"image_stream_details,omitempty"`
	AdditionalContext  map[string]any `json:"additional_context,omitempty"`
	Timestamp          time.Time      `json:"timestamp"`
}

ImageStreamEvent defines an image stream creation/update event

func (*ImageStreamEvent) SetTimestamp

func (ise *ImageStreamEvent) SetTimestamp(t time.Time)

type InsightEventName

type InsightEventName string
const (
	InsightStarted              InsightEventName = "started"
	InsightConfiguration        InsightEventName = "configuration"
	InsightNamespaceCreated     InsightEventName = "namespace_created"
	InsightExecutionStarted     InsightEventName = "execution_started"
	InsightExecutionCompleted   InsightEventName = "execution_completed"
	InsightStepStarted          InsightEventName = "step_started"
	InsightStepCompleted        InsightEventName = "step_completed"
	InsightSecretCreated        InsightEventName = "secret_created"
	InsightNamespaceInitialized InsightEventName = "namespace_initialized"
	InsightNamespaceArtifacts   InsightEventName = "namespace_artifacts"
	InsightLeaseCredentials     InsightEventName = "lease_credentials"
	InsightLeaseReleased        InsightEventName = "lease_released"
)

type InsightsEvent

type InsightsEvent struct {
	Name              string    `json:"name"`
	AdditionalContext Context   `json:"additional_context,omitempty"`
	Timestamp         time.Time `json:"timestamp"`
}

InsightsEvent defines a test platform insight event.

func NewInsightsEvent

func NewInsightsEvent(name InsightEventName, additionalContext Context) *InsightsEvent

func (*InsightsEvent) SetTimestamp

func (ie *InsightsEvent) SetTimestamp(t time.Time)

SetTimestamp sets the timestamp of the event.

type LeaseAcquisitionMetricEvent

type LeaseAcquisitionMetricEvent struct {
	LeaseName                    string    `json:"name"`
	Slice                        string    `json:"slice,omitempty"`
	Region                       string    `json:"region,omitempty"`
	RawLeaseName                 string    `json:"raw_lease_name,omitempty"`
	AcquisitionDurationSeconds   float64   `json:"acquisition_duration_seconds"`
	LeasesRemainingAtAcquisition int       `json:"leases_remaining_at_acquisition"`
	LeasesTotal                  int       `json:"leases_total"`
	Timestamp                    time.Time `json:"timestamp"`
}

LeaseAcquisitionMetricEvent is the event for a single lease acquisition.

func (*LeaseAcquisitionMetricEvent) GetRawLeaseName

func (l *LeaseAcquisitionMetricEvent) GetRawLeaseName() string

GetRawLeaseName returns the raw lease name.

func (*LeaseAcquisitionMetricEvent) Name

Name returns the name of the event.

func (*LeaseAcquisitionMetricEvent) SetParsedName

func (l *LeaseAcquisitionMetricEvent) SetParsedName(region, leaseName, slice string)

SetParsedName sets the parsed lease name components.

func (*LeaseAcquisitionMetricEvent) SetPoolMetrics

func (l *LeaseAcquisitionMetricEvent) SetPoolMetrics(free, total int)

SetPoolMetrics sets the pool metrics.

func (*LeaseAcquisitionMetricEvent) SetTimestamp

func (l *LeaseAcquisitionMetricEvent) SetTimestamp(t time.Time)

SetTimestamp sets the event's timestamp.

func (*LeaseAcquisitionMetricEvent) Store

func (l *LeaseAcquisitionMetricEvent) Store(lp *leasesPlugin)

Store persists the acquisition event on the plugin

type LeaseReleaseMetricEvent

type LeaseReleaseMetricEvent struct {
	LeaseName                string    `json:"name"`
	Slice                    string    `json:"slice,omitempty"`
	Region                   string    `json:"region,omitempty"`
	RawLeaseName             string    `json:"raw_lease_name,omitempty"`
	ReleaseDurationSeconds   float64   `json:"release_duration_seconds"`
	LeasesAvailableAtRelease int       `json:"leases_available_at_release"`
	LeasesTotal              int       `json:"leases_total"`
	Released                 bool      `json:"released"`
	Error                    string    `json:"error,omitempty"`
	Timestamp                time.Time `json:"timestamp"`
}

LeaseReleaseMetricEvent is the event for a single lease release.

func (*LeaseReleaseMetricEvent) GetRawLeaseName

func (l *LeaseReleaseMetricEvent) GetRawLeaseName() string

GetRawLeaseName returns the raw lease name.

func (*LeaseReleaseMetricEvent) Name

func (l *LeaseReleaseMetricEvent) Name() string

Name returns the name of the event.

func (*LeaseReleaseMetricEvent) SetParsedName

func (l *LeaseReleaseMetricEvent) SetParsedName(region, leaseName, slice string)

SetParsedName sets the parsed lease name components.

func (*LeaseReleaseMetricEvent) SetPoolMetrics

func (l *LeaseReleaseMetricEvent) SetPoolMetrics(free, total int)

SetPoolMetrics sets the pool metrics.

func (*LeaseReleaseMetricEvent) SetTimestamp

func (l *LeaseReleaseMetricEvent) SetTimestamp(t time.Time)

SetTimestamp sets the event's timestamp.

func (*LeaseReleaseMetricEvent) Store

func (l *LeaseReleaseMetricEvent) Store(lp *leasesPlugin)

Store persists the release event on the plugin

type MachineInfo

type MachineInfo struct {
	Name  string `json:"name"`
	Phase string `json:"phase"`
}

type MachineSetCount

type MachineSetCount struct {
	Name       string          `json:"name"`
	Current    int             `json:"current"`
	Autoscaler *AutoscalerInfo `json:"autoscaler,omitempty"`
	Machines   []MachineInfo   `json:"machines,omitempty"`
}

type MachinesEvent

type MachinesEvent struct {
	Workload      string            `json:"workload"`
	TotalMachines int               `json:"total_machines"`
	MachineSets   []MachineSetCount `json:"machine_sets"`
	Timestamp     time.Time         `json:"timestamp"`
}

func (*MachinesEvent) SetTimestamp

func (e *MachinesEvent) SetTimestamp(ts time.Time)

type MachinesPlugin

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

func NewMachinesPlugin

func NewMachinesPlugin(ctx context.Context, logger *logrus.Entry, client ctrlruntimeclient.Client, autoscalers []autoscalingv1beta1.MachineAutoscaler) *MachinesPlugin

func (*MachinesPlugin) Events

func (p *MachinesPlugin) Events() []MetricsEvent

func (*MachinesPlugin) Name

func (p *MachinesPlugin) Name() string

func (*MachinesPlugin) Record

func (p *MachinesPlugin) Record(ev MetricsEvent)

type MetricsAgent

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

MetricsAgent handles incoming events to each Plugin.

func NewMetricsAgent

func NewMetricsAgent(ctx context.Context, clusterConfig *rest.Config, censor *secrets.DynamicCensor) (*MetricsAgent, error)

NewMetricsAgent registers the built-in plugins by default.

func (*MetricsAgent) AddNodeWorkload

func (ma *MetricsAgent) AddNodeWorkload(ctx context.Context, namespace, podName, workloadName string, podClient ctrlruntimeclient.Client)

AddNodeWorkload tracks a workload's pod and the node it runs on for metrics collection

func (*MetricsAgent) Record

func (ma *MetricsAgent) Record(ev MetricsEvent)

Record records an event to the MetricsAgent

func (*MetricsAgent) RecordConfigurationInsight

func (ma *MetricsAgent) RecordConfigurationInsight(targets []string, promote bool, org, repo, branch, variant, baseNamespace, consoleHost, nodeName string, clusterProfiles []ClusterProfileForTarget)

RecordConfigurationInsight records configuration insight

func (*MetricsAgent) RecordStepEvent

func (ma *MetricsAgent) RecordStepEvent(step api.Step, objects []ctrlruntimeclient.Object, start, finish time.Time, runErr error)

RecordStepEvent records a single Finished event for a step, including objects metadata.

func (*MetricsAgent) RegisterLeaseClient

func (ma *MetricsAgent) RegisterLeaseClient(client lease.Client)

RegisterLeaseClient provides the lease client to the agent after initialization.

func (*MetricsAgent) RemoveNodeWorkload

func (ma *MetricsAgent) RemoveNodeWorkload(workloadName string)

RemoveNodeWorkload removes a workload from any node it's running on

func (*MetricsAgent) Run

func (ma *MetricsAgent) Run()

Run listens for events on the events channel until the channel is closed.

func (*MetricsAgent) Stop

func (ma *MetricsAgent) Stop()

Stop closes the events channel and blocks until flush completes.

func (*MetricsAgent) StoreMachinesSnapshot

func (ma *MetricsAgent) StoreMachinesSnapshot(obj ctrlruntimeclient.Object)

func (*MetricsAgent) StoreMachinesSnapshotForBuildPod

func (ma *MetricsAgent) StoreMachinesSnapshotForBuildPod(ctx context.Context, namespace, podName string, podClient ctrlruntimeclient.Client)

StoreMachinesSnapshotForBuildPod waits until the build pod exists and has ci-workload label, then snapshots machines.

func (*MetricsAgent) StorePodLifecycleMetrics

func (ma *MetricsAgent) StorePodLifecycleMetrics(name, namespace string, phase corev1.PodPhase)

type MetricsEvent

type MetricsEvent interface {
	SetTimestamp(time.Time)
}

MetricsEvent is the interface that every metric event must implement.

type NodeEvent

type NodeEvent struct {
	Node         string             `json:"node"`
	Arch         string             `json:"arch"`
	MachineType  string             `json:"machine_type"`
	MachineID    string             `json:"machine_id"`
	AgeSeconds   int64              `json:"age_seconds"`
	Resources    ResourcesInfo      `json:"resources"`
	UsageStats   ResourceUsageStats `json:"usage_stats"`
	Labels       map[string]string  `json:"labels"`
	Timestamp    time.Time          `json:"timestamp"`
	PollStarted  time.Time          `json:"poll_started"`
	Workloads    []string           `json:"workloads"`
	WatchHistory []WatchPeriod      `json:"watch_history"`
}

NodeEvent contains all the node details you want to report.

func (*NodeEvent) SetTimestamp

func (ne *NodeEvent) SetTimestamp(t time.Time)

type ObjectRef

type ObjectRef struct {
	Kind      string `json:"kind"`
	Namespace string `json:"namespace"`
	Name      string `json:"name"`
	UID       string `json:"uid"`
}

ObjectRef is a minimal, typed reference for a k8s object.

func BuildObjectRefs

func BuildObjectRefs(objs []ctrlruntimeclient.Object) []ObjectRef

BuildObjectRefs converts a list of objects into stable references using metadata accessors and kind from GVK/TypeAccessor with a safe fallback.

type Plugin

type Plugin interface {
	Name() string
	Record(ev MetricsEvent)
	Events() []MetricsEvent
}

Plugin is responsible for collecting and flushing one category of events.

type PodLifecycleMetricsEvent

type PodLifecycleMetricsEvent struct {
	PodName        string     `json:"pod_name,omitempty"`
	Namespace      string     `json:"namespace,omitempty"`
	CreationTime   *time.Time `json:"creation_time,omitempty"`
	StartTime      *time.Time `json:"start_time,omitempty"`
	CompletionTime *time.Time `json:"completion_time,omitempty"`
	CIWorkload     string     `json:"ci_workload,omitempty"`

	ConditionTransitionTimes map[string]time.Time `json:"condition_transition_times,omitempty"`

	SchedulingLatency     *time.Duration `json:"scheduling_latency,omitempty"`
	InitializationLatency *time.Duration `json:"initialization_latency,omitempty"`
	ReadyLatency          *time.Duration `json:"ready_latency,omitempty"`
	CompletionLatency     *time.Duration `json:"completion_latency,omitempty"`

	PodPhase               corev1.PodPhase `json:"pod_phase,omitempty"`
	InitContainerRestarts  int             `json:"init_container_restarts,omitempty"`
	InitContainerLastError string          `json:"init_container_last_error,omitempty"`
	Timestamp              time.Time       `json:"timestamp,omitempty"`
}

func (*PodLifecycleMetricsEvent) SetTimestamp

func (e *PodLifecycleMetricsEvent) SetTimestamp(ts time.Time)

type PodLifecyclePlugin

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

func NewPodLifecyclePlugin

func NewPodLifecyclePlugin(ctx context.Context, logger *logrus.Entry, client ctrlruntimeclient.Client) *PodLifecyclePlugin

func (*PodLifecyclePlugin) Events

func (p *PodLifecyclePlugin) Events() []MetricsEvent

func (*PodLifecyclePlugin) Name

func (p *PodLifecyclePlugin) Name() string

func (*PodLifecyclePlugin) Record

func (p *PodLifecyclePlugin) Record(ev MetricsEvent)

type ResourceDetails

type ResourceDetails struct {
	CPU              string `json:"cpu"`
	Memory           string `json:"memory"`
	EphemeralStorage string `json:"ephemeral-storage"`
	Pods             string `json:"pods"`
}

ResourceDetails contains the details of a specific resource

type ResourceUsageStats

type ResourceUsageStats struct {
	MinCPU int64 `json:"min_cpu_milli"`
	MaxCPU int64 `json:"max_cpu_milli"`
	AvgCPU int64 `json:"avg_cpu_milli"`
	MinMem int64 `json:"min_memory_bytes"`
	MaxMem int64 `json:"max_memory_bytes"`
	AvgMem int64 `json:"avg_memory_bytes"`
}

type ResourcesInfo

type ResourcesInfo struct {
	Capacity    ResourceDetails `json:"capacity"`
	Allocatable ResourceDetails `json:"allocatable"`
}

ResourcesInfo contains the capacity and allocatable resources on a node

type TagImportEvent

type TagImportEvent struct {
	Namespace         string         `json:"namespace"`
	ImageStreamName   string         `json:"image_stream_name"`
	TagName           string         `json:"tag_name"`
	FullTagName       string         `json:"full_tag_name"`
	SourceImage       string         `json:"source_image"`
	SourceImageKind   string         `json:"source_image_kind"`
	StartTime         time.Time      `json:"start_time"`
	CompletionTime    time.Time      `json:"completion_time"`
	DurationSeconds   float64        `json:"duration_seconds"`
	RetryCount        int            `json:"retry_count"`
	Success           bool           `json:"success"`
	Error             string         `json:"error,omitempty"`
	AdditionalContext map[string]any `json:"additional_context,omitempty"`
	Timestamp         time.Time      `json:"timestamp"`
}

TagImportEvent defines a tag import event

func (*TagImportEvent) SetTimestamp

func (tie *TagImportEvent) SetTimestamp(t time.Time)

type WatchPeriod

type WatchPeriod struct {
	StartTime time.Time `json:"start_time"`
	EndTime   time.Time `json:"end_time"`
}

WatchPeriod represents a period when a node was being watched

type WorkloadNodeCount

type WorkloadNodeCount struct {
	Workload      string            `json:"workload"`
	TotalMachines int               `json:"total_machines"`
	MachineSets   []MachineSetCount `json:"machine_sets"`
}

Jump to

Keyboard shortcuts

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