metrics

package
v0.0.0-...-7220889 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

The metrics implementation inside the package of the same name is a default implementation of the Metrics interface. It will never talk to external services. It is intended only for local development.

Index

Constants

View Source
const (
	// Cr50FwReflashKind is the name/kind in the karte metrics
	// used for query or update the cr 50 fw reflash information.
	Cr50FwReflashKind = "cr50_flash"
	// PerResourceTaskKindGlob is the template for the name/kind for
	// query the complete record for each task for each resource.
	PerResourceTaskKindGlob = "run_task_%s"
	// RunLibraryKind is the actionKind for query the
	// record for overall PARIS recovery result each run.
	RunLibraryKind = "run_recovery"
	// ServoEachDeviceFwUpdateKind is the actionkind for query the record for each
	// of the servo device's fw update information.
	ServoEachDeviceFwUpdateKind = "servo_firmware_update_%s"
	// USBDriveDetectionKind is the actionKind for query the
	// record for the DUT's servo's USB-drive.
	USBDriveDetectionKind = "servo_usbdrive_detection"
	// USBDriveReplacedKind is the actionKind for query the
	// record for DUT's old/replaced USB-drive.
	USBDriveReplacedKind = "servo_usbdrive_replaced_detection"
	// BadBlocksROExecutionKind is an actionKind that indicates the RO
	// badblocks has been executed.
	BadBlocksROExecutionKind = "backblocks_ro_execution"
	// BadBlocksRWExecutionKind is an actionKind that indicates the RW
	// badblocks has been executed.
	BadBlocksRWExecutionKind = "backblocks_rw_execution"
	// AuditCameraKind is an actionKind for tracking audit camera tasks.
	AuditCameraKind = "audit_camera"
)
View Source
const (
	// ActionStatusUnspecified is an unknown status.
	ActionStatusUnspecified ActionStatus = ""
	// ActionStatusSuccess represents a successful action.
	ActionStatusSuccess ActionStatus = "success"
	// ActionStatusFail represents a failed action.
	ActionStatusFail ActionStatus = "fail"
	// ActionStatusSkip represents a skipped action.
	// TODO(gregorynisbet): Add support for skipped actions to Karte OR record the number of skipped actions as a plan-level observation.
	ActionStatusSkip ActionStatus = "skip"

	AllowFailUnspecified AllowFail = ""
	YesAllowFail         AllowFail = "allow-fail"
	NoAllowFail          AllowFail = "no-allow-fail"
)
View Source
const (
	ActionTypeUnspecified = ""
	ActionTypeVerifier    = "verifier"
	ActionTypeCondition   = "condition"
	ActionTypeRecovery    = "recovery"
)

Variables

This section is empty.

Functions

func CountFailedRepairFromMetrics

func CountFailedRepairFromMetrics(ctx context.Context, dutName string, taskName string, metricsService Metrics) (int, error)

CountFailedRepairFromMetrics determines the number of failed PARIS repair task since the last successful PARIS repair task.

An empty taskName means do not filter based on the task name.

func DefaultActionAddObservations

func DefaultActionAddObservations(ctx context.Context, observations ...*Observation)

DefaultActionAddObservations adds observation to default action in context.

func TasknameToMetricsKind

func TasknameToMetricsKind(tn string) string

TasknameToMetricsKind returns a Karte action kind based on taskname.

func WithAction

func WithAction(ctx context.Context, action *Action) context.Context

WithAction sets metrics to the context. If Logger is not provided process will be finished with panic.

Types

type Action

type Action struct {
	// Name is the identifier for an action. It is controlled by Karte.
	Name string
	// ActionKind is a coarse-grained type of observation e.g. "ssh".
	ActionKind string
	// SwarmingTaskID is the ID of the associated swarming task.
	SwarmingTaskID string
	// BuildbucketID is the ID of the buildbucket build.
	BuildbucketID string
	// Board is the board of the device.
	Board string
	// Model is the model of the device.
	Model string
	// AssetTag is the asset tag of the DUT that the observation is recorded for.
	AssetTag string
	// StartTime is when the event started.
	StartTime time.Time
	// StopTime is when the event ended.
	StopTime time.Time
	// Status is whether the event was successful, failed, or unknown.
	Status ActionStatus
	// Hostname is the hostname of the device or the name of the unit.
	Hostname string
	// FailReason is an error message with information describing the failure.
	FailReason string
	// Observations are the observations associated with the current observation.
	Observations []*Observation
	// Recovered by is the name of the action that recovered us.
	RecoveredBy string
	// Restarts is how many times we have re-traversed the plan.
	Restarts int32
	// Set whether failures are allowed or not
	AllowFail AllowFail
	// Plan name is the name of the currently-executing plan.
	PlanName string
	// Action type is "entrypoint", "critical", "recovery", or "condition".
	Type ActionType
}

Action is an event performed on a DUT. TODO(gregorynisbet): Rename an action to something else so we don't collide with the other notion of an action.

func GetDefaultAction

func GetDefaultAction(ctx context.Context) *Action

GetDefaultAction returns default action from context.

func (*Action) UpdateStatus

func (a *Action) UpdateStatus(err error)

UpdateStatus updates status of the action and error reason if error was provided.

type ActionStatus

type ActionStatus string

ActionStatus is the status of an action.

type ActionType

type ActionType string

ActionType describes the use of the action within the plan.

type AllowFail

type AllowFail string

AllowFail is whether failure is allowed.

type MetricSaver

type MetricSaver func(action *Action) error

MetricSaver a function to provide contextless saver of metrics.

type Metrics

type Metrics interface {
	// Create takes an action and creates it on the Karte side.
	// On success, it updates its action argument to reflect the Karte state.
	// Local versions of Create should emulate this.
	Create(ctx context.Context, action *Action) error

	// Search lists all the actions matching a set of constraints, up to
	// a limit on the number of returned actions.
	Search(ctx context.Context, q *Query) (*QueryResult, error)
}

Metrics is a simple interface for logging structured events and metrics.

func NewLogMetrics

func NewLogMetrics(l logger.Logger) Metrics

NewLogMetrics creates a default metric sink.

type Observation

type Observation struct {
	// MetricKind is the metric kind (e.g. battery percentage).
	MetricKind string
	// ValueType is the type of value (e.g. String).
	ValueType ValueType
	// Value is the value itself.
	Value string
}

Observation is the type of a measurement associated with an event performed on a DUT.

func NewFloat64Observation

func NewFloat64Observation(kind string, value float64) *Observation

NewFloat64Observation produces a new float-valued observation of the given kind.

func NewInt64Observation

func NewInt64Observation(kind string, value int64) *Observation

NewInt64Observation produces a new int-valued observation of the given kind.

func NewStringObservation

func NewStringObservation(kind string, value string) *Observation

NewStringObservation produces a new string-valued observation of the given kind.

type Query

type Query struct {
	// StartTime is the starting time for the query as a unix timestamp.
	StartTime time.Time
	// StopTime is the ending time for the query as a unix timestamp.
	StopTime time.Time
	// AssetTag is the asset tag for the DUT in question.
	AssetTag string
	// Hostname is the hostname for the DUT in question.
	// The hostname is less reliable than the asset tag because
	// it identifies a location rather than a device per se.
	Hostname string
	// Kind filters the actions by the "ActionKind" field.
	ActionKind string
	// Limit imposes a limit on the total number of actions returned.
	Limit int
	// PageToken is an opaque blob of data that is used to start the query at a specific point.
	PageToken string
	// OrderDescending controls how the result set should be ordered by time
	OrderDescending bool
}

A Query is a collection of time-bounded search criteria for actions on DUTs.

func NewLastActionBeforeTimeQuery

func NewLastActionBeforeTimeQuery(assetTag string, kind string, stopTime time.Time) *Query

NewLastActionBeforeTimeQuery returns a query for the last record before the stop time of a given kind for the asset in question.

func NewLastActionQuery

func NewLastActionQuery(assetTag string, kind string) *Query

NewLastActionQuery returns a query for the last record of a given kind for the asset in question.

func NewListActionsInRangeQuery

func NewListActionsInRangeQuery(assetTag string, kind string, startTime time.Time, stopTime time.Time, pageToken string, limit int) *Query

NewListActionsInRangeQuery lists the actions for a given asset and given range in order.

Sample usage:

q := NewListActionsInRangeQuery(..., "token1", 10)
res, err := metrics.Search(ctx, q)
if err != nil {
   ...
}
q = NewListActionsInRangeQuery(..., res.PageToken, 10)
res, err = metrics.Search(ctx, q)
...

func (*Query) Lower

func (q *Query) Lower() (string, error)

Lower takes a query and lowers it to a string using the filter syntax that Karte accepts. See karte/api/filter_syntax.md for more information.

type QueryResult

type QueryResult struct {
	// Actions are the actions satisfying the criteria in question.
	Actions []*Action
	// PageToken is the token for resuming the query, if such a token exists.
	PageToken string
}

A QueryResult is the result of running a query.

type ValueType

type ValueType string

A ValueType is the type of an observation, such as a number or a string.

const (
	// ValueTypeUnspecified is an unknown value type.
	ValueTypeUnspecified ValueType = ""
	// ValueTypeString represents a string-valued measurement.
	ValueTypeString ValueType = "string"
	// ValueTypeNumber represents a real-valued measurement.
	ValueTypeNumber ValueType = "number"
)

Directories

Path Synopsis
Package mockmetrics is a generated GoMock package.
Package mockmetrics is a generated GoMock package.

Jump to

Keyboard shortcuts

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